优化pinia相关

This commit is contained in:
zhangtao
2025-01-10 19:37:56 +08:00
parent 1ae731eafe
commit 01c3cb1368
10 changed files with 71 additions and 53 deletions
+32 -1
View File
@@ -1,7 +1,37 @@
import { defineStore } from "pinia";
import { getCurrentUserInfo } from "@/api/system/user";
import { getInitConfig } from "@/api/system/config";
import { getNoticeList } from '@/api/system/notice'
export const useNoticeStore = defineStore("notice", {
state: () => ({
noticeList: [], // 存储系统配置
total: 0, // 存储系统配置
isNoticeLoaded: false, // 标记配置是否已加载
}),
actions: {
async getNotice() {
try {
const response = await getNoticeList({ available: true });
console.log(response);
const { status_code, data } = response.data;
if (status_code === 200) {
this.noticeList = data.items;
this.total = data.total;
console.log(this.noticeList);
this.isNoticeLoaded = true;
}
} catch (error) {
console.error("获取通知失败", error);
}
},
clearUserInfo() {
this.noticeList = [];
this.total = 0;
this.isNoticeLoaded = false;
},
},
});
export const useUserStore = defineStore("user", {
state: () => ({
@@ -18,6 +48,7 @@ export const useUserStore = defineStore("user", {
delete result.data.menus;
this.setRoute(routers);
this.basicInfo = { ...this.basicInfo, ...result.data };
console.log(this.basicInfo);
} catch (error) {
console.error(error);
}
@@ -43,7 +74,7 @@ export const useConfigStore = defineStore("config", {
isConfigLoaded: false, // 标记配置是否已加载
}),
actions: {
async fetchConfig() {
async getConfig() {
try {
const response = await getInitConfig();
const { status_code, data } = response.data;