身份切换

master
lzq 2026-03-02 18:11:08 +08:00
parent aec179db0d
commit db70664f18
4 changed files with 277 additions and 170 deletions

View File

@ -6,176 +6,29 @@ import {
import Strings from '@/common/utils/strings.ts' import Strings from '@/common/utils/strings.ts'
import Evt from '@/common/utils/evt.ts' import Evt from '@/common/utils/evt.ts'
interface IdentityInfo {
identityCategory: string
customerId: string
/**
* Idcst_org.id
*/
orgId: string
/**
*
*/
customerName: string
/**
*
*/
phone: string
/**
* YueJie-->YuE-->XianFu-->
*/
settlementWay: string
settlementWayTxt: string
/**
* 0-->1-->
*/
manager: boolean
/**
* GeTiHu-->QiYe-->
*/
orgCategory: string
orgCategoryTxt: string
/**
*
*/
uscc: string
/**
*
*/
orgName: string
/**
*
*/
businessLicense: string
/**
*
*/
licenseStartTime: string
/**
*
*/
licenseEndTime: string
/**
*
*/
legalRepresentative: string
/**
*
*/
idcard: string
/**
*
*/
idcardStartTime: string
/**
*
*/
idcardEndTime: string
/**
*
*/
idcardFront: string
/**
*
*/
idcardBack: string
/**
*
*/
province: string
/**
*
*/
city: string
/**
*
*/
area: string
/**
*
*/
town: string
/**
*
*/
provinceName: string
/**
*
*/
cityName: string
/**
*
*/
areaName: string
/**
*
*/
townName: string
/**
*
*/
address: string
/**
*
*/
lng: string
/**
*
*/
lat: string
}
export const useAppUserStore = defineStore('AppUser', () => { export const useAppUserStore = defineStore('AppUser', () => {
const userId = ref<string | null>(null) const userId = ref<string | null>(null)
const roles = ref<string[]>([]) const roles = ref<string[]>([])
const bizObj = ref<string | null>(null)
const nickname = ref<string | null>(null) const nickname = ref<string | null>(null)
const avatar = ref<string | null>(null) const avatar = ref<string | null>(null)
const token = ref<string | null>(null) const token = ref<string | null>(null)
const tenantId = ref<string | null>(null) const tenantId = ref<string | null>(null)
const tenantName = ref<string | null>(null) const tenantName = ref<string | null>(null)
const currentIdentity = ref<IdentityInfo | null>(null) const currentCustomerId = ref<string | null>(null)
const identities = ref<IdentityInfo[]>([]) const identities = ref<LoginTypes.IdentityInfo[]>([])
const currentIdentity = ref<LoginTypes.IdentityInfo | null>(null)
const isAuthenticated = computed(() => !Strings.isEmpty(token.value)) const isAuthenticated = computed(() => !Strings.isEmpty(token.value))
const hasCaiGou = ref<boolean>(false)
const isXiaoNa = computed(() => { const isCaiGou = ref<boolean>(false)
return roles.value.includes('ROLE_XiaoNa') const hasChanFei = ref<boolean>(false)
}) const isChanFei = ref<boolean>(false)
const hasSiJi = ref<boolean>(false)
const isAdmin = computed(() => { const isSiJi = ref<boolean>(false)
return roles.value.includes('ROLE_ADMIN') const hasXiaoNa = ref<boolean>(false)
}) const isXiaoNa = ref<boolean>(false)
const hasYunShu = ref<boolean>(false)
const isYunShu = ref<boolean>(false)
const isAdmin = ref<boolean>(false)
function $reset() { function $reset() {
userId.value = null userId.value = null
@ -184,8 +37,23 @@ export const useAppUserStore = defineStore('AppUser', () => {
token.value = null token.value = null
tenantId.value = null tenantId.value = null
tenantName.value = null tenantName.value = null
bizObj.value = null
roles.value = [] roles.value = []
currentCustomerId.value = null
currentIdentity.value = null
identities.value = []
tenantId.value = null
tenantName.value = null
hasCaiGou.value = false
isCaiGou.value = false
hasChanFei.value = false
isChanFei.value = false
hasSiJi.value = false
isSiJi.value = false
hasXiaoNa.value = false
isXiaoNa.value = false
hasYunShu.value = false
isYunShu.value = false
isAdmin.value = false
} }
Evt.on('logout', $reset) Evt.on('logout', $reset)
@ -197,18 +65,27 @@ export const useAppUserStore = defineStore('AppUser', () => {
token, token,
tenantId, tenantId,
tenantName, tenantName,
bizObj,
isAuthenticated, isAuthenticated,
roles, roles,
hasCaiGou,
isCaiGou,
hasChanFei,
isChanFei,
hasSiJi,
isSiJi,
hasXiaoNa,
isXiaoNa, isXiaoNa,
hasYunShu,
isYunShu,
isAdmin, isAdmin,
identities, identities,
currentIdentity, currentIdentity,
currentCustomerId,
$reset, $reset,
} }
}, { }, {
persist: { persist: {
pick: [ 'userId', 'avatar', 'nickname', 'token', 'tenantId', 'tenantName', 'bizObj' ], pick: [ 'userId', 'avatar', 'nickname', 'token', 'tenantId', 'tenantName' ],
}, },
}) })

View File

@ -45,8 +45,21 @@ export function reloadUserInfo() {
avatar: data.avatar, avatar: data.avatar,
tenantId: data.tenantId, tenantId: data.tenantId,
tenantName: data.tenantName, tenantName: data.tenantName,
bizObj: data.bizObj,
roles: data.roles, roles: data.roles,
currentCustomerId: data.currentCustomerId,
identities: data.identities,
currentIdentity: data.currentIdentity,
hasCaiGou: data.hasCaiGou,
isCaiGou: data.isCaiGou,
hasChanFei: data.hasChanFei,
isChanFei: data.isChanFei,
hasSiJi: data.hasSiJi,
isSiJi: data.isSiJi,
hasXiaoNa: data.hasXiaoNa,
isXiaoNa: data.isXiaoNa,
hasYunShu: data.hasYunShu,
isYunShu: data.isYunShu,
isAdmin: data.isAdmin,
}) })
}) })
} }
@ -59,9 +72,7 @@ export function hasPermission(resSn?: string) {
export function changeIdentity(id: string) { export function changeIdentity(id: string) {
return AppApi.changeIdentity(id) return AppApi.changeIdentity(id)
.then(() => { .then(reloadUserInfo)
return reloadUserInfo()
})
} }
export function saveFile(r: Promise<R<{ content: Blob, filename: string }>>, defaultName: string = '下载的文件') { export function saveFile(r: Promise<R<{ content: Blob, filename: string }>>, defaultName: string = '下载的文件') {

View File

@ -6,10 +6,22 @@ import AIcon from '@/components/a-icon/AIcon.vue'
import { useAppPageStore } from '@/common/app/app-page-store.ts' import { useAppPageStore } from '@/common/app/app-page-store.ts'
import { elIcons } from '@/common/element/element.ts' import { elIcons } from '@/common/element/element.ts'
import ATabbar from '@/pages/a-frame/ATabbar.vue' import ATabbar from '@/pages/a-frame/ATabbar.vue'
import { useAppUserStore } from '@/common/app/app-user-store.ts'
import { changeIdentity } from '@/common/app'
import Colls from '@/common/utils/colls.ts'
const appPageStore = useAppPageStore() const appPageStore = useAppPageStore()
const isCollapse = ref(false) const isCollapse = ref(false)
const changingIdentity = ref(false)
const appUserStore = useAppUserStore()
function changeIdentityHandle(val: string) {
changingIdentity.value = true
changeIdentity(val)
.finally(() => {
changingIdentity.value = false
})
}
onMounted(() => { onMounted(() => {
Evt.emit('connect_ws') Evt.emit('connect_ws')
@ -42,6 +54,19 @@ onUnmounted(() => {
<ElButton text> <ElButton text>
<AIcon name="settings"/> <AIcon name="settings"/>
</ElButton> </ElButton>
<ElSelect
v-if="!Colls.isEmpty(appUserStore.identities)"
:class="{'change-identity-changing':changingIdentity}"
:disabled="changingIdentity"
:model-value="appUserStore.currentCustomerId"
:show-arrow="changingIdentity"
:suffix-icon="changingIdentity?elIcons.Loading:elIcons.ArrowDown"
class="change-identity" @change="changeIdentityHandle">
<ElOption v-for="item in appUserStore.identities"
:key="item.identityCategory"
:label="item.identityCategoryTxt"
:value="item.customerId"/>
</ElSelect>
</div> </div>
<AAvatar/> <AAvatar/>
</div> </div>
@ -62,6 +87,15 @@ onUnmounted(() => {
</template> </template>
<style lang="stylus" scoped> <style lang="stylus" scoped>
@keyframes el-select__icon-rotate {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.a-frame { .a-frame {
height 100% height 100%
width 100%; width 100%;
@ -81,13 +115,35 @@ onUnmounted(() => {
& > section { & > section {
height 100% height 100%
//padding-right 20px
.a-frame-header { .a-frame-header {
height 110px height 110px
padding 0 10px 0 0 padding 0 10px 0 0
background-color: #FAFBFC; background-color: #FAFBFC;
.change-identity {
width: 120px
:deep(.el-select__wrapper) {
box-shadow: unset !important
}
:deep(.el-select__wrapper.is-disabled) {
background-color unset !important
}
:deep(.el-select__icon) {
color var(--el-color-primary)
}
}
.change-identity-changing {
:deep(.el-select__icon) {
animation: el-select__icon-rotate 1s linear infinite;
}
}
& > div:nth-child(1) { & > div:nth-child(1) {
height 60px height 60px
width 100% width 100%

View File

@ -14,10 +14,160 @@ declare global {
logo: string | null logo: string | null
} }
interface IdentityInfo {
identityCategory: string
identityCategoryTxt: string
customerId: string
/**
* Idcst_org.id
*/
orgId: string
/**
*
*/
customerName: string
/**
*
*/
phone: string
/**
* YueJie-->YuE-->XianFu-->
*/
settlementWay: string
settlementWayTxt: string
/**
* 0-->1-->
*/
manager: boolean
/**
* GeTiHu-->QiYe-->
*/
orgCategory: string
orgCategoryTxt: string
/**
*
*/
uscc: string
/**
*
*/
orgName: string
/**
*
*/
businessLicense: string
/**
*
*/
licenseStartTime: string
/**
*
*/
licenseEndTime: string
/**
*
*/
legalRepresentative: string
/**
*
*/
idcard: string
/**
*
*/
idcardStartTime: string
/**
*
*/
idcardEndTime: string
/**
*
*/
idcardFront: string
/**
*
*/
idcardBack: string
/**
*
*/
province: string
/**
*
*/
city: string
/**
*
*/
area: string
/**
*
*/
town: string
/**
*
*/
provinceName: string
/**
*
*/
cityName: string
/**
*
*/
areaName: string
/**
*
*/
townName: string
/**
*
*/
address: string
/**
*
*/
lng: string
/**
*
*/
lat: string
}
interface UserDetail { interface UserDetail {
id: string id: string
nickname: string nickname: string
bizObj?: string
avatar?: string avatar?: string
tenantId?: string tenantId?: string
tenantName?: string tenantName?: string
@ -27,6 +177,19 @@ declare global {
setting: UserSetting setting: UserSetting
currentCustomerId: string currentCustomerId: string
currentOrgId: string currentOrgId: string
hasCaiGou: boolean
isCaiGou: boolean
hasChanFei: boolean
isChanFei: boolean
hasSiJi: boolean
isSiJi: boolean
hasXiaoNa: boolean
isXiaoNa: boolean
hasYunShu: boolean
isYunShu: boolean
isAdmin: boolean
identities: IdentityInfo[]
currentIdentity: IdentityInfo
} }