Bläddra i källkod

代码生成支持复选框

RuoYi 5 år sedan
förälder
incheckning
165a957d67

+ 1 - 1
ruoyi-common/ruoyi-common-redis/src/main/java/com/ruoyi/common/redis/service/RedisService.java

@@ -109,7 +109,7 @@ public class RedisService
109 109
      * 缓存List数据
110 110
      *
111 111
      * @param key 缓存的键值
112
-     * @param values 待缓存的List数据
112
+     * @param dataList 待缓存的List数据
113 113
      * @return 缓存的对象
114 114
      */
115 115
     public <T> long setCacheList(final String key, final List<T> dataList)

+ 1 - 1
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java

@@ -238,7 +238,7 @@ public class VelocityUtils
238 238
     /**
239 239
      * 获取上级菜单ID字段
240 240
      * 
241
-     * @param options 生成其他选项
241
+     * @param paramsObj 生成其他选项
242 242
      * @return 上级菜单ID字段
243 243
      */
244 244
     public static String getParentMenuId(JSONObject paramsObj)

+ 31 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index-tree.vue.vm

@@ -151,6 +151,23 @@
151 151
             ></el-option>
152 152
           </el-select>
153 153
         </el-form-item>
154
+#elseif($column.htmlType == "checkbox" && "" != $dictType)
155
+        <el-form-item label="${comment}">
156
+          <el-checkbox-group v-model="form.${field}">
157
+            <el-checkbox
158
+              v-for="dict in ${field}Options"
159
+              :key="dict.dictValue"
160
+              :label="dict.dictValue">
161
+              {{dict.dictLabel}}
162
+            </el-checkbox>
163
+          </el-checkbox-group>
164
+        </el-form-item>
165
+#elseif($column.htmlType == "checkbox" && $dictType)
166
+        <el-form-item label="${comment}">
167
+          <el-checkbox-group v-model="form.${field}">
168
+            <el-checkbox>请选择字典生成</el-checkbox>
169
+          </el-checkbox-group>
170
+        </el-form-item>
154 171
 #elseif($column.htmlType == "select" && $dictType)
155 172
         <el-form-item label="${comment}">
156 173
           <el-select v-model="form.${field}" placeholder="请选择${comment}">
@@ -312,7 +329,7 @@ export default {
312 329
 #end
313 330
     // $comment字典翻译
314 331
     ${column.javaField}Format(row, column) {
315
-      return this.selectDictLabel(this.${column.javaField}Options, row.${column.javaField});
332
+      return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
316 333
     },
317 334
 #end
318 335
 #end
@@ -328,6 +345,9 @@ export default {
328 345
 #if($column.htmlType == "radio")
329 346
         $column.javaField: "0"#if($velocityCount != $columns.size()),#end
330 347
 
348
+#elseif($column.htmlType == "checkbox")
349
+        $column.javaField: []#if($velocityCount != $columns.size()),#end
350
+
331 351
 #else
332 352
         $column.javaField: undefined#if($velocityCount != $columns.size()),#end
333 353
 
@@ -361,6 +381,11 @@ export default {
361 381
       }
362 382
       get${BusinessName}(row.${pkColumn.javaField}).then(response => {
363 383
         this.form = response.data;
384
+#foreach ($column in $columns)
385
+#if($column.htmlType == "checkbox")
386
+        this.form.$column.javaField = this.form.${column.javaField}.split(",");
387
+#end
388
+#end
364 389
         this.open = true;
365 390
         this.title = "修改${functionName}";
366 391
       });
@@ -369,6 +394,11 @@ export default {
369 394
     submitForm: function() {
370 395
       this.#[[$]]#refs["form"].validate(valid => {
371 396
         if (valid) {
397
+#foreach ($column in $columns)
398
+#if($column.htmlType == "checkbox")
399
+          this.form.$column.javaField = this.form.${column.javaField}.join(",");
400
+#end
401
+#end
372 402
           if (this.form.${pkColumn.javaField} != undefined) {
373 403
             update${BusinessName}(this.form).then(response => {
374 404
               if (response.code === 200) {

+ 31 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm

@@ -185,6 +185,23 @@
185 185
             <el-option label="请选择字典生成" value="" />
186 186
           </el-select>
187 187
         </el-form-item>
188
+#elseif($column.htmlType == "checkbox" && "" != $dictType)
189
+        <el-form-item label="${comment}">
190
+          <el-checkbox-group v-model="form.${field}">
191
+            <el-checkbox
192
+              v-for="dict in ${field}Options"
193
+              :key="dict.dictValue"
194
+              :label="dict.dictValue">
195
+              {{dict.dictLabel}}
196
+            </el-checkbox>
197
+          </el-checkbox-group>
198
+        </el-form-item>
199
+#elseif($column.htmlType == "checkbox" && $dictType)
200
+        <el-form-item label="${comment}">
201
+          <el-checkbox-group v-model="form.${field}">
202
+            <el-checkbox>请选择字典生成</el-checkbox>
203
+          </el-checkbox-group>
204
+        </el-form-item>
188 205
 #elseif($column.htmlType == "radio" && "" != $dictType)
189 206
         <el-form-item label="${comment}">
190 207
           <el-radio-group v-model="form.${field}">
@@ -326,7 +343,7 @@ export default {
326 343
 #end
327 344
     // $comment字典翻译
328 345
     ${column.javaField}Format(row, column) {
329
-      return this.selectDictLabel(this.${column.javaField}Options, row.${column.javaField});
346
+      return this.selectDictLabel#if($column.htmlType == "checkbox")s#end(this.${column.javaField}Options, row.${column.javaField});
330 347
     },
331 348
 #end
332 349
 #end
@@ -342,6 +359,9 @@ export default {
342 359
 #if($column.htmlType == "radio")
343 360
         $column.javaField: "0"#if($velocityCount != $columns.size()),#end
344 361
 
362
+#elseif($column.htmlType == "checkbox")
363
+        $column.javaField: []#if($velocityCount != $columns.size()),#end
364
+
345 365
 #else
346 366
         $column.javaField: undefined#if($velocityCount != $columns.size()),#end
347 367
 
@@ -378,6 +398,11 @@ export default {
378 398
       const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
379 399
       get${BusinessName}(${pkColumn.javaField}).then(response => {
380 400
         this.form = response.data;
401
+#foreach ($column in $columns)
402
+#if($column.htmlType == "checkbox")
403
+        this.form.$column.javaField = this.form.${column.javaField}.split(",");
404
+#end
405
+#end
381 406
         this.open = true;
382 407
         this.title = "修改${functionName}";
383 408
       });
@@ -386,6 +411,11 @@ export default {
386 411
     submitForm: function() {
387 412
       this.#[[$]]#refs["form"].validate(valid => {
388 413
         if (valid) {
414
+#foreach ($column in $columns)
415
+#if($column.htmlType == "checkbox")
416
+          this.form.$column.javaField = this.form.${column.javaField}.join(",");
417
+#end
418
+#end
389 419
           if (this.form.${pkColumn.javaField} != undefined) {
390 420
             update${BusinessName}(this.form).then(response => {
391 421
               if (response.code === 200) {

+ 2 - 1
ruoyi-ui/src/main.js

@@ -19,7 +19,7 @@ import './assets/icons' // icon
19 19
 import './permission' // permission control
20 20
 import { getDicts } from "@/api/system/dict/data";
21 21
 import { getConfigKey } from "@/api/system/config";
22
-import { parseTime, resetForm, addDateRange, selectDictLabel, handleTree } from "@/utils/ruoyi";
22
+import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, handleTree } from "@/utils/ruoyi";
23 23
 import Pagination from "@/components/Pagination";
24 24
 
25 25
 // 全局方法挂载
@@ -29,6 +29,7 @@ Vue.prototype.parseTime = parseTime
29 29
 Vue.prototype.resetForm = resetForm
30 30
 Vue.prototype.addDateRange = addDateRange
31 31
 Vue.prototype.selectDictLabel = selectDictLabel
32
+Vue.prototype.selectDictLabels = selectDictLabels
32 33
 Vue.prototype.download = download
33 34
 Vue.prototype.handleTree = handleTree
34 35
 

+ 28 - 13
ruoyi-ui/src/utils/ruoyi.js

@@ -77,6 +77,21 @@ export function selectDictLabel(datas, value) {
77 77
 	return actions.join('');
78 78
 }
79 79
 
80
+// 回显数据字典(字符串数组)
81
+export function selectDictLabels(datas, value, separator) {
82
+	var actions = [];
83
+	var currentSeparator = undefined === separator ? "," : separator;
84
+	var temp = value.split(currentSeparator);
85
+	Object.keys(value.split(currentSeparator)).some((val) => {
86
+        Object.keys(datas).some((key) => {
87
+            if (datas[key].dictValue == ('' + temp[val])) {
88
+				actions.push(datas[key].dictLabel + currentSeparator);
89
+			}
90
+		})
91
+	})
92
+	return actions.join('').substring(0, actions.join('').length - 1);
93
+}
94
+
80 95
 // 通用下载方法
81 96
 export function download(fileName) {
82 97
 	window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
@@ -98,10 +113,10 @@ export function sprintf(str) {
98 113
 
99 114
 // 转换字符串,undefined,null等转化为""
100 115
 export function praseStrEmpty(str) {
101
-    if (!str || str == "undefined" || str == "null") {
102
-        return "";
103
-    }
104
-    return str;
116
+	if (!str || str == "undefined" || str == "null") {
117
+		return "";
118
+	}
119
+	return str;
105 120
 }
106 121
 
107 122
 /**
@@ -120,17 +135,17 @@ export function handleTree(data, id, parentId, children, rootId) {
120 135
 	//对源数据深度克隆
121 136
 	const cloneData = JSON.parse(JSON.stringify(data))
122 137
 	//循环所有项
123
-	const treeData =  cloneData.filter(father => {
124
-	  let branchArr = cloneData.filter(child => {
125
-		//返回每一项的子级数组
126
-		return father[id] === child[parentId]
127
-	  });
128
-	  branchArr.length > 0 ? father.children = branchArr : '';
129
-	  //返回第一层
130
-	  return father[parentId] === rootId;
138
+	const treeData = cloneData.filter(father => {
139
+		let branchArr = cloneData.filter(child => {
140
+			//返回每一项的子级数组
141
+			return father[id] === child[parentId]
142
+		});
143
+		branchArr.length > 0 ? father.children = branchArr : '';
144
+		//返回第一层
145
+		return father[parentId] === rootId;
131 146
 	});
132 147
 	return treeData != '' ? treeData : data;
133
-  }
148
+}
134 149
 
135 150
   /**
136 151
    * 参数处理