Merge pull request 'v2.1dev' (#457) from shiningrise/Admin.NET.Pro:v2.1dev into v2.1
Reviewed-on: https://code.adminnet.top/Admin.NET/Admin.NET.Pro/pulls/457
This commit is contained in:
commit
755560ee41
@ -20,6 +20,8 @@ public class SysAuthService : IDynamicApiController, ITransient
|
|||||||
private readonly SqlSugarRepository<SysUser> _sysUserRep;
|
private readonly SqlSugarRepository<SysUser> _sysUserRep;
|
||||||
private readonly SysConfigService _sysConfigService;
|
private readonly SysConfigService _sysConfigService;
|
||||||
private readonly SysCacheService _sysCacheService;
|
private readonly SysCacheService _sysCacheService;
|
||||||
|
private readonly SysTenantService _sysTenantService;
|
||||||
|
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||||
private readonly ICaptcha _captcha;
|
private readonly ICaptcha _captcha;
|
||||||
private readonly IEventPublisher _eventPublisher;
|
private readonly IEventPublisher _eventPublisher;
|
||||||
@ -28,6 +30,7 @@ public class SysAuthService : IDynamicApiController, ITransient
|
|||||||
SqlSugarRepository<SysUser> sysUserRep,
|
SqlSugarRepository<SysUser> sysUserRep,
|
||||||
SysConfigService sysConfigService,
|
SysConfigService sysConfigService,
|
||||||
SysCacheService sysCacheService,
|
SysCacheService sysCacheService,
|
||||||
|
SysTenantService sysTenantService,
|
||||||
IHttpContextAccessor httpContextAccessor,
|
IHttpContextAccessor httpContextAccessor,
|
||||||
ICaptcha captcha,
|
ICaptcha captcha,
|
||||||
IEventPublisher eventPublisher)
|
IEventPublisher eventPublisher)
|
||||||
@ -36,6 +39,7 @@ public class SysAuthService : IDynamicApiController, ITransient
|
|||||||
_sysUserRep = sysUserRep;
|
_sysUserRep = sysUserRep;
|
||||||
_sysConfigService = sysConfigService;
|
_sysConfigService = sysConfigService;
|
||||||
_sysCacheService = sysCacheService;
|
_sysCacheService = sysCacheService;
|
||||||
|
_sysTenantService = sysTenantService;
|
||||||
_httpContextAccessor = httpContextAccessor;
|
_httpContextAccessor = httpContextAccessor;
|
||||||
_captcha = captcha;
|
_captcha = captcha;
|
||||||
_eventPublisher = eventPublisher;
|
_eventPublisher = eventPublisher;
|
||||||
@ -114,8 +118,8 @@ public class SysAuthService : IDynamicApiController, ITransient
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
// 判断账号是否存在
|
// 判断账号是否存在
|
||||||
var user = await _sysUserRep.AsQueryable().Includes(t => t.SysOrg).ClearFilter<ITenantIdFilter>()
|
var user = await _sysUserRep.AsQueryable().Includes(t => t.SysOrg)
|
||||||
//.WhereIF(tenantId > 0, u => u.TenantId == tenantId)
|
.WhereIF(tenantId > 0, u => u.TenantId == tenantId)
|
||||||
.WhereIF(!string.IsNullOrWhiteSpace(account), u => u.Account.Equals(account))
|
.WhereIF(!string.IsNullOrWhiteSpace(account), u => u.Account.Equals(account))
|
||||||
.WhereIF(!string.IsNullOrWhiteSpace(phone), u => u.Phone.Equals(phone))
|
.WhereIF(!string.IsNullOrWhiteSpace(phone), u => u.Phone.Equals(phone))
|
||||||
.FirstAsync();
|
.FirstAsync();
|
||||||
@ -405,4 +409,20 @@ public class SysAuthService : IDynamicApiController, ITransient
|
|||||||
return 401;
|
return 401;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根据域名获取租户ID 🔖
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[SuppressMonitor]
|
||||||
|
[DisplayName("根据域名获取租户ID")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public long GetTenantIdByHostname(string hostname)
|
||||||
|
{
|
||||||
|
var list = _sysCacheService.Get<List<SysTenant>>(CacheConst.KeyTenant);
|
||||||
|
var tenant = list.Find(p => p.Host.Contains(hostname));
|
||||||
|
if(tenant != null)
|
||||||
|
return tenant.Id;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
// 是否有权操作此账号
|
// 是否有权操作此账号
|
||||||
if (!_userManager.SuperAdmin && input.AccountType is AccountTypeEnum.SuperAdmin) throw Oops.Oh(ErrorCodeEnum.D1033);
|
if (!_userManager.SuperAdmin && input.AccountType is AccountTypeEnum.SuperAdmin) throw Oops.Oh(ErrorCodeEnum.D1033);
|
||||||
|
|
||||||
var query = _sysUserRep.AsQueryable().ClearFilter<ITenantIdFilter>();
|
var query = _sysUserRep.AsQueryable();
|
||||||
if (await query.AnyAsync(u => u.Account == input.Account)) throw Oops.Oh(ErrorCodeEnum.D1003);
|
if (await query.AnyAsync(u => u.Account == input.Account)) throw Oops.Oh(ErrorCodeEnum.D1003);
|
||||||
if (!string.IsNullOrWhiteSpace(input.Phone) && await query.AnyAsync(u => u.Phone == input.Phone)) throw Oops.Oh(ErrorCodeEnum.D1032);
|
if (!string.IsNullOrWhiteSpace(input.Phone) && await query.AnyAsync(u => u.Phone == input.Phone)) throw Oops.Oh(ErrorCodeEnum.D1032);
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ public class SysUserService : IDynamicApiController, ITransient
|
|||||||
[DisplayName("更新用户")]
|
[DisplayName("更新用户")]
|
||||||
public virtual async Task UpdateUser(UpdateUserInput input)
|
public virtual async Task UpdateUser(UpdateUserInput input)
|
||||||
{
|
{
|
||||||
var query = _sysUserRep.AsQueryable().ClearFilter<ITenantIdFilter>().Where(u => u.Id != input.Id);
|
var query = _sysUserRep.AsQueryable().Where(u => u.Id != input.Id);
|
||||||
if (await query.AnyAsync(u => u.Account == input.Account)) throw Oops.Oh(ErrorCodeEnum.D1003);
|
if (await query.AnyAsync(u => u.Account == input.Account)) throw Oops.Oh(ErrorCodeEnum.D1003);
|
||||||
if (!string.IsNullOrWhiteSpace(input.Phone) && await query.AnyAsync(u => u.Phone == input.Phone)) throw Oops.Oh(ErrorCodeEnum.D1032);
|
if (!string.IsNullOrWhiteSpace(input.Phone) && await query.AnyAsync(u => u.Phone == input.Phone)) throw Oops.Oh(ErrorCodeEnum.D1032);
|
||||||
|
|
||||||
|
|||||||
@ -154,5 +154,8 @@
|
|||||||
"element-plus",
|
"element-plus",
|
||||||
"vue-next-admin",
|
"vue-next-admin",
|
||||||
"next-admin"
|
"next-admin"
|
||||||
]
|
],
|
||||||
|
"volta": {
|
||||||
|
"node": "22.19.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
import request from '/@/utils/request';
|
import request from '/@/utils/request';
|
||||||
|
enum Api {
|
||||||
|
GetTenantIdByHostname = '/api/sysAuth/tenantIdByHostname',
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* (不建议写成 request.post(xxx),因为这样 post 时,无法 params 与 data 同时传参)
|
* (不建议写成 request.post(xxx),因为这样 post 时,无法 params 与 data 同时传参)
|
||||||
*
|
*
|
||||||
@ -25,3 +27,9 @@ export function useLoginApi() {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getTenantIdByHostname = (hostname: string) =>
|
||||||
|
request({
|
||||||
|
url: `${Api.GetTenantIdByHostname}/${hostname}`,
|
||||||
|
method: 'get',
|
||||||
|
});
|
||||||
|
|||||||
@ -229,7 +229,8 @@ const onSignIn = async () => {
|
|||||||
const publicKey = window.__env__.VITE_SM_PUBLIC_KEY;
|
const publicKey = window.__env__.VITE_SM_PUBLIC_KEY;
|
||||||
const password = sm2.doEncrypt(state.ruleForm.password, publicKey, 1);
|
const password = sm2.doEncrypt(state.ruleForm.password, publicKey, 1);
|
||||||
|
|
||||||
const tenantid = route.query.tid ?? 0;
|
//const tenantid = route.query.tid ?? 0;
|
||||||
|
const tenantid = Local.get('tid') ?? 0;
|
||||||
const [err, res] = await feature(getAPI(SysAuthApi).apiSysAuthLoginPost({ ...state.ruleForm, password: password, tenantId: Number(tenantid) }));
|
const [err, res] = await feature(getAPI(SysAuthApi).apiSysAuthLoginPost({ ...state.ruleForm, password: password, tenantId: Number(tenantid) }));
|
||||||
if (err) {
|
if (err) {
|
||||||
getCaptcha(); // 重新获取验证码
|
getCaptcha(); // 重新获取验证码
|
||||||
|
|||||||
@ -102,7 +102,7 @@ import { Local } from '/@/utils/storage';
|
|||||||
// 引入多语言
|
// 引入多语言
|
||||||
import { languageList, getCountryCode } from '/@/i18n';
|
import { languageList, getCountryCode } from '/@/i18n';
|
||||||
import '/node_modules/flag-icons/css/flag-icons.min.css';
|
import '/node_modules/flag-icons/css/flag-icons.min.css';
|
||||||
|
import { getTenantIdByHostname } from '/@/api/login/index';
|
||||||
// 引入组件
|
// 引入组件
|
||||||
const Account = defineAsyncComponent(() => import('/@/views/login/component/account.vue'));
|
const Account = defineAsyncComponent(() => import('/@/views/login/component/account.vue'));
|
||||||
const Mobile = defineAsyncComponent(() => import('/@/views/login/component/mobile.vue'));
|
const Mobile = defineAsyncComponent(() => import('/@/views/login/component/mobile.vue'));
|
||||||
@ -129,7 +129,13 @@ onMounted(async () => {
|
|||||||
if (!route.query.tid) Local.remove('tid');
|
if (!route.query.tid) Local.remove('tid');
|
||||||
var tenantid = Number(route.query.tid);
|
var tenantid = Number(route.query.tid);
|
||||||
if (isNaN(tenantid)) {
|
if (isNaN(tenantid)) {
|
||||||
tenantid = 0;
|
// 确保hostname不包含端口号
|
||||||
|
const hostnameWithoutPort = window.location.hostname;
|
||||||
|
const data = await getTenantIdByHostname(hostnameWithoutPort);
|
||||||
|
console.log('tenantid', data.data.result);
|
||||||
|
tenantid = data.data.result;
|
||||||
|
if (tenantid > 99999)
|
||||||
|
Local.set('tid', tenantid);
|
||||||
} else if (tenantid > 99999) {
|
} else if (tenantid > 99999) {
|
||||||
Local.set('tid', tenantid);
|
Local.set('tid', tenantid);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -101,6 +101,7 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
|
|||||||
port: env.VITE_PORT as unknown as number,
|
port: env.VITE_PORT as unknown as number,
|
||||||
open: JSON.parse(env.VITE_OPEN),
|
open: JSON.parse(env.VITE_OPEN),
|
||||||
hmr: true,
|
hmr: true,
|
||||||
|
allowedHosts:true,
|
||||||
proxy: {
|
proxy: {
|
||||||
'^/[Uu]pload': {
|
'^/[Uu]pload': {
|
||||||
target: env.VITE_API_URL,
|
target: env.VITE_API_URL,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user