perf: 同步完整版分支代码

This commit is contained in:
xiaoxian521
2021-12-06 17:11:15 +08:00
parent e9dc8274a0
commit f6057458de
39 changed files with 651 additions and 647 deletions

View File

@@ -1,23 +1,13 @@
import { storageLocal } from "/@/utils/storage";
import { deviceDetection } from "/@/utils/deviceDetection";
import { defineStore } from "pinia";
import { store } from "/@/store";
import { appType } from "./types";
import { defineStore } from "pinia";
import { getConfig } from "/@/config";
interface AppState {
sidebar: {
opened: boolean;
withoutAnimation: boolean;
// 判断是否手动点击Hamburger
isClickHamburger: boolean;
};
layout: string;
device: string;
}
export const useAppStore = defineStore({
id: "pure-app",
state: (): AppState => ({
state: (): appType => ({
sidebar: {
opened: storageLocal.getItem("sidebarStatus")
? !!+storageLocal.getItem("sidebarStatus")

View File

@@ -1,15 +1,8 @@
import { defineStore } from "pinia";
import { store } from "/@/store";
import { getConfig } from "/@/config";
import { positionType } from "./types";
import { storageLocal } from "/@/utils/storage";
interface Itag {
path: string;
parentPath: string;
name: string;
meta: any;
}
import { multiType, positionType } from "./types";
export const useMultiTagsStore = defineStore({
id: "pure-multiTags",
@@ -43,16 +36,16 @@ export const useMultiTagsStore = defineStore({
},
handleTags<T>(
mode: string,
value?: T | Itag,
value?: T | multiType,
position?: positionType
): any {
): T {
switch (mode) {
case "equal":
this.multiTags = value;
break;
case "push":
{
const tagVal = value as Itag;
const tagVal = value as multiType;
// 判断tag是否已存在:
const tagHasExits = this.multiTags.some(tag => {
return tag.path === tagVal?.path;

View File

@@ -1,16 +1,11 @@
import { defineStore } from "pinia";
import { store } from "/@/store";
import { setType } from "./types";
import { getConfig } from "/@/config";
interface SettingState {
title: string;
fixedHeader: boolean;
hiddenSideBar: boolean;
}
export const useSettingStore = defineStore({
id: "pure-setting",
state: (): SettingState => ({
state: (): setType => ({
title: getConfig().Title,
fixedHeader: getConfig().FixedHeader,
hiddenSideBar: getConfig().HiddenSideBar

View File

@@ -9,3 +9,32 @@ export type positionType = {
startIndex?: number;
length?: number;
};
export type appType = {
sidebar: {
opened: boolean;
withoutAnimation: boolean;
// 判断是否手动点击Hamburger
isClickHamburger: boolean;
};
layout: string;
device: string;
};
export type multiType = {
path: string;
parentPath: string;
name: string;
meta: any;
};
export type setType = {
title: string;
fixedHeader: boolean;
hiddenSideBar: boolean;
};
export type userType = {
token: string;
name?: string;
};

84
src/store/modules/user.ts Normal file
View File

@@ -0,0 +1,84 @@
import { defineStore } from "pinia";
import { store } from "/@/store";
import { userType } from "./types";
import { useRouter } from "vue-router";
import { getLogin, refreshToken } from "/@/api/user";
import { storageLocal, storageSession } from "/@/utils/storage";
import { getToken, setToken, removeToken } from "/@/utils/auth";
import { useMultiTagsStoreHook } from "/@/store/modules/multiTags";
const data = getToken();
let token = "";
let name = "";
if (data) {
const dataJson = JSON.parse(data);
if (dataJson) {
token = dataJson?.accessToken;
name = dataJson?.name ?? "admin";
}
}
export const useUserStore = defineStore({
id: "pure-user",
state: (): userType => ({
token,
name
}),
actions: {
SET_TOKEN(token) {
this.token = token;
},
SET_NAME(name) {
this.name = name;
},
// 登入
async loginByUsername(data) {
return new Promise<void>((resolve, reject) => {
getLogin(data)
.then(data => {
if (data) {
setToken(data);
resolve();
}
})
.catch(error => {
reject(error);
});
});
},
// 登出 清空缓存
logOut() {
this.token = "";
this.name = "";
removeToken();
storageLocal.clear();
storageSession.clear();
useMultiTagsStoreHook().handleTags("equal", [
{
path: "/welcome",
parentPath: "/",
meta: {
title: "message.hshome",
icon: "el-icon-s-home",
i18n: true,
showLink: true
}
}
]);
useRouter().push("/login");
},
// 刷新token
async refreshToken(data) {
return refreshToken(data).then(data => {
if (data) {
setToken(data);
return data;
}
});
}
}
});
export function useUserStoreHook() {
return useUserStore(store);
}