瀏覽代碼

listInfo中添加按钮条件隐藏逻辑

lph 1 年之前
父節點
當前提交
2212d26548
共有 2 個文件被更改,包括 47 次插入4 次删除
  1. 9 0
      zkqy-ui/src/utils/index.js
  2. 38 4
      zkqy-ui/src/views/tablelist/commonTable/BtnMenu.vue

+ 9 - 0
zkqy-ui/src/utils/index.js

@@ -420,3 +420,12 @@ export function toUnderline(str = '') {
 export const $ = name => document.querySelector(name)
 
 export const getContainerSize = dom => ({ width: dom.getBoundingClientRect().width, height: dom.getBoundingClientRect().height })
+
+/**
+ * 判断是否有值
+ * @param {*} value 
+ * @returns 
+ */
+export function hasValue(value) {
+  return value !== null && value !== undefined && value !== false && value !== '';
+}

+ 38 - 4
zkqy-ui/src/views/tablelist/commonTable/BtnMenu.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="myDiv">
-    <el-dropdown trigger="click" :hide-on-click="false">
+    <el-dropdown trigger="click" v-if="btnObj" :hide-on-click="false">
       <span class="el-dropdown-link">
         <el-button v-if="btnObj.btnParentId == 0" type="warning"
           ><span
@@ -11,7 +11,7 @@
               :icon-class="btnObj.btnIcon" />{{ btnObj.btnName }}
             <i class="el-icon-arrow-down el-icon--right"></i></span
         ></el-button>
-        <span v-else>
+        <el-button v-else>
           <span
             ><svg-icon
               class="pre-icon"
@@ -20,7 +20,7 @@
               :icon-class="btnObj.btnIcon" />{{ btnObj.btnName }}
             <i class="el-icon-arrow-down el-icon--right"></i
           ></span>
-        </span>
+        </el-button>
       </span>
       <el-dropdown-menu slot="dropdown">
         <template v-for="item in btnObj.children">
@@ -57,10 +57,44 @@ export default {
   },
   computed: {
     btnObj() {
-      return this.listAll;
+      let btnObj = JSON.parse(JSON.stringify(this.listAll));
+      let rootRes = this.isHiddenBtn(this.row, btnObj.btnShowCondition);
+      if (rootRes) return null;
+      btnObj.children = btnObj.children.filter((item) => {
+        return !this.isHiddenBtn(this.row, item.btnShowCondition);
+      });
+      console.log("btnObj", btnObj);
+      return btnObj;
     },
   },
   methods: {
+    // 判断按钮是否隐藏
+    isHiddenBtn(row, condition) {
+      if (condition.length == 0) return false;
+      let con = JSON.parse(condition);
+      let res = con.every((item) => {
+        return !this.judgeBtnHandler(row, item);
+      });
+      return res;
+    },
+    judgeBtnHandler(row, con) {
+      let { fieldName, refValue, mark } = con;
+      console.log(row[fieldName], mark, refValue);
+      switch (mark) {
+        case ">":
+          return row[fieldName] > refValue;
+        case "<":
+          return row[fieldName] < refValue;
+        case "=":
+          return row[fieldName] == refValue;
+        case ">=":
+          return row[fieldName] >= refValue;
+        case "<=":
+          return row[fieldName] <= refValue;
+        default:
+          return true;
+      }
+    },
     clickHandler(btnData, row) {
       this.$emit("excuteHandler", btnData, row);
     },