forked from admin/deShanXiao
初始版本,目前线上可用
This commit is contained in:
46
frontEnd/src/store/index.ts
Normal file
46
frontEnd/src/store/index.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { defineStore } from "pinia"
|
||||
import { RouteRecordRaw } from "vue-router";
|
||||
|
||||
interface globalState {
|
||||
loadingShow: boolean;
|
||||
globalLodingShow: boolean;
|
||||
globalLodingShowText: string;
|
||||
currentMenue: RouteRecordRaw | null;
|
||||
historyRouterPath: string;
|
||||
loadingText: string
|
||||
}
|
||||
export const globalState = defineStore('globalState', {
|
||||
state(): globalState{
|
||||
return {
|
||||
loadingShow: false,
|
||||
loadingText: '',
|
||||
currentMenue: null,
|
||||
historyRouterPath: '/',
|
||||
globalLodingShow: false,
|
||||
globalLodingShowText: ""
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setLoadingShow(state: boolean, showText = '请稍候...' ) {
|
||||
this.loadingShow = state;
|
||||
this.loadingText = showText;
|
||||
},
|
||||
toggleLoadingShow() {
|
||||
this.loadingShow = !this.loadingShow;
|
||||
},
|
||||
setSelectMenue(menue: RouteRecordRaw) {
|
||||
this.currentMenue = menue;
|
||||
},
|
||||
setHistoryRouterPath(path: string) {
|
||||
this.historyRouterPath = path;
|
||||
localStorage.setItem('historyRouterPath', path);
|
||||
},
|
||||
setLoadingText(text:string) {
|
||||
this.loadingText = text;
|
||||
},
|
||||
setGlobalLoadingShow(state: boolean, showText = '请稍候...') {
|
||||
this.globalLodingShow = state;
|
||||
this.globalLodingShowText = showText;
|
||||
}
|
||||
}
|
||||
})
|
||||
44
frontEnd/src/store/user/user.ts
Normal file
44
frontEnd/src/store/user/user.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { userType } from "@/types/user";
|
||||
|
||||
interface user {
|
||||
userInfor: userType;
|
||||
token: string | undefined;
|
||||
refreshToken: string | undefined;
|
||||
}
|
||||
|
||||
export const userInfor = defineStore("userInfor", {
|
||||
state(): user {
|
||||
return {
|
||||
userInfor: {
|
||||
name: "",
|
||||
},
|
||||
token: "",
|
||||
refreshToken: "",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
setLoginState(userData: userType) {
|
||||
this.userInfor = userData;
|
||||
localStorage.setItem("userInfor", JSON.stringify(userData));
|
||||
},
|
||||
removeLoginState() {
|
||||
localStorage.removeItem("userInfor");
|
||||
},
|
||||
setToken(token: string) {
|
||||
this.token = token;
|
||||
localStorage.setItem("token", token);
|
||||
},
|
||||
setRefToken(toekn: string) {
|
||||
this.refreshToken = toekn;
|
||||
localStorage.setItem("refreshToken", toekn);
|
||||
},
|
||||
removeToken() {
|
||||
this.token = undefined;
|
||||
this.refreshToken = undefined;
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("refreshToken");
|
||||
localStorage.removeItem("historyRouterPath");
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user