Pārlūkot izejas kodu

chore: 优化主键字段名获取方式

喵你个旺呀 1 gadu atpakaļ
vecāks
revīzija
5101ccb37a

+ 0 - 2
Admin.NET/Admin.NET.Core/Service/CodeGen/CustomViewEngine.cs

@@ -63,8 +63,6 @@ public class CustomViewEngine : ViewEngineModel
     public List<CodeGenConfig> PrimaryKeyFieldList { get; set; }
     
     public List<TableUniqueConfigItem> TableUniqueConfigList { get; set; }
-
-    public List<string> PrimaryKeyNames => PrimaryKeyFieldList.Select(u => u.PropertyName).ToList();
     
     /// <summary>
     /// 格式化主键查询条件

+ 2 - 2
Admin.NET/Admin.NET.Web.Entry/wwwroot/template/editDialog.vue.vm

@@ -44,7 +44,7 @@
 						</el-form-item>
 					</el-col>
 					}else if(column.EffectType == "DictSelector" || column.EffectType == "EnumSelector"){
-					@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" @(Model.IsStatus(column) ? $"v-if='!ruleForm.{Model.ToLowerFirstLetter(Model.PrimaryKeyNames.First())}'" : "")>
+					@:<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" @(Model.IsStatus(column) ? $"v-if='!ruleForm.{Model.PrimaryKeyFieldList.First().LowerPropertyName}'" : "")>
 						@:<el-form-item label="@column.ColumnComment" prop="@(column.LowerPropertyName)">
 							if (Model.IsStatus(column)) {
 							@:<el-switch v-model="ruleForm.@column.LowerPropertyName" :active-value="1" :inactive-value="2" size="small" />
@@ -219,7 +219,7 @@
 		ruleFormRef.value.validate(async (isValid: boolean, fields?: any) => {
 			if (isValid) {
 				let values = ruleForm.value;
-				await @(Model.LowerClassName)Api[ruleForm.value.@(Model.ToLowerFirstLetter(Model.PrimaryKeyNames.First())) ? 'update' : 'add'](values);
+				await @(Model.LowerClassName)Api[ruleForm.value.@(Model.PrimaryKeyFieldList.First().LowerPropertyName) ? 'update' : 'add'](values);
 				closeDialog();
 			} else {
 				ElMessage({

+ 2 - 4
Admin.NET/Admin.NET.Web.Entry/wwwroot/template/index.vue.vm

@@ -99,7 +99,7 @@
       </el-form>
     </el-card>
     <el-card class="full-table" shadow="hover" style="margin-top: 5px">
-      <el-table :data="tableData" @@selection-change="(val: any[]) => { selectData = val; }" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="@Model.ToLowerFirstLetter(Model.PrimaryKeyNames.First())" @@sort-change="sortChange" border>
+      <el-table :data="tableData" @@selection-change="(val: any[]) => { selectData = val; }" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="@Model.PrimaryKeyFieldList.First().LowerPropertyName" @@sort-change="sortChange" border>
         <el-table-column type="selection" width="40" align="center" v-auth="'@(Model.LowerClassName):batchDelete'" />
         <el-table-column type="index" label="序号" width="55" align="center"/>
         @foreach (var column in Model.TableField.Where(u => u.WhetherTable == "Y")){
@@ -328,9 +328,7 @@
       cancelButtonText: "取消",
       type: "warning",
     }).then(async () => {
-      @foreach (var column in @Model.TableField.Where(u => u.ColumnKey == "True")) {
-      @:const count = await @(Model.LowerClassName)Api.batchDelete({ @(column.LowerPropertyName)List: selectData.value.map(u => { @(Model.PrimaryKeysFormat(", ", "u.{0}", true)) }) });
-      }
+      const count = await @(Model.LowerClassName)Api.batchDelete(selectData.value.map(u => { @(Model.PrimaryKeysFormat(", ", "u.{0}", true)) } ));
       handleQuery();
       ElMessage.success(`成功批量删除${count}条记录`);
     }).catch(() => {});