Bladeren bron

Merge branch 'master' of git.sagacloud.cn:web/ibms

zhangyu 5 jaren geleden
bovenliggende
commit
87e578e5e7

+ 6 - 0
src/api/scan/request.js

@@ -851,6 +851,12 @@ export function getDataDictionary(param, success) {
     http.postJson(url, data, success)
 }
 
+//all - 查询数据字典 --列表表头
+export function cacheDictionary(param, success) {
+    let url = `${baseUrl}/datacenter/class-def/query-dict`;
+    http.postJson(url, param, success)
+}
+
 //批量处理字典信息操作
 export function setInfoPoint(param, success) {
     let url = `${baseUrl}/datacenter/data-dictionary/project/dict-batch`;

+ 49 - 172
src/components/config_point/dictionaryCascader.vue

@@ -1,207 +1,67 @@
 <template>
   <div>
     <el-form ref="form" :rules='rules' :model="form">
-      <el-form-item prop="dict">
-        <el-cascader style='width: 100%;' :options='options' v-model='form.dict' @active-item-change='handleChange' :props='props' filterable
-          @change="changeSelect" ref="dictCas"></el-cascader>
+      <el-form-item prop="dict" class="cascader-container">
+        <el-cascader :options='options' v-model='form.dict' :props='props' filterable @change="changeSelect" ref="dictCas">
+        </el-cascader>
+        <el-tooltip class="item" effect="dark" :content="`于${cacheTime}缓存,点击重新缓存`" placement="top">
+          <el-button icon="el-icon-refresh" class="update-button" @click="getDictionary"></el-button>
+        </el-tooltip>
       </el-form-item>
     </el-form>
   </div>
 </template>
 <script>
-import {
-  getDataDictionary,//查询信息点
-  queryPhysicsAllType,//查询所有部件类型
-  queryDictionaryHead,//查询所有空间类型
-
-} from "@/api/scan/request"
-import { mapGetters, mapActions } from "vuex";
+import { mapGetters, mapMutations, mapActions } from "vuex";
 import tools from "@/utils/scan/tools";
 export default {
   data() {
     return {
-      options: [
-        {
-          Code: 'Pj',
-          Name: '项目',
-          children: []
-        }, {
-          Code: 'Bd',
-          Name: '建筑',
-          children: []
-        }, {
-          Code: 'Fl',
-          Name: '楼层',
-          children: []
-        }, {
-          Code: 'Eq',
-          Name: '设备',
-          children: []
-        }, {
-          Code: 'Ec',
-          Name: '部件',
-          children: []
-        }, {
-          Code: 'Sy',
-          Name: '系统',
-          children: []
-        }, {
-          Code: 'Sp',
-          Name: '空间',
-          children: []
-        }, {
-          Code: 'VOTn',
-          Name: '租户',
-          children: []
-        },
-      ],
+      options: [],
       form: {
         dict: [],
       },
       props: {
-        value: 'Code',
-        label: 'Name',
-        children: 'children'
+        value: 'InfoPointCode',
+        label: 'InfoPointName',
+        children: 'Content'
       },
       rules: {
         dict: [{ required: true, message: '请选择对应数据字典', trigger: 'blur' }]
       },
-      typeRelation: {
-        Pj: 'Project',
-        Bd: 'Building',
-        Fl: 'Floor',
-        VOTn: 'Tenant',
-      },
-      timer: null
     }
   },
+  computed: {
+    ...mapGetters("project", ["dictionary", "cacheTime"]),
+  },
   created() {
-    this.getAllData()
+    if (!this.dictionary.length) {
+      this.getDictionary().then(res => {
+        this.getDictSuc(res.Content)
+      })
+    } else {
+      this.getDictSuc(this.dictionary);
+    }
   },
   methods: {
-    //选择
-    handleChange(val) {
-      let type = val[0];
-      let singleStr = "Pj-Bd-Fl-VOTn";
-      console.log(val)
-      if (type == "Eq" && val.length == 2) {
-        this.getDataPoint(val[1])
-      } else if (type == "Ec" && val.length == 2) {
-        this.getDataPoint(val[1])
-      } else if (type == "Sy" && val.length == 3) {
-        this.getDataPoint(val[2])
-      } else if (type == "Sp" && val.length == 2) {
-        this.getDataPoint(val[1])
-      } else if (singleStr.indexOf(type) > -1) {
-        this.hasChildren(type) && this.getDataPoint(type)
-      }
-    },
+    ...mapActions('project', ['getDictionary']),
     //获取物理世界所有设备类型
-    getAllData() {
-      queryPhysicsAllType('Equipment', res => {
-        this.options[3].children = this.formatOptions(res.Content)
-      })
-      queryPhysicsAllType('Component', res => {
-        this.options[4].children = this.formatOptions(res.Content)
-      })
-      queryPhysicsAllType('Major-System', res => {
-        let data = JSON.parse(JSON.stringify(res.Content).replace(/ListClassDef/g, 'children'));
-        this.options[5].children = this.formatOptions(data)
-      })
-      let param1 = {
-        Distinct: true,
-        Filters: "ParentId='Space'"
-      }
-      queryDictionaryHead(param1, res => {
-        this.options[6].children = this.formatOptions(res.Content)
-      })
-    },
-    //格式化options数据
-    formatOptions(arr) {
-      return arr.map(item => {
-        return {
-          Code: item.Code,
-          Name: item.Name,
-          children: item.children && item.children.length ? this.formatOptions(item.children) : []
-        }
-      })
-    },
-    //请求信息点
-    getDataPoint(type) {
-      let param = {
-        data: {
-          Filters: "InputMode='M' or InputMode='L'",
-          PageNumber: 1,
-          PageSize: 500,
-          Orders: 'InfoPointName asc'
-        },
-        type: this.typeRelation[type] || type
-      }
-      getDataDictionary(param, res => {
-        let tempArr = res.Content.map(item => {
-          return {
-            Code: item.InfoPointCode,
-            Name: item.InfoPointName
-          }
-        })
-        this.pointDataSource = {}
-        res.Content.map(item => {
-          let code = item.InfoPointCode
-          this.pointDataSource[code] = item
-        })
-        this.timer = setTimeout(() => {
-          if (this.interval()) {
-            this.pushPoints(this.options, tempArr, type);
-            this.changeSelect(this.form.dict);
-            clearTimeout(this.timer);
-            this.timer = null;
-            return
-          }
-          this.timer()
-        }, 100);
-      })
-    },
-    interval() {
-      for (let i = 0; i < this.options.length; i++) {
-        if (this.options[i].children.length > 0) {
-          return true;
-        }
-      }
-      return false;
-    },
-    //根据返回数据拼接options
-    pushPoints(options, arr, Code) {
-      options.map(option => {
-        if (option.Code == Code) {
-          option.children = arr;
-        } else {
-          if (option.children) {
-            this.pushPoints(option.children, arr, Code)
-          }
-        }
-      })
+    getDictSuc(list) {
+      this.options = list;
+      this.changeSelect(this.form.dict);
     },
     changeSelect(val) {
-      if (this.$refs.dictCas.getCheckedNodes()[0]) {
-        let labels = this.$refs.dictCas.getCheckedNodes()[0].pathLabels
-        this.$emit('change', { val: val, labels: labels })
-      }
-    },
-    //减少请求次数
-    hasChildren(Code) {
-      let flag = true;
-      this.options.map(option => {
-        if (option.Code == Code && option.children.length) {
-          flag = false;
+      setTimeout(() => {
+        if (this.$refs.dictCas.getCheckedNodes()[0]) {
+          let labels = this.$refs.dictCas.getCheckedNodes()[0].pathLabels;
+          let data = this.$refs.dictCas.getCheckedNodes()[0].data;
+          this.$emit('change', { val: val, labels: labels, data: data })
         }
-      })
-      return flag;
+      }, 500)
     },
     //设置值
     setCascaderVal(value) {
       this.form.dict = tools.deepCopy(value)
-      value.splice(value.length - 1, 1)
-      this.handleChange(value)
     },
     //校验是否选择
     validate(cb) {
@@ -217,4 +77,21 @@ export default {
 }
 </script>
 <style lang="less" scoped>
-</style>
+.cascader-container {
+  /deep/ .el-cascader {
+    width: 89%;
+    display: block;
+    float: left;
+    .el-input .el-input__inner {
+      border-radius: 4px 0 0 4px;
+      vertical-align: bottom;
+    }
+  }
+  .update-button {
+    display: block;
+    float: left;
+    border-left: 0;
+    border-radius: 0 4px 4px 0;
+  }
+}
+</style>

+ 3 - 3
src/components/config_point/step3_edit/index.vue

@@ -583,11 +583,11 @@ export default {
       return str
     },
     //对应数据字典变化
-    changeDictionaryCas({ val, labels }) {
+    changeDictionaryCas({ val, labels, data }) {
       this.dictionaryData = val;
       this.dictionaryNames = labels
-      this.infoDict = this.$refs.dictionaryCas.pointDataSource
-      this.unitObj = this.infoDict[val[val.length - 1]]
+      // this.infoDict = this.$refs.dictionaryCas.pointDataSource
+      this.unitObj = data
       this.InfomationPoint = this.unitObj.InfoPointName || ''
       this.ValueDescription = this.delDataSource(this.unitObj.DataSource)
     }

+ 3 - 3
src/components/config_point/step3_point/3_temps.vue

@@ -599,11 +599,11 @@ export default {
       return str
     },
     //对应数据字典变化
-    changeDictionaryCas({ val, labels }) {
+    changeDictionaryCas({ val, labels, data }) {
       this.dictionaryData = val;
       this.dictionaryNames = labels
-      this.infoDict = this.$refs.dictionaryCas.pointDataSource
-      this.unitObj = this.infoDict[val[val.length - 1]]
+      // this.infoDict = this.$refs.dictionaryCas.pointDataSource
+      this.unitObj = data
       this.InfomationPoint = this.unitObj.InfoPointName || ''
     },
     //分页发生更改

+ 31 - 3
src/store/modules/project.js

@@ -1,9 +1,12 @@
+import { cacheDictionary } from "@/api/scan/request"
 const project_mess = {
     namespaced: true,
     state: {
         datasourceId: "", //数据源id
         protocolType: "", //数据源类型
-        dataName: ""
+        dataName: "",
+        dictionary: [], // 数据字典
+        cacheTime:''
     },
     mutations: {
         set_datasource(state, val) {
@@ -17,12 +20,37 @@ const project_mess = {
         }
     },
     actions: {
-
+        getDictionary({ state }){
+            let pa = ["Project", "Building", "Floor", "Equipment", "GeneralSystem", "Tenant", "Component", "Space"];
+            let firstLevelMap = {
+                Project: 'Pj',
+                Building: 'Bd',
+                Floor: 'Fl',
+                Tenant: 'VOTn',
+                Equipment: 'Eq',
+                GeneralSystem: 'Sy',
+                Space: 'Sp',
+                Component: 'Ec'
+            }
+            return new Promise((resolve,reject) => {
+                cacheDictionary(pa, res => {
+                    state.dictionary = res.Content.map(t => {
+                        t.InfoPointCode = firstLevelMap[t.InfoPointCode];
+                        return t;
+                    });
+                    let date = new Date();
+                    state.cacheTime = `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()} ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
+                    resolve(res);
+                })
+            })
+        }
     },
     getters: {
         datasourceId: state => state.datasourceId,
         protocolType: state => state.protocolType,
-        dataName: state => state.dataName
+        dataName: state => state.dataName,
+        dictionary: state => state.dictionary,
+        cacheTime: state => state.cacheTime
     }
 }