基本完成 index.vue.vm 模板

This commit is contained in:
YunaiV 2021-02-12 11:53:32 +08:00
parent 0b25eb1c2a
commit b8351f50f2
3 changed files with 97 additions and 88 deletions

View File

@ -20,8 +20,8 @@ import {
parseTime,
resetForm,
addDateRange,
addBeginAndEndTime,
selectDictLabel,
selectDictLabels,
download,
handleTree,
downloadExcel,
@ -41,8 +41,8 @@ Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.addBeginAndEndTime = addBeginAndEndTime
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.getDictDatas = getDictDatas
Vue.prototype.getDictDataLabel = getDictDataLabel
Vue.prototype.DICT_TYPE = DICT_TYPE

View File

@ -69,6 +69,35 @@ export function addDateRange(params, dateRange, propName) {
return search;
}
/**
* 添加开始和结束时间到 params 参数中
*
* @param params 参数
* @param dateRange 时间范围
* 大小为 2 的数组每个时间为 yyyy-MM-dd 格式
* @param propName 加入的参数名可以为空
*/
export function addBeginAndEndTime(params, dateRange, propName) {
// 必须传入参数
if (!dateRange) {
return params;
}
// 如果未传递 propName 属性,默认为 time
if (!propName) {
propName = 'Time';
} else {
propName = propName.charAt(0).toUpperCase() + propName.slice(1);
}
// 设置参数
if (dateRange[0]) {
params['begin' + propName] = dateRange[0] + ' 00:00:00';
}
if (dateRange[1]) {
params['end' + propName] = dateRange[0] + ' 23:59:59';
}
return params;
}
// 回显数据字典
export function selectDictLabel(datas, value) {
var actions = [];
@ -81,21 +110,6 @@ export function selectDictLabel(datas, value) {
return actions.join('');
}
// 回显数据字典(字符串数组)
export function selectDictLabels(datas, value, separator) {
var actions = [];
var currentSeparator = undefined === separator ? "," : separator;
var temp = value.split(currentSeparator);
Object.keys(value.split(currentSeparator)).some((val) => {
Object.keys(datas).some((key) => {
if (datas[key].dictValue == ('' + temp[val])) {
actions.push(datas[key].dictLabel + currentSeparator);
}
})
})
return actions.join('').substring(0, actions.join('').length - 1);
}
// 通用下载方法
export function download(fileName) {
window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;

View File

@ -58,7 +58,7 @@
</el-row>
<!-- 列表 -->
<el-table v-loading="loading" :data="${businessName}List">
<el-table v-loading="loading" :data="list">
#foreach($column in $columns)
#if ($column.listOperationResult)
#set ($dictType=$column.dictType)
@ -211,7 +211,7 @@ export default {
showSearch: true,
// 总条数
total: 0,
// ${functionName}表格数据
// ${table.tableComment}表格数据
list: [],
// 弹出层标题
title: "",
@ -250,27 +250,20 @@ export default {
this.getList();
},
methods: {
/** 查询${functionName}列表 */
/** 查询列表 */
getList() {
this.loading = true;
#foreach ($column in $columns)
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
this.queryParams.params = {};
#break
#end
#end
#foreach ($column in $columns)
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
if (null != this.dateRange${AttrName} && '' != this.dateRange${AttrName}) {
this.queryParams.params["begin${AttrName}"] = this.dateRange${AttrName}[0];
this.queryParams.params["end${AttrName}"] = this.dateRange${AttrName}[1];
}
#end
#end
list${BusinessName}(this.queryParams).then(response => {
this.list = response.rows;
this.total = response.total;
let params = {...this.queryParams};
#foreach ($column in $columns)
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
this.addBeginAndEndTime(params, this.dateRange${AttrName}, ${column.javaField});
#end
#end
// 执行查询
get${simpleClassName}Page(params).then(response => {
this.list = response.data.list;
this.total = response.data.total;
this.loading = false;
});
},
@ -282,18 +275,13 @@ export default {
// 表单重置
reset() {
this.form = {
#foreach ($column in $columns)
#if($column.htmlType == "radio")
$column.javaField: #if($column.javaType == "Integer" || $column.javaType == "Long")0#else"0"#end#if($velocityCount != $columns.size()),#end
#elseif($column.htmlType == "checkbox")
$column.javaField: []#if($velocityCount != $columns.size()),#end
#else
$column.javaField: null#if($velocityCount != $columns.size()),#end
#end
#end
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
$column.javaField: [],
#else
$column.javaField: null,
#end
#end
};
this.resetForm("form");
},
@ -304,12 +292,12 @@ export default {
},
/** 重置按钮操作 */
resetQuery() {
#foreach ($column in $columns)
#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN")
#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
#foreach ($column in $columns)
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
this.dateRange${AttrName} = [];
#end
#end
#end
#end
this.resetForm("queryForm");
this.handleQuery();
},
@ -317,21 +305,21 @@ export default {
handleAdd() {
this.reset();
this.open = true;
this.title = "添加${functionName}";
this.title = "添加${table.tableComment}";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids
get${BusinessName}(${pkColumn.javaField}).then(response => {
const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
get${simpleClassName}(${primaryColumn.javaField}).then(response => {
this.form = response.data;
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")## checkbox 特殊处理
this.form.$column.javaField = this.form.${column.javaField}.split(",");
#end
#end
#end
#end
this.open = true;
this.title = "修改${functionName}";
this.title = "修改${table.tableComment}";
});
},
/** 提交按钮 */
@ -340,36 +328,37 @@ export default {
if (valid) {
return;
}
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
this.form.$column.javaField = this.form.${column.javaField}.join(",");
#end
#end
if (this.form.${pkColumn.javaField} != null) {
update${BusinessName}(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
add${BusinessName}(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
#foreach ($column in $columns)
#if($column.htmlType == "checkbox")
this.form.$column.javaField = this.form.${column.javaField}.join(",");
#end
#end
// 修改的提交
if (this.form.${primaryColumn.javaField} != null) {
update${simpleClassName}(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
return;
}
// 添加的提交
create${simpleClassName}(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ${pkColumn.javaField}s = row.${pkColumn.javaField};
this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", {
const ${primaryColumn.javaField} = row.${primaryColumn.javaField};
this.$confirm('是否确认删除${table.tableComment}编号为"' + ${primaryColumn.javaField} + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return del${BusinessName}(${pkColumn.javaField}s);
return delete${simpleClassName}(${primaryColumn.javaField});
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
@ -377,15 +366,21 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有${functionName}数据项?', "警告", {
this.$confirm('是否确认导出所有${table.tableComment}数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return export${BusinessName}(queryParams);
let params = {...this.queryParams};
#foreach ($column in $columns)
#if ($column.htmlType == "datetime" && $column.listOperationCondition == "BETWEEN")
#set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
this.addBeginAndEndTime(params, this.dateRange${AttrName}, ${column.javaField});
#end
#end
return export${simpleClassName}(params);
}).then(response => {
this.download(response.msg);
this.downloadExcel(response, '${table.classComment}.xls');
})
}
}