作者 RuoYi

代码生成支持复选框

@@ -157,6 +157,23 @@ @@ -157,6 +157,23 @@
157 <el-option label="请选择字典生成" value="" /> 157 <el-option label="请选择字典生成" value="" />
158 </el-select> 158 </el-select>
159 </el-form-item> 159 </el-form-item>
  160 +#elseif($column.htmlType == "checkbox" && "" != $dictType)
  161 + <el-form-item label="${comment}">
  162 + <el-checkbox-group v-model="form.${field}">
  163 + <el-checkbox
  164 + v-for="dict in ${field}Options"
  165 + :key="dict.dictValue"
  166 + :label="dict.dictValue">
  167 + {{dict.dictLabel}}
  168 + </el-checkbox>
  169 + </el-checkbox-group>
  170 + </el-form-item>
  171 +#elseif($column.htmlType == "checkbox" && $dictType)
  172 + <el-form-item label="${comment}">
  173 + <el-checkbox-group v-model="form.${field}">
  174 + <el-checkbox>请选择字典生成</el-checkbox>
  175 + </el-checkbox-group>
  176 + </el-form-item>
160 #elseif($column.htmlType == "radio" && "" != $dictType) 177 #elseif($column.htmlType == "radio" && "" != $dictType)
161 <el-form-item label="${comment}"> 178 <el-form-item label="${comment}">
162 <el-radio-group v-model="form.${field}"> 179 <el-radio-group v-model="form.${field}">
@@ -312,7 +329,7 @@ export default { @@ -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,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,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,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) {
@@ -185,6 +185,23 @@ @@ -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,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,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,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,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) {
@@ -18,7 +18,7 @@ import './assets/icons' // icon @@ -18,7 +18,7 @@ import './assets/icons' // icon
18 import './permission' // permission control 18 import './permission' // permission control
19 import { getDicts } from "@/api/system/dict/data"; 19 import { getDicts } from "@/api/system/dict/data";
20 import { getConfigKey } from "@/api/system/config"; 20 import { getConfigKey } from "@/api/system/config";
21 -import { parseTime, resetForm, addDateRange, selectDictLabel, download, handleTree } from "@/utils/ruoyi"; 21 +import { parseTime, resetForm, addDateRange, selectDictLabel, selectDictLabels, download, handleTree } from "@/utils/ruoyi";
22 import Pagination from "@/components/Pagination"; 22 import Pagination from "@/components/Pagination";
23 23
24 // 全局方法挂载 24 // 全局方法挂载
@@ -28,6 +28,7 @@ Vue.prototype.parseTime = parseTime @@ -28,6 +28,7 @@ Vue.prototype.parseTime = parseTime
28 Vue.prototype.resetForm = resetForm 28 Vue.prototype.resetForm = resetForm
29 Vue.prototype.addDateRange = addDateRange 29 Vue.prototype.addDateRange = addDateRange
30 Vue.prototype.selectDictLabel = selectDictLabel 30 Vue.prototype.selectDictLabel = selectDictLabel
  31 +Vue.prototype.selectDictLabels = selectDictLabels
31 Vue.prototype.download = download 32 Vue.prototype.download = download
32 Vue.prototype.handleTree = handleTree 33 Vue.prototype.handleTree = handleTree
33 34
@@ -77,6 +77,21 @@ export function selectDictLabel(datas, value) { @@ -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;
@@ -130,5 +145,5 @@ export function handleTree(data, id, parentId, children, rootId) { @@ -130,5 +145,5 @@ export function handleTree(data, id, parentId, children, rootId) {
130 return father[parentId] === rootId; 145 return father[parentId] === rootId;
131 }); 146 });
132 return treeData != '' ? treeData : data; 147 return treeData != '' ? treeData : data;
133 - } 148 +}
134 149
@@ -120,7 +120,7 @@ create table sys_role ( @@ -120,7 +120,7 @@ create table sys_role (
120 -- ---------------------------- 120 -- ----------------------------
121 -- 初始化-角色信息表数据 121 -- 初始化-角色信息表数据
122 -- ---------------------------- 122 -- ----------------------------
123 -insert into sys_role values('1', '系统管理员', 'admin', 1, 1, '0', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '系统管理员'); 123 +insert into sys_role values('1', '超级管理员', 'admin', 1, 1, '0', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '超级管理员');
124 insert into sys_role values('2', '普通角色', 'common', 2, 2, '0', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '普通角色'); 124 insert into sys_role values('2', '普通角色', 'common', 2, 2, '0', '0', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', '普通角色');
125 125
126 126