Преглед изворни кода

代码生成支持复选框

RuoYi пре 5 година
родитељ
комит
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
      * 缓存List数据
109
      * 缓存List数据
110
      *
110
      *
111
      * @param key 缓存的键值
111
      * @param key 缓存的键值
112
-     * @param values 待缓存的List数据
112
+     * @param dataList 待缓存的List数据
113
      * @return 缓存的对象
113
      * @return 缓存的对象
114
      */
114
      */
115
     public <T> long setCacheList(final String key, final List<T> dataList)
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
      * 获取上级菜单ID字段
239
      * 获取上级菜单ID字段
240
      * 
240
      * 
241
-     * @param options 生成其他选项
241
+     * @param paramsObj 生成其他选项
242
      * @return 上级菜单ID字段
242
      * @return 上级菜单ID字段
243
      */
243
      */
244
     public static String getParentMenuId(JSONObject paramsObj)
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
             ></el-option>
151
             ></el-option>
152
           </el-select>
152
           </el-select>
153
         </el-form-item>
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
 #elseif($column.htmlType == "select" && $dictType)
171
 #elseif($column.htmlType == "select" && $dictType)
155
         <el-form-item label="${comment}">
172
         <el-form-item label="${comment}">
156
           <el-select v-model="form.${field}" placeholder="请选择${comment}">
173
           <el-select v-model="form.${field}" placeholder="请选择${comment}">
@@ -312,7 +329,7 @@ export default {
312
 #end
329
 #end
313
     // $comment字典翻译
330
     // $comment字典翻译
314
     ${column.javaField}Format(row, column) {
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
 #end
334
 #end
318
 #end
335
 #end
@@ -328,6 +345,9 @@ export default {
328
 #if($column.htmlType == "radio")
345
 #if($column.htmlType == "radio")
329
         $column.javaField: "0"#if($velocityCount != $columns.size()),#end
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
 #else
351
 #else
332
         $column.javaField: undefined#if($velocityCount != $columns.size()),#end
352
         $column.javaField: undefined#if($velocityCount != $columns.size()),#end
333
 
353
 
@@ -361,6 +381,11 @@ export default {
361
       }
381
       }
362
       get${BusinessName}(row.${pkColumn.javaField}).then(response => {
382
       get${BusinessName}(row.${pkColumn.javaField}).then(response => {
363
         this.form = response.data;
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
         this.open = true;
389
         this.open = true;
365
         this.title = "修改${functionName}";
390
         this.title = "修改${functionName}";
366
       });
391
       });
@@ -369,6 +394,11 @@ export default {
369
     submitForm: function() {
394
     submitForm: function() {
370
       this.#[[$]]#refs["form"].validate(valid => {
395
       this.#[[$]]#refs["form"].validate(valid => {
371
         if (valid) {
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
           if (this.form.${pkColumn.javaField} != undefined) {
402
           if (this.form.${pkColumn.javaField} != undefined) {
373
             update${BusinessName}(this.form).then(response => {
403
             update${BusinessName}(this.form).then(response => {
374
               if (response.code === 200) {
404
               if (response.code === 200) {

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

@@ -185,6 +185,23 @@
185
             <el-option label="请选择字典生成" value="" />
185
             <el-option label="请选择字典生成" value="" />
186
           </el-select>
186
           </el-select>
187
         </el-form-item>
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
 #elseif($column.htmlType == "radio" && "" != $dictType)
205
 #elseif($column.htmlType == "radio" && "" != $dictType)
189
         <el-form-item label="${comment}">
206
         <el-form-item label="${comment}">
190
           <el-radio-group v-model="form.${field}">
207
           <el-radio-group v-model="form.${field}">
@@ -326,7 +343,7 @@ export default {
326
 #end
343
 #end
327
     // $comment字典翻译
344
     // $comment字典翻译
328
     ${column.javaField}Format(row, column) {
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
 #end
348
 #end
332
 #end
349
 #end
@@ -342,6 +359,9 @@ export default {
342
 #if($column.htmlType == "radio")
359
 #if($column.htmlType == "radio")
343
         $column.javaField: "0"#if($velocityCount != $columns.size()),#end
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
 #else
365
 #else
346
         $column.javaField: undefined#if($velocityCount != $columns.size()),#end
366
         $column.javaField: undefined#if($velocityCount != $columns.size()),#end
347
 
367
 
@@ -378,6 +398,11 @@ export default {
378
       const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
398
       const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
379
       get${BusinessName}(${pkColumn.javaField}).then(response => {
399
       get${BusinessName}(${pkColumn.javaField}).then(response => {
380
         this.form = response.data;
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
         this.open = true;
406
         this.open = true;
382
         this.title = "修改${functionName}";
407
         this.title = "修改${functionName}";
383
       });
408
       });
@@ -386,6 +411,11 @@ export default {
386
     submitForm: function() {
411
     submitForm: function() {
387
       this.#[[$]]#refs["form"].validate(valid => {
412
       this.#[[$]]#refs["form"].validate(valid => {
388
         if (valid) {
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
           if (this.form.${pkColumn.javaField} != undefined) {
419
           if (this.form.${pkColumn.javaField} != undefined) {
390
             update${BusinessName}(this.form).then(response => {
420
             update${BusinessName}(this.form).then(response => {
391
               if (response.code === 200) {
421
               if (response.code === 200) {

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

@@ -19,7 +19,7 @@ import './assets/icons' // icon
19
 import './permission' // permission control
19
 import './permission' // permission control
20
 import { getDicts } from "@/api/system/dict/data";
20
 import { getDicts } from "@/api/system/dict/data";
21
 import { getConfigKey } from "@/api/system/config";
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
 import Pagination from "@/components/Pagination";
23
 import Pagination from "@/components/Pagination";
24
 
24
 
25
 // 全局方法挂载
25
 // 全局方法挂载
@@ -29,6 +29,7 @@ Vue.prototype.parseTime = parseTime
29
 Vue.prototype.resetForm = resetForm
29
 Vue.prototype.resetForm = resetForm
30
 Vue.prototype.addDateRange = addDateRange
30
 Vue.prototype.addDateRange = addDateRange
31
 Vue.prototype.selectDictLabel = selectDictLabel
31
 Vue.prototype.selectDictLabel = selectDictLabel
32
+Vue.prototype.selectDictLabels = selectDictLabels
32
 Vue.prototype.download = download
33
 Vue.prototype.download = download
33
 Vue.prototype.handleTree = handleTree
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
 	return actions.join('');
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
 export function download(fileName) {
96
 export function download(fileName) {
82
 	window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
97
 	window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
@@ -98,10 +113,10 @@ export function sprintf(str) {
98
 
113
 
99
 // 转换字符串,undefined,null等转化为""
114
 // 转换字符串,undefined,null等转化为""
100
 export function praseStrEmpty(str) {
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
 	const cloneData = JSON.parse(JSON.stringify(data))
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
 	return treeData != '' ? treeData : data;
147
 	return treeData != '' ? treeData : data;
133
-  }
148
+}
134
 
149
 
135
   /**
150
   /**
136
    * 参数处理
151
    * 参数处理