存储部门信息

This commit is contained in:
禺狨 2023-04-17 11:34:14 +08:00
parent da56cd085e
commit a0754cde00
3 changed files with 29 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import {
logoutAction, logoutAction,
saveCurrentDepId, saveCurrentDepId,
} from "../../store/user/loginUserSlice"; } from "../../store/user/loginUserSlice";
import { setDepKey, setDepName, getDepName } from "../../utils/index";
import { ChangePasswordModel } from "../change-password"; import { ChangePasswordModel } from "../change-password";
import { UserInfoModel } from "../user-info"; import { UserInfoModel } from "../user-info";
import { ExclamationCircleFilled } from "@ant-design/icons"; import { ExclamationCircleFilled } from "@ant-design/icons";
@ -32,7 +33,7 @@ export const Header: React.FC = () => {
useEffect(() => { useEffect(() => {
if (departments.length > 0) { if (departments.length > 0) {
setCurrentDepartment(departments[0].name); setCurrentDepartment(getDepName() || departments[0].name);
const arr: any = [ const arr: any = [
{ {
key: "1", key: "1",
@ -129,6 +130,8 @@ export const Header: React.FC = () => {
onOk() { onOk() {
setCurrentDepartment(name); setCurrentDepartment(name);
dispatch(saveCurrentDepId(Number(key))); dispatch(saveCurrentDepId(Number(key)));
setDepKey(key);
setDepName(name);
const box = [...departments]; const box = [...departments];
const arr: any = [ const arr: any = [
{ {

View File

@ -1,4 +1,5 @@
import { createSlice } from "@reduxjs/toolkit"; import { createSlice } from "@reduxjs/toolkit";
import { getDepKey } from "../../utils/index";
type UserStoreInterface = { type UserStoreInterface = {
user: null; user: null;
@ -10,7 +11,7 @@ type UserStoreInterface = {
let defaultValue: UserStoreInterface = { let defaultValue: UserStoreInterface = {
user: null, user: null,
departments: [], departments: [],
currentDepId: 0, currentDepId: Number(getDepKey()) || 0,
isLogin: false, isLogin: false,
}; };

View File

@ -72,3 +72,26 @@ export function inStrArray(array: string[], value: string): boolean {
} }
return false; return false;
} }
export function getDepKey(): string {
return window.localStorage.getItem("playedu-frontend-depatmentKey") || "";
}
export function setDepKey(token: string) {
window.localStorage.setItem("playedu-frontend-depatmentKey", token);
}
export function clearDepKey() {
window.localStorage.removeItem("playedu-frontend-depatmentKey");
}
export function getDepName(): string {
return window.localStorage.getItem("playedu-frontend-depatmentName") || "";
}
export function setDepName(token: string) {
window.localStorage.setItem("playedu-frontend-depatmentName", token);
}
export function clearDepName() {
window.localStorage.removeItem("playedu-frontend-depatmentName");
}