Bladeren bron

!1807 库表管理 默认值设置 编辑
Merge pull request !1807 from CyrusZhou/v2

zuohuaijun 10 maanden geleden
bovenliggende
commit
04e235c0ec

+ 4 - 0
Admin.NET/Admin.NET.Core/Service/DataBase/Dto/DbColumnInput.cs

@@ -27,6 +27,8 @@ public class DbColumnInput
     public int IsPrimarykey { get; set; }
 
     public int DecimalDigits { get; set; }
+
+    public string DefaultValue { get; set; }
 }
 
 public class UpdateDbColumnInput
@@ -40,6 +42,8 @@ public class UpdateDbColumnInput
     public string OldColumnName { get; set; }
 
     public string Description { get; set; }
+
+    public string DefaultValue { get; set; }
 }
 
 public class DeleteDbColumnInput

+ 4 - 1
Admin.NET/Admin.NET.Core/Service/DataBase/SysDatabaseService.cs

@@ -141,7 +141,8 @@ public class SysDatabaseService : IDynamicApiController, ITransient
             IsPrimarykey = input.IsPrimarykey == 1,
             Length = input.Length,
             DecimalDigits = input.DecimalDigits,
-            DataType = input.DataType
+            DataType = input.DataType,
+            DefaultValue = input.DefaultValue
         };
         var db = _db.AsTenant().GetConnectionScope(input.ConfigId);
         db.DbMaintenance.AddColumn(input.TableName, column);
@@ -171,6 +172,7 @@ public class SysDatabaseService : IDynamicApiController, ITransient
     {
         var db = _db.AsTenant().GetConnectionScope(input.ConfigId);
         db.DbMaintenance.RenameColumn(input.TableName, input.OldColumnName, input.ColumnName);
+        db.DbMaintenance.AddDefaultValue(input.TableName, input.ColumnName, input.DefaultValue);
         if (db.DbMaintenance.IsAnyColumnRemark(input.ColumnName, input.TableName))
             db.DbMaintenance.DeleteColumnRemark(input.ColumnName, input.TableName);
         db.DbMaintenance.AddColumnRemark(input.ColumnName, input.TableName, string.IsNullOrWhiteSpace(input.Description) ? input.ColumnName : input.Description);
@@ -218,6 +220,7 @@ public class SysDatabaseService : IDynamicApiController, ITransient
                 IsNullable = u.IsNullable == 1,
                 DecimalDigits = u.DecimalDigits,
                 ColumnDescription = u.ColumnDescription,
+                DefaultValue = u.DefaultValue,
             });
         });
         db.CodeFirst.InitTables(typeBuilder.BuilderType());

+ 5 - 5
Admin.NET/Admin.NET.Web.Entry/wwwroot/template/Entity.cs.vm

@@ -29,17 +29,17 @@ public partial class @(Model.EntityName) @Model.BaseClassName
         propSuffix += $", Length = {column.Length}, DecimalDigits={column.DecimalDigits}";
     }
     
+    if(!string.IsNullOrWhiteSpace(column.DefaultValue)){
+        propSuffix +=$", DefaultValue = \"{column.DefaultValue}\"";
+    }
+
     @:/// <summary>
     @:/// @column.ColumnDescription
     @:/// </summary>
     if(!column.IsNullable){
     @:[Required]
     }
-    var DefaultValue="";
-    if(!string.IsNullOrWhiteSpace(column.DefaultValue)){
-    DefaultValue=$", DefaultValue = \"{column.DefaultValue}\"";
-    }
-    @:[SugarColumn(ColumnName = "@column.DbColumnName", ColumnDescription = "@column.ColumnDescription"@DefaultValue@propSuffix)]
+    @:[SugarColumn(ColumnName = "@column.DbColumnName", ColumnDescription = "@column.ColumnDescription"@propSuffix)]
     @:public virtual @column.DataType @column.PropertyName { get; set; }
     @:
 }

+ 69 - 65
Web/src/api-services/models/db-column-input.ts

@@ -1,82 +1,86 @@
 /* tslint:disable */
-/* eslint-disable */
+
 /**
  * Admin.NET 通用权限开发平台
  * 让 .NET 开发更简单、更通用、更流行。整合最新技术,模块插件式开发,前后端分离,开箱即用。<br/><u><b><font color='FF0000'> 👮不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!</font></b></u>
  *
  * OpenAPI spec version: 1.0.0
- * 
+ *
  *
  * NOTE: This class is auto generated by the swagger code generator program.
  * https://github.com/swagger-api/swagger-codegen.git
  * Do not edit the class manually.
  */
-
- /**
- * 
+/**
  *
  * @export
  * @interface DbColumnInput
  */
 export interface DbColumnInput {
-
-    /**
-     * @type {string}
-     * @memberof DbColumnInput
-     */
-    configId?: string | null;
-
-    /**
-     * @type {string}
-     * @memberof DbColumnInput
-     */
-    tableName?: string | null;
-
-    /**
-     * @type {string}
-     * @memberof DbColumnInput
-     */
-    dbColumnName?: string | null;
-
-    /**
-     * @type {string}
-     * @memberof DbColumnInput
-     */
-    dataType?: string | null;
-
-    /**
-     * @type {number}
-     * @memberof DbColumnInput
-     */
-    length?: number;
-
-    /**
-     * @type {string}
-     * @memberof DbColumnInput
-     */
-    columnDescription?: string | null;
-
-    /**
-     * @type {number}
-     * @memberof DbColumnInput
-     */
-    isNullable?: number;
-
-    /**
-     * @type {number}
-     * @memberof DbColumnInput
-     */
-    isIdentity?: number;
-
-    /**
-     * @type {number}
-     * @memberof DbColumnInput
-     */
-    isPrimarykey?: number;
-
-    /**
-     * @type {number}
-     * @memberof DbColumnInput
-     */
-    decimalDigits?: number;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof DbColumnInput
+	 */
+	configId?: string | null;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof DbColumnInput
+	 */
+	tableName?: string | null;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof DbColumnInput
+	 */
+	dbColumnName?: string | null;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof DbColumnInput
+	 */
+	dataType?: string | null;
+	/**
+	 *
+	 * @type {number}
+	 * @memberof DbColumnInput
+	 */
+	length?: number;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof DbColumnInput
+	 */
+	columnDescription?: string | null;
+	/**
+	 *
+	 * @type {number}
+	 * @memberof DbColumnInput
+	 */
+	isNullable?: number;
+	/**
+	 *
+	 * @type {number}
+	 * @memberof DbColumnInput
+	 */
+	isIdentity?: number;
+	/**
+	 *
+	 * @type {number}
+	 * @memberof DbColumnInput
+	 */
+	isPrimarykey?: number;
+	/**
+	 *
+	 * @type {number}
+	 * @memberof DbColumnInput
+	 */
+	decimalDigits?: number;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof DbColumnInput
+	 */
+	defaultValue?: string | null;
 }

+ 39 - 35
Web/src/api-services/models/update-db-column-input.ts

@@ -1,52 +1,56 @@
 /* tslint:disable */
-/* eslint-disable */
+
 /**
  * Admin.NET 通用权限开发平台
  * 让 .NET 开发更简单、更通用、更流行。整合最新技术,模块插件式开发,前后端分离,开箱即用。<br/><u><b><font color='FF0000'> 👮不得利用本项目从事危害国家安全、扰乱社会秩序、侵犯他人合法权益等法律法规禁止的活动!任何基于本项目二次开发而产生的一切法律纠纷和责任,我们不承担任何责任!</font></b></u>
  *
  * OpenAPI spec version: 1.0.0
- * 
+ *
  *
  * NOTE: This class is auto generated by the swagger code generator program.
  * https://github.com/swagger-api/swagger-codegen.git
  * Do not edit the class manually.
  */
-
- /**
- * 
+/**
  *
  * @export
  * @interface UpdateDbColumnInput
  */
 export interface UpdateDbColumnInput {
-
-    /**
-     * @type {string}
-     * @memberof UpdateDbColumnInput
-     */
-    configId?: string | null;
-
-    /**
-     * @type {string}
-     * @memberof UpdateDbColumnInput
-     */
-    tableName?: string | null;
-
-    /**
-     * @type {string}
-     * @memberof UpdateDbColumnInput
-     */
-    columnName?: string | null;
-
-    /**
-     * @type {string}
-     * @memberof UpdateDbColumnInput
-     */
-    oldColumnName?: string | null;
-
-    /**
-     * @type {string}
-     * @memberof UpdateDbColumnInput
-     */
-    description?: string | null;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof UpdateDbColumnInput
+	 */
+	configId?: string | null;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof UpdateDbColumnInput
+	 */
+	tableName?: string | null;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof UpdateDbColumnInput
+	 */
+	columnName?: string | null;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof UpdateDbColumnInput
+	 */
+	oldColumnName?: string | null;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof UpdateDbColumnInput
+	 */
+	description?: string | null;
+	/**
+	 *
+	 * @type {string}
+	 * @memberof DbColumnInput
+	 */
+	defaultValue?: string | null;
 }

+ 5 - 0
Web/src/views/system/database/component/addColumn.vue

@@ -57,6 +57,11 @@
 							<el-input-number v-model="state.ruleForm.decimalDigits" class="w100" controls-position="right" />
 						</el-form-item>
 					</el-col>
+					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
+						<el-form-item label="默认值" prop="defaultValue">
+							<el-input v-model="state.ruleForm.defaultValue" placeholder="默认值" clearable />
+						</el-form-item>
+					</el-col>
 				</el-row>
 			</el-form>
 			<template #footer>

+ 6 - 1
Web/src/views/system/database/component/addTable.vue

@@ -24,7 +24,7 @@
 			</el-form>
 			<el-divider content-position="left">数据列信息</el-divider>
 			<el-table :data="state.tableData" style="width: 100%" max-height="400">
-				<el-table-column prop="dbColumnName" label="字段名" width="220" fixed>
+				<el-table-column prop="dbColumnName" label="字段名" width="200" fixed>
 					<template #default="scope">
 						<el-input v-model="scope.row.dbColumnName" autocomplete="off" />
 					</template>
@@ -71,6 +71,11 @@
 					<template #default="scope">
 						<el-input-number v-model="scope.row.decimalDigits" controls-position="right" class="w100" />
 					</template>
+				</el-table-column>				
+				<el-table-column prop="defaultValue" label="默认值" width="90">
+					<template #default="scope">
+						<el-input v-model="scope.row.defaultValue" autocomplete="off" />
+					</template>
 				</el-table-column>
 				<el-table-column label="操作" min-width="200" align="center" fixed="right">
 					<template #default="scope">

+ 5 - 0
Web/src/views/system/database/component/editColumn.vue

@@ -19,6 +19,11 @@
 							<el-input v-model="state.ruleForm.description" placeholder="描述" clearable type="textarea" />
 						</el-form-item>
 					</el-col>
+					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
+						<el-form-item label="默认值" prop="defaultValue">
+							<el-input v-model="state.ruleForm.defaultValue" placeholder="默认值" clearable />
+						</el-form-item>
+					</el-col>
 				</el-row>
 			</el-form>
 			<template #footer>

+ 1 - 0
Web/src/views/system/database/index.vue

@@ -240,6 +240,7 @@ const openEditColumn = (row: any) => {
 		columnName: row.dbColumnName,
 		oldColumnName: row.dbColumnName,
 		description: row.columnDescription,
+		defaultValue: row.defaultValue,
 	};
 	editColumnRef.value?.openDialog(column);
 };