소스 검색

枚举

Signed-off-by: hsshuxian <3049816743@qq.com>
hsshuxian 5 달 전
부모
커밋
372e59acb9
3개의 변경된 파일166개의 추가작업 그리고 33개의 파일을 삭제
  1. 45 0
      ems-ui-cloud/src/api/basecfg/emum.js
  2. 1 0
      ems-ui-cloud/src/views/basecfg/device/index.vue
  3. 120 33
      ems-ui-cloud/src/views/basecfg/device/model.vue

+ 45 - 0
ems-ui-cloud/src/api/basecfg/emum.js

@@ -0,0 +1,45 @@
+import request from '@/utils/request'
+
+/**
+ * 查询能源对象属性枚举列表
+ */
+export function getAttrList(modelCode, attrKey) {
+  return request({
+    url: '/ems/object/attr/emum/list?modelCode=' + modelCode + '&attrKey=' + attrKey,
+    method: 'get'
+  })
+}
+/**
+ * 获取能源对象属性枚举详细信息
+ */
+export function getAttrEnumInfo(modelCode, attrKey, attrValue) {
+  return request({
+    url: `/ems/object/attr/emum/`,
+    method: 'get',
+    params: {
+      modelCode: modelCode,
+      attrKey: attrKey,
+      attrValue: attrValue
+    }
+  })
+}
+/**
+ * 新增能源对象属性枚举
+ */
+export function addAttrEnums(data) {
+  return request({
+    url: '/ems/object/attr/emum/batch',
+    method: 'post',
+    data: data
+  })
+}
+
+/**
+ * 删除能源对象属性枚举
+ */
+export function delAttrEnum(id) {
+  return request({
+    url: '/ems/object/attr/emum/' + id,
+    method: 'delete'
+  })
+}

+ 1 - 0
ems-ui-cloud/src/views/basecfg/device/index.vue

@@ -183,6 +183,7 @@
                   </li>
                 </ul>
               </div>
+
               <div  v-if="attrList.length > 0" class="attr-list-container">设备自定义参数:
                 <el-form-item label="" prop="attrList">
                   <el-table class="attr-table" v-loading="loading" :data="form.customAttrs" max-height="280px"

+ 120 - 33
ems-ui-cloud/src/views/basecfg/device/model.vue

@@ -125,12 +125,6 @@
         <el-form-item label="模型名称" prop="modelName">
           <el-input v-model="form.modelName" placeholder="请输入模型名称"/>
         </el-form-item>
-        <!-- 对象类型选择,但值由标签页控制 -->
-<!--        <el-form-item label="对象类型" prop="objType">-->
-<!--          <el-select v-model="form.objType" placeholder="请选择对象类型" disabled>-->
-<!--            <el-option :label="objTypeMapping[activeObjType]" :value="activeObjType" />-->
-<!--          </el-select>-->
-<!--        </el-form-item>-->
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button type="primary" @click="submitForm">确 定</el-button>
@@ -170,8 +164,9 @@
             <pagination v-show="total>0" :total="total" :page.sync="queryAttrParams.pageNum"
                         :limit.sync="queryAttrParams.pageSize"
                         @pagination="getAttrList"/>
-            <!-- 添加或修改服务区用电属性对话框 -->
-            <el-dialog :title="title" :visible.sync="attrOpen" width="500px" append-to-body>
+
+            <!-- 添加或修改属性对话框 -->
+            <el-dialog :title="title" :visible.sync="attrOpen" width="650px" append-to-body>
               <el-form ref="attrForm" :model="attrForm" :rules="attrRules" label-width="150px">
                 <el-form-item label="属性名称" prop="attrName">
                   <el-input v-model="attrForm.attrName" placeholder="请输入属性名称"/>
@@ -198,6 +193,42 @@
                     </el-option>
                   </el-select>
                 </el-form-item>
+
+              <!--属性值表格-->
+                <el-form-item label="枚举类型值" prop="customAttrs" v-if="attrForm.attrValueType === 'String'">
+                  <el-table class="attr-table" v-loading="loading" :data="customAttrs" max-height="280px" key="'customAttrs'">
+                    <el-table-column label="模型代码" align="center" prop="modelCode">
+                      <template slot-scope="scope">
+                        <el-input size="mini" v-model="scope.row.modelCode" placeholder="请输入模型代码"  />
+                      </template>
+                    </el-table-column>
+                    <el-table-column label="属性标识" align="center" prop="attrKey">
+                      <template slot-scope="scope">
+                        <el-input size="mini" v-model="scope.row.attrKey" placeholder="请输入属性标识" />
+                      </template>
+                    </el-table-column>
+                    <el-table-column label="枚举值" align="center" prop="attrValue">
+                      <template slot-scope="scope">
+                        <el-input size="mini" v-model="scope.row.attrValue" placeholder="请输入枚举值" />
+                      </template>
+                    </el-table-column>
+                    <el-table-column label="描述" align="center" prop="attrValueName">
+                      <template slot-scope="scope">
+                        <el-input size="mini" v-model="scope.row.attrValueName" placeholder="请输入描述" />
+                      </template>
+                    </el-table-column>
+                    <el-table-column align="center" label="操作">
+                      <template slot="header">
+                        <div class="operateBtns" @click="addCustomAttr">
+                          <span>添加</span><i class="el-icon-circle-plus-outline"></i>
+                        </div>
+                      </template>
+                      <template slot-scope="scope">
+                        <i class="el-icon-delete" @click="deleteCustomAttr(scope.$index)"></i>
+                      </template>
+                    </el-table-column>
+                  </el-table>
+                </el-form-item>
               </el-form>
               <div slot="footer" class="dialog-footer">
                 <el-button type="primary" @click="submitAttrForm">确 定</el-button>
@@ -295,9 +326,6 @@
             <!-- 添加或修改能力对话框 -->
             <el-dialog :title="title" :visible.sync="abilityOpen" width="500px" append-to-body>
               <el-form ref="abilityForm" :model="abilityForm" :rules="abilityRules" label-width="80px">
-<!--                <el-form-item label="模型code" prop="modelCode">-->
-<!--                  <el-input v-model="abilityForm.modelCode" placeholder="请输入模型code"/>-->
-<!--                </el-form-item>-->
                 <el-form-item label="能力键" prop="abilityKey">
                   <el-input v-model="abilityForm.abilityKey" placeholder="请输入能力键"/>
                 </el-form-item>
@@ -329,11 +357,14 @@ import { listModel, getModel, delModel, addModel, updateModel, getModelByCode }
 import { getEvent, delEvent, addEvent, updateEvent } from '@/api/basecfg/objEvent'
 import { getAttr, delAttr, addAttr, updateAttr } from '@/api/basecfg/objAttribute'
 import { getAbility, delAbility, addAbility, updateAbility } from '@/api/basecfg/objAbility'
+import {getAttrList,delAttrEnum,addAttrEnums} from '@/api/basecfg/emum'
 
 export default {
   name: 'Model',
   data() {
     return {
+      // 用于存储表格数据
+      customAttrs: [],
       // 遮罩层
       loading: true,
       // 选中数组
@@ -402,7 +433,8 @@ export default {
         id: null,
         modelCode: null,
         modelName: null,
-        objType: null // 这里将由标签页控制
+        // 这里将由标签页控制
+        objType: null
       },
       eventForm: {},
       attrForm: {},
@@ -462,7 +494,6 @@ export default {
       attrList: [],
       // 能源对象能力表格数据
       abilityList: [],
-
       showDrawer: false,
       subDialogShow: false,
       // subTitle: '',
@@ -473,17 +504,43 @@ export default {
     this.getList()
   },
   methods: {
-
     handleTabClick(tab) {
       this.activeObjType = tab.name;
-      this.form.objType = null; // 重置表单时清除预设的 objType
+      this.form.objType = null;
       this.getList();
     },
+    getObjAttrList(modelCode, attrKey) {
+      this.loading = true;
+      getAttrList(modelCode, attrKey).then((response) => {
+        this.customAttrs = response.data || [];
+          this.loading = false;
+        })
+
+    },
+    // 添加自定义属性的方法
+    addCustomAttr() {
+      this.customAttrs.push({
+        modelCode:this.attrForm.modelCode,
+        attrKey:  null,
+        attrValue: null,
+        attrValueName: null,
+      });
+    },
+    //删除自定义属性的方法
+    deleteCustomAttr(index) {
+      const customAttr = this.customAttrs[index];
+      const attrEnumId = customAttr.id;
+      this.$modal.confirm('是否确认删除枚举值编号为"' + attrEnumId + '"的数据项?').then(() => {
+        return delAttrEnum(attrEnumId);
+      }).then(() => {
+        this.customAttrs.splice(index, 1);
+        this.$modal.msgSuccess('删除成功');
+      })
+    },
     // 设配详情
     handleDetail(row) {
       this.showDrawer = true
       this.curRow = row
-     //console.log('模型代码', this.modelCode)
       getModel(this.curRow.id).then(response => {
         const data = response.data
         console.log('data', data)
@@ -498,6 +555,8 @@ export default {
       this.attrOpen = true
       this.title = '添加能源对象属性'
       this.attrForm.modelCode= this.curRow.modelCode
+      console.log("新增123",this.attrForm)
+      this.getObjAttrList(this.attrForm.modelCode, this.attrForm.attrKey);
     },
     handleEventAdd() {
       this.eventReset()
@@ -529,7 +588,6 @@ export default {
       })
     },
     getEventList(modelcode) {
-      console.log('对象事件!!!!')
       this.loading = true
       getModelByCode(modelcode).then(response => {
         const data = response.data
@@ -619,6 +677,7 @@ export default {
         this.attrOpen = true
         this.title = '修改能源对象属性'
         this.attrForm.modelCode= this.curRow.modelCode
+        this.getObjAttrList(this.attrForm.modelCode, this.attrForm.attrKey);
 
       })
     },
@@ -680,27 +739,55 @@ export default {
       })
     },
 
+    /** 获取数据库中已存在的枚举值*/
+    async getExistingEnums() {
+      try {
+        this.loading = true;
+        const response = await getAttrList(this.attrForm.modelCode, this.attrForm.attrKey);
+        this.existingEnums = response.data || [];
+        this.loading = false;
+      } catch (error) {
+        this.$modal.msgError("获取枚举值失败:" + error.message);
+        this.loading = false;
+        throw error;
+      }
+    },
     /** 提交按钮 */
     submitAttrForm() {
-      this.$refs['attrForm'].validate(valid => {
+      this.$refs["attrForm"].validate(async (valid) => {
         if (valid) {
-          if (this.attrForm.id != null) {
-            updateAttr(this.attrForm).then(response => {
-              this.$modal.msgSuccess('修改成功')
-              this.attrOpen = false
-              console.log('id', this.attrForm.modelCode)
-              this.getAttrList(this.attrForm.modelCode)
-            })
-          } else {
-            addAttr(this.attrForm).then(response => {
-              this.$modal.msgSuccess('新增成功')
-              this.attrOpen = false
-              this.getAttrList(this.attrForm.modelCode)
-            })
+          try {
+            await this.getExistingEnums();
+            const newCustomAttrs = this.customAttrs.filter(attr => {
+              return !this.existingEnums.some(existingAttr =>
+                existingAttr.attrKey === attr.attrKey &&
+                existingAttr.attrValue === attr.attrValue
+              );
+            });
+            if (newCustomAttrs.length > 0) {
+              await addAttrEnums(newCustomAttrs); // 调用接口添加枚举值
+              this.$modal.msgSuccess("枚举值添加成功");
+            } else {
+              this.$modal.msgSuccess("没有新的枚举值需要添加");
+            }
+
+            if (this.attrForm.id != null) {
+              await updateAttr(this.attrForm);
+              this.$modal.msgSuccess("修改成功");
+            } else {
+              await addAttr(this.attrForm);
+              this.$modal.msgSuccess("新增成功");
+            }
+
+            this.attrOpen = false;
+            this.getAttrList(this.attrForm.modelCode);
+          } catch (error) {
+            this.$modal.msgError("操作失败:" + error.message);
           }
         }
-      })
+      });
     },
+
     submitEventForm() {
       this.$refs['eventForm'].validate(valid => {
         if (valid) {
@@ -800,7 +887,7 @@ export default {
       const id = row.id || this.ids
       getModel(id).then(response => {
         this.form = response.data
-        this.form.objType = this.activeObjType; // 设置默认对象类型
+        this.form.objType = this.activeObjType;
         this.open = true
         this.title = '修改能源对象属性'
       })