This commit is contained in:
2023-04-27 16:01:54 +08:00
parent 8e6ecdd677
commit 5fecd74d59
49 changed files with 4654 additions and 856 deletions

View File

@ -1,3 +1,6 @@
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";
const store = createPinia();
store.use(piniaPluginPersistedstate);
export default store;

View File

@ -0,0 +1,46 @@
import { defineStore } from "pinia";
import { cloneDeep } from "lodash-es";
const useNotificationStore = defineStore("notification", {
state: () => ({
unreadList: [],
}),
actions: {
pushItem(row) {
const _row = cloneDeep(row);
const isNotExisted = this.unreadList.every(
(el) => el.msgId !== _row.msgId
);
if (isNotExisted) {
this.unreadList.unshift(_row);
}
},
pushItems(rows) {
for (const row of rows) {
const _row = cloneDeep(row);
const isNotExisted = this.unreadList.every(
(el) => el.msgId !== _row.msgId
);
if (isNotExisted) {
this.unreadList.push(_row);
}
}
},
removeItem(id) {
this.unreadList = this.unreadList.filter((el) => el.msgId !== id);
},
},
getters: {
getList: (state) => {
return (params) =>
state.unreadList.slice(
(params.pageNum - 1) * params.pageSize + 1,
(params.pageNum - 1) * params.pageSize + 1 + params.pageSize
);
},
unreadCount: (state) => state.unreadList.length,
},
persist: true,
});
export default useNotificationStore;

View File

@ -1,6 +1,7 @@
import { login, logout, getInfo } from "@/api/login";
import { getToken, setToken, removeToken } from "@/utils/auth";
import { getInfo, login, logout } from "@/api/login";
import { getToken, removeToken, setToken } from "@/utils/auth";
import defAva from "@/assets/images/profile.jpg";
import { v4 as uuidv4 } from "uuid";
const useUserStore = defineStore("user", {
state: () => ({
@ -8,7 +9,9 @@ const useUserStore = defineStore("user", {
name: "",
avatar: "",
roles: [],
userId: null,
permissions: [],
uniqueId: ""
}),
actions: {
// 登录
@ -47,8 +50,11 @@ const useUserStore = defineStore("user", {
} else {
this.roles = ["ROLE_DEFAULT"];
}
this.userId = user.userId;
this.name = user.userName;
this.avatar = avatar;
const uniqueId = uuidv4();
this.uniqueId = uniqueId;
resolve(res);
})
.catch((error) => {
@ -71,8 +77,11 @@ const useUserStore = defineStore("user", {
reject(error);
});
});
},
}
},
persist: {
paths: ["uniqueId"]
}
});
export default useUserStore;