mirror of
https://github.com/PlayEdu/h5.git
synced 2025-12-25 22:43:41 +08:00
项目初始化
This commit is contained in:
12
src/store/index.ts
Normal file
12
src/store/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import systemConfigReducer from "./system/systemConfigSlice";
|
||||
import loginUserReducer from "./user/loginUserSlice";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
loginUser: loginUserReducer,
|
||||
systemConfig: systemConfigReducer,
|
||||
},
|
||||
});
|
||||
|
||||
export default store;
|
||||
48
src/store/system/systemConfigSlice.ts
Normal file
48
src/store/system/systemConfigSlice.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
type SystemConfigStoreInterface = {
|
||||
systemApiUrl: string;
|
||||
systemPcUrl: string;
|
||||
systemH5Url: string;
|
||||
systemLogo: string;
|
||||
systemName: string;
|
||||
pcIndexFooterMsg: string;
|
||||
playerPoster: string;
|
||||
playerIsEnabledBulletSecret: boolean;
|
||||
playerIsDisabledDrag: boolean;
|
||||
playerBulletSecretText: string;
|
||||
playerBulletSecretColor: string;
|
||||
playerBulletSecretOpacity: string;
|
||||
};
|
||||
|
||||
let defaultValue: SystemConfigStoreInterface = {
|
||||
systemApiUrl: "",
|
||||
systemPcUrl: "",
|
||||
systemH5Url: "",
|
||||
systemLogo: "",
|
||||
systemName: "",
|
||||
pcIndexFooterMsg: "",
|
||||
playerPoster: "",
|
||||
playerIsEnabledBulletSecret: false,
|
||||
playerIsDisabledDrag: false,
|
||||
playerBulletSecretText: "",
|
||||
playerBulletSecretColor: "",
|
||||
playerBulletSecretOpacity: "",
|
||||
};
|
||||
|
||||
const systemConfigSlice = createSlice({
|
||||
name: "systemConfig",
|
||||
initialState: {
|
||||
value: defaultValue,
|
||||
},
|
||||
reducers: {
|
||||
saveConfigAction(stage, e) {
|
||||
stage.value = e.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default systemConfigSlice.reducer;
|
||||
export const { saveConfigAction } = systemConfigSlice.actions;
|
||||
|
||||
export type { SystemConfigStoreInterface };
|
||||
58
src/store/user/loginUserSlice.ts
Normal file
58
src/store/user/loginUserSlice.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import {
|
||||
getDepKey,
|
||||
clearDepKey,
|
||||
clearDepName,
|
||||
setDepName,
|
||||
clearToken,
|
||||
} from "../../utils/index";
|
||||
|
||||
type UserStoreInterface = {
|
||||
user: null;
|
||||
departments: string[];
|
||||
currentDepId: number;
|
||||
isLogin: boolean;
|
||||
};
|
||||
|
||||
let defaultValue: UserStoreInterface = {
|
||||
user: null,
|
||||
departments: [],
|
||||
currentDepId: Number(getDepKey()) || 0,
|
||||
isLogin: false,
|
||||
};
|
||||
|
||||
const loginUserSlice = createSlice({
|
||||
name: "loginUser",
|
||||
initialState: {
|
||||
value: defaultValue,
|
||||
},
|
||||
reducers: {
|
||||
loginAction(stage, e) {
|
||||
stage.value.user = e.payload.user;
|
||||
stage.value.departments = e.payload.departments;
|
||||
stage.value.isLogin = true;
|
||||
if (e.payload.departments.length > 0 && stage.value.currentDepId === 0) {
|
||||
stage.value.currentDepId = e.payload.departments[0].id;
|
||||
setDepName(e.payload.departments[0].name);
|
||||
}
|
||||
},
|
||||
logoutAction(stage) {
|
||||
stage.value.user = null;
|
||||
stage.value.departments = [];
|
||||
stage.value.isLogin = false;
|
||||
stage.value.currentDepId = 0;
|
||||
clearToken();
|
||||
clearDepKey();
|
||||
clearDepName();
|
||||
},
|
||||
saveCurrentDepId(stage, e) {
|
||||
stage.value.currentDepId = e.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default loginUserSlice.reducer;
|
||||
export const { loginAction, logoutAction, saveCurrentDepId } =
|
||||
loginUserSlice.actions;
|
||||
|
||||
export type { UserStoreInterface };
|
||||
Reference in New Issue
Block a user