feat : 用户账号切换

This commit is contained in:
clay
2024-06-19 01:26:24 +08:00
parent 5410b6d248
commit 59014f6367
3 changed files with 47 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ export const getCodeImg = () => {
})
}
export const login = (data) => {
return request({
url: '/auth/login',
@@ -14,6 +15,12 @@ export const login = (data) => {
data
})
}
export const switchAccount = (userId) => {
return request({
url: `/auth/switch/account/${userId}`,
method: 'post',
})
}
export const getUserInfo = () => {
return request({

View File

@@ -15,6 +15,12 @@ export const getSubCompOpt = () => {
method: 'get'
})
}
export const getUserAccount = () => {
return request({
url: `/admin/mosr/user/account/list`,
method: 'get'
})
}
// 查询角色信息
export const getRolesOpt = () => {

View File

@@ -11,6 +11,10 @@
</div>
<div class="person" v-if="visitedP">
<ul>
<el-select v-model="selectUserId" @change="accountChange">
<el-option v-for="item in accountList" :label="item.userName" :value="item.userId"/>
</el-select>
<li @click="handleToAuth">个人中心</li>
<li @click="handleLogout">退出登录</li>
</ul>
@@ -26,13 +30,18 @@ import Breadcrumb from './Breadcrumb.vue';
import Hamburger from './Hamburger.vue';
import {useAuthStore} from '@/stores/userstore.js'
import {usePermisstionStroe} from '@/stores/permisstion'
import { useTagsView } from '@/stores/tagsview';
import {useTagsView} from '@/stores/tagsview';
import {getUserAccount} from "@/api/user/user";
import {switchAccount} from "@/api/login";
import {setToken} from "../../utils/auth";
const authStore = useAuthStore()
const permisstionStore = usePermisstionStroe()
const tagsViewStore = useTagsView()
const userInfo = ref({})
const visitedP = ref(false)
const accountList = ref([])
const selectUserId = ref()
const router = useRouter()
onMounted(() => {
setUserInfo()
@@ -48,7 +57,29 @@ const nullBlockClick = () => {
visitedP.value = false
}
const handleVisitedP = () => {
visitedP.value = !visitedP.value
getUserAccount().then(res => {
console.log(res)
accountList.value = res.data
nextTick(() => {
visitedP.value = !visitedP.value
})
})
}
const accountChange = () => {
switchAccount(selectUserId.value).then(res =>{
if (res.code == 1000){
visitedP.value = !visitedP.value
authStore.userLogout()
permisstionStore.removeMenu()
permisstionStore.setIsSuccessReq()
tagsViewStore.removeAllTagView()
setToken(res.data)
router.push('/')
}
})
}
const handleToAuth = () => {
@@ -63,6 +94,7 @@ const handleLogout = () => {
tagsViewStore.removeAllTagView()
router.push('/login')
}
</script>
<style lang="scss" scoped>