diff --git a/.gitignore b/.gitignore index 0b1472e..eb78f8f 100644 --- a/.gitignore +++ b/.gitignore @@ -267,3 +267,4 @@ __pycache__/ /ZR.Admin.WebApi/wwwroot/uploads /ZR.Admin.WebApi/wwwroot/Generatecode /ZR.Admin.WebApi/wwwroot/export +/ZR.Vue/src/views/business/Gendemo.vue diff --git a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj index 3bfc425..313b4f3 100644 --- a/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj +++ b/ZR.Admin.WebApi/ZR.Admin.WebApi.csproj @@ -63,6 +63,7 @@ + diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt index 8038bd1..8d53e48 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplControllers.txt @@ -51,7 +51,6 @@ namespace ${options.ApiControllerNamespace}.Controllers var predicate = Expressionable.Create<${replaceDto.ModelTypeName}>(); //搜索条件查询语法参考Sqlsugar - //predicate = predicate.And(m => m.Name.Contains(parm.Name)); ${QueryCondition} $if(genTable.SortField != "") var response = _${replaceDto.ModelTypeName}Service.GetPages(predicate.ToExpression(), parm, x => x.${genTable.SortField}, "${genTable.SortType}"); @@ -161,5 +160,25 @@ ${end} string sFileName = ExportExcel(list, "${replaceDto.ModelTypeName}", "${genTable.FunctionName}"); return SUCCESS(new { path = "/export/" + sFileName, fileName = sFileName }); } + +$if(genTable.SortField != "") + /// + /// 保存排序 + /// + /// + /// + /// + [ActionPermissionFilter(Permission = "${replaceDto.PermissionPrefix}:update")] + [HttpGet("ChangeSort")] + [Log(Title = "保存排序", BusinessType = BusinessType.UPDATE)] + public IActionResult ChangeSort(int id = 0, int orderNum = 0) + { + if (id <= 0) { return ToResponse(ApiResult.Error(101, "请求参数错误")); } + + bool result = _${replaceDto.ModelTypeName}Service.Update(w => w.${replaceDto.PKName} == id, it => new ${replaceDto.ModelTypeName}() { ${genTable.SortField} = orderNum });; + + return SUCCESS(result); + } +$end } } \ No newline at end of file diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt index d03f985..348ac51 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVue.txt @@ -20,6 +20,11 @@ ${vueQueryFormHtml} 删除 +$if(genTable.SortField != "") + + 修改排序 + +$end @@ -59,7 +64,10 @@ import { add${genTable.BusinessName}, del${genTable.BusinessName}, update${genTable.BusinessName}, - get${genTable.BusinessName} + get${genTable.BusinessName}, +$if(genTable.SortField != "") + changeSort +$end } from '@/api/${genTable.ModuleName}/${lowerBusinessName}.js'; export default { @@ -68,7 +76,7 @@ export default { return { labelWidth: "100px", formLabelWidth:"100px", - // 选中${replaceDto.PKName}数组 + // 选中${replaceDto.FistLowerPk}数组 ids: [], // 非单个禁用 single: true, @@ -91,12 +99,16 @@ export default { $foreach(item in genTable.Columns) $if((item.HtmlType == "radio" || item.HtmlType == "select")) // ${item.ColumnComment}选项列表 - ${item.CsharpField2}Options: [], + ${item.ColumnName}Options: [], $end $end $if(replaceDto.UploadFile == 1) //文件上传地址 uploadUrl: process.env.VUE_APP_BASE_API + "upload/SaveFile", +$end +$if(genTable.SortField != "") + // 是否显示编辑排序 + showEditSort: false, $end // 数据列表 dataList: [], @@ -117,7 +129,7 @@ ${VueViewEditFormRuleContent} $foreach(item in genTable.Columns) $if((item.HtmlType == "radio" || item.HtmlType == "select") && item.DictType != "") this.getDicts("${item.DictType}").then((response) => { - this.${item.CsharpField2}Options = response.data; + this.${item.ColumnName}Options = response.data; }) $end $end @@ -162,7 +174,7 @@ $end }, // 多选框选中数据 handleSelectionChange(selection) { - this.ids = selection.map((item) => item.${replaceDto.PKName}); + this.ids = selection.map((item) => item.${replaceDto.FistLowerPk}); this.single = selection.length != 1 this.multiple = !selection.length; }, @@ -178,7 +190,7 @@ $end }, /** 删除按钮操作 */ handleDelete(row) { - const Ids = row.${replaceDto.PKName} || this.ids; + const Ids = row.${replaceDto.FistLowerPk} || this.ids; del${genTable.BusinessName}(Ids).then((res) => { this.msgSuccess("删除成功"); this.handleQuery(); @@ -187,8 +199,8 @@ $end /** 修改按钮操作 */ handleUpdate(row) { this.reset(); - const ${replaceDto.PKName} = row.${replaceDto.PKName} || this.ids; - get${genTable.BusinessName}(${replaceDto.PKName}).then((res) => { + const id = row.${replaceDto.FistLowerPk} || this.ids; + get${genTable.BusinessName}(id).then((res) => { if (res.code == 200) { this.form = res.data; this.open = true; @@ -196,6 +208,22 @@ $end } }); }, +$if(genTable.SortField != "") + // 显示编辑排序 + handleShowSort() { + this.showEditSort = !this.showEditSort; + }, + // 保存排序 + handleChangeSort(item, orderNum) { + changeSort({ orderNum: orderNum, id: item.${replaceDto.FistLowerPk} }).then( + (response) => { + this.msgSuccess("修改成功"); + this.getList(); + this.showEditSort = false; + } + ); + }, +$end $if(replaceDto.UploadFile == 1) //文件上传前判断方法 beforeFileUpload(file) { @@ -231,7 +259,7 @@ $end if (valid) { console.log(JSON.stringify(this.form)); - if (this.form.${replaceDto.PKName} != undefined || this.title === "修改数据") { + if (this.form.${replaceDto.FistLowerPk} != undefined || this.title === "修改数据") { update${genTable.BusinessName}(this.form).then((res) => { if (!res.data) { this.msgError("修改失败"); diff --git a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVueApi.txt b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVueApi.txt index 9b44308..c70b678 100644 --- a/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVueApi.txt +++ b/ZR.Admin.WebApi/wwwroot/CodeGenTemplate/TplVueApi.txt @@ -64,4 +64,16 @@ export function export${replaceDto.ModelTypeName}(query) { method: 'get', params: query }) -} \ No newline at end of file +} + +$if(genTable.SortField != "") +//排序 +export function changeSort(data) { + return request({ + url: '${genTable.ModuleName}/${replaceDto.ModelTypeName}/ChangeSort', + method: 'get', + params: data + }) +} + +$end \ No newline at end of file diff --git a/ZR.CodeGenerator/CodeGenerateTemplate.cs b/ZR.CodeGenerator/CodeGenerateTemplate.cs index 6cab4db..4928b61 100644 --- a/ZR.CodeGenerator/CodeGenerateTemplate.cs +++ b/ZR.CodeGenerator/CodeGenerateTemplate.cs @@ -215,15 +215,27 @@ namespace ZR.CodeGenerator /// Vue 查询列表 /// /// + /// /// - public static string TplTableColumn(GenTableColumn dbFieldInfo) + public static string TplTableColumn(GenTableColumn dbFieldInfo, GenTable genTable) { string columnName = dbFieldInfo.ColumnName; string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName); string showToolTip = dbFieldInfo.CsharpType == "string" ? ":show-overflow-tooltip=\"true\"" : ""; string formatter = !string.IsNullOrEmpty(dbFieldInfo.DictType) ? $" :formatter=\"{columnName}Format\"" : ""; StringBuilder sb = new StringBuilder(); - if (dbFieldInfo.IsList && dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD)) + + //有排序字段 + if (!string.IsNullOrEmpty(genTable?.SortField.ToString()) && genTable?.SortField.ToString() == dbFieldInfo.CsharpField) + { + sb.AppendLine($@" "); + sb.AppendLine(@" "); + sb.AppendLine(@" "); + } + else if (dbFieldInfo.IsList && dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD)) { sb.AppendLine($" "); sb.AppendLine("