Browse Source

按钮防止重复点击

duy 2 years ago
parent
commit
abc3406d57
3 changed files with 22 additions and 6 deletions
  1. 3 2
      src/main.js
  2. 16 0
      src/util/preventClick.js
  3. 3 4
      src/views/exctab/ElementIdentification/index.vue

+ 3 - 2
src/main.js

@@ -33,8 +33,9 @@ import tenantPackage from './views/system/tenantpackage';
 
 
 //iconfont
 //iconfont
 import "@/styles/icon/index.scss"
 import "@/styles/icon/index.scss"
-
-
+//自定义指令按钮
+import preventClick from './util/preventClick'
+Vue.use(preventClick)
 // 注册全局crud驱动
 // 注册全局crud驱动
 window.$crudCommon = crudCommon;
 window.$crudCommon = crudCommon;
 // 加载Vue拓展
 // 加载Vue拓展

+ 16 - 0
src/util/preventClick.js

@@ -0,0 +1,16 @@
+export default {
+     install(Vue) {
+       Vue.directive('preventClick', {
+         inserted(button, bind) {
+          button.addEventListener('click', () => {
+          if (!button.disabled) {
+               button.disabled = true;
+               setTimeout(() => {
+                button.disabled = false
+              }, 2000)
+             }
+           })
+         }
+       })
+     }
+   }

+ 3 - 4
src/views/exctab/ElementIdentification/index.vue

@@ -663,7 +663,7 @@
           </div>
           </div>
         <span slot="footer" class="dialog-footer">
         <span slot="footer" class="dialog-footer">
           <el-button @click="eleDialog = false">取 消</el-button>
           <el-button @click="eleDialog = false">取 消</el-button>
-          <el-button type="primary" @click="submitEleDialog" :disabled="eleDialogBtn">确 定</el-button>
+          <el-button type="primary" @click="submitEleDialog" v-preventClick>确 定</el-button>
         </span>
         </span>
       </el-dialog>
       </el-dialog>
     </div>
     </div>
@@ -1104,7 +1104,7 @@ export default {
             this.eleForm.tableOwner
             this.eleForm.tableOwner
           ) {
           ) {
    
    
-
+           
             this.submitExcelRelationWbsTreeAndElement({
             this.submitExcelRelationWbsTreeAndElement({
               nodeName: this.eleForm.nodeName,
               nodeName: this.eleForm.nodeName,
               tableType: this.eleForm.tableType,
               tableType: this.eleForm.tableType,
@@ -1346,7 +1346,6 @@ export default {
       this.activeName="link"
       this.activeName="link"
     },
     },
     async submitExcelRelationWbsTreeAndElement(da) {
     async submitExcelRelationWbsTreeAndElement(da) {
-      this.eleDialogBtn=true
       //保存接口
       //保存接口
       da.elementList.forEach((ele) => {
       da.elementList.forEach((ele) => {
         ele.eName = ele.textInfo;
         ele.eName = ele.textInfo;
@@ -1357,7 +1356,7 @@ export default {
       console.log(res);
       console.log(res);
       if (res.code == 200) {
       if (res.code == 200) {
       // this.refreshNodeBy()//刷新树形控件数据
       // this.refreshNodeBy()//刷新树形控件数据
-       this.eleDialogBtn=false
+    
         this.$message({
         this.$message({
           type: "success",
           type: "success",
           message: "设置成功",
           message: "设置成功",