feat : 用户账号切换
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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 = () => {
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user