Przeglądaj źródła

添加多库代码生成

扶强 4 lat temu
rodzic
commit
3c0ee55804

+ 9 - 9
Admin.NET/Admin.NET.Application/AppConfig.json

@@ -2,15 +2,15 @@
   "ConnectionStrings": {
     "DefaultConnection": "DataSource=C:\\db\\Admin.NET.db",
     "DefaultDbType": "Sqlite", // MySql、SqlServer、Sqlite、Oracle、PostgreSQL、Dm、Kdbndp、Oscar、MySqlConnector、Access
-    "InitTable": true // 是否生成库表和种子数据
-    //"DbConfigs": [
-    //  {
-    //    "DbConfigId": "Test",
-    //    "DbType": "Sqlite",
-    //    "DbConnection": "DataSource=C:\\db\\Test.db"
-    //  }
-    //]
-  },
+    "InitTable": true, // 是否生成库表和种子数据
+    "DbConfigs": [
+      {
+        "DbConfigId": "Test",
+        "DbType": "Sqlite",
+        "DbConnection": "DataSource=C:\\db\\Test.db"
+      }
+    ]
+},
   "Wechat": {
     //公众号
     "WechatAppId": "",

+ 39 - 0
Admin.NET/Admin.NET.Application/Entity/Student.cs

@@ -0,0 +1,39 @@
+using Admin.NET.Application.Const;
+using Admin.NET.Core;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Admin.NET.Application.Entity
+{
+    /// <summary>
+    /// 多库代码生成测试学生表
+    /// </summary>
+    [SugarTable("d_student", "多库代码生成测试学生表")]
+    [SqlSugarEntity(DbConfigId = TestConst.ConfigId)]
+    public class Student : EntityBase
+    {
+        /// <summary>
+        /// 姓名
+        /// </summary>
+        [SugarColumn(ColumnDescription = "姓名", Length = 20)]
+        [Required, MaxLength(20)]
+        public string Name { get; set; }
+
+        /// <summary>
+        /// 年龄
+        /// </summary>
+        [SugarColumn(ColumnDescription = "年龄")]
+        public int Age { get; set; }
+
+        /// <summary>
+        /// 出生日期
+        /// </summary>
+        [SugarColumn(ColumnDescription = "出生日期")]
+        public DateTime BirthDate { get; set; }
+    }
+}

+ 33 - 0
Admin.NET/Admin.NET.Application/Entity/TreeTest.cs

@@ -0,0 +1,33 @@
+using Admin.NET.Application.Const;
+using Admin.NET.Core;
+using SqlSugar;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Admin.NET.Application.Entity
+{
+    /// <summary>
+    /// 多库代码生成树形测试表
+    /// </summary>
+    [SugarTable("d_treetest", "多库代码生成树形测试表")]
+    [SqlSugarEntity(DbConfigId = TestConst.ConfigId)]
+    public class TreeTest : EntityBase
+    {
+        /// <summary>
+        /// 名称
+        /// </summary>
+        public string Name { get; set; }
+        /// <summary>
+        /// 父级
+        /// </summary>
+        public long ParentId { get; set; }//父级字段
+        /// <summary>
+        /// Child
+        /// </summary>
+        [SqlSugar.SugarColumn(IsIgnore = true)]
+        public List<TreeTest> Child { get; set; }
+    }
+}

+ 88 - 2
Admin.NET/Admin.NET.Core/Admin.NET.Core.xml

@@ -221,6 +221,16 @@
             默认表主键
             </summary>
         </member>
+        <member name="T:Admin.NET.Core.SqlSugarDb">
+            <summary>
+            SqlSugar数据库链接集合(多库代码生成用)
+            </summary>
+        </member>
+        <member name="F:Admin.NET.Core.SqlSugarDb.connectionConfigs">
+            <summary>
+            SqlSugar数据库链接集合
+            </summary>
+        </member>
         <member name="T:Admin.NET.Core.EntityBaseId">
             <summary>
             框架实体基类Id
@@ -301,6 +311,26 @@
             生成方式
             </summary>
         </member>
+        <member name="P:Admin.NET.Core.SysCodeGen.DbConfigId">
+            <summary>
+            库定位器名
+            </summary>
+        </member>
+        <member name="P:Admin.NET.Core.SysCodeGen.DbName">
+            <summary>
+            数据库名(保留字段)
+            </summary>
+        </member>
+        <member name="P:Admin.NET.Core.SysCodeGen.DbType">
+            <summary>
+            数据库类型
+            </summary>
+        </member>
+        <member name="P:Admin.NET.Core.SysCodeGen.ConnectionString">
+            <summary>
+            数据库链接
+            </summary>
+        </member>
         <member name="P:Admin.NET.Core.SysCodeGen.TableName">
             <summary>
             数据库表名
@@ -3049,13 +3079,19 @@
             <param name="input"></param>
             <returns></returns>
         </member>
-        <member name="M:Admin.NET.Core.Service.CodeGen.CodeGenService.GetTableList">
+        <member name="M:Admin.NET.Core.Service.CodeGen.CodeGenService.GetDatabaseList">
+            <summary>
+            获取数据库库集合
+            </summary>
+            <returns></returns>
+        </member>
+        <member name="M:Admin.NET.Core.Service.CodeGen.CodeGenService.GetTableList(System.String)">
             <summary>
             获取数据库表(实体)集合
             </summary>
             <returns></returns>
         </member>
-        <member name="M:Admin.NET.Core.Service.CodeGen.CodeGenService.GetColumnListByTableName(System.String)">
+        <member name="M:Admin.NET.Core.Service.CodeGen.CodeGenService.GetColumnListByTableName(System.String,System.String)">
             <summary>
             根据表名获取列
             </summary>
@@ -3253,6 +3289,26 @@
             是否移除表前缀
             </summary>
         </member>
+        <member name="P:Admin.NET.Core.Service.CodeGenInput.DbConfigId">
+            <summary>
+            库定位器名
+            </summary>
+        </member>
+        <member name="P:Admin.NET.Core.Service.CodeGenInput.DbName">
+            <summary>
+            数据库名(保留字段)
+            </summary>
+        </member>
+        <member name="P:Admin.NET.Core.Service.CodeGenInput.DbType">
+            <summary>
+            数据库类型
+            </summary>
+        </member>
+        <member name="P:Admin.NET.Core.Service.CodeGenInput.ConnectionString">
+            <summary>
+            数据库链接
+            </summary>
+        </member>
         <member name="P:Admin.NET.Core.Service.CodeGenInput.GenerateType">
             <summary>
             生成方式
@@ -3388,6 +3444,31 @@
             菜单父级
             </summary>
         </member>
+        <member name="P:Admin.NET.Core.Service.CustomViewEngine.DbConfigId">
+            <summary>
+            库定位器
+            </summary>
+        </member>
+        <member name="T:Admin.NET.Core.Service.DatabaseOutput">
+            <summary>
+            多库代码生成库列表输出
+            </summary>
+        </member>
+        <member name="P:Admin.NET.Core.Service.DatabaseOutput.DbConfigId">
+            <summary>
+            库定位器名
+            </summary>
+        </member>
+        <member name="P:Admin.NET.Core.Service.DatabaseOutput.DbType">
+            <summary>
+            数据库类型
+            </summary>
+        </member>
+        <member name="P:Admin.NET.Core.Service.DatabaseOutput.ConnectionString">
+            <summary>
+            数据库连接字符串
+            </summary>
+        </member>
         <member name="T:Admin.NET.Core.Service.TableColumnOuput">
             <summary>
             数据库表列
@@ -3423,6 +3504,11 @@
             数据库表列表参数
             </summary>
         </member>
+        <member name="P:Admin.NET.Core.Service.TableOutput.DbConfigId">
+            <summary>
+            库定位器名
+            </summary>
+        </member>
         <member name="P:Admin.NET.Core.Service.TableOutput.TableName">
             <summary>
             表名(字母形式的)

+ 15 - 1
Admin.NET/Admin.NET.Core/Const/SqlSugarConst.cs

@@ -1,4 +1,7 @@
-namespace Admin.NET.Core
+using SqlSugar;
+using System.Collections.Generic;
+
+namespace Admin.NET.Core
 {
     /// <summary>
     /// SqlSugar相关常量
@@ -15,4 +18,15 @@
         /// </summary>
         public const string PrimaryKey = "Id";
     }
+
+    /// <summary>
+    /// SqlSugar数据库链接集合(多库代码生成用)
+    /// </summary>
+    public class SqlSugarDb
+    {
+        /// <summary>
+        /// SqlSugar数据库链接集合
+        /// </summary>
+        public static List<ConnectionConfig> connectionConfigs = new List<ConnectionConfig>();
+    }
 }

+ 28 - 0
Admin.NET/Admin.NET.Core/Entity/SysCodeGen.cs

@@ -31,6 +31,34 @@ namespace Admin.NET.Core
         [SugarColumn(ColumnDescription = "生成方式")]
         public string GenerateType { get; set; }
 
+        /// <summary>
+        /// 库定位器名
+        /// </summary>
+        [MaxLength(50)]
+        [SugarColumn(ColumnDescription = "库定位器名")]
+        public string DbConfigId { get; set; }
+
+        /// <summary>
+        /// 数据库名(保留字段)
+        /// </summary>
+        [MaxLength(50)]
+        [SugarColumn(ColumnDescription = "数据库库名")]
+        public string DbName { get; set; }
+
+        /// <summary>
+        /// 数据库类型
+        /// </summary>
+        [MaxLength(50)]
+        [SugarColumn(ColumnDescription = "数据库类型")]
+        public string DbType { get; set; }
+
+        /// <summary>
+        /// 数据库链接
+        /// </summary>
+        [MaxLength(200)]
+        [SugarColumn(ColumnDescription = "数据库链接")]
+        public string ConnectionString { get; set; }
+
         /// <summary>
         /// 数据库表名
         /// </summary>

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

@@ -131,6 +131,8 @@ namespace Admin.NET.Core.Service
                 codeGenConfig.QueryType = "=="; // QueryTypeEnum.eq.ToString();
                 codeGenConfigs.Add(codeGenConfig);
             }
+            //多库代码生成,这里要切回主库
+            _sysCodeGenConfigRep.Context.AsTenant().ChangeDatabase(SqlSugarConst.ConfigId);
             _sysCodeGenConfigRep.Context.Insertable(codeGenConfigs).ExecuteCommand();
         }
     }

+ 44 - 4
Admin.NET/Admin.NET.Core/Service/CodeGen/CodeGenService.cs

@@ -121,19 +121,50 @@ namespace Admin.NET.Core.Service.CodeGen
             return await _sysCodeGenRep.AsQueryable().SingleAsync(m => m.Id == input.Id);
         }
 
+        /// <summary>
+        /// 获取数据库库集合
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("codeGenerate/DatabaseList")]
+        public async Task<List<DatabaseOutput>> GetDatabaseList()
+        {
+            List<ConnectionConfig> list = SqlSugarDb.connectionConfigs;
+            var result = new List<DatabaseOutput>();
+            foreach (var item in list)
+            {
+                result.Add(new DatabaseOutput()
+                {
+                    DbConfigId = item.ConfigId,
+                    DbType = item.DbType.ToString(),
+                    ConnectionString = item.ConnectionString,
+                });
+            }
+            return await Task.FromResult(result);
+        }
+
+
         /// <summary>
         /// 获取数据库表(实体)集合
         /// </summary>
         /// <returns></returns>
-        [HttpGet("/codeGenerate/InformationList")]
-        public async Task<List<TableOutput>> GetTableList()
+        [HttpGet("/codeGenerate/InformationList/{dbConfigId}")]
+        public async Task<List<TableOutput>> GetTableList(string dbConfigId = SqlSugarConst.ConfigId)
         {
+            //切库,多库代码生成用
+            if (dbConfigId != SqlSugarConst.ConfigId)
+                _sysCodeGenRep.Context.AsTenant().ChangeDatabase(dbConfigId);
+
+            List<DbTableInfo> dbTableInfos = _sysCodeGenRep.Context.DbMaintenance.GetTableInfoList(false);//这里不能走缓存,否则切库不起作用
+            List<string> dbTableNames = dbTableInfos.Select(x => x.Name).ToList();
+
             IEnumerable<EntityInfo> entityInfos = await _commonService.GetEntityInfos();
+            entityInfos = entityInfos.Where(x => dbTableNames.Contains(x.DbTableName));
             var result = new List<TableOutput>();
             foreach (var item in entityInfos)
             {
                 result.Add(new TableOutput()
                 {
+                    DbConfigId = dbConfigId,
                     EntityName = item.EntityName,
                     TableName = item.DbTableName,
                     TableComment = item.TableDescription
@@ -146,9 +177,13 @@ namespace Admin.NET.Core.Service.CodeGen
         /// 根据表名获取列
         /// </summary>
         /// <returns></returns>
-        [HttpGet("/codeGenerate/ColumnList/{tableName}")]
-        public List<TableColumnOuput> GetColumnListByTableName(string tableName)
+        [HttpGet("/codeGenerate/ColumnList/{dbConfigId}/{tableName}")]
+        public List<TableColumnOuput> GetColumnListByTableName(string tableName, string dbConfigId = SqlSugarConst.ConfigId)
         {
+            //切库,多库代码生成用
+            if (dbConfigId != SqlSugarConst.ConfigId)
+                _sysCodeGenRep.Context.AsTenant().ChangeDatabase(dbConfigId);
+
             // 获取实体类型属性
             var entityType = _sysCodeGenRep.Context.DbMaintenance.GetTableInfoList().FirstOrDefault(u => u.Name == tableName);
             if (entityType == null) return null;
@@ -171,6 +206,10 @@ namespace Admin.NET.Core.Service.CodeGen
         [NonAction]
         public List<TableColumnOuput> GetColumnList([FromQuery] AddCodeGenInput input)
         {
+            //切库,多库代码生成用
+            if (!string.IsNullOrEmpty(input.DbConfigId) && input.DbConfigId != SqlSugarConst.ConfigId)
+                _sysCodeGenRep.Context.AsTenant().ChangeDatabase(input.DbConfigId);
+
             var entityType = _commonService.GetEntityInfos().Result.FirstOrDefault(m => m.EntityName == input.TableName);
             if (entityType == null)
                 return null;
@@ -205,6 +244,7 @@ namespace Admin.NET.Core.Service.CodeGen
 
                 var data = new CustomViewEngine(_sysCodeGenRep)
                 {
+                    DbConfigId = input.DbConfigId,
                     AuthorName = input.AuthorName,
                     BusName = input.BusName,
                     NameSpace = input.NameSpace,

+ 20 - 0
Admin.NET/Admin.NET.Core/Service/CodeGen/Dto/CodeGenInput.cs

@@ -22,6 +22,26 @@ namespace Admin.NET.Core.Service
         /// </summary>
         public virtual string TablePrefix { get; set; }
 
+        /// <summary>
+        /// 库定位器名
+        /// </summary>
+        public virtual string DbConfigId { get; set; }
+
+        /// <summary>
+        /// 数据库名(保留字段)
+        /// </summary>
+        public virtual string DbName { get; set; }
+
+        /// <summary>
+        /// 数据库类型
+        /// </summary>
+        public virtual string DbType { get; set; }
+
+        /// <summary>
+        /// 数据库链接
+        /// </summary>
+        public virtual string ConnectionString { get; set; }
+
         /// <summary>
         /// 生成方式
         /// </summary>

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

@@ -18,6 +18,11 @@ namespace Admin.NET.Core.Service
             _sysCodeGenRep = sysCodeGenRep;
         }
 
+        /// <summary>
+        /// 库定位器
+        /// </summary>
+        public string DbConfigId { get; set; } = SqlSugarConst.ConfigId;
+
         public string AuthorName { get; set; }
 
         public string BusName { get; set; }
@@ -47,11 +52,17 @@ namespace Admin.NET.Core.Service
         {
             ColumnList = GetColumnListByTableName(tbName.ToString());
             var col = ColumnList.Where(c => c.ColumnName == colName.ToString()).FirstOrDefault();
+            //多库代码生成切库调用后切换回原库
+            _sysCodeGenRep.Context.AsTenant().ChangeDatabase(SqlSugarConst.ConfigId);
             return col.NetType;
         }
 
         public List<TableColumnOuput> GetColumnListByTableName(string tableName)
         {
+            //多库代码生成切换库
+            if (DbConfigId != SqlSugarConst.ConfigId)
+                _sysCodeGenRep.Context.AsTenant().ChangeDatabase(DbConfigId);
+
             // 获取实体类型属性
             var entityType = _sysCodeGenRep.Context.DbMaintenance.GetTableInfoList().FirstOrDefault(u => u.Name == tableName);
             if (entityType == null) return null;

+ 27 - 0
Admin.NET/Admin.NET.Core/Service/CodeGen/Dto/DatabaseOutput.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Admin.NET.Core.Service
+{
+    /// <summary>
+    /// 多库代码生成库列表输出
+    /// </summary>
+    public class DatabaseOutput
+    {
+        /// <summary>
+        /// 库定位器名
+        /// </summary>
+        public dynamic DbConfigId { get; set; }
+        /// <summary>
+        /// 数据库类型
+        /// </summary>
+        public string DbType { get; set; }
+        /// <summary>
+        /// 数据库连接字符串
+        /// </summary>
+        public string ConnectionString { get; set; }
+    }
+}

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

@@ -5,6 +5,11 @@
     /// </summary>
     public class TableOutput
     {
+        /// <summary>
+        /// 库定位器名
+        /// </summary>
+        public string DbConfigId { get; set; }
+
         /// <summary>
         /// 表名(字母形式的)
         /// </summary>

+ 2 - 1
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -30,7 +30,8 @@ namespace Admin.NET.Core
                 var dbOptions = App.GetOptions<ConnectionStringsOptions>();
                 DealConnectionStr(ref dbOptions); // 处理本地库根目录路径
 
-                var connectionConfigs = new List<ConnectionConfig>();
+                // var connectionConfigs = new List<ConnectionConfig>();
+                var connectionConfigs = SqlSugarDb.connectionConfigs; //方便多库生成
                 var configureExternalServices = new ConfigureExternalServices
                 {
                     EntityService = (type, column) => // 修改列可空

+ 9 - 4
Vben2/src/api/sys/admin.ts

@@ -8,6 +8,7 @@ enum Api {
   UserPageList = '/sysUser/pageList',
   AddUser = '/sysUser/add',
   DeleteUser = '/sysUser/delete',
+  GetDatabaseList = '/codeGenerate/DatabaseList',
   UpdateUser = '/sysUser/update',
   SetUserStatus = '/sysUser/setStatus',
   GrantUserRole = '/sysUser/grantRole',
@@ -366,13 +367,17 @@ export function deleGenerate(params: any) {
     params,
   });
 }
+// 获取数据库(上下文定位器)集合
+export function getDatabaseList(params?: any) {
+  return defHttp.get<any>({ url: Api.GetDatabaseList, params });
+}
 // 获取数据库表(实体)集合
-export function getTableList(params?: any) {
-  return defHttp.get<any>({ url: Api.GetTableList, params });
+export function getTableList(dbConfigId: string) {
+  return defHttp.get<any>({ url: Api.GetTableList + '/' + dbConfigId });
 }
 // 根据表名获取列
-export function getColumnList(tableName: string) {
-  return defHttp.get<any>({ url: Api.GetColumnList + '/' + tableName });
+export function getColumnList(dbConfigId: string, tableName: string) {
+  return defHttp.get<any>({ url: Api.GetColumnList + '/' + dbConfigId + '/' + tableName });
 }
 // 本地生成
 export function generateRunLocal(params: any) {

+ 326 - 74
Vben2/src/views/sys/admin/code/codeGenerate.data.ts

@@ -1,29 +1,55 @@
 import { BasicColumn } from '/@/components/Table';
 import { FormSchema } from '/@/components/Table';
-import { getMenuList, getDictDataDropdown, getTableList, getColumnList } from '/@/api/sys/admin';
+import {
+  getMenuList,
+  getDictDataDropdown,
+  getDatabaseList,
+  getTableList,
+  getColumnList,
+} from '/@/api/sys/admin';
 
-const apiTableList = async (param: any) => {
-  const result = await getTableList(param);
+const apiDatabaseList = async (param: any) => {
+  const result = await getDatabaseList(param);
   return result;
 };
+let currentCongidId = '';
+let tableList: any[] = [];
+const apiTableList = async (param: any) => {
+  //const result = await getTableList(param);
+  //return result;
+  if (tableList.length === 0 || currentCongidId !== param) {
+    //console.log(param);
+    const result = await getTableList(param);
+    tableList = result;
+  } else {
+  }
+  currentCongidId = param;
+  return tableList;
+};
 let currentTable = '';
 let columnList: any[] = [];
 const apiColumnList = async (param: any) => {
-  if (typeof param !== 'string') return [];
-  if (columnList.length === 0 || currentTable !== param) {
-    const result = await getColumnList(param);
+  //if (typeof param !== 'string') return [];
+  if (columnList.length === 0 || currentTable !== param.e) {
+    //console.log('param:' + param);
+    const result = await getColumnList(param.dbConfigId, param.e);
     columnList = result;
   } else {
   }
-  currentTable = param;
+  currentTable = param.e;
   return columnList;
 };
+
 const apiDictTypeDropDown = async () => {
   const result = await getDictDataDropdown('code_gen_create_type');
   return result;
 };
 
 export const codeShowColumns: BasicColumn[] = [
+  {
+    title: '库定位器',
+    dataIndex: 'dbConfigId',
+  },
   {
     title: '表名称',
     dataIndex: 'tableName',
@@ -54,17 +80,87 @@ export const codeFormSchema: FormSchema[] = [
     component: 'Input',
     show: false,
   },
+  {
+    field: 'dbConfigId',
+    label: '库定位器',
+    component: 'ApiSelect',
+    componentProps: ({ formModel, formActionType }) => {
+      return {
+        api: apiDatabaseList,
+        fieldNames: {
+          label: 'dbConfigId',
+          value: 'dbConfigId',
+        },
+        onChange: (e: any, option: any) => {
+          formModel.tableName = undefined;
+          formModel.dbType = option.dbType;
+          formModel.connectionString = option.connectionString;
+          const { updateSchema } = formActionType;
+          updateSchema([
+            {
+              field: 'dbType',
+              componentProps: {
+                // api: apiTableList,
+                // immediate: false,
+                // params: e,
+                //fieldNames: {
+                //  label: 'dbType',
+                //  value: 'dbType',
+                //},
+              },
+            },
+            {
+              field: 'connectionString',
+              componentProps: {
+                // api: apiTableList,
+                // immediate: false,
+                // params: e,
+                //fieldNames: {
+                //  label: 'connectionString',
+                //  value: 'connectionString',
+                //},
+              },
+            },
+            {
+              field: 'tableName',
+              componentProps: {
+                api: apiTableList,
+                immediate: false,
+                params: e,
+                fieldNames: {
+                  label: 'tableName',
+                  value: 'entityName',
+                },
+              },
+            },
+          ]);
+        },
+      };
+    },
+  },
+  {
+    field: 'dbType',
+    label: '数据库类型',
+    component: 'Input',
+    dynamicDisabled: true,
+  },
+  {
+    field: 'connectionString',
+    label: '链接串',
+    component: 'InputTextArea',
+    dynamicDisabled: true,
+  },
   {
     field: 'tableName',
     label: '生成表',
     component: 'ApiSelect',
-    componentProps: {
-      api: apiTableList,
-      fieldNames: {
-        label: 'tableName',
-        value: 'entityName',
-      },
-    },
+    // componentProps: {
+    //   api: apiTableList,
+    //   fieldNames: {
+    //     label: 'tableName',
+    //     value: 'entityName',
+    //   },
+    // },
   },
   {
     field: 'busName',
@@ -200,41 +296,109 @@ export const columns = [
   },
 ];
 
+//外键
 export const fkFormSchema: FormSchema[] = [
   {
-    field: 'tableName',
-    label: '数据库表',
+    field: 'dbConfigId',
+    label: '库定位器',
     component: 'ApiSelect',
     componentProps: ({ formModel, formActionType }) => {
       return {
-        api: apiTableList,
+        api: apiDatabaseList,
         fieldNames: {
-          label: 'tableName',
-          value: 'tableName',
+          label: 'dbConfigId',
+          value: 'dbConfigId',
         },
         onChange: (e: any, option: any) => {
-          formModel.columnName = undefined;
-          formModel.entityName = option.entityName;
+          formModel.tableName = option.tableName;
+          formModel.dbType = option.dbType;
+          formModel.connectionString = option.connectionString;
           const { updateSchema } = formActionType;
-          updateSchema({
-            field: 'columnName',
-            componentProps: {
-              api: apiColumnList,
-              immediate: false,
-              fieldNames: {
-                label: 'columnName',
-                value: 'columnName',
-              },
-              params: e,
-              onChange: (e: any, option: any) => {
-                formModel.columnNetType = option.netType;
+          const dbConfigId = e;
+          console.log('dbchange' + dbConfigId);
+          updateSchema([
+            {
+              field: 'tableName',
+              label: '数据库表',
+              component: 'ApiSelect',
+              componentProps: ({ formModel, formActionType }) => {
+                return {
+                  api: apiTableList,
+                  immediate: false,
+                  params: e,
+                  fieldNames: {
+                    label: 'tableName',
+                    value: 'tableName',
+                  },
+                  onChange: (e: any, option: any) => {
+                    formModel.columnName = undefined;
+                    formModel.entityName = option.entityName;
+                    const { updateSchema } = formActionType;
+                    console.log('tableNamechange' + dbConfigId);
+                    updateSchema({
+                      field: 'columnName',
+                      componentProps: {
+                        api: apiColumnList,
+                        immediate: false,
+                        fieldNames: {
+                          label: 'columnName',
+                          value: 'columnName',
+                        },
+                        params: { dbConfigId, e },
+                        onChange: (e: any, option: any) => {
+                          console.log(e + 'columnNamechange' + dbConfigId);
+                          formModel.columnNetType = option.netType;
+                        },
+                      },
+                    });
+                  },
+                };
               },
             },
-          });
+          ]);
         },
       };
     },
   },
+  // {
+  //   field: 'tableName',
+  //   label: '数据库表',
+  //   component: 'ApiSelect',
+  //   componentProps: ({ formModel, formActionType }) => {
+  //     return {
+  //       api: apiTableList,
+  //       fieldNames: {
+  //         label: 'tableName',
+  //         value: 'tableName',
+  //       },
+  //       onChange: (e: any, option: any) => {
+  //         formModel.columnName = undefined;
+  //         formModel.entityName = option.entityName;
+  //         const { updateSchema } = formActionType;
+  //         updateSchema({
+  //           field: 'columnName',
+  //           componentProps: {
+  //             api: apiColumnList,
+  //             immediate: false,
+  //             fieldNames: {
+  //               label: 'columnName',
+  //               value: 'columnName',
+  //             },
+  //             params: e,
+  //             onChange: (e: any, option: any) => {
+  //               formModel.columnNetType = option.netType;
+  //             },
+  //           },
+  //         });
+  //       },
+  //     };
+  //   },
+  // },
+  {
+    field: 'tableName',
+    label: '数据库表',
+    component: 'ApiSelect',
+  },
   {
     field: 'columnName',
     label: '显示字段',
@@ -254,57 +418,83 @@ export const fkFormSchema: FormSchema[] = [
   },
 ];
 
+//树形
 export const treeFormSchema: FormSchema[] = [
   {
-    field: 'tableName',
-    label: '数据库表',
+    field: 'dbConfigId',
+    label: '库定位器',
     component: 'ApiSelect',
     componentProps: ({ formModel, formActionType }) => {
       return {
-        api: apiTableList,
+        api: apiDatabaseList,
         fieldNames: {
-          label: 'tableName',
-          value: 'tableName',
+          label: 'dbConfigId',
+          value: 'dbConfigId',
         },
         onChange: (e: any, option: any) => {
-          formModel.columnName = undefined;
-          formModel.entityName = option.entityName;
+          formModel.tableName = undefined;
+          formModel.dbType = option.dbType;
+          formModel.connectionString = option.connectionString;
           const { updateSchema } = formActionType;
+          const dbConfigId = e;
           updateSchema([
             {
-              field: 'displayColumn',
-              componentProps: {
-                api: apiColumnList,
-                immediate: false,
-                params: e,
-                fieldNames: {
-                  label: 'columnName',
-                  value: 'columnName',
-                },
-              },
-            },
-            {
-              field: 'valueColumn',
-              componentProps: {
-                api: apiColumnList,
-                immediate: false,
-                params: e,
-                fieldNames: {
-                  label: 'columnName',
-                  value: 'columnName',
-                },
-              },
-            },
-            {
-              field: 'pidColumn',
-              componentProps: {
-                api: apiColumnList,
-                immediate: false,
-                params: e,
-                fieldNames: {
-                  label: 'columnName',
-                  value: 'columnName',
-                },
+              field: 'tableName',
+              label: '数据库表',
+              component: 'ApiSelect',
+              componentProps: ({ formModel, formActionType }) => {
+                return {
+                  api: apiTableList,
+                  immediate: false,
+                  params: e,
+                  fieldNames: {
+                    label: 'tableName',
+                    value: 'tableName',
+                  },
+                  onChange: (e: any, option: any) => {
+                    formModel.columnName = undefined;
+                    formModel.entityName = option.entityName;
+                    const { updateSchema } = formActionType;
+                    updateSchema([
+                      {
+                        field: 'displayColumn',
+                        componentProps: {
+                          api: apiColumnList,
+                          immediate: false,
+                          params: { dbConfigId, e },
+                          fieldNames: {
+                            label: 'columnName',
+                            value: 'columnName',
+                          },
+                        },
+                      },
+                      {
+                        field: 'valueColumn',
+                        componentProps: {
+                          api: apiColumnList,
+                          immediate: false,
+                          params: { dbConfigId, e },
+                          fieldNames: {
+                            label: 'columnName',
+                            value: 'columnName',
+                          },
+                        },
+                      },
+                      {
+                        field: 'pidColumn',
+                        componentProps: {
+                          api: apiColumnList,
+                          immediate: false,
+                          params: { dbConfigId, e },
+                          fieldNames: {
+                            label: 'columnName',
+                            value: 'columnName',
+                          },
+                        },
+                      },
+                    ]);
+                  },
+                };
               },
             },
           ]);
@@ -312,6 +502,68 @@ export const treeFormSchema: FormSchema[] = [
       };
     },
   },
+  // {
+  //   field: 'tableName',
+  //   label: '数据库表',
+  //   component: 'ApiSelect',
+  //   componentProps: ({ formModel, formActionType }) => {
+  //     return {
+  //       api: apiTableList,
+  //       fieldNames: {
+  //         label: 'tableName',
+  //         value: 'tableName',
+  //       },
+  //       onChange: (e: any, option: any) => {
+  //         formModel.columnName = undefined;
+  //         formModel.entityName = option.entityName;
+  //         const { updateSchema } = formActionType;
+  //         updateSchema([
+  //           {
+  //             field: 'displayColumn',
+  //             componentProps: {
+  //               api: apiColumnList,
+  //               immediate: false,
+  //               params: e,
+  //               fieldNames: {
+  //                 label: 'columnName',
+  //                 value: 'columnName',
+  //               },
+  //             },
+  //           },
+  //           {
+  //             field: 'valueColumn',
+  //             componentProps: {
+  //               api: apiColumnList,
+  //               immediate: false,
+  //               params: e,
+  //               fieldNames: {
+  //                 label: 'columnName',
+  //                 value: 'columnName',
+  //               },
+  //             },
+  //           },
+  //           {
+  //             field: 'pidColumn',
+  //             componentProps: {
+  //               api: apiColumnList,
+  //               immediate: false,
+  //               params: e,
+  //               fieldNames: {
+  //                 label: 'columnName',
+  //                 value: 'columnName',
+  //               },
+  //             },
+  //           },
+  //         ]);
+  //       },
+  //     };
+  //   },
+  // },
+  {
+    field: 'tableName',
+    label: '数据库表',
+    component: 'ApiSelect',
+  },
   {
     field: 'displayColumn',
     label: '显示文本字段',

+ 2 - 1
Vben2/src/views/sys/admin/code/fkModal.vue

@@ -16,10 +16,11 @@
       var row: any = {};
       const [registerForm, { resetFields, validate }] = useForm({
         labelWidth: 100,
+        baseColProps: { span: 12 },
         schemas: fkFormSchema,
         showActionButtonGroup: false,
         actionColOptions: {
-          span: 23,
+          span: 24,
         },
       });
       const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {

+ 2 - 1
Vben2/src/views/sys/admin/code/treeModal.vue

@@ -16,10 +16,11 @@
       var row: any = {};
       const [registerForm, { resetFields, validate }] = useForm({
         labelWidth: 100,
+        baseColProps: { span: 12 },
         schemas: treeFormSchema,
         showActionButtonGroup: false,
         actionColOptions: {
-          span: 23,
+          span: 24,
         },
       });
       const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {