feat: 添加多租户界面及种子数据
This commit is contained in:
@@ -571,6 +571,83 @@ namespace Yi.Framework.Rbac.SqlSugarCore.DataSeeds
|
|||||||
};
|
};
|
||||||
entities.Add(guide);
|
entities.Add(guide);
|
||||||
|
|
||||||
|
//租户管理
|
||||||
|
MenuEntity tenant = new MenuEntity(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
MenuName = "租户管理",
|
||||||
|
PermissionCode = "system:tenant:list",
|
||||||
|
MenuType = MenuTypeEnum.Menu,
|
||||||
|
Router = "tenant",
|
||||||
|
IsShow = true,
|
||||||
|
IsLink = false,
|
||||||
|
IsCache = true,
|
||||||
|
Component = "system/tenant/index",
|
||||||
|
MenuIcon = "list",
|
||||||
|
OrderNum = 101,
|
||||||
|
ParentId = system.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(tenant);
|
||||||
|
|
||||||
|
MenuEntity tenantQuery = new MenuEntity(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
|
||||||
|
MenuName = "租户查询",
|
||||||
|
PermissionCode = "system:tenant:query",
|
||||||
|
MenuType = MenuTypeEnum.Component,
|
||||||
|
OrderNum = 100,
|
||||||
|
ParentId = tenant.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(tenantQuery);
|
||||||
|
|
||||||
|
MenuEntity tenantAdd = new MenuEntity(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
|
||||||
|
MenuName = "租户新增",
|
||||||
|
PermissionCode = "system:tenant:add",
|
||||||
|
MenuType = MenuTypeEnum.Component,
|
||||||
|
OrderNum = 100,
|
||||||
|
ParentId = tenant.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(tenantAdd);
|
||||||
|
|
||||||
|
MenuEntity tenantEdit = new MenuEntity(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
|
||||||
|
MenuName = "租户修改",
|
||||||
|
PermissionCode = "system:tenant:edit",
|
||||||
|
MenuType = MenuTypeEnum.Component,
|
||||||
|
OrderNum = 100,
|
||||||
|
ParentId = tenant.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(tenantEdit);
|
||||||
|
|
||||||
|
MenuEntity tenantRemove = new MenuEntity(_guidGenerator.Create())
|
||||||
|
{
|
||||||
|
|
||||||
|
MenuName = "租户删除",
|
||||||
|
PermissionCode = "system:tenant:remove",
|
||||||
|
MenuType = MenuTypeEnum.Component,
|
||||||
|
OrderNum = 100,
|
||||||
|
ParentId = tenant.Id,
|
||||||
|
IsDeleted = false
|
||||||
|
};
|
||||||
|
entities.Add(tenantRemove);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//用户管理
|
//用户管理
|
||||||
MenuEntity user = new MenuEntity(_guidGenerator.Create())
|
MenuEntity user = new MenuEntity(_guidGenerator.Create())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Yi.Framework.TenantManagement.Application.Contracts.Dtos
|
namespace Yi.Framework.TenantManagement.Application.Contracts.Dtos
|
||||||
{
|
{
|
||||||
public class TenantCreateInput
|
public class TenantCreateInput
|
||||||
{
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string TenantConnectionString { get; set; }
|
||||||
|
|
||||||
|
public SqlSugar.DbType DbType { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Yi.Framework.Ddd.Application.Contracts;
|
||||||
|
|
||||||
namespace Yi.Framework.TenantManagement.Application.Contracts.Dtos
|
namespace Yi.Framework.TenantManagement.Application.Contracts.Dtos
|
||||||
{
|
{
|
||||||
public class TenantGetListInput
|
public class TenantGetListInput: PagedAllResultRequestDto
|
||||||
{
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
//public int? EntityVersion { get; set; }
|
||||||
|
|
||||||
|
//public string? TenantConnectionString { get; set; }
|
||||||
|
|
||||||
|
//public DbType? DbType { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -9,5 +10,12 @@ namespace Yi.Framework.TenantManagement.Application.Contracts.Dtos
|
|||||||
{
|
{
|
||||||
public class TenantGetListOutputDto:EntityDto<Guid>
|
public class TenantGetListOutputDto:EntityDto<Guid>
|
||||||
{
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int EntityVersion { get; set; }
|
||||||
|
|
||||||
|
public string TenantConnectionString { get; set; }
|
||||||
|
|
||||||
|
public SqlSugar.DbType DbType { get; set; }
|
||||||
|
public DateTime CreationTime { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -9,5 +10,13 @@ namespace Yi.Framework.TenantManagement.Application.Contracts.Dtos
|
|||||||
{
|
{
|
||||||
public class TenantGetOutputDto:EntityDto<Guid>
|
public class TenantGetOutputDto:EntityDto<Guid>
|
||||||
{
|
{
|
||||||
|
public string Name { get; set; }
|
||||||
|
public int EntityVersion { get; set; }
|
||||||
|
|
||||||
|
public string TenantConnectionString { get; set; }
|
||||||
|
|
||||||
|
public SqlSugar.DbType DbType { get; set; }
|
||||||
|
|
||||||
|
public DateTime CreationTime { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
using System;
|
using System.Data;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Yi.Framework.TenantManagement.Application.Contracts.Dtos
|
namespace Yi.Framework.TenantManagement.Application.Contracts.Dtos
|
||||||
{
|
{
|
||||||
public class TenantUpdateInput
|
public class TenantUpdateInput
|
||||||
{
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public int? EntityVersion { get; set; }
|
||||||
|
|
||||||
|
public string? TenantConnectionString { get; set; }
|
||||||
|
|
||||||
|
public SqlSugar.DbType? DbType { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.Ddd.Application.Contracts\Yi.Framework.Ddd.Application.Contracts.csproj" />
|
<ProjectReference Include="..\..\..\framework\Yi.Framework.Ddd.Application.Contracts\Yi.Framework.Ddd.Application.Contracts.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\framework\Yi.Framework.SqlSugarCore.Abstractions\Yi.Framework.SqlSugarCore.Abstractions.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,10 +1,19 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using SqlSugar;
|
||||||
|
using Volo.Abp;
|
||||||
using Volo.Abp.Application.Dtos;
|
using Volo.Abp.Application.Dtos;
|
||||||
|
using Volo.Abp.Data;
|
||||||
using Volo.Abp.Domain.Repositories;
|
using Volo.Abp.Domain.Repositories;
|
||||||
|
using Volo.Abp.Modularity;
|
||||||
|
using Volo.Abp.Uow;
|
||||||
using Yi.Framework.Ddd.Application;
|
using Yi.Framework.Ddd.Application;
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
using Yi.Framework.TenantManagement.Application.Contracts;
|
using Yi.Framework.TenantManagement.Application.Contracts;
|
||||||
@@ -19,9 +28,11 @@ namespace Yi.Framework.TenantManagement.Application
|
|||||||
public class TenantService : YiCrudAppService<TenantAggregateRoot, TenantGetOutputDto, TenantGetListOutputDto, Guid, TenantGetListInput, TenantCreateInput, TenantUpdateInput>, ITenantService
|
public class TenantService : YiCrudAppService<TenantAggregateRoot, TenantGetOutputDto, TenantGetListOutputDto, Guid, TenantGetListInput, TenantCreateInput, TenantUpdateInput>, ITenantService
|
||||||
{
|
{
|
||||||
private ISqlSugarRepository<TenantAggregateRoot, Guid> _repository;
|
private ISqlSugarRepository<TenantAggregateRoot, Guid> _repository;
|
||||||
public TenantService(ISqlSugarRepository<TenantAggregateRoot, Guid> repository) : base(repository)
|
private IDataSeeder _dataSeeder;
|
||||||
|
public TenantService(ISqlSugarRepository<TenantAggregateRoot, Guid> repository, IDataSeeder dataSeeder) : base(repository)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
|
_dataSeeder = dataSeeder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,9 +50,14 @@ namespace Yi.Framework.TenantManagement.Application
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Task<PagedResultDto<TenantGetListOutputDto>> GetListAsync(TenantGetListInput input)
|
public override async Task<PagedResultDto<TenantGetListOutputDto>> GetListAsync(TenantGetListInput input)
|
||||||
{
|
{
|
||||||
return base.GetListAsync(input);
|
RefAsync<int> total = 0;
|
||||||
|
|
||||||
|
var entities = await _repository._DbQueryable.WhereIF(!string.IsNullOrEmpty(input.Name), x => x.Name.Contains(input.Name!))
|
||||||
|
.WhereIF(input.StartTime is not null && input.EndTime is not null, x => x.CreationTime >= input.StartTime && x.CreationTime <= input.EndTime)
|
||||||
|
.ToPageListAsync(input.SkipCount, input.MaxResultCount, total);
|
||||||
|
return new PagedResultDto<TenantGetListOutputDto>(total, await MapToGetListOutputDtosAsync(entities));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -49,9 +65,13 @@ namespace Yi.Framework.TenantManagement.Application
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Task<TenantGetOutputDto> CreateAsync(TenantCreateInput input)
|
public override async Task<TenantGetOutputDto> CreateAsync(TenantCreateInput input)
|
||||||
{
|
{
|
||||||
return base.CreateAsync(input);
|
if (await _repository.IsAnyAsync(x => x.Name == input.Name))
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("创建失败,当前租户已存在");
|
||||||
|
}
|
||||||
|
return await base.CreateAsync(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -60,11 +80,17 @@ namespace Yi.Framework.TenantManagement.Application
|
|||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="input"></param>
|
/// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public override Task<TenantGetOutputDto> UpdateAsync(Guid id, TenantUpdateInput input)
|
public override async Task<TenantGetOutputDto> UpdateAsync(Guid id, TenantUpdateInput input)
|
||||||
{
|
{
|
||||||
return base.UpdateAsync(id, input);
|
if (await _repository.IsAnyAsync(x => x.Name == input.Name && x.Id != id))
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("更新后租户名已经存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
return await base.UpdateAsync(id, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 租户删除
|
/// 租户删除
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -74,5 +100,45 @@ namespace Yi.Framework.TenantManagement.Application
|
|||||||
{
|
{
|
||||||
return base.DeleteAsync(id);
|
return base.DeleteAsync(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 初始化租户
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPut("tenant/init/{id}")]
|
||||||
|
public async Task InitAsync([FromRoute]Guid id)
|
||||||
|
{
|
||||||
|
using (CurrentTenant.Change(id))
|
||||||
|
{
|
||||||
|
CodeFirst(await _repository.GetDbContextAsync());
|
||||||
|
await _dataSeeder.SeedAsync(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CodeFirst(ISqlSugarClient db)
|
||||||
|
{
|
||||||
|
|
||||||
|
var moduleContainer = ServiceProvider.GetRequiredService<IModuleContainer>();
|
||||||
|
|
||||||
|
//尝试创建数据库
|
||||||
|
db.DbMaintenance.CreateDatabase();
|
||||||
|
|
||||||
|
List<Type> types = new List<Type>();
|
||||||
|
foreach (var module in moduleContainer.Modules)
|
||||||
|
{
|
||||||
|
types.AddRange(module.Assembly.GetTypes()
|
||||||
|
.Where(x => x.GetCustomAttribute<IgnoreCodeFirstAttribute>() == null)
|
||||||
|
.Where(x => x.GetCustomAttribute<SugarTable>() != null)
|
||||||
|
.Where(x=>x.GetCustomAttribute<MasterTenantAttribute>()==null)
|
||||||
|
.Where(x => x.GetCustomAttribute<SplitTableAttribute>() is null));
|
||||||
|
}
|
||||||
|
if (types.Count > 0)
|
||||||
|
{
|
||||||
|
db.CodeFirst.InitTables(types.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
Yi.Abp.Net8/src/Yi.Abp.Web/yi-abp-dev.db
Normal file
BIN
Yi.Abp.Net8/src/Yi.Abp.Web/yi-abp-dev.db
Normal file
Binary file not shown.
55
Yi.RuoYi.Vue3/src/api/system/tenant.js
Normal file
55
Yi.RuoYi.Vue3/src/api/system/tenant.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
/* 以下为api的模板,通用的crud,将以下变量替换即可:
|
||||||
|
tenant : 实体模型
|
||||||
|
*/
|
||||||
|
// 分页查询
|
||||||
|
export function listData(query) {
|
||||||
|
return request({
|
||||||
|
url: '/tenant',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// id查询
|
||||||
|
export function getData(id) {
|
||||||
|
return request({
|
||||||
|
url: `/tenant/${id}`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增
|
||||||
|
export function addData(data) {
|
||||||
|
return request({
|
||||||
|
url: '/tenant',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改
|
||||||
|
export function updateData(id,data) {
|
||||||
|
return request({
|
||||||
|
url: `/tenant/${id}`,
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
export function InitData(id) {
|
||||||
|
return request({
|
||||||
|
url: `/tenant/init/${id}`,
|
||||||
|
method: 'put'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除
|
||||||
|
export function delData(ids) {
|
||||||
|
return request({
|
||||||
|
url: `/tenant`,
|
||||||
|
method: 'delete',
|
||||||
|
params:{id:ids}
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -117,13 +117,13 @@
|
|||||||
<el-col :span="24">
|
<el-col :span="24">
|
||||||
<el-form-item label="菜单类型" prop="menuType">
|
<el-form-item label="菜单类型" prop="menuType">
|
||||||
<el-radio-group v-model="form.menuType">
|
<el-radio-group v-model="form.menuType">
|
||||||
<el-radio :label=0>目录</el-radio>
|
<el-radio label="Catalogue">目录</el-radio>
|
||||||
<el-radio :label=1>菜单</el-radio>
|
<el-radio label="Menu">菜单</el-radio>
|
||||||
<el-radio :label=2>按钮</el-radio>
|
<el-radio label="Component">按钮</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="24" v-if="form.menuType != 2">
|
<el-col :span="24" v-if="form.menuType != 'Component'">
|
||||||
<el-form-item label="菜单图标" prop="menuIcon">
|
<el-form-item label="菜单图标" prop="menuIcon">
|
||||||
<el-popover
|
<el-popover
|
||||||
placement="bottom-start"
|
placement="bottom-start"
|
||||||
@@ -159,7 +159,7 @@
|
|||||||
<el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
|
<el-input-number v-model="form.orderNum" controls-position="right" :min="0" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" v-if="form.menuType != 2">
|
<el-col :span="12" v-if="form.menuType != 'Component'">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<template #label>
|
<template #label>
|
||||||
<span>
|
<span>
|
||||||
@@ -176,7 +176,7 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
|
|
||||||
|
|
||||||
<el-col :span="12" v-if="form.menuType != 2">
|
<el-col :span="12" v-if="form.menuType != 'Component'">
|
||||||
<el-form-item prop="router">
|
<el-form-item prop="router">
|
||||||
<template #label>
|
<template #label>
|
||||||
<span>
|
<span>
|
||||||
@@ -189,7 +189,7 @@
|
|||||||
<el-input v-model="form.router" placeholder="请输入路由地址" />
|
<el-input v-model="form.router" placeholder="请输入路由地址" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" v-if="form.menuType == 1">
|
<el-col :span="12" v-if="form.menuType == 'Menu'">
|
||||||
<el-form-item prop="component">
|
<el-form-item prop="component">
|
||||||
<template #label>
|
<template #label>
|
||||||
<span>
|
<span>
|
||||||
@@ -202,7 +202,7 @@
|
|||||||
<el-input v-model="form.component" placeholder="请输入组件路径" />
|
<el-input v-model="form.component" placeholder="请输入组件路径" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" v-if="form.menuType != 0">
|
<el-col :span="12" v-if="form.menuType !='Catalogue'">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-input v-model="form.permissionCode" placeholder="请输入权限标识" maxlength="100" />
|
<el-input v-model="form.permissionCode" placeholder="请输入权限标识" maxlength="100" />
|
||||||
<template #label>
|
<template #label>
|
||||||
@@ -215,7 +215,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" v-if="form.menuType == 1">
|
<el-col :span="12" v-if="form.menuType == 'Menu'">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-input v-model="form.query" placeholder="请输入路由参数" maxlength="255" />
|
<el-input v-model="form.query" placeholder="请输入路由参数" maxlength="255" />
|
||||||
<template #label>
|
<template #label>
|
||||||
@@ -228,7 +228,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" v-if="form.menuType == 1">
|
<el-col :span="12" v-if="form.menuType == 'Menu'">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<template #label>
|
<template #label>
|
||||||
<span>
|
<span>
|
||||||
@@ -244,7 +244,7 @@
|
|||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" v-if="form.menuType != 2">
|
<el-col :span="12" v-if="form.menuType != 'Component'">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<template #label>
|
<template #label>
|
||||||
<span>
|
<span>
|
||||||
@@ -263,7 +263,7 @@
|
|||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" v-if="form.menuType != 2">
|
<el-col :span="12" v-if="form.menuType !='Component'">
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<template #label>
|
<template #label>
|
||||||
<span>
|
<span>
|
||||||
|
|||||||
299
Yi.RuoYi.Vue3/src/views/system/tenant/index.vue
Normal file
299
Yi.RuoYi.Vue3/src/views/system/tenant/index.vue
Normal file
@@ -0,0 +1,299 @@
|
|||||||
|
|
||||||
|
<template>
|
||||||
|
|
||||||
|
<div class="app-container">
|
||||||
|
<!-- <div>
|
||||||
|
该文件为通用Crud模板文件,按照规范只需要 替换以下变量即可,
|
||||||
|
租户 : 实体中文名称
|
||||||
|
system:tenant :crud权限编码
|
||||||
|
system/tenant : api文件路径,例如:webfirst/tableApi
|
||||||
|
</div> -->
|
||||||
|
<el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="100px">
|
||||||
|
<el-form-item label="租户名称" prop="name">
|
||||||
|
<el-input v-model="queryParams.name" placeholder="请输入租户名称" clearable style="width: 240px"
|
||||||
|
@keyup.enter="handleQuery" prop="name" />
|
||||||
|
</el-form-item>
|
||||||
|
<!-- <el-form-item label="状态" prop="isDeleted">
|
||||||
|
<el-select
|
||||||
|
v-model="queryParams.isDeleted"
|
||||||
|
placeholder="状态"
|
||||||
|
clearable
|
||||||
|
style="width: 240px"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="dict in sys_normal_disable"
|
||||||
|
:key="dict.value"
|
||||||
|
:label="dict.label"
|
||||||
|
:value="dict.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item> -->
|
||||||
|
<el-form-item label="创建时间" style="width: 308px">
|
||||||
|
<el-date-picker
|
||||||
|
v-model="dateRange"
|
||||||
|
value-format="YYYY-MM-DD"
|
||||||
|
type="daterange"
|
||||||
|
range-separator="-"
|
||||||
|
start-placeholder="开始日期"
|
||||||
|
end-placeholder="结束日期"
|
||||||
|
></el-date-picker>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||||
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
|
||||||
|
<el-row :gutter="10" class="mb8">
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:tenant:add']">新增</el-button>
|
||||||
|
</el-col>
|
||||||
|
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate"
|
||||||
|
v-hasPermi="['system:tenant:edit']">修改</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
|
||||||
|
v-hasPermi="['system:tenant:remove']">删除</el-button>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="1.5">
|
||||||
|
<el-button type="warning" plain icon="Download" @click="handleExport"
|
||||||
|
v-hasPermi="['system:tenant:export']">导出</el-button>
|
||||||
|
</el-col>
|
||||||
|
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||||
|
</el-row>
|
||||||
|
|
||||||
|
<el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
|
||||||
|
<el-table-column type="selection" width="55" align="center" />
|
||||||
|
|
||||||
|
<!-----------------------这里开始就是数据表单的全部列------------------------>
|
||||||
|
<el-table-column label="租户编号" align="center" prop="id" width="380"/>
|
||||||
|
|
||||||
|
<el-table-column label="租户名称" align="center" prop="name" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column label="连接字符串" align="center" prop="tenantConnectionString" :show-overflow-tooltip="true" />
|
||||||
|
|
||||||
|
<el-table-column label="数据库类型" align="center" prop="dbType" :show-overflow-tooltip="true" />
|
||||||
|
<el-table-column
|
||||||
|
label="创建时间"
|
||||||
|
align="center"
|
||||||
|
prop="creationTime"
|
||||||
|
width="180"
|
||||||
|
>
|
||||||
|
<template #default="scope">
|
||||||
|
<span>{{ parseTime(scope.row.creationTime) }}</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
<!-- <el-table-column label="状态" align="center" prop="isDeleted">
|
||||||
|
<template #default="scope">
|
||||||
|
<dict-tag
|
||||||
|
:options="sys_normal_disable"
|
||||||
|
:value="scope.row.isDeleted"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
</el-table-column> -->
|
||||||
|
<!-- <el-table-column
|
||||||
|
label="备注"
|
||||||
|
align="center"
|
||||||
|
prop="remark"
|
||||||
|
:show-overflow-tooltip="true"
|
||||||
|
/> -->
|
||||||
|
|
||||||
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
|
<template #default="scope">
|
||||||
|
|
||||||
|
<el-button type="text" icon="Edit" @click="handleInit(scope.row.id)"
|
||||||
|
v-hasPermi="['system:tenant:edit']">初始化</el-button>
|
||||||
|
<el-button type="text" icon="Edit" @click="handleUpdate(scope.row)"
|
||||||
|
v-hasPermi="['system:tenant:edit']">修改</el-button>
|
||||||
|
<el-button type="text" icon="Delete" @click="handleDelete(scope.row)"
|
||||||
|
v-hasPermi="['system:tenant:remove']">删除</el-button>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
|
</el-table>
|
||||||
|
|
||||||
|
<pagination v-show="total > 0" :total="Number(total)" v-model:page="queryParams.skipCount"
|
||||||
|
v-model:limit="queryParams.maxResultCount" @pagination="getList" />
|
||||||
|
|
||||||
|
<!-- ---------------------这里是新增和更新的对话框--------------------- -->
|
||||||
|
<el-dialog :title="title" v-model="open" width="600px" append-to-body>
|
||||||
|
<el-form ref="dataRef" :model="form" :rules="rules" label-width="100px">
|
||||||
|
|
||||||
|
|
||||||
|
<el-form-item label="租户名称" prop="name">
|
||||||
|
<el-input v-model="form.name" placeholder="请输入租户名称" />
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="数据库类型" prop="dbType">
|
||||||
|
<el-radio-group v-model="form.dbType">
|
||||||
|
<el-radio
|
||||||
|
v-for="dict in ['Sqlite','Mysql','Sqlserver']"
|
||||||
|
:key="dict"
|
||||||
|
:label="dict"
|
||||||
|
>{{ dict }}</el-radio
|
||||||
|
>
|
||||||
|
</el-radio-group>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="连接字符串" prop="tenantConnectionString">
|
||||||
|
<el-input v-model="form.tenantConnectionString" type="textarea" placeholder="请输入内容"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<h3>连接字符串示例:</h3>
|
||||||
|
<p>Sqlite: DataSource=[xxxx]</p>
|
||||||
|
<p>Mysql: server=[xxxx];port=3306;database=[xxxx];user id=[xxxx];password=[xxxx]</p>
|
||||||
|
<p>Sqlserver: Data Source=[xxxx];Initial Catalog=[xxxx];User ID=[xxxx];password=[xxxx]</p>
|
||||||
|
</el-form>
|
||||||
|
<template #footer>
|
||||||
|
<div class="dialog-footer">
|
||||||
|
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||||
|
<el-button @click="cancel">取 消</el-button>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</el-dialog>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup>
|
||||||
|
import {
|
||||||
|
listData,
|
||||||
|
getData,
|
||||||
|
delData,
|
||||||
|
addData,
|
||||||
|
updateData,
|
||||||
|
InitData
|
||||||
|
} from "@/api/system/tenant";
|
||||||
|
import { ref } from "@vue/reactivity";
|
||||||
|
|
||||||
|
|
||||||
|
const { proxy } = getCurrentInstance();
|
||||||
|
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
|
||||||
|
|
||||||
|
const dataList = ref([]);
|
||||||
|
const open = ref(false);
|
||||||
|
const loading = ref(true);
|
||||||
|
const showSearch = ref(true);
|
||||||
|
const ids = ref([]);
|
||||||
|
const single = ref(true);
|
||||||
|
const multiple = ref(true);
|
||||||
|
const total = ref(0);
|
||||||
|
const title = ref("");
|
||||||
|
const dateRange = ref([]);
|
||||||
|
const data = reactive({
|
||||||
|
form: {},
|
||||||
|
queryParams: {
|
||||||
|
skipCount: 1,
|
||||||
|
maxResultCount: 10,
|
||||||
|
name: undefined,
|
||||||
|
code: undefined,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
code: [{ required: true, message: "租户编号不能为空", trigger: "blur" }],
|
||||||
|
name: [{ required: true, message: "租户名称不能为空", trigger: "blur" }],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
const { queryParams, form, rules } = toRefs(data);
|
||||||
|
|
||||||
|
/** 查询列表 */
|
||||||
|
function getList() {
|
||||||
|
loading.value = true;
|
||||||
|
listData(proxy.addDateRange(queryParams.value, dateRange.value)).then(
|
||||||
|
(response) => {
|
||||||
|
dataList.value = response.data.items;
|
||||||
|
total.value = response.data.totalCount;
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/** 取消按钮 */
|
||||||
|
function cancel() {
|
||||||
|
open.value = false;
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** 表单重置 */
|
||||||
|
function reset() {
|
||||||
|
proxy.resetForm("dataRef");
|
||||||
|
}
|
||||||
|
/** 搜索按钮操作 */
|
||||||
|
function handleQuery() {
|
||||||
|
queryParams.value.skipCount = 1;
|
||||||
|
getList();
|
||||||
|
}
|
||||||
|
/** 重置按钮操作 */
|
||||||
|
function resetQuery() {
|
||||||
|
dateRange.value = [];
|
||||||
|
proxy.resetForm("queryRef");
|
||||||
|
handleQuery();
|
||||||
|
}
|
||||||
|
/** 新增按钮操作 */
|
||||||
|
function handleAdd() {
|
||||||
|
reset();
|
||||||
|
open.value = true;
|
||||||
|
title.value = "添加租户";
|
||||||
|
}
|
||||||
|
/** 多选框选中数据 */
|
||||||
|
function handleSelectionChange(selection) {
|
||||||
|
ids.value = selection.map((item) => item.id);
|
||||||
|
single.value = selection.length != 1;
|
||||||
|
multiple.value = !selection.length;
|
||||||
|
}
|
||||||
|
/** 修改按钮操作 */
|
||||||
|
function handleUpdate(row) {
|
||||||
|
reset();
|
||||||
|
const id = row.id || ids.value;
|
||||||
|
getData(id).then((response) => {
|
||||||
|
form.value = response.data;
|
||||||
|
open.value = true;
|
||||||
|
title.value = "修改租户";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 初始化按钮操作 */
|
||||||
|
function handleInit(id){
|
||||||
|
InitData(id).then((response) => {
|
||||||
|
proxy.$modal.msgSuccess("初始化成功");
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 提交按钮 */
|
||||||
|
function submitForm() {
|
||||||
|
proxy.$refs["dataRef"].validate((valid) => {
|
||||||
|
if (valid) {
|
||||||
|
if (form.value.id != undefined) {
|
||||||
|
updateData(form.value.id, form.value).then((response) => {
|
||||||
|
proxy.$modal.msgSuccess("修改成功");
|
||||||
|
open.value = false;
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
addData(form.value).then((response) => {
|
||||||
|
proxy.$modal.msgSuccess("新增成功");
|
||||||
|
open.value = false;
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/** 删除按钮操作 */
|
||||||
|
function handleDelete(row) {
|
||||||
|
const delIds = row.id || ids.value;
|
||||||
|
proxy.$modal
|
||||||
|
.confirm('是否确认删除编号为"' + delIds + '"的数据项?')
|
||||||
|
.then(function () {
|
||||||
|
return delData(delIds);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
getList();
|
||||||
|
proxy.$modal.msgSuccess("删除成功");
|
||||||
|
})
|
||||||
|
.catch(() => { });
|
||||||
|
}
|
||||||
|
/** 导出按钮操作 */
|
||||||
|
function handleExport() { }
|
||||||
|
|
||||||
|
getList();
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user