Просмотр исходного кода

1、优化租户业务库模式 2、增加租户业务表示例 3、其他优化

zuohuaijun 3 лет назад
Родитель
Сommit
fc39c76bf5

+ 28 - 0
Admin.NET/Admin.NET.Application/Entity/Business.cs

@@ -0,0 +1,28 @@
+namespace Admin.NET.Application.Entity;
+
+/// <summary>
+/// 租户业务分库表
+/// </summary>
+[SugarTable("d_tenant_business", "租户业务分库表")]
+[TenantBusiness]
+public class TenantBusiness : EntityBase
+{
+    /// <summary>
+    /// 姓名
+    /// </summary>
+    [SugarColumn(ColumnDescription = "姓名", Length = 32)]
+    [Required, MaxLength(32)]
+    public virtual string Name { get; set; }
+
+    /// <summary>
+    /// 年龄
+    /// </summary>
+    [SugarColumn(ColumnDescription = "年龄")]
+    public int Age { get; set; }
+
+    /// <summary>
+    /// 出生日期
+    /// </summary>
+    [SugarColumn(ColumnDescription = "出生日期")]
+    public DateTime BirthDate { get; set; }
+}

+ 34 - 0
Admin.NET/Admin.NET.Application/Service/TenantBusinessService.cs

@@ -0,0 +1,34 @@
+namespace Admin.NET.Application.Service;
+
+/// <summary>
+/// 租户业务服务
+/// </summary>
+[ApiDescriptionSettings("租户业务服务", Order = 200)]
+public class TenantBusinessService : IDynamicApiController, ITransient
+{
+    private readonly SqlSugarRepository<TenantBusiness> _tenantBusinessRep;
+
+    public TenantBusinessService(SqlSugarRepository<TenantBusiness> businessRep)
+    {
+        _tenantBusinessRep = businessRep;
+    }
+
+    /// <summary>
+    /// 增加租户业务数据
+    /// </summary>
+    /// <returns></returns>
+    public async Task<bool> AddBusiness()
+    {
+        var tenantBusiness = new TenantBusiness() { Name = "zuohuaijun" };
+        return await _tenantBusinessRep.InsertAsync(tenantBusiness);
+    }
+
+    /// <summary>
+    /// 查询租户业务数据
+    /// </summary>
+    /// <returns></returns>
+    public async Task<List<TenantBusiness>> GetBusinessList()
+    {
+        return await _tenantBusinessRep.GetListAsync();
+    }
+}

+ 4 - 4
Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj

@@ -25,9 +25,9 @@
   <ItemGroup>
     <PackageReference Include="AngleSharp" Version="0.17.1" />
     <PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" />
-    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.7.5" />
-    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.7.5" />
-    <PackageReference Include="Furion.Pure" Version="4.7.5" />
+    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.7.6" />
+    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.7.6" />
+    <PackageReference Include="Furion.Pure" Version="4.7.6" />
     <PackageReference Include="Lazy.Captcha.Core" Version="1.1.6" />
     <PackageReference Include="Magicodes.IE.Excel" Version="2.7.0" />
     <PackageReference Include="Magicodes.IE.Pdf" Version="2.7.0" />
@@ -38,7 +38,7 @@
     <PackageReference Include="OnceMi.AspNetCore.OSS" Version="1.1.9" />
     <PackageReference Include="SKIT.FlurlHttpClient.Wechat.Api" Version="2.20.1" />
     <PackageReference Include="SKIT.FlurlHttpClient.Wechat.TenpayV3" Version="2.13.1" />
-    <PackageReference Include="SqlSugarCore" Version="5.1.3.30" />
+    <PackageReference Include="SqlSugarCore" Version="5.1.3.32" />
     <PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.22" />
     <PackageReference Include="UAParser" Version="3.1.47" />
     <PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />

+ 17 - 6
Admin.NET/Admin.NET.Core/Admin.NET.Core.xml

@@ -19,6 +19,11 @@
             非实体表特性
             </summary>
         </member>
+        <member name="T:Admin.NET.Core.TenantBusinessAttribute">
+            <summary>
+            租户业务表特性
+            </summary>
+        </member>
         <member name="M:Admin.NET.Core.CacheSetup.AddCache(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
             <summary>
             缓存注册(新生命Redis组件)
@@ -6187,7 +6192,7 @@
         </member>
         <member name="M:Admin.NET.Core.Service.SysTenantService.CreateTenantDb(Admin.NET.Core.Service.TenantInput)">
             <summary>
-            创建租户数据库(根据默认库结构)
+            创建租户数据库
             </summary>
             <param name="input"></param>
             <returns></returns>
@@ -6882,21 +6887,27 @@
             </summary>
             <param name="db"></param>
         </member>
-        <member name="M:Admin.NET.Core.SqlSugarSetup.InitDatabase(SqlSugar.ITenant,Admin.NET.Core.DbConnectionConfig,System.Int64)">
+        <member name="M:Admin.NET.Core.SqlSugarSetup.InitDatabase(SqlSugar.SqlSugarScope,Admin.NET.Core.DbConnectionConfig)">
             <summary>
-            初始化数据库结构
+            初始化数据库
             </summary>
             <param name="db"></param>
             <param name="config"></param>
-            <param name="tenantId"></param>
         </member>
-        <member name="M:Admin.NET.Core.SqlSugarSetup.InitTenantDb(SqlSugar.ITenant,System.Int64)">
+        <member name="M:Admin.NET.Core.SqlSugarSetup.InitTenantConnection(SqlSugar.ITenant,System.Int64)">
             <summary>
-            增加租户库连接
+            初始化租户库连接
             </summary>
             <param name="iTenant"></param>
             <param name="tenantId"></param>
         </member>
+        <member name="M:Admin.NET.Core.SqlSugarSetup.InitTenantDatabase(SqlSugar.ITenant,Admin.NET.Core.DbConnectionConfig)">
+            <summary>
+            初始化租户业务数据库
+            </summary>
+            <param name="itenant"></param>
+            <param name="config"></param>
+        </member>
         <member name="M:Admin.NET.Core.SqlSugarSetup.SetDeletedEntityFilter(SqlSugar.SqlSugarScopeProvider)">
             <summary>
             配置实体假删除过滤器

+ 10 - 0
Admin.NET/Admin.NET.Core/Attribute/TenantBusinessAttribute.cs

@@ -0,0 +1,10 @@
+namespace Admin.NET.Core;
+
+/// <summary>
+/// 租户业务表特性
+/// </summary>
+[SuppressSniffer]
+[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
+public class TenantBusinessAttribute : Attribute
+{
+}

+ 1 - 1
Admin.NET/Admin.NET.Core/Captcha/LazyCaptchaSetup.cs

@@ -36,7 +36,7 @@ public class RandomCaptcha : DefaultCaptcha
     protected override void ChangeOptions(CaptchaOptions options)
     {
         // 随机验证码类型
-        options.CaptchaType = captchaTypes[random.Next(0, captchaTypes.Length)];
+        options.CaptchaType = captchaTypes[10]; // captchaTypes[random.Next(0, captchaTypes.Length)];
 
         // 当是算数运算时,CodeLength是指运算数个数
         if (options.CaptchaType.IsArithmetic())

+ 4 - 12
Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs

@@ -65,18 +65,10 @@ public class SysAuthService : IDynamicApiController, ITransient
 
         var encryptPasswod = MD5Encryption.Encrypt(input.Password);
 
-        // 判断用户名密码
-        Expression<Func<SysUser, bool>> sysUserExp = u => u.Account.Equals(input.Account) && u.Password.Equals(encryptPasswod);
-        SysUser user = null;
-        if (input.TenantId > 0)
-        {
-            var db = App.GetRequiredService<ISqlSugarClient>().AsTenant();
-            user = await SqlSugarSetup.InitTenantDb(db, input.TenantId).Queryable<SysUser>().FirstAsync(sysUserExp);
-        }
-        else
-        {
-            user = await _sysUserRep.GetFirstAsync(sysUserExp);
-        }
+        // 判断用户名密码 
+        var user = await _sysUserRep.AsQueryable().Filter(null, true)
+            .WhereIF(input.TenantId > 0, u => u.TenantId == input.TenantId)
+            .FirstAsync(u => u.Account.Equals(input.Account) && u.Password.Equals(encryptPasswod));
         _ = user ?? throw Oops.Oh(ErrorCodeEnum.D1000);
 
         // 账号是否被冻结

+ 0 - 4
Admin.NET/Admin.NET.Core/Service/Role/SysRoleService.cs

@@ -103,10 +103,6 @@ public class SysRoleService : IDynamicApiController, ITransient
     [HttpPost("/sysRole/update")]
     public async Task UpdateRole(UpdateRoleInput input)
     {
-        var adminRole = await _sysRoleRep.GetFirstAsync(u => u.Id == input.Id);
-        if (adminRole.Code == CommonConst.SysAdminRole)
-            throw Oops.Oh(ErrorCodeEnum.D1020);
-
         var isExist = await _sysRoleRep.IsAnyAsync(u => (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id);
         if (isExist)
             throw Oops.Oh(ErrorCodeEnum.D1006);

+ 5 - 13
Admin.NET/Admin.NET.Core/Service/Tenant/SysTenantService.cs

@@ -86,7 +86,6 @@ public class SysTenantService : IDynamicApiController, ITransient
         await _tenantRep.InsertAsync(tenant);
         await UpdateTenantCache();
 
-        if (tenant.TenantType == TenantTypeEnum.Db) return;
         await InitNewTenant(tenant);
     }
 
@@ -322,7 +321,7 @@ public class SysTenantService : IDynamicApiController, ITransient
     }
 
     /// <summary>
-    /// 创建租户数据库(根据默认库结构)
+    /// 创建租户数据库
     /// </summary>
     /// <param name="input"></param>
     /// <returns></returns>
@@ -335,22 +334,15 @@ public class SysTenantService : IDynamicApiController, ITransient
         if (tenant.DbType == SqlSugar.DbType.Oracle)
             throw Oops.Oh(ErrorCodeEnum.Z1002);
 
-        var dbConnection = new DbConnectionConfig
+        var config = new DbConnectionConfig
         {
             EnableInitDb = true,
+            EnableDiffLog = false,
             DbType = tenant.DbType,
-            ConfigId = tenant.ConfigId,
+            ConfigId = tenant.Id.ToString(),
             ConnectionString = tenant.Connection,
             IsAutoCloseConnection = true,
         };
-        SqlSugarSetup.SetDbConfig(dbConnection);
-        var db = App.GetRequiredService<ISqlSugarClient>();
-        db.AsTenant().AddConnection(dbConnection);
-        db.DbMaintenance.CreateDatabase();
-        SqlSugarSetup.InitDatabase(db.AsTenant(), dbConnection, tenant.Id);
-
-        // 去掉租户库里面的租户菜单(租户表)
-
-
+        SqlSugarSetup.InitTenantDatabase(App.GetRequiredService<ISqlSugarClient>().AsTenant(), config);
     }
 }

+ 5 - 5
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarRepository.cs

@@ -12,11 +12,11 @@ public class SqlSugarRepository<T> : SimpleClient<T> where T : class, new()
     {
         iTenant = App.GetRequiredService<ISqlSugarClient>().AsTenant();
 
-        // 根据当前租户Id切换数据
-        var tenantId = App.GetRequiredService<UserManager>().TenantId;
-        if (tenantId > 1)
-        {
-            base.Context = SqlSugarSetup.InitTenantDb(iTenant, tenantId);
+        // 根据租户业务实体是否切
+        if (typeof(T).IsDefined(typeof(TenantBusinessAttribute), false))
+        {            
+            var tenantId = App.GetRequiredService<UserManager>().TenantId; // 根据租户Id切库
+            base.Context = SqlSugarSetup.InitTenantConnection(iTenant, tenantId);
         }
         else
         {

+ 45 - 23
Admin.NET/Admin.NET.Core/SqlSugar/SqlSugarSetup.cs

@@ -25,11 +25,7 @@ public static class SqlSugarSetup
         // 初始化数据库表结构及种子数据
         dbOptions.ConnectionConfigs.ForEach(config =>
         {
-            if (config.EnableInitDb && config.DbType != SqlSugar.DbType.Oracle)
-            {
-                sqlSugar.DbMaintenance.CreateDatabase();
-                InitDatabase(sqlSugar.AsTenant(), config);
-            }
+            InitDatabase(sqlSugar, config);
         });
 
         services.AddSingleton<ISqlSugarClient>(sqlSugar); // 单例注册
@@ -152,11 +148,15 @@ public static class SqlSugarSetup
         //        Parameters = JsonConvert.SerializeObject(u.Parameters),
         //        Duration = u.Time == null ? 0 : (long)u.Time.Value.TotalMilliseconds
         //    };
-        //    await client.GetConnectionScope(SqlSugarConst.ConfigId).Insertable(LogDiff).ExecuteCommandAsync();
+        //    await db.AsTenant().GetConnectionScope(SqlSugarConst.ConfigId).Insertable(LogDiff).ExecuteCommandAsync();
         //    Console.ForegroundColor = ConsoleColor.Red;
         //    Console.WriteLine(DateTime.Now + $"\r\n**********差异日志开始**********\r\n{Environment.NewLine}{JsonConvert.SerializeObject(LogDiff)}{Environment.NewLine}**********差异日志结束**********\r\n");
         //};
 
+        // 超管时排除各种过滤器
+        if (App.User?.FindFirst(ClaimConst.AccountType)?.Value == ((int)AccountTypeEnum.SuperAdmin).ToString())
+            return;
+
         // 配置实体假删除过滤器
         SetDeletedEntityFilter(db);
         // 配置租户过滤器
@@ -168,13 +168,17 @@ public static class SqlSugarSetup
     }
 
     /// <summary>
-    /// 初始化数据库结构
+    /// 初始化数据库
     /// </summary>
     /// <param name="db"></param>
     /// <param name="config"></param>
-    /// <param name="tenantId"></param>
-    public static void InitDatabase(ITenant db, DbConnectionConfig config, long tenantId = 0)
+    public static void InitDatabase(SqlSugarScope db, DbConnectionConfig config)
     {
+        if (!config.EnableInitDb || config.DbType == SqlSugar.DbType.Oracle) return;
+
+        // 创建数据库
+        db.DbMaintenance.CreateDatabase();
+
         // 获取所有实体表-初始化表结构
         var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass
             && u.IsDefined(typeof(SugarTable), false) && !u.IsDefined(typeof(NotTableAttribute), false));
@@ -184,7 +188,7 @@ public static class SqlSugarSetup
         {
             var tAtt = entityType.GetCustomAttribute<TenantAttribute>();
             if (tAtt != null && tAtt.configId.ToString() != config.ConfigId) continue;
-            if (tAtt == null && config.ConfigId != SqlSugarConst.ConfigId && tenantId < 1) continue;
+            if (tAtt == null && config.ConfigId != SqlSugarConst.ConfigId) continue;
 
             var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();
             if (splitTable == null)
@@ -208,16 +212,10 @@ public static class SqlSugarSetup
             var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();
             var tAtt = entityType.GetCustomAttribute<TenantAttribute>();
             if (tAtt != null && tAtt.configId.ToString() != config.ConfigId) continue;
-            if (tAtt == null && config.ConfigId != SqlSugarConst.ConfigId && tenantId < 1) continue;
+            if (tAtt == null && config.ConfigId != SqlSugarConst.ConfigId) continue;
 
             var seedDataTable = seedData.ToList().ToDataTable();
             seedDataTable.TableName = db2.EntityMaintenance.GetEntityInfo(entityType).DbTableName;
-            // 创建租户库时修改租户Id
-            if (tenantId > 1 && seedDataTable.Columns.Contains(SqlSugarConst.TenantId))
-            {
-                foreach (DataRow dr in seedDataTable.Rows)
-                    dr[SqlSugarConst.TenantId] = tenantId;
-            }
             if (seedDataTable.Columns.Contains(SqlSugarConst.PrimaryKey))
             {
                 var storage = db2.Storageable(seedDataTable).WhereColumns(SqlSugarConst.PrimaryKey).ToStorage();
@@ -233,11 +231,11 @@ public static class SqlSugarSetup
     }
 
     /// <summary>
-    /// 增加租户库连接
+    /// 初始化租户库连接
     /// </summary>
     /// <param name="iTenant"></param>
     /// <param name="tenantId"></param>
-    public static SqlSugarScopeProvider InitTenantDb(ITenant iTenant, long tenantId)
+    public static SqlSugarScopeProvider InitTenantConnection(ITenant iTenant, long tenantId)
     {
         var tenant = App.GetRequiredService<SysCacheService>().Get<List<SysTenant>>(CacheConst.KeyTenant).FirstOrDefault(u => u.Id == tenantId);
         if (!iTenant.IsAnyConnection(tenantId.ToString()))
@@ -254,6 +252,34 @@ public static class SqlSugarSetup
         return iTenant.GetConnectionScope(tenantId.ToString());
     }
 
+    /// <summary>
+    /// 初始化租户业务数据库
+    /// </summary>
+    /// <param name="itenant"></param>
+    /// <param name="config"></param>
+    public static void InitTenantDatabase(ITenant itenant, DbConnectionConfig config)
+    {
+        SetDbConfig(config);
+
+        itenant.AddConnection(config);
+        var db = itenant.GetConnectionScope(config.ConfigId);
+        db.DbMaintenance.CreateDatabase();
+
+        // 获取所有实体表-初始化租户业务表
+        var entityTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass
+            && u.IsDefined(typeof(SugarTable), false) && !u.IsDefined(typeof(NotTableAttribute), false)
+            && u.IsDefined(typeof(TenantBusinessAttribute), false));
+        if (!entityTypes.Any()) return;
+        foreach (var entityType in entityTypes)
+        {
+            var splitTable = entityType.GetCustomAttribute<SplitTableAttribute>();
+            if (splitTable == null)
+                db.CodeFirst.InitTables(entityType);
+            else
+                db.CodeFirst.SplitTables().InitTables(entityType);
+        }
+    }
+
     /// <summary>
     /// 配置实体假删除过滤器
     /// </summary>
@@ -389,10 +415,6 @@ public static class SqlSugarSetup
     /// </summary>
     private static void SetCustomEntityFilter(SqlSugarScopeProvider db)
     {
-        // 排除超管过滤
-        if (App.User?.FindFirst(ClaimConst.AccountType)?.Value == ((int)AccountTypeEnum.SuperAdmin).ToString())
-            return;
-
         // 配置用户机构范围缓存
         var cacheKey = $"db:{db.CurrentConnectionConfig.ConfigId}:Custom";
         var tableFilterItemList = db.DataCache.Get<List<TableFilterItem<object>>>(cacheKey);

+ 2 - 2
Web/src/components/dragVerify/dragVerifyImgRotate.vue

@@ -16,8 +16,8 @@
 			</div>
 
 			<div class="dv_handler dv_handler_bg" :class="{goFirst:isOk}" @mousedown="dragStart" @touchstart="dragStart"
-				ref="handler" :style="handlerStyle" style="background-color: var(--el-color-primary)">
-				<i :class="handlerIcon"></i>
+				ref="handler" :style="handlerStyle" style="background-color: var(--el-color-primary);">
+				<i :class="handlerIcon" style="color: #FFF;"></i>
 			</div>
 		</div>
 	</div>

+ 10 - 1
Web/src/router/backEnd.ts

@@ -2,7 +2,7 @@ import { RouteRecordRaw } from 'vue-router';
 import pinia from '/@/stores/index';
 import { useUserInfo } from '/@/stores/userInfo';
 import { useRequestOldRoutes } from '/@/stores/requestOldRoutes';
-import { Session } from '/@/utils/storage';
+import { Local, Session } from '/@/utils/storage';
 import { NextLoading } from '/@/utils/loading';
 import { dynamicRoutes, notFoundAndNoPower } from '/@/router/route';
 import { formatTwoStageRoutes, formatFlatteningRoutes, router } from '/@/router/index';
@@ -11,6 +11,7 @@ import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
 
 import { getAPI } from '/@/utils/axios-utils';
 import { SysMenuApi } from '/@/api-services/api';
+import { ElMessage } from 'element-plus';
 
 const layouModules: any = import.meta.glob('../layout/routerView/*.{vue,tsx}');
 const viewsModules: any = import.meta.glob('../views/**/*.{vue,tsx}');
@@ -102,6 +103,14 @@ export async function setAddRoute() {
  */
 export async function getBackEndControlRoutes() {
 	var res = await getAPI(SysMenuApi).loginMenuGet();
+	if (res.data.result == undefined || res.data.result.length < 1) {
+		ElMessage.error('没有任何菜单权限,请联系管理员!');
+		setTimeout(() => {
+			Session.clear();
+			Local.clear();
+			window.location.reload();
+		}, 3000);
+	}
 	return res.data.result;
 }
 

+ 30 - 16
Web/src/views/login/component/account.vue

@@ -56,18 +56,20 @@
 		<div class="font12 mt30 login-animation4 login-msg">{{ $t('message.mobile.msgText') }}</div>
 	</el-form>
 
-	<el-dialog v-model="verifyVisible" title="" width="300px" center>
-		<DragVerifyImgRotate
-			ref="dragRef"
-			:imgsrc="verifyImg"
-			v-model:isPassing="isPass"
-			text="请按住滑块拖动"
-			successText="验证通过"
-			handlerIcon="fa fa-angle-double-right"
-			successIcon="fa fa-hand-peace-o"
-			@passcallback="passVerify"
-		/>
-	</el-dialog>
+	<div class="dialog-header">
+		<el-dialog v-model="verifyVisible" width="300px" center :show-close="false">
+			<DragVerifyImgRotate
+				ref="dragRef"
+				:imgsrc="verifyImg"
+				v-model:isPassing="isPass"
+				text="请按住滑块拖动"
+				successText="验证通过"
+				handlerIcon="fa fa-angle-double-right"
+				successIcon="fa fa-hand-peace-o"
+				@passcallback="passVerify"
+			/>
+		</el-dialog>
+	</div>
 </template>
 
 <script lang="ts">
@@ -84,7 +86,7 @@ import { Session, Local } from '/@/utils/storage';
 import { formatAxis } from '/@/utils/formatTime';
 import { NextLoading } from '/@/utils/loading';
 
-import { getAPI } from '/@/utils/axios-utils';
+import { feature, getAPI } from '/@/utils/axios-utils';
 import { SysAuthApi } from '/@/api-services/api';
 import { SysTenant } from '/@/api-services/models';
 
@@ -157,10 +159,12 @@ export default defineComponent({
 			Session.clear();
 			Local.clear();
 
-			var res = await getAPI(SysAuthApi).loginPost(state.ruleForm);
-			if (res.data.result?.accessToken == null) {
+			const [err, res] = await feature(getAPI(SysAuthApi).loginPost(state.ruleForm));
+			if (err) {
 				getCaptcha(); // 重新获取验证码
-
+				return;
+			}
+			if (res?.data.result?.accessToken == undefined) {
 				ElMessage.error('登录失败,请检查账号!');
 				return;
 			}
@@ -235,6 +239,16 @@ export default defineComponent({
 </script>
 
 <style scoped lang="scss">
+.dialog-header {
+	:deep(.el-dialog) {
+		.el-dialog__header {
+			// padding: 0px !important;
+			// background: #fff !important;
+			display: none;
+		}
+	}
+}
+
 .login-content-form {
 	margin-top: 20px;
 

+ 2 - 5
Web/src/views/system/tenant/component/editTenant.vue

@@ -18,7 +18,7 @@
 					</el-col>
 					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
 						<el-form-item label="管理员" prop="adminName" :rules="[{ required: true, message: '管理员不能为空', trigger: 'blur' }]">
-							<el-input v-model="ruleForm.adminName" placeholder="管理员" clearable :disabled="ruleForm.tenantType == 1" />
+							<el-input v-model="ruleForm.adminName" placeholder="管理员" clearable />
 						</el-form-item>
 					</el-col>
 					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
@@ -91,7 +91,7 @@
 </template>
 
 <script lang="ts">
-import { reactive, toRefs, defineComponent, getCurrentInstance, ref, watch } from 'vue';
+import { reactive, toRefs, defineComponent, getCurrentInstance, ref } from 'vue';
 
 import { getAPI } from '/@/utils/axios-utils';
 import { SysTenantApi } from '/@/api-services/api';
@@ -113,9 +113,6 @@ export default defineComponent({
 			isShowDialog: false,
 			ruleForm: {} as UpdateTenantInput,
 		});
-		watch(state, () => {
-			if (state.ruleForm.tenantType == 1) state.ruleForm.adminName = 'Administrator';
-		});
 		// 打开弹窗
 		const openDialog = (row: any) => {
 			state.ruleForm = row;

+ 3 - 4
Web/src/views/system/tenant/index.vue

@@ -27,7 +27,7 @@
 				<el-table-column prop="tenantType" label="租户类型" align="center" show-overflow-tooltip>
 					<template #default="scope">
 						<el-tag v-if="scope.row.tenantType === 0"> ID隔离 </el-tag>
-						<el-tag v-else> 库隔离 </el-tag>
+						<el-tag type="danger" v-else> 库隔离 </el-tag>
 					</template>
 				</el-table-column>
 				<el-table-column prop="status" label="状态" width="70" align="center" show-overflow-tooltip>
@@ -203,15 +203,14 @@ export default defineComponent({
 		};
 		// 创建租户库
 		const createTenant = (row: any) => {
-			ElMessageBox.confirm(`确定创建/更新数据库:【${row.name}】?`, '提示', {
+			ElMessageBox.confirm(`确定创建/更新租户数据库:【${row.name}】?`, '提示', {
 				confirmButtonText: '确定',
 				cancelButtonText: '取消',
 				type: 'warning',
 			})
 				.then(async () => {
 					await getAPI(SysTenantApi).sysTenantCreateDbPost({ id: row.id });
-					handleQuery();
-					ElMessage.success('创建/更新数据库成功');
+					ElMessage.success('创建/更新租户数据库成功');
 				})
 				.catch(() => {});
 		};