zhengnaiwen_citu преди 4 месеца
родител
ревизия
553690af5d
променени са 3 файла, в които са добавени 79 реда и са изтрити 16 реда
  1. 1 1
      src/api/system.js
  2. 71 12
      src/views/system/dictionaries/dictionariesEdit.vue
  3. 7 3
      src/views/system/dictionaries/index.vue

+ 1 - 1
src/api/system.js

@@ -265,7 +265,7 @@ export function deleteDictionaries (params) {
 
 // 保存字典
 export function saveDictionaries (params) {
-  return http.post('/dict/save', params)
+  return http.post('/dict/batch/save', params)
 }
 
 // 字典明细

+ 71 - 12
src/views/system/dictionaries/dictionariesEdit.vue

@@ -1,5 +1,5 @@
 <template>
-  <m-dialog :title="`${itemData ? '编辑' : '新增'}字典`" ref="dialog" @sure="onSure">
+  <m-dialog title="字典配置" ref="dialog" @sure="onSure">
     <m-form ref="form" :items="formItems" v-model="formValues" v-loading="loading">
       <template #dictTitle>
         <el-tag>{{ formValues.dictTitle }}</el-tag>
@@ -16,17 +16,24 @@
         >
           <template #dictTitle="{ $index }">
             <el-form-item :prop="`items.${$index}.dictTitle`" :rules="{ required: true, trigger: 'blur' }">
-              <el-input placeholder="字典项名称" v-model="formValues.items[$index].dictTitle"></el-input>
+              <el-input placeholder="字典项名称" v-model="formValues.items[$index].dictTitle" clearable></el-input>
             </el-form-item>
           </template>
           <template #dictValue="{ $index }">
             <el-form-item :prop="`items.${$index}.dictValue`" :rules="{ required: true, trigger: 'blur' }">
-              <el-input placeholder="字典项值" v-model="formValues.items[$index].dictValue"></el-input>
+              <el-input placeholder="字典项值" v-model="formValues.items[$index].dictValue" clearable></el-input>
             </el-form-item>
           </template>
           <template #dictColor="{ $index }">
-            <el-form-item :prop="`items.${$index}.dictColor`" :rules="{ required: true, trigger: 'blur' }">
-              <el-input placeholder="色值" v-model="formValues.items[$index].dictColor"></el-input>
+            <el-form-item :prop="`items.${$index}.dictColor`">
+              <el-select placeholder="色值" v-model="formValues.items[$index].dictColor" clearable>
+                <el-option
+                  v-for="item in options"
+                  :key="item.value"
+                  :label="item.label"
+                  :value="item.value">
+                </el-option>
+              </el-select>
             </el-form-item>
           </template>
           <template #actions="{ $index }">
@@ -43,14 +50,41 @@
 
 <script>
 import {
-  getDictionariesDetails
+  getDictionariesDetails,
+  saveDictionaries
 } from '@/api/system'
 export default {
   name: 'dictionariesEdit',
   data () {
     return {
       loading: false,
-      itemData: null,
+      options: [
+        {
+          value: 'orange',
+          label: 'orange'
+        },
+        {
+          value: 'primary',
+          label: 'primary'
+        },
+        {
+          value: 'success',
+          label: 'success'
+        },
+        {
+          value: 'info',
+          label: 'info'
+        },
+        {
+          value: 'warning',
+          label: 'warning'
+        },
+        {
+          value: 'danger',
+          label: 'danger'
+        }
+      ],
+      itemData: {},
       headers: [
         { label: '字典项名称', prop: 'dictTitle' },
         { label: '字典项值', prop: 'dictValue' },
@@ -72,9 +106,9 @@ export default {
   },
   methods: {
     async open (item) {
-      this.itemData = item ?? null
+      this.itemData = item
       this.formValues = {
-        dictTitle: item?.dictTitle ?? null,
+        dictTitle: item.dictTitle,
         items: [
           { dictTitle: null, dictValue: null, dictColor: null }
         ]
@@ -91,7 +125,7 @@ export default {
         this.formValues.items = data.map(e => ({
           dictTitle: e.dictTitle,
           dictValue: e.dictValue,
-          dictColor: null
+          ...e.webContent
         }))
       } catch (error) {
         this.$message.error(error)
@@ -110,8 +144,33 @@ export default {
       this.formValues.items.splice(index, 1)
     },
     onSure () {
-      this.$refs.form.validate(valid => {
-        console.log(valid)
+      this.$refs.form.validate(async valid => {
+        if (!valid) {
+          return
+        }
+        this.loading = true
+        try {
+          await saveDictionaries({
+            dictCode: this.itemData.dictValue,
+            level: 1,
+            itemReqVoList: this.formValues.items.map(e => {
+              return {
+                dictTitle: e.dictTitle,
+                dictValue: e.dictValue,
+                webContent: {
+                  dictColor: e.dictColor
+                }
+              }
+            })
+          })
+          this.$message.success('保存成功')
+          this.$refs.dialog.close()
+          this.$emit('success')
+        } catch (error) {
+          this.$message.error(error)
+        } finally {
+          this.loading = false
+        }
       })
     }
   }

+ 7 - 3
src/views/system/dictionaries/index.vue

@@ -13,13 +13,16 @@
       <!-- <template #card-tools>
         <m-button type="orange" icon="el-icon-plus" @click="onAdd">新增</m-button>
       </template> -->
+      <template #dictCode="{ row }">
+        <el-tag>{{ row.dictCode === 'systemCode' ? '系统级' : '用户级'}}</el-tag>
+      </template>
       <template #actions="{ row }">
         <!-- <m-button type="primary" text @click="onEdit(row)">编辑</m-button> -->
         <m-button type="primary" text @click="onEdit(row)">字典配置</m-button>
         <!-- <m-button type="danger" text @click="onDelete(row)">删除</m-button> -->
       </template>
     </m-table>
-    <DictionariesEdit ref="dictionariesEditRefs"></DictionariesEdit>
+    <DictionariesEdit ref="dictionariesEditRefs" @success="onInit"></DictionariesEdit>
   </div>
 </template>
 
@@ -42,7 +45,8 @@ export default {
       },
       headers: [
         { label: '名称', prop: 'dictTitle' },
-        { label: '类型', prop: 'dictCode' },
+        { label: '类型', prop: 'dictCode', align: 'center' },
+        { label: '标识', prop: 'dictValue', align: 'center' },
         { label: '创建时间', prop: 'createDate' },
         { label: '操作', prop: 'actions', fixed: 'right', width: 300 }
       ],
@@ -75,7 +79,7 @@ export default {
             placeholder: '请输入名称',
             clearable: false,
             items: [
-              { label: '系统', value: 'systemCode' },
+              { label: '系统', value: 'systemCode' },
               { label: '用户级', value: 'userCode' }
             ]
           }