Explorar el Código

增加字典标签样式回显

Ricky hace 4 años
padre
commit
57f56c2769

+ 51 - 0
ruoyi-ui/src/components/DictTag/index.vue

@@ -0,0 +1,51 @@
1
+<template>
2
+  <div>
3
+    <template v-for="(item, index) in options">
4
+      <template v-if="values.includes(item.dictValue)">
5
+        <span
6
+          v-if="item.listClass == 'default' || item.listClass == ''"
7
+          :key="item.dictValue"
8
+          :index="index"
9
+          :class="item.cssClass"
10
+          >{{ item.dictLabel }}</span
11
+        >
12
+        <el-tag
13
+          v-else
14
+          :key="item.dictValue"
15
+          :index="index"
16
+          :type="item.listClass == 'primary' ? '' : item.listClass"
17
+          :class="item.cssClass"
18
+        >
19
+          {{ item.dictLabel }}
20
+        </el-tag>
21
+      </template>
22
+    </template>
23
+  </div>
24
+</template>
25
+
26
+<script>
27
+export default {
28
+  name: "DictTag",
29
+  props: {
30
+    options: {
31
+      type: Array,
32
+      default: null,
33
+    },
34
+    value: [String, Array],
35
+  },
36
+  computed: {
37
+    values() {
38
+      if (this.value) {
39
+        return Array.isArray(this.value) ? this.value : [this.value];
40
+      } else {
41
+        return [];
42
+      }
43
+    },
44
+  },
45
+};
46
+</script>
47
+<style scoped>
48
+.el-tag + .el-tag {
49
+  margin-left: 10px;
50
+}
51
+</style>

+ 58 - 6
ruoyi-ui/src/views/system/dict/data.vue

@@ -85,10 +85,19 @@
85 85
     <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
86 86
       <el-table-column type="selection" width="55" align="center" />
87 87
       <el-table-column label="字典编码" align="center" prop="dictCode" />
88
-      <el-table-column label="字典标签" align="center" prop="dictLabel" />
88
+      <el-table-column label="字典标签" align="center" prop="dictLabel">
89
+        <template slot-scope="scope">
90
+          <span v-if="scope.row.listClass == '' || scope.row.listClass == 'default'">{{scope.row.dictLabel}}</span>
91
+          <el-tag v-else :type="scope.row.listClass == 'primary' ? '' : scope.row.listClass">{{scope.row.dictLabel}}</el-tag>
92
+        </template>
93
+      </el-table-column>
89 94
       <el-table-column label="字典键值" align="center" prop="dictValue" />
90 95
       <el-table-column label="字典排序" align="center" prop="dictSort" />
91
-      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
96
+      <el-table-column label="状态" align="center" prop="status">
97
+        <template slot-scope="scope">
98
+          <dict-tag :options="statusOptions" :value="scope.row.status"/>
99
+        </template>
100
+      </el-table-column>
92 101
       <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
93 102
       <el-table-column label="创建时间" align="center" prop="createTime" width="180">
94 103
         <template slot-scope="scope">
@@ -135,9 +144,22 @@
135 144
         <el-form-item label="数据键值" prop="dictValue">
136 145
           <el-input v-model="form.dictValue" placeholder="请输入数据键值" />
137 146
         </el-form-item>
147
+        <el-form-item label="样式属性" prop="cssClass">
148
+          <el-input v-model="form.cssClass" placeholder="请输入样式属性" />
149
+        </el-form-item>
138 150
         <el-form-item label="显示排序" prop="dictSort">
139 151
           <el-input-number v-model="form.dictSort" controls-position="right" :min="0" />
140 152
         </el-form-item>
153
+        <el-form-item label="回显样式" prop="listClass">
154
+          <el-select v-model="form.listClass">
155
+            <el-option
156
+              v-for="item in listClassOptions"
157
+              :key="item.value"
158
+              :label="item.label"
159
+              :value="item.value"
160
+            ></el-option>
161
+          </el-select>
162
+        </el-form-item>
141 163
         <el-form-item label="状态" prop="status">
142 164
           <el-radio-group v-model="form.status">
143 165
             <el-radio
@@ -162,9 +184,14 @@
162 184
 <script>
163 185
 import { listData, getData, delData, addData, updateData } from "@/api/system/dict/data";
164 186
 import { listType, getType } from "@/api/system/dict/type";
187
+// 字典标签组件(使用频繁可在全局挂载)
188
+import DictTag from '@/components/DictTag'
165 189
 
166 190
 export default {
167 191
   name: "Data",
192
+  components: {
193
+    DictTag
194
+  },
168 195
   data() {
169 196
     return {
170 197
       // 遮罩层
@@ -187,6 +214,33 @@ export default {
187 214
       title: "",
188 215
       // 是否显示弹出层
189 216
       open: false,
217
+      // 数据标签回显样式
218
+      listClassOptions: [
219
+        {
220
+          value: "default",
221
+          label: "默认"
222
+        },
223
+        {
224
+          value: "primary",
225
+          label: "主要"
226
+        },
227
+        {
228
+          value: "success",
229
+          label: "成功"
230
+        },
231
+        {
232
+          value: "info",
233
+          label: "信息"
234
+        },
235
+        {
236
+          value: "warning",
237
+          label: "警告"
238
+        },
239
+        {
240
+          value: "danger",
241
+          label: "危险"
242
+        }
243
+      ],
190 244
       // 状态数据字典
191 245
       statusOptions: [],
192 246
       // 类型数据字典
@@ -247,10 +301,6 @@ export default {
247 301
         this.loading = false;
248 302
       });
249 303
     },
250
-    // 数据状态字典翻译
251
-    statusFormat(row, column) {
252
-      return this.selectDictLabel(this.statusOptions, row.status);
253
-    },
254 304
     // 取消按钮
255 305
     cancel() {
256 306
       this.open = false;
@@ -262,6 +312,8 @@ export default {
262 312
         dictCode: undefined,
263 313
         dictLabel: undefined,
264 314
         dictValue: undefined,
315
+        cssClass: undefined,
316
+        listClass: 'default',
265 317
         dictSort: 0,
266 318
         status: "0",
267 319
         remark: undefined

+ 10 - 5
ruoyi-ui/src/views/system/dict/index.vue

@@ -122,7 +122,11 @@
122 122
           </router-link>
123 123
         </template>
124 124
       </el-table-column>
125
-      <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
125
+      <el-table-column label="状态" align="center" prop="status">
126
+        <template slot-scope="scope">
127
+          <dict-tag :options="statusOptions" :value="scope.row.status"/>
128
+        </template>
129
+      </el-table-column>
126 130
       <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
127 131
       <el-table-column label="创建时间" align="center" prop="createTime" width="180">
128 132
         <template slot-scope="scope">
@@ -189,9 +193,14 @@
189 193
 
190 194
 <script>
191 195
 import { listType, getType, delType, addType, updateType, refreshCache } from "@/api/system/dict/type";
196
+// 字典标签组件(使用频繁可在全局挂载)
197
+import DictTag from '@/components/DictTag'
192 198
 
193 199
 export default {
194 200
   name: "Dict",
201
+  components: {
202
+    DictTag
203
+  },
195 204
   data() {
196 205
     return {
197 206
       // 遮罩层
@@ -254,10 +263,6 @@ export default {
254 263
         }
255 264
       );
256 265
     },
257
-    // 字典状态字典翻译
258
-    statusFormat(row, column) {
259
-      return this.selectDictLabel(this.statusOptions, row.status);
260
-    },
261 266
     // 取消按钮
262 267
     cancel() {
263 268
       this.open = false;