소스 검색

feat: 代码生成增加列是否可排序功能

vintom 2 년 전
부모
커밋
33e35ab3d5

+ 7 - 0
Admin.NET/Admin.NET.Core/Entity/SysCodeGenConfig.cs

@@ -112,6 +112,13 @@ public class SysCodeGenConfig : EntityBase
     [MaxLength(8)]
     public string? WhetherRequired { get; set; }
 
+    /// <summary>
+    /// 是否可排序(字典)
+    /// </summary>
+    [SugarColumn(ColumnDescription = "是否可排序", Length = 8)]
+    [MaxLength(8)]
+    public string? WhetherSortable { get; set; }
+
     /// <summary>
     /// 是否是查询条件
     /// </summary>

+ 5 - 0
Admin.NET/Admin.NET.Core/Service/CodeGen/Dto/CodeGenConfig.cs

@@ -106,6 +106,11 @@ public class CodeGenConfig
     /// </summary>
     public string WhetherRequired { get; set; }
 
+    /// <summary>
+    /// 是否可排序(字典)
+    /// </summary>
+    public string WhetherSortable { get; set; }
+
     /// <summary>
     /// 是否是查询条件
     /// </summary>

+ 1 - 1
Admin.NET/Admin.NET.Web.Entry/wwwroot/Template/Service.cs.vm

@@ -116,7 +116,7 @@ if (@column.QueryWhether == "Y"){
     }
 }
 }
-        return await query.ToPagedListAsync(input.Page, input.PageSize);
+        return await query.OrderBuilder(input).ToPagedListAsync(input.Page, input.PageSize);
     }
 
     /// <summary>

+ 12 - 4
Admin.NET/Admin.NET.Web.Entry/wwwroot/Template/index.vue.vm

@@ -108,12 +108,13 @@
 				v-loading="loading"
 				tooltip-effect="light"
 				row-key="@(@pkFieldName)"
+                @@sort-change="sortChange"
 				border="">
         <el-table-column type="index" label="序号" width="55" align="center"/>
         @foreach (var column in Model.TableField){
         if(@column.WhetherTable == "Y"){
         if(@column.EffectType == "Upload"||@column.EffectType == "fk"||@column.EffectType == "ApiTreeSelect"||@column.EffectType == "Switch"||@column.EffectType == "ConstSelector"){
-        @:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" width="@(column.ColumnComment!=null && column.ColumnComment.Length > 5 ? column.ColumnComment.Length * 15 : 120)" show-overflow-tooltip="">
+        @:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" width="@(column.ColumnComment!=null && column.ColumnComment.Length > 5 ? column.ColumnComment.Length * 15 : 120)" @(column.WhetherSortable == "Y" ? "sortable='custom'" : "") show-overflow-tooltip="">
           @:<template #default="scope">
             if(@column.EffectType == "Upload"){
             @:<el-image
@@ -142,21 +143,21 @@
         </el-table-column>
         }
         else if(@column.EffectType == "Select"){
-          @:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" width="@(column.ColumnComment!=null && column.ColumnComment.Length > 5 ? column.ColumnComment.Length * 15 : 140)" show-overflow-tooltip="" >
+          @:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" width="@(column.ColumnComment!=null && column.ColumnComment.Length > 5 ? column.ColumnComment.Length * 15 : 140)" @(column.WhetherSortable == "Y" ? "sortable='custom'" : "") show-overflow-tooltip="" >
             @:<template #default="scope">
               @:<el-tag :type="di('@(@column.DictTypeCode)', scope.row.@(@column.LowerPropertyName))?.tagType"> {{di("@(@column.DictTypeCode)", scope.row.@(@column.LowerPropertyName))?.value}} </el-tag>
             @:</template>
           @:</el-table-column>
         }
         else if(@column.EffectType == "EnumSelector"){
-          @:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" width="@(column.ColumnComment!=null && column.ColumnComment.Length > 5 ? column.ColumnComment.Length * 15 : 140)" show-overflow-tooltip="" >
+          @:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" width="@(column.ColumnComment!=null && column.ColumnComment.Length > 5 ? column.ColumnComment.Length * 15 : 140)" @(column.WhetherSortable == "Y" ? "sortable='custom'" : "") show-overflow-tooltip="" >
             @:<template #default="scope">
               @:<el-tag>{{ getEnumDesc(scope.row.@column.LowerPropertyName, getEnum@(@column.PropertyName)Data_Index)}}</el-tag>
             @:</template>
           @:</el-table-column>
         }
         else {
-        @:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" width="@(column.ColumnComment!=null && column.ColumnComment.Length > 5 ? column.ColumnComment.Length * 15 : 140)" show-overflow-tooltip="" />
+        @:<el-table-column prop="@column.LowerPropertyName" label="@column.ColumnComment" width="@(column.ColumnComment!=null && column.ColumnComment.Length > 5 ? column.ColumnComment.Length * 15 : 140)" @(column.WhetherSortable == "Y" ? "sortable='custom'" : "") show-overflow-tooltip="" />
         }
         }
         }
@@ -276,6 +277,13 @@
   }
   };
 
+  // 列排序
+  const sortChange = async (column: any) => {
+	queryParams.value.field = column.prop;
+	queryParams.value.order = column.order;
+	await handleQuery();
+  };
+
   // 打开新增页面
   const openAdd@(@Model.ClassName) = () => {
     edit@(@Model.ClassName)Title.value = '添加@(@Model.BusName)';

+ 5 - 0
Web/src/views/system/codeGen/component/genConfigDialog.vue

@@ -46,6 +46,11 @@
 						<el-checkbox v-model="scope.row.whetherRequired" :disabled="judgeColumns(scope.row)" />
 					</template>
 				</el-table-column>
+				<el-table-column prop="whetherSortable" label="可排序" width="80" align="center" show-overflow-tooltip>
+					<template #default="scope">
+						<el-checkbox v-model="scope.row.whetherSortable" />
+					</template>
+				</el-table-column>
 				<el-table-column prop="queryWhether" label="是否是查询" min-width="80" align="center" show-overflow-tooltip>
 					<template #default="scope">
 						<el-switch v-model="scope.row.queryWhether" :active-value="true" :inactive-value="false" />