mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-11-10 14:57:09 +08:00
chore(login): 调整租户登录逻辑
This commit is contained in:
@@ -6,7 +6,6 @@ export * from './modules/route'
|
||||
export * from './modules/tabs'
|
||||
export * from './modules/dict'
|
||||
export * from './modules/user'
|
||||
export * from './modules/tenant'
|
||||
|
||||
const pinia = createPinia()
|
||||
pinia.use(piniaPluginPersistedstate)
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { computed, reactive } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
const storeSetup = () => {
|
||||
interface TenantInfo {
|
||||
tenantEnabled: boolean
|
||||
tenantCode: string
|
||||
export const useTenantStore = defineStore('tenant', () => {
|
||||
const tenantEnabled = ref(false)
|
||||
const tenantId = ref('')
|
||||
|
||||
const setTenantEnable = (status: boolean) => {
|
||||
tenantEnabled.value = status
|
||||
}
|
||||
const tenantInfo = reactive<TenantInfo>({
|
||||
tenantEnabled: false,
|
||||
tenantCode: '',
|
||||
const setTenantId = (id: string) => {
|
||||
tenantId.value = id
|
||||
}
|
||||
|
||||
// 判断是否需要用户输入租户编码
|
||||
const needInputTenantId = computed(() => {
|
||||
return tenantEnabled.value && !tenantId.value
|
||||
})
|
||||
const tenantEnabled = computed(() => tenantInfo.tenantEnabled)
|
||||
const tenantCode = computed(() => tenantInfo.tenantCode)
|
||||
const setTenantEnable = (tenantStatus: boolean) => {
|
||||
tenantInfo.tenantEnabled = tenantStatus
|
||||
}
|
||||
const setTenantCode = (tenantCode: string) => {
|
||||
tenantInfo.tenantCode = tenantCode
|
||||
}
|
||||
return {
|
||||
tenantCode,
|
||||
tenantEnabled,
|
||||
setTenantCode,
|
||||
setTenantEnable,
|
||||
}
|
||||
}
|
||||
|
||||
export const useTenantStore = defineStore('tenant', storeSetup, {
|
||||
persist: { paths: ['tenantInfo'], storage: localStorage },
|
||||
return {
|
||||
tenantEnabled,
|
||||
tenantId,
|
||||
setTenantEnable,
|
||||
setTenantId,
|
||||
needInputTenantId,
|
||||
}
|
||||
}, {
|
||||
persist: { paths: ['tenantEnabled', 'tenantId'], storage: localStorage },
|
||||
})
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { useTenantStore } from './tenant'
|
||||
import { resetRouter } from '@/router'
|
||||
import {
|
||||
type AccountLoginReq,
|
||||
@@ -18,6 +19,7 @@ import { clearToken, getToken, setToken } from '@/utils/auth'
|
||||
import { resetHasRouteFlag } from '@/router/guard'
|
||||
|
||||
const storeSetup = () => {
|
||||
const tenantStore = useTenantStore()
|
||||
const userInfo = reactive<UserInfo>({
|
||||
id: '',
|
||||
username: '',
|
||||
@@ -41,7 +43,6 @@ const storeSetup = () => {
|
||||
const pwdExpiredShow = ref<boolean>(true)
|
||||
const roles = ref<string[]>([]) // 当前用户角色
|
||||
const permissions = ref<string[]>([]) // 当前角色权限标识集合
|
||||
|
||||
// 重置token
|
||||
const resetToken = () => {
|
||||
token.value = ''
|
||||
@@ -53,6 +54,7 @@ const storeSetup = () => {
|
||||
const accountLogin = async (req: AccountLoginReq, tenantCode?: string) => {
|
||||
const res = await accountLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.ACCOUNT }, tenantCode)
|
||||
setToken(res.data.token)
|
||||
tenantStore.setTenantId(res.data.tenantId)
|
||||
token.value = res.data.token
|
||||
}
|
||||
|
||||
@@ -60,6 +62,7 @@ const storeSetup = () => {
|
||||
const emailLogin = async (req: EmailLoginReq, tenantCode?: string) => {
|
||||
const res = await emailLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.EMAIL }, tenantCode)
|
||||
setToken(res.data.token)
|
||||
tenantStore.setTenantId(res.data.tenantId)
|
||||
token.value = res.data.token
|
||||
}
|
||||
|
||||
@@ -67,13 +70,15 @@ const storeSetup = () => {
|
||||
const phoneLogin = async (req: PhoneLoginReq, tenantCode?: string) => {
|
||||
const res = await phoneLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.PHONE }, tenantCode)
|
||||
setToken(res.data.token)
|
||||
tenantStore.setTenantId(res.data.tenantId)
|
||||
token.value = res.data.token
|
||||
}
|
||||
|
||||
// 三方账号登录
|
||||
const socialLogin = async (source: string, req: any) => {
|
||||
const res = await socialLoginApi({ ...req, source, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.SOCIAL })
|
||||
const res: any = await socialLoginApi({ ...req, source, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.SOCIAL })
|
||||
setToken(res.data.token)
|
||||
tenantStore.setTenantId(res.data.tenantId)
|
||||
token.value = res.data.token
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user