feat : 用户账号切换
This commit is contained in:
@@ -7,6 +7,7 @@ export const getCodeImg = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const login = (data) => {
|
export const login = (data) => {
|
||||||
return request({
|
return request({
|
||||||
url: '/auth/login',
|
url: '/auth/login',
|
||||||
@@ -14,6 +15,12 @@ export const login = (data) => {
|
|||||||
data
|
data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
export const switchAccount = (userId) => {
|
||||||
|
return request({
|
||||||
|
url: `/auth/switch/account/${userId}`,
|
||||||
|
method: 'post',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export const getUserInfo = () => {
|
export const getUserInfo = () => {
|
||||||
return request({
|
return request({
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ export const getSubCompOpt = () => {
|
|||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
export const getUserAccount = () => {
|
||||||
|
return request({
|
||||||
|
url: `/admin/mosr/user/account/list`,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// 查询角色信息
|
// 查询角色信息
|
||||||
export const getRolesOpt = () => {
|
export const getRolesOpt = () => {
|
||||||
|
|||||||
@@ -11,6 +11,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="person" v-if="visitedP">
|
<div class="person" v-if="visitedP">
|
||||||
<ul>
|
<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="handleToAuth">个人中心</li>
|
||||||
<li @click="handleLogout">退出登录</li>
|
<li @click="handleLogout">退出登录</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -26,13 +30,18 @@ import Breadcrumb from './Breadcrumb.vue';
|
|||||||
import Hamburger from './Hamburger.vue';
|
import Hamburger from './Hamburger.vue';
|
||||||
import {useAuthStore} from '@/stores/userstore.js'
|
import {useAuthStore} from '@/stores/userstore.js'
|
||||||
import {usePermisstionStroe} from '@/stores/permisstion'
|
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 authStore = useAuthStore()
|
||||||
const permisstionStore = usePermisstionStroe()
|
const permisstionStore = usePermisstionStroe()
|
||||||
const tagsViewStore = useTagsView()
|
const tagsViewStore = useTagsView()
|
||||||
const userInfo = ref({})
|
const userInfo = ref({})
|
||||||
const visitedP = ref(false)
|
const visitedP = ref(false)
|
||||||
|
const accountList = ref([])
|
||||||
|
const selectUserId = ref()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
setUserInfo()
|
setUserInfo()
|
||||||
@@ -48,7 +57,29 @@ const nullBlockClick = () => {
|
|||||||
visitedP.value = false
|
visitedP.value = false
|
||||||
}
|
}
|
||||||
const handleVisitedP = () => {
|
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 = () => {
|
const handleToAuth = () => {
|
||||||
@@ -63,6 +94,7 @@ const handleLogout = () => {
|
|||||||
tagsViewStore.removeAllTagView()
|
tagsViewStore.removeAllTagView()
|
||||||
router.push('/login')
|
router.push('/login')
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user