新增退出登录功能
This commit is contained in:
parent
8b92378de4
commit
f896433068
|
|
@ -8,15 +8,9 @@ export function getUsers(data = {}) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUser(id) {
|
export function getUser() {
|
||||||
if (id) {
|
|
||||||
return request({
|
|
||||||
url: `/user/${id}`,
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return request({
|
return request({
|
||||||
url: '/user',
|
url: '/index/getUserInfo',
|
||||||
method: 'get'
|
method: 'get'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,17 @@
|
||||||
<template>
|
<template>
|
||||||
<n-layout-header class="layout__header" bordered>
|
<n-layout-header class="layout__header" bordered>
|
||||||
<!-- <SideMenu menu-mode="horizontal" /> -->
|
<!-- <SideMenu menu-mode="horizontal" /> -->
|
||||||
<div class="user_msg">
|
<log-out />
|
||||||
<n-image
|
|
||||||
class="user_avatar"
|
|
||||||
src="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
|
|
||||||
preview-disabled
|
|
||||||
/>
|
|
||||||
<span class="user_name">用户名</span>
|
|
||||||
</div>
|
|
||||||
</n-layout-header>
|
</n-layout-header>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import SideMenu from '@/layout/components/Menu/index.vue'
|
import SideMenu from '@/layout/components/Menu/index.vue'
|
||||||
|
import LogOut from '../Logout/index.vue'
|
||||||
import { defineComponent } from 'vue'
|
import { defineComponent } from 'vue'
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'LayoutHeader',
|
name: 'LayoutHeader',
|
||||||
components: { SideMenu }
|
components: { SideMenu, LogOut }
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
<template>
|
||||||
|
<Modal
|
||||||
|
:options="getModalOptions"
|
||||||
|
:on-positive-click="handleConfirm"
|
||||||
|
:on-negative-click="handleClose"
|
||||||
|
:on-close="handleClose"
|
||||||
|
>
|
||||||
|
<template #Context>
|
||||||
|
<n-form
|
||||||
|
ref="formRef"
|
||||||
|
:model="form"
|
||||||
|
label-placement="left"
|
||||||
|
:rules="rules"
|
||||||
|
:on-positive-click="handleConfirm"
|
||||||
|
:on-negative-click="handleClose"
|
||||||
|
>
|
||||||
|
<n-form-item
|
||||||
|
label="登录密码:"
|
||||||
|
path="password"
|
||||||
|
>
|
||||||
|
<n-input
|
||||||
|
v-model:value="form.password"
|
||||||
|
type="password"
|
||||||
|
:maxlength="20"
|
||||||
|
placeholder="请输入登录密码"
|
||||||
|
/>
|
||||||
|
</n-form-item>
|
||||||
|
</n-form>
|
||||||
|
</template>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
<script>
|
||||||
|
import Modal from '@/components/Modal/index.vue'
|
||||||
|
export default {
|
||||||
|
name: 'UpdateModal',
|
||||||
|
components: { Modal }
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
@ -1,24 +1,94 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="user_msg">
|
<n-dropdown trigger="hover" :options="options" @select="selectKey">
|
||||||
<n-image
|
<div class="user_msg">
|
||||||
class="user_avatar"
|
<n-image
|
||||||
src="https://07akioni.oss-cn-beijing.aliyuncs.com/07akioni.jpeg"
|
class="user_avatar"
|
||||||
preview-disabled
|
:src="userInfo.avatar"
|
||||||
/>
|
preview-disabled
|
||||||
<span class="user_name">用户名</span>
|
/>
|
||||||
</div>
|
<span class="user_name">{{ userInfo.realname }}</span>
|
||||||
|
</div>
|
||||||
|
</n-dropdown>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
import { reactive, toRefs, h } from 'vue'
|
||||||
|
import { NIcon } from 'naive-ui'
|
||||||
|
import {
|
||||||
|
Pencil as EditIcon,
|
||||||
|
LogOutOutline as LogoutIcon
|
||||||
|
} from '@vicons/ionicons5'
|
||||||
|
import { useDialog } from 'naive-ui'
|
||||||
|
import { loginOut } from '@/api/login/index.js'
|
||||||
|
import { mapActions, mapState } from 'pinia'
|
||||||
|
import { useUserStore } from '@/store/modules/user.js'
|
||||||
export default {
|
export default {
|
||||||
name: 'Logout',
|
name: 'LogOut',
|
||||||
props: {
|
setup() {
|
||||||
userInfo: {
|
const renderIcon = (icon) => {
|
||||||
type: Object,
|
return () => {
|
||||||
default()=> {
|
return h(NIcon, null, {
|
||||||
|
default: () => h(icon)
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const data = reactive({
|
||||||
|
userInfo: {
|
||||||
|
realname: '管理员'
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
label: '修改密码',
|
||||||
|
key: 'edit',
|
||||||
|
icon: renderIcon(EditIcon)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '退出登录',
|
||||||
|
key: 'out',
|
||||||
|
icon: renderIcon(LogoutIcon)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
// 选中选项触发的回调
|
||||||
|
const dialog = useDialog()
|
||||||
|
|
||||||
|
return {
|
||||||
|
...toRefs(data),
|
||||||
|
dialog
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...mapState(useUserStore, {
|
||||||
|
userInfo: 'userInfo'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
...mapActions(useUserStore, ['logout']),
|
||||||
|
selectKey(key) {
|
||||||
|
console.log(key)
|
||||||
|
if (key === 'out') {
|
||||||
|
this.dialog.warning({
|
||||||
|
title: '提示',
|
||||||
|
content: '确定要退出登录吗?',
|
||||||
|
positiveText: '确定',
|
||||||
|
negativeText: '取消',
|
||||||
|
onPositiveClick: () => {
|
||||||
|
loginOut().then((res) => {
|
||||||
|
if (res.code === 0) {
|
||||||
|
this.$router.replace('/login')
|
||||||
|
this.logout()
|
||||||
|
$message.success(res.msg)
|
||||||
|
} else {
|
||||||
|
$message.error(res.msg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else if (key === 'edit') {
|
||||||
|
console.log('修改密码')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|
|
||||||
|
|
@ -25,16 +25,36 @@
|
||||||
</n-space>
|
</n-space>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script >
|
||||||
// import { reactive } from 'vue'
|
// import { reactive } from 'vue'
|
||||||
import Header from './components/Header/index.vue'
|
import Header from './components/Header/index.vue'
|
||||||
import SideBar from './components/Sidebar/index.vue'
|
import SideBar from './components/Sidebar/index.vue'
|
||||||
import Tags from './components/Tags/index.vue'
|
import Tags from './components/Tags/index.vue'
|
||||||
import { useSettingStore } from '@/store/modules/setting.js'
|
import { useSettingStore } from '@/store/modules/setting.js'
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
const settingStore = useSettingStore()
|
import { useUserStore } from '@/store/modules/user.js'
|
||||||
const menuMode = computed(() => settingStore.getMenuMode)
|
export default {
|
||||||
const tagsMenuSetting = computed(() => settingStore.getTagsMenuSetting)
|
components: { Header, SideBar, Tags },
|
||||||
|
setup() {
|
||||||
|
const settingStore = useSettingStore()
|
||||||
|
const menuMode = computed(() => settingStore.getMenuMode)
|
||||||
|
const tagsMenuSetting = computed(() => settingStore.getTagsMenuSetting)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
*/
|
||||||
|
const useUser = useUserStore()
|
||||||
|
function getUserNow() {
|
||||||
|
useUser.getUserInfo()
|
||||||
|
}
|
||||||
|
getUserNow()
|
||||||
|
return {
|
||||||
|
settingStore,
|
||||||
|
menuMode,
|
||||||
|
tagsMenuSetting
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,8 @@ export const useUserStore = defineStore('user', {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
userId() {
|
userInfoMsg() {
|
||||||
return this.userInfo?.id
|
return this.userInfo
|
||||||
},
|
|
||||||
name() {
|
|
||||||
return this.userInfo?.name
|
|
||||||
},
|
|
||||||
avatar() {
|
|
||||||
return this.userInfo?.avatar
|
|
||||||
},
|
|
||||||
role() {
|
|
||||||
return this.userInfo?.role || []
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
|
@ -27,15 +18,14 @@ export const useUserStore = defineStore('user', {
|
||||||
try {
|
try {
|
||||||
const res = await getUser()
|
const res = await getUser()
|
||||||
if (res.code === 0) {
|
if (res.code === 0) {
|
||||||
const { id, name, avatar, role } = res.data
|
this.userInfo = res.data
|
||||||
this.userInfo = { id, name, avatar, role }
|
return Promise.resolve(res.msg)
|
||||||
return Promise.resolve(res.data)
|
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject(res.message)
|
return Promise.reject(res.msg)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
return Promise.reject(error.message)
|
return Promise.reject(error.msg)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
logout() {
|
logout() {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { getRoleAll } from '@/api/system/role/index'
|
||||||
import { dataToSelect } from '@/utils/handleData.js'
|
import { dataToSelect } from '@/utils/handleData.js'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
const rolesOptions = ref([])
|
const rolesOptions = ref([])
|
||||||
async function getRolesOption() {
|
const getRolesOption = async function() {
|
||||||
const res = await getRoleAll()
|
const res = await getRoleAll()
|
||||||
rolesOptions.value = dataToSelect(res.data, { label: 'name', value: 'id' })
|
rolesOptions.value = dataToSelect(res.data, { label: 'name', value: 'id' })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue