feat: 隐藏账号切换
This commit is contained in:
parent
1c75a9b070
commit
d88c38df56
@ -3,37 +3,37 @@ import ChangePassword from './changePassword.vue'
|
||||
import { userStore } from '@/stores'
|
||||
import { storeToRefs } from 'pinia'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { getSN, isNotStudyMachine } from '@/utils'
|
||||
import { useTips } from '@/hooks'
|
||||
import { debounce } from 'lodash-es'
|
||||
import { loading } from '@/components/mj/mj-loading'
|
||||
// import { getSN, isNotStudyMachine } from '@/utils'
|
||||
// import { useTips } from '@/hooks'
|
||||
// import { debounce } from 'lodash-es'
|
||||
// import { loading } from '@/components/mj/mj-loading'
|
||||
import hud from '@/utils/hud'
|
||||
import settingApi from '@/api/system/setting'
|
||||
import userApi from '@/api/system/user'
|
||||
// import settingApi from '@/api/system/setting'
|
||||
// import userApi from '@/api/system/user'
|
||||
|
||||
const emits = defineEmits(['updateAccount'])
|
||||
// const emits = defineEmits(['updateAccount'])
|
||||
const router = useRouter()
|
||||
const { logout, changeAccount, getUserNow, clearUser } = userStore()
|
||||
const { userInfo, userRecords } = storeToRefs(userStore())
|
||||
const { logout } = userStore()
|
||||
const { userInfo } = storeToRefs(userStore())
|
||||
|
||||
interface AccountItemType {
|
||||
account?: string
|
||||
avatarFrameUrl?: string
|
||||
avatarUrl?: string
|
||||
nickName?: string
|
||||
nickNameFrameUrl?: string
|
||||
personalImageNum?: number
|
||||
token?: string
|
||||
}
|
||||
// interface AccountItemType {
|
||||
// account?: string
|
||||
// avatarFrameUrl?: string
|
||||
// avatarUrl?: string
|
||||
// nickName?: string
|
||||
// nickNameFrameUrl?: string
|
||||
// personalImageNum?: number
|
||||
// token?: string
|
||||
// }
|
||||
|
||||
const OSS_URL = import.meta.env.VITE_OSS_URL
|
||||
const bg = `url(${OSS_URL}/urm/header_bg.svg) 100%/cover no-repeat`
|
||||
const addAccount = `url(${OSS_URL}/urm/system_setting_account_add.svg) 100%/cover no-repeat`
|
||||
// const addAccount = `url(${OSS_URL}/urm/system_setting_account_add.svg) 100%/cover no-repeat`
|
||||
const showDia = ref(false)
|
||||
const accountLoading = ref(false)
|
||||
// const accountLoading = ref(false)
|
||||
|
||||
const activeAccount = ref<AccountItemType>({})
|
||||
const accountList = ref<AccountItemType[]>([])
|
||||
// const activeAccount = ref<AccountItemType>({})
|
||||
// const accountList = ref<AccountItemType[]>([])
|
||||
|
||||
// 退出登录
|
||||
async function handleConfirmLogout() {
|
||||
@ -47,95 +47,90 @@ async function handleConfirmLogout() {
|
||||
})
|
||||
}
|
||||
|
||||
// 切换账号
|
||||
async function handleSwitchAccount(i: AccountItemType) {
|
||||
if (i.account === userInfo.value.account) return
|
||||
try {
|
||||
loading.show('正在切换中...')
|
||||
|
||||
if (isNotStudyMachine) {
|
||||
const { data } = await userApi.switchUser({
|
||||
account: i.account,
|
||||
targetAccountOldToken: i.token,
|
||||
})
|
||||
await changeAccount(data.data)
|
||||
} else {
|
||||
const { data } = await settingApi.changeLoginAccApi({ account: i.account as string })
|
||||
await changeAccount(data.data)
|
||||
}
|
||||
activeAccount.value = i
|
||||
// await getInspectorInfo()
|
||||
// location.reload()
|
||||
} catch (err: any) {
|
||||
if (isNotStudyMachine) {
|
||||
clearUser(i.account!)
|
||||
}
|
||||
router.push({ path: '/login', query: { back: 1, a: i.account } })
|
||||
if (err.data.message) {
|
||||
useTips({
|
||||
tips: err.data.message,
|
||||
})
|
||||
}
|
||||
} finally {
|
||||
loading.hide()
|
||||
}
|
||||
}
|
||||
|
||||
// 登录过设备的账号
|
||||
async function getCurrentDeviceRelateAcc() {
|
||||
// web环境使用本地账户信息
|
||||
if (isNotStudyMachine) {
|
||||
accountList.value = userRecords.value
|
||||
activeAccount.value = getUserNow()
|
||||
return
|
||||
}
|
||||
accountLoading.value = true
|
||||
try {
|
||||
const { data } = await settingApi.getCurrentDeviceRelateAccApi()
|
||||
accountList.value = data.data
|
||||
activeAccount.value = data.data.find(
|
||||
(item: AccountItemType) => item.account === userInfo.value.account,
|
||||
)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
} finally {
|
||||
accountLoading.value = false
|
||||
}
|
||||
}
|
||||
function handleAddAccount() {
|
||||
router.push({ path: '/login', query: { back: 1 } })
|
||||
}
|
||||
function handleDelete(i: AccountItemType) {
|
||||
if (i.account === userInfo.value.account) return
|
||||
|
||||
hud.alert({
|
||||
content: `确定要删除账号${hud.highlight(i.nickName)}吗?`,
|
||||
ok: async () => {
|
||||
if (isNotStudyMachine) {
|
||||
clearUser(i.account!)
|
||||
accountList.value = userRecords.value
|
||||
return
|
||||
}
|
||||
// 安卓端删除设备关联账号
|
||||
settingApi
|
||||
.deleteDeviceRelateAccApi({
|
||||
simSerialNumber: getSN(),
|
||||
account: i.account,
|
||||
})
|
||||
.then(() => getCurrentDeviceRelateAcc())
|
||||
},
|
||||
})
|
||||
}
|
||||
const _handleDelete = debounce(handleDelete, 500, {
|
||||
leading: true,
|
||||
trailing: false,
|
||||
})
|
||||
onMounted(() => {
|
||||
getCurrentDeviceRelateAcc()
|
||||
})
|
||||
onActivated(() => {
|
||||
getCurrentDeviceRelateAcc()
|
||||
})
|
||||
// 切换账号 - 暂时隐藏
|
||||
// async function handleSwitchAccount(i: AccountItemType) {
|
||||
// if (i.account === userInfo.value.account) return
|
||||
// try {
|
||||
// loading.show('正在切换中...')
|
||||
//
|
||||
// if (isNotStudyMachine) {
|
||||
// const { data } = await userApi.switchUser({
|
||||
// account: i.account,
|
||||
// targetAccountOldToken: i.token,
|
||||
// })
|
||||
// await changeAccount(data.data)
|
||||
// } else {
|
||||
// const { data } = await settingApi.changeLoginAccApi({ account: i.account as string })
|
||||
// await changeAccount(data.data)
|
||||
// }
|
||||
// activeAccount.value = i
|
||||
// } catch (err: any) {
|
||||
// if (isNotStudyMachine) {
|
||||
// clearUser(i.account!)
|
||||
// }
|
||||
// router.push({ path: '/login', query: { back: 1, a: i.account } })
|
||||
// if (err.data.message) {
|
||||
// useTips({
|
||||
// tips: err.data.message,
|
||||
// })
|
||||
// }
|
||||
// } finally {
|
||||
// loading.hide()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// async function getCurrentDeviceRelateAcc() {
|
||||
// if (isNotStudyMachine) {
|
||||
// accountList.value = userRecords.value
|
||||
// activeAccount.value = getUserNow()
|
||||
// return
|
||||
// }
|
||||
// accountLoading.value = true
|
||||
// try {
|
||||
// const { data } = await settingApi.getCurrentDeviceRelateAccApi()
|
||||
// accountList.value = data.data
|
||||
// activeAccount.value = data.data.find(
|
||||
// (item: AccountItemType) => item.account === userInfo.value.account,
|
||||
// )
|
||||
// } catch (err) {
|
||||
// console.log(err)
|
||||
// } finally {
|
||||
// accountLoading.value = false
|
||||
// }
|
||||
// }
|
||||
// function handleAddAccount() {
|
||||
// router.push({ path: '/login', query: { back: 1 } })
|
||||
// }
|
||||
// function handleDelete(i: AccountItemType) {
|
||||
// if (i.account === userInfo.value.account) return
|
||||
//
|
||||
// hud.alert({
|
||||
// content: `确定要删除账号${hud.highlight(i.nickName)}吗?`,
|
||||
// ok: async () => {
|
||||
// if (isNotStudyMachine) {
|
||||
// clearUser(i.account!)
|
||||
// accountList.value = userRecords.value
|
||||
// return
|
||||
// }
|
||||
// settingApi
|
||||
// .deleteDeviceRelateAccApi({
|
||||
// simSerialNumber: getSN(),
|
||||
// account: i.account,
|
||||
// })
|
||||
// .then(() => getCurrentDeviceRelateAcc())
|
||||
// },
|
||||
// })
|
||||
// }
|
||||
// const _handleDelete = debounce(handleDelete, 500, {
|
||||
// leading: true,
|
||||
// trailing: false,
|
||||
// })
|
||||
// onMounted(() => {
|
||||
// getCurrentDeviceRelateAcc()
|
||||
// })
|
||||
// onActivated(() => {
|
||||
// getCurrentDeviceRelateAcc()
|
||||
// })
|
||||
</script>
|
||||
<template>
|
||||
<div class="account_module hidden_scroll">
|
||||
@ -187,7 +182,7 @@ onActivated(() => {
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
<!-- 切换账号 -->
|
||||
<!-- 切换账号 - 暂时隐藏
|
||||
<div class="switch_account">
|
||||
<div
|
||||
class="header"
|
||||
@ -224,6 +219,7 @@ onActivated(() => {
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
<ChangePassword v-model="showDia" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user