fix 代码生成编辑表前端排序bug

This commit is contained in:
不做码农 2021-12-11 11:16:49 +08:00
parent 1fa9d2aad5
commit 21aeb1057b
4 changed files with 66 additions and 58 deletions

View File

@ -195,12 +195,17 @@ namespace ZR.Admin.WebApi.Controllers
sortField = genTableDto.SortField,
sortType = genTable.SortType
});
int rows = GenTableService.UpdateGenTable(genTable);
if (rows > 0)
int updateCount = 0;
bool result = GenTableService.UseTran2(() =>
{
GenTableColumnService.UpdateGenTableColumn(genTable.Columns);
}
return SUCCESS(rows);
int rows = GenTableService.UpdateGenTable(genTable);
if (rows > 0)
{
updateCount = GenTableColumnService.UpdateGenTableColumn(genTable.Columns);
}
});
return SUCCESS(updateCount);
}
/// <summary>
@ -219,11 +224,6 @@ namespace ZR.Admin.WebApi.Controllers
var genTableInfo = GenTableService.GetGenTableInfo(dto.TableId);
genTableInfo.Columns = GenTableColumnService.GenTableColumns(dto.TableId);
//var dictList = genTableInfo.Columns.FindAll(x => !string.IsNullOrEmpty(x.DictType));
//foreach (var item in dictList)
//{
// item.DictDatas = SysDictDataService.SelectDictDataByType(item.DictType);
//}
dto.GenTable = genTableInfo;
dto.ZipPath = Path.Combine(WebHostEnvironment.WebRootPath, "Generatecode");
dto.GenCodePath = Path.Combine(dto.ZipPath, DateTime.Now.ToString("yyyyMMdd"));

View File

@ -58,7 +58,7 @@ namespace ZR.CodeGenerator
replaceDto.ShowBtnExport = dto.CheckedBtn.Any(f => f == 4);
//循环表字段信息
foreach (GenTableColumn dbFieldInfo in dto.GenTable.Columns)
foreach (GenTableColumn dbFieldInfo in dto.GenTable.Columns.OrderBy(x => x.Sort))
{
if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
{
@ -417,7 +417,7 @@ namespace ZR.CodeGenerator
private static void InitJntTemplate(GenerateDto dto, ReplaceDto replaceDto)
{
//Engine.Current.Clean();
dto.GenTable.Columns = dto.GenTable.Columns.OrderBy(x => x.Sort).ToList();
//jnt模板引擎全局变量
Engine.Configure((options) =>
{

View File

@ -64,31 +64,26 @@ namespace ZR.Repository.System
/// <returns></returns>
public int UpdateGenTableColumn(List<GenTableColumn> tableColumn)
{
foreach (var item in tableColumn)
{
Context.Updateable<GenTableColumn>()
.Where(f => f.TableId == item.TableId)
.SetColumns(it => new GenTableColumn()
{
ColumnComment = item.ColumnComment,
CsharpField = item.CsharpField,
CsharpType = item.CsharpType,
IsQuery = item.IsQuery,
IsEdit = item.IsEdit,
IsInsert = item.IsInsert,
IsList = item.IsList,
QueryType = item.QueryType,
HtmlType = item.HtmlType,
IsRequired = item.IsRequired,
Sort = item.Sort,
Update_time = DateTime.Now,
DictType = item.DictType
})
.Where(f => f.ColumnId == item.ColumnId)
.ExecuteCommand();
}
return 1;
return Context.Updateable(tableColumn)
.WhereColumns(it => new { it.ColumnId, it.TableId})
.UpdateColumns(it => new
{
it.ColumnComment,
it.CsharpField,
it.CsharpType,
it.IsQuery,
it.IsEdit,
it.IsInsert,
it.IsList,
it.QueryType,
it.HtmlType,
it.IsRequired,
it.Sort,
it.Update_time,
it.DictType,
it.Update_by
})
.ExecuteCommand();
}
}
}

View File

@ -89,7 +89,8 @@
</el-table-column>
<el-table-column label="字典类型" min-width="12%">
<template slot-scope="scope">
<el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择" v-if="scope.row.htmlType == 'select' || scope.row.htmlType == 'radio' || scope.row.htmlType =='checkbox'">
<el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择"
v-if="scope.row.htmlType == 'select' || scope.row.htmlType == 'radio' || scope.row.htmlType =='checkbox'">
<el-option v-for="dict in dictOptions" :key="dict.dictType" :label="dict.dictName" :value="dict.dictType">
<span style="float: left">{{ dict.dictName }}</span>
<span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span>
@ -177,13 +178,14 @@ export default {
if (validateResult) {
const genTable = Object.assign({}, basicForm.model, genForm.model);
genTable.columns = this.cloumns;
// genTable.params = {
// treeCode: genTable.treeCode,
// treeName: genTable.treeName,
// treeParentCode: genTable.treeParentCode,
// parentMenuId: genTable.parentMenuId,
// };
// console.log(JSON.stringify(genTable));
genTable.params = {
// treeCode: genTable.treeCode,
// treeName: genTable.treeName,
// treeParentCode: genTable.treeParentCode,
//parentMenuId: genTable.parentMenuId,
};
console.log("genForm", genTable);
// return;
updateGenTable(genTable).then((res) => {
this.msgSuccess(res.msg);
if (res.code === 200) {
@ -207,21 +209,32 @@ export default {
this.$store.dispatch("tagsView/delView", this.$route);
this.$router.push({ path: "/tool/gen", query: { t: Date.now() } });
},
sortTable(columns) {
const el = this.$refs.dragTable.$el.querySelectorAll(
".el-table__body-wrapper > table > tbody"
)[0];
var that = this;
const sortable = Sortable.create(el, {
handle: ".allowDrag",
onEnd: (evt) => {
const targetRow = that.cloumns.splice(evt.oldIndex, 1)[0];
columns.splice(evt.newIndex, 0, targetRow);
for (let index in columns) {
columns[index].sort = parseInt(index) + 1;
}
this.$nextTick(() => {
this.columns = columns;
});
},
});
},
},
mounted() {
const el = this.$refs.dragTable.$el.querySelectorAll(
".el-table__body-wrapper > table > tbody"
)[0];
const sortable = Sortable.create(el, {
handle: ".allowDrag",
onEnd: (evt) => {
const targetRow = this.cloumns.splice(evt.oldIndex, 1)[0];
this.cloumns.splice(evt.newIndex, 0, targetRow);
for (let index in this.cloumns) {
this.cloumns[index].sort = parseInt(index) + 1;
}
watch: {
cloumns: {
handler(val) {
this.sortTable(val);
},
});
},
},
};
</script>