feat:更新代码
This commit is contained in:
@@ -6,7 +6,7 @@ export const useAppStore = defineStore(
|
||||
{
|
||||
state: () => ({
|
||||
sidebar: {
|
||||
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
|
||||
opened: true,
|
||||
withoutAnimation: false,
|
||||
hide: false
|
||||
},
|
||||
@@ -14,20 +14,14 @@ export const useAppStore = defineStore(
|
||||
size: Cookies.get('size') || 'default'
|
||||
}),
|
||||
actions: {
|
||||
toggleSideBar(withoutAnimation) {
|
||||
toggleSideBar(withoutAnimation) {
|
||||
if (this.sidebar.hide) {
|
||||
return false;
|
||||
}
|
||||
this.sidebar.opened = !this.sidebar.opened
|
||||
this.sidebar.withoutAnimation = withoutAnimation
|
||||
if (this.sidebar.opened) {
|
||||
// Cookies.set('sidebarStatus', 1)
|
||||
} else {
|
||||
// Cookies.set('sidebarStatus', 0)
|
||||
}
|
||||
this.sidebar.opened = !this.sidebar.opened
|
||||
this.sidebar.withoutAnimation = withoutAnimation
|
||||
},
|
||||
closeSideBar({ withoutAnimation }) {
|
||||
// Cookies.set('sidebarStatus', 0)
|
||||
closeSideBar({ withoutAnimation }) {
|
||||
this.sidebar.opened = false
|
||||
this.sidebar.withoutAnimation = withoutAnimation
|
||||
},
|
||||
@@ -38,7 +32,7 @@ export const useAppStore = defineStore(
|
||||
this.size = size;
|
||||
Cookies.set('size', size)
|
||||
},
|
||||
toggleSideBarHide(status) {
|
||||
toggleSideBarHide(status) {
|
||||
this.sidebar.hide = status
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ export const useSettingsStore = defineStore(
|
||||
{
|
||||
state: () => ({
|
||||
title: '',
|
||||
theme: storageSetting.theme === undefined ? '#434343' : storageSetting.theme,
|
||||
theme: storageSetting.theme === undefined ? '#409EFF' : storageSetting.theme,
|
||||
sideTheme: storageSetting.sideTheme === undefined ? sideTheme : storageSetting.sideTheme,
|
||||
showSettings: showSettings,
|
||||
topNav: storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { login, logout, getInfo } from '@/api/login.js'
|
||||
import { getToken, setToken, removeToken } from '@/utils/auth.js'
|
||||
import { login, logout, getInfo ,getAvatarsApi} from '@/api/login.js'
|
||||
import { getToken, setToken, removeToken ,getUserInfo} from '@/utils/auth.js'
|
||||
import { defineStore } from 'pinia'
|
||||
import { ElMessage } from 'element-plus'
|
||||
|
||||
@@ -10,7 +10,7 @@ export const useUserStore = defineStore(
|
||||
token: getToken(),
|
||||
name: '',
|
||||
avatar: '',
|
||||
roles: '',
|
||||
roles: '',
|
||||
}),
|
||||
actions: {
|
||||
// 登录
|
||||
@@ -23,9 +23,14 @@ export const useUserStore = defineStore(
|
||||
ElMessage({ message: res.meta?.message || '登录失败', type: 'error' });
|
||||
return Promise.reject(res);
|
||||
}
|
||||
if(!res.data.user.is_admin){
|
||||
ElMessage({ message: '暂无权限登录,请联系管理员', type: 'error' });
|
||||
return Promise.reject(res);
|
||||
}
|
||||
const { token, user } = res.data;
|
||||
this.name = user.name;
|
||||
sessionStorage.setItem('userData', JSON.stringify(user));
|
||||
await this.getAvatars();
|
||||
setToken(token);
|
||||
this.token = token;
|
||||
|
||||
@@ -53,6 +58,18 @@ export const useUserStore = defineStore(
|
||||
reject(error instanceof Error ? error : new Error('解析用户数据失败'));
|
||||
}
|
||||
});
|
||||
},
|
||||
// 获取用户头像
|
||||
async getAvatars() {
|
||||
try {
|
||||
const userData = await getUserInfo()
|
||||
const res = await getAvatarsApi(userData.uid);
|
||||
const url = URL.createObjectURL(res);
|
||||
this.avatar = url;
|
||||
} catch (error) {
|
||||
console.error('获取头像失败:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
// 退出系统
|
||||
async logOut() {
|
||||
|
||||
Reference in New Issue
Block a user