Commit b8351f50f23ecd43d1a7612c649b57ba7311a485

Authored by YunaiV
1 parent 0b25eb1c

基本完成 index.vue.vm 模板

ruoyi-ui/src/main.js
... ... @@ -20,8 +20,8 @@ import {
20 20 parseTime,
21 21 resetForm,
22 22 addDateRange,
  23 + addBeginAndEndTime,
23 24 selectDictLabel,
24   - selectDictLabels,
25 25 download,
26 26 handleTree,
27 27 downloadExcel,
... ... @@ -41,8 +41,8 @@ Vue.prototype.getConfigKey = getConfigKey
41 41 Vue.prototype.parseTime = parseTime
42 42 Vue.prototype.resetForm = resetForm
43 43 Vue.prototype.addDateRange = addDateRange
  44 +Vue.prototype.addBeginAndEndTime = addBeginAndEndTime
44 45 Vue.prototype.selectDictLabel = selectDictLabel
45   -Vue.prototype.selectDictLabels = selectDictLabels
46 46 Vue.prototype.getDictDatas = getDictDatas
47 47 Vue.prototype.getDictDataLabel = getDictDataLabel
48 48 Vue.prototype.DICT_TYPE = DICT_TYPE
... ...
ruoyi-ui/src/utils/ruoyi.js
... ... @@ -69,6 +69,35 @@ export function addDateRange(params, dateRange, propName) {
69 69 return search;
70 70 }
71 71  
  72 +/**
  73 + * 添加开始和结束时间到 params 参数中
  74 + *
  75 + * @param params 参数
  76 + * @param dateRange 时间范围。
  77 + * 大小为 2 的数组,每个时间为 yyyy-MM-dd 格式
  78 + * @param propName 加入的参数名,可以为空
  79 + */
  80 +export function addBeginAndEndTime(params, dateRange, propName) {
  81 + // 必须传入参数
  82 + if (!dateRange) {
  83 + return params;
  84 + }
  85 + // 如果未传递 propName 属性,默认为 time
  86 + if (!propName) {
  87 + propName = 'Time';
  88 + } else {
  89 + propName = propName.charAt(0).toUpperCase() + propName.slice(1);
  90 + }
  91 + // 设置参数
  92 + if (dateRange[0]) {
  93 + params['begin' + propName] = dateRange[0] + ' 00:00:00';
  94 + }
  95 + if (dateRange[1]) {
  96 + params['end' + propName] = dateRange[0] + ' 23:59:59';
  97 + }
  98 + return params;
  99 +}
  100 +
72 101 // 回显数据字典
73 102 export function selectDictLabel(datas, value) {
74 103 var actions = [];
... ... @@ -81,21 +110,6 @@ export function selectDictLabel(datas, value) {
81 110 return actions.join('');
82 111 }
83 112  
84   -// 回显数据字典(字符串数组)
85   -export function selectDictLabels(datas, value, separator) {
86   - var actions = [];
87   - var currentSeparator = undefined === separator ? "," : separator;
88   - var temp = value.split(currentSeparator);
89   - Object.keys(value.split(currentSeparator)).some((val) => {
90   - Object.keys(datas).some((key) => {
91   - if (datas[key].dictValue == ('' + temp[val])) {
92   - actions.push(datas[key].dictLabel + currentSeparator);
93   - }
94   - })
95   - })
96   - return actions.join('').substring(0, actions.join('').length - 1);
97   -}
98   -
99 113 // 通用下载方法
100 114 export function download(fileName) {
101 115 window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
... ...
src/main/resources/codegen/vue/views/index.vue.vm
... ... @@ -58,7 +58,7 @@
58 58 </el-row>
59 59  
60 60 <!-- 列表 -->
61   - <el-table v-loading="loading" :data="${businessName}List">
  61 + <el-table v-loading="loading" :data="list">
62 62 #foreach($column in $columns)
63 63 #if ($column.listOperationResult)
64 64 #set ($dictType=$column.dictType)
... ... @@ -211,7 +211,7 @@ export default {
211 211 showSearch: true,
212 212 // 总条数
213 213 total: 0,
214   - // ${functionName}表格数据
  214 + // ${table.tableComment}表格数据
215 215 list: [],
216 216 // 弹出层标题
217 217 title: "",
... ... @@ -250,27 +250,20 @@ export default {
250 250 this.getList();
251 251 },
252 252 methods: {
253   - /** 查询${functionName}列表 */
  253 + /** 查询列表 */
254 254 getList() {
255 255 this.loading = true;
256   -#foreach ($column in $columns)
257   -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
258   - this.queryParams.params = {};
259   -#break
260   -#end
261   -#end
262   -#foreach ($column in $columns)
263   -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
264   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
265   - if (null != this.dateRange${AttrName} && '' != this.dateRange${AttrName}) {
266   - this.queryParams.params["begin${AttrName}"] = this.dateRange${AttrName}[0];
267   - this.queryParams.params["end${AttrName}"] = this.dateRange${AttrName}[1];
268   - }
269   -#end
270   -#end
271   - list${BusinessName}(this.queryParams).then(response => {
272   - this.list = response.rows;
273   - this.total = response.total;
  256 + let params = {...this.queryParams};
  257 + #foreach ($column in $columns)
  258 + #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
  259 + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  260 + this.addBeginAndEndTime(params, this.dateRange${AttrName}, ${column.javaField});
  261 + #end
  262 + #end
  263 + // 执行查询
  264 + get${simpleClassName}Page(params).then(response => {
  265 + this.list = response.data.list;
  266 + this.total = response.data.total;
274 267 this.loading = false;
275 268 });
276 269 },
... ... @@ -282,18 +275,13 @@ export default {
282 275 // 表单重置
283 276 reset() {
284 277 this.form = {
285   -#foreach ($column in $columns)
286   -#if($column.htmlType == "radio")
287   - $column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
288   -
289   -#elseif($column.htmlType == "checkbox")
290   - $column.javaField: []#if($velocityCount != $columns.size()),#end
291   -
292   -#else
293   - $column.javaField: null#if($velocityCount != $columns.size()),#end
294   -
295   -#end
296   -#end
  278 + #foreach ($column in $columns)
  279 + #if($column.htmlType == "checkbox")
  280 + $column.javaField: [],
  281 + #else
  282 + $column.javaField: null,
  283 + #end
  284 + #end
297 285 };
298 286 this.resetForm("form");
299 287 },
... ... @@ -304,12 +292,12 @@ export default {
304 292 },
305 293 /** 重置按钮操作 */
306 294 resetQuery() {
307   -#foreach ($column in $columns)
308   -#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
309   -#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  295 + #foreach ($column in $columns)
  296 + #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
  297 + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
310 298 this.dateRange${AttrName} = [];
311   -#end
312   -#end
  299 + #end
  300 + #end
313 301 this.resetForm("queryForm");
314 302 this.handleQuery();
315 303 },
... ... @@ -317,21 +305,21 @@ export default {
317 305 handleAdd() {
318 306 this.reset();
319 307 this.open = true;
320   - this.title = "添加${functionName}";
  308 + this.title = "添加${table.tableComment}";
321 309 },
322 310 /** 修改按钮操作 */
323 311 handleUpdate(row) {
324 312 this.reset();
325   - const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
326   - get${BusinessName}(${pkColumn.javaField}).then(response => {
  313 + const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
  314 + get${simpleClassName}(${primaryColumn.javaField}).then(response => {
327 315 this.form = response.data;
328   -#foreach ($column in $columns)
329   -#if($column.htmlType == "checkbox")
  316 + #foreach ($column in $columns)
  317 + #if($column.htmlType == "checkbox")## checkbox 特殊处理
330 318 this.form.$column.javaField = this.form.${column.javaField}.split(",");
331   -#end
332   -#end
  319 + #end
  320 + #end
333 321 this.open = true;
334   - this.title = "修改${functionName}";
  322 + this.title = "修改${table.tableComment}";
335 323 });
336 324 },
337 325 /** 提交按钮 */
... ... @@ -340,36 +328,37 @@ export default {
340 328 if (valid) {
341 329 return;
342 330 }
343   -#foreach ($column in $columns)
344   -#if($column.htmlType == "checkbox")
345   - this.form.$column.javaField = this.form.${column.javaField}.join(",");
346   -#end
347   -#end
348   - if (this.form.${pkColumn.javaField} != null) {
349   - update${BusinessName}(this.form).then(response => {
350   - this.msgSuccess("修改成功");
351   - this.open = false;
352   - this.getList();
353   - });
354   - } else {
355   - add${BusinessName}(this.form).then(response => {
356   - this.msgSuccess("新增成功");
357   - this.open = false;
358   - this.getList();
359   - });
360   - }
  331 + #foreach ($column in $columns)
  332 + #if($column.htmlType == "checkbox")
  333 + this.form.$column.javaField = this.form.${column.javaField}.join(",");
  334 + #end
  335 + #end
  336 + // 修改的提交
  337 + if (this.form.${primaryColumn.javaField} != null) {
  338 + update${simpleClassName}(this.form).then(response => {
  339 + this.msgSuccess("修改成功");
  340 + this.open = false;
  341 + this.getList();
  342 + });
  343 + return;
361 344 }
  345 + // 添加的提交
  346 + create${simpleClassName}(this.form).then(response => {
  347 + this.msgSuccess("新增成功");
  348 + this.open = false;
  349 + this.getList();
  350 + });
362 351 });
363 352 },
364 353 /** 删除按钮操作 */
365 354 handleDelete(row) {
366   - const ${pkColumn.javaField}s = row.${pkColumn.javaField};
367   - this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", {
  355 + const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
  356 + this.$confirm('是否确认删除${table.tableComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?', "警告", {
368 357 confirmButtonText: "确定",
369 358 cancelButtonText: "取消",
370 359 type: "warning"
371 360 }).then(function() {
372   - return del${BusinessName}(${pkColumn.javaField}s);
  361 + return delete${simpleClassName}(${primaryColumn.javaField});
373 362 }).then(() => {
374 363 this.getList();
375 364 this.msgSuccess("删除成功");
... ... @@ -377,15 +366,21 @@ export default {
377 366 },
378 367 /** 导出按钮操作 */
379 368 handleExport() {
380   - const queryParams = this.queryParams;
381   - this.$confirm('是否确认导出所有${functionName}数据项?', "警告", {
  369 + this.$confirm('是否确认导出所有${table.tableComment}数据项?', "警告", {
382 370 confirmButtonText: "确定",
383 371 cancelButtonText: "取消",
384 372 type: "warning"
385 373 }).then(function() {
386   - return export${BusinessName}(queryParams);
  374 + let params = {...this.queryParams};
  375 + #foreach ($column in $columns)
  376 + #if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
  377 + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
  378 + this.addBeginAndEndTime(params, this.dateRange${AttrName}, ${column.javaField});
  379 + #end
  380 + #end
  381 + return export${simpleClassName}(params);
387 382 }).then(response => {
388   - this.download(response.msg);
  383 + this.downloadExcel(response, '${table.classComment}.xls');
389 384 })
390 385 }
391 386 }
... ...