将staff信息存入仓库
parent
3460dda994
commit
68431ef6e6
|
@ -1,6 +1,7 @@
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
export interface Token {
|
export interface Token {
|
||||||
|
staffId: string;
|
||||||
accessToken: string;
|
accessToken: string;
|
||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
clientSecret: string;
|
clientSecret: string;
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
import {configureStore, ThunkAction, Action, PayloadAction, createSlice, combineReducers} from '@reduxjs/toolkit';
|
import {configureStore, ThunkAction, Action, PayloadAction, createSlice, combineReducers} from '@reduxjs/toolkit';
|
||||||
import {Token} from "./Staff"
|
import {Department, Staff, Token} from "./Staff"
|
||||||
import {persistStore, persistReducer} from 'redux-persist'
|
import {persistStore, persistReducer} from 'redux-persist'
|
||||||
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web
|
import storage from 'redux-persist/lib/storage' // defaults to localStorage for web
|
||||||
|
|
||||||
const tokenSlice = createSlice({
|
const tokenSlice = createSlice({
|
||||||
name: 'token',
|
name: 'token',
|
||||||
initialState: {
|
initialState: {
|
||||||
|
staffId: '',
|
||||||
accessToken: '',
|
accessToken: '',
|
||||||
refreshToken: '',
|
refreshToken: '',
|
||||||
clientSecret: ''
|
clientSecret: ''
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
setToken: (state, action: PayloadAction<Token>) => {
|
setToken: (state, action: PayloadAction<Token>) => {
|
||||||
|
state.staffId = action.payload.staffId
|
||||||
state.accessToken = action.payload.accessToken
|
state.accessToken = action.payload.accessToken
|
||||||
state.refreshToken = action.payload.refreshToken
|
state.refreshToken = action.payload.refreshToken
|
||||||
state.clientSecret = action.payload.clientSecret
|
state.clientSecret = action.payload.clientSecret
|
||||||
|
@ -21,8 +23,29 @@ const tokenSlice = createSlice({
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const staffSlice = createSlice({
|
||||||
|
name: 'staff',
|
||||||
|
initialState: {
|
||||||
|
staffName: "",
|
||||||
|
managingDepartment: { departmentId: 0,
|
||||||
|
departmentName: ''},
|
||||||
|
staffDepartments: [{ departmentId: 0,
|
||||||
|
departmentName: ''}]
|
||||||
|
},
|
||||||
|
reducers: {
|
||||||
|
setStaff: (state, action: PayloadAction<Staff>) => {
|
||||||
|
state.staffName = action.payload.staffName
|
||||||
|
state.managingDepartment = action.payload.managingDepartment
|
||||||
|
state.staffDepartments = action.payload.staffDepartments
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export const {setToken, setAccessToken} = tokenSlice.actions;
|
export const {setToken, setAccessToken} = tokenSlice.actions;
|
||||||
|
export const {setStaff} = staffSlice.actions;
|
||||||
export const getToken = (state: RootState) => state.token;
|
export const getToken = (state: RootState) => state.token;
|
||||||
|
export const getStaff = (state: RootState) => state.staff;
|
||||||
|
|
||||||
const persistConfig = {
|
const persistConfig = {
|
||||||
key: 'root',
|
key: 'root',
|
||||||
|
@ -33,7 +56,8 @@ const persistedReducer = persistReducer(persistConfig, tokenSlice.reducer)
|
||||||
|
|
||||||
export const store = configureStore({
|
export const store = configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
token: persistedReducer
|
token: persistedReducer,
|
||||||
|
staff: staffSlice.reducer
|
||||||
},
|
},
|
||||||
middleware: getDefaultMiddleware => {
|
middleware: getDefaultMiddleware => {
|
||||||
return getDefaultMiddleware({
|
return getDefaultMiddleware({
|
||||||
|
|
|
@ -2,12 +2,12 @@ import React, {useState, useEffect} from 'react';
|
||||||
import {UploadOutlined, UserOutlined, VideoCameraOutlined} from '@ant-design/icons';
|
import {UploadOutlined, UserOutlined, VideoCameraOutlined} from '@ant-design/icons';
|
||||||
import {Layout, Menu, theme, Typography, Button, Dropdown, MenuProps} from 'antd';
|
import {Layout, Menu, theme, Typography, Button, Dropdown, MenuProps} from 'antd';
|
||||||
import {useAppDispatch, useAppSelector} from "../models/hooks";
|
import {useAppDispatch, useAppSelector} from "../models/hooks";
|
||||||
import {getToken, setToken, store} from "../models/store";
|
import {getStaff, getToken, setStaff, setToken, store} from "../models/store";
|
||||||
import {Link, Outlet, useLocation, useNavigate} from "react-router-dom";
|
import {Link, Outlet, useLocation, useNavigate} from "react-router-dom";
|
||||||
import Icon from '@ant-design/icons';
|
import Icon from '@ant-design/icons';
|
||||||
import {Logo} from "../assets/icons";
|
import {Logo} from "../assets/icons";
|
||||||
import axiosInstance from "../utils/axiosInstance";
|
import axiosInstance from "../utils/axiosInstance";
|
||||||
import {Department, Staff} from "../models/Staff";
|
import {Department, Staff, Token} from "../models/Staff";
|
||||||
|
|
||||||
const {Title} = Typography;
|
const {Title} = Typography;
|
||||||
const {Header, Content, Footer, Sider} = Layout;
|
const {Header, Content, Footer, Sider} = Layout;
|
||||||
|
@ -18,7 +18,8 @@ function HeaderBar(props: any) {
|
||||||
token: {colorBgContainer, colorPrimary},
|
token: {colorBgContainer, colorPrimary},
|
||||||
} = theme.useToken();
|
} = theme.useToken();
|
||||||
|
|
||||||
const token = useAppSelector(getToken);
|
const token:Token = useAppSelector(getToken);
|
||||||
|
const staff:Staff = useAppSelector(getStaff);
|
||||||
const dispatch = useAppDispatch()
|
const dispatch = useAppDispatch()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ function HeaderBar(props: any) {
|
||||||
break
|
break
|
||||||
case 'logout':
|
case 'logout':
|
||||||
dispatch(setToken({
|
dispatch(setToken({
|
||||||
|
staffId: '',
|
||||||
accessToken: '',
|
accessToken: '',
|
||||||
refreshToken: '',
|
refreshToken: '',
|
||||||
clientSecret: ''
|
clientSecret: ''
|
||||||
|
@ -88,13 +90,13 @@ function HeaderBar(props: any) {
|
||||||
marginRight: '12px', height: '100%',
|
marginRight: '12px', height: '100%',
|
||||||
display: 'flex', justifyContent: 'center', alignItems: 'center'
|
display: 'flex', justifyContent: 'center', alignItems: 'center'
|
||||||
}}>
|
}}>
|
||||||
<span style={{marginRight: '12px'}}>{departmentToString(props.staff)}</span>
|
<span style={{marginRight: '12px'}}>{departmentToString(staff)}</span>
|
||||||
<span style={{fontWeight: "bold", marginRight: '12px'}}>{props.staff.staffName}</span>
|
<span style={{fontWeight: "bold", marginRight: '12px'}}>{staff.staffName}</span>
|
||||||
<div style={{
|
<div style={{
|
||||||
width: '24px', height: '24px', backgroundColor: colorPrimary, borderRadius: '12px',
|
width: '24px', height: '24px', backgroundColor: colorPrimary, borderRadius: '12px',
|
||||||
display: 'flex', justifyContent: 'center', alignItems: 'center'
|
display: 'flex', justifyContent: 'center', alignItems: 'center'
|
||||||
}}>
|
}}>
|
||||||
<span style={{color: 'white'}}>{props.staff.staffName[0]}</span>
|
<span style={{color: 'white'}}>{staff.staffName[0]}</span>
|
||||||
</div>
|
</div>
|
||||||
</Button>
|
</Button>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
|
@ -120,6 +122,7 @@ function HomeView() {
|
||||||
const token = useAppSelector(getToken);
|
const token = useAppSelector(getToken);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
console.log(store.getState())
|
console.log(store.getState())
|
||||||
|
|
||||||
let items = [{
|
let items = [{
|
||||||
|
@ -148,13 +151,6 @@ function HomeView() {
|
||||||
token: {colorBgContainer, colorPrimary},
|
token: {colorBgContainer, colorPrimary},
|
||||||
} = theme.useToken();
|
} = theme.useToken();
|
||||||
|
|
||||||
|
|
||||||
const [staff, setStaff] = useState({
|
|
||||||
staffName: "",
|
|
||||||
managingDepartment: null,
|
|
||||||
staffDepartments: []
|
|
||||||
})
|
|
||||||
|
|
||||||
const [menuItems, setMenuItems] = useState(items.slice(0, 2))
|
const [menuItems, setMenuItems] = useState(items.slice(0, 2))
|
||||||
const [defaultSelectedKeys, setDefaultSelectedKeys] = useState([''])
|
const [defaultSelectedKeys, setDefaultSelectedKeys] = useState([''])
|
||||||
|
|
||||||
|
@ -164,8 +160,9 @@ function HomeView() {
|
||||||
method: 'get'
|
method: 'get'
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
const staff = response.data
|
const staff:Staff = response.data
|
||||||
setStaff(response.data)
|
dispatch(setStaff(staff))
|
||||||
|
|
||||||
if (location.pathname === '/')
|
if (location.pathname === '/')
|
||||||
navigate('/invoice/mine')
|
navigate('/invoice/mine')
|
||||||
|
|
||||||
|
@ -225,9 +222,9 @@ function HomeView() {
|
||||||
<MyMenu items={menuItems} defaultSelectedKeys={defaultSelectedKeys}/>
|
<MyMenu items={menuItems} defaultSelectedKeys={defaultSelectedKeys}/>
|
||||||
</Sider>
|
</Sider>
|
||||||
<Layout>
|
<Layout>
|
||||||
<HeaderBar staff={staff}/>
|
<HeaderBar/>
|
||||||
<Content style={{margin: '0'}}>
|
<Content style={{margin: '0'}}>
|
||||||
<Outlet/>
|
<Outlet />
|
||||||
</Content>
|
</Content>
|
||||||
<Footer style={{textAlign: 'center'}}></Footer>
|
<Footer style={{textAlign: 'center'}}></Footer>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
@ -235,14 +235,6 @@ class InvoiceUploadView extends React.Component<any, any> {
|
||||||
this.setState({open: value})
|
this.setState({open: value})
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(value: Boolean) {
|
|
||||||
this.setState({loading: value})
|
|
||||||
}
|
|
||||||
|
|
||||||
setUploadStep(value: number) {
|
|
||||||
this.setState({uploadStep: value})
|
|
||||||
}
|
|
||||||
|
|
||||||
showUploadView = () => {
|
showUploadView = () => {
|
||||||
this.setOpen(true);
|
this.setOpen(true);
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,6 +21,7 @@ function LoginView() {
|
||||||
axios.post(baseUrl + 'login', data).then(function (response) {
|
axios.post(baseUrl + 'login', data).then(function (response) {
|
||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
dispatch(setToken({
|
dispatch(setToken({
|
||||||
|
staffId: values.staffId,
|
||||||
accessToken: response.data.accessToken,
|
accessToken: response.data.accessToken,
|
||||||
refreshToken: response.data.refreshToken,
|
refreshToken: response.data.refreshToken,
|
||||||
clientSecret: response.data.clientSecret
|
clientSecret: response.data.clientSecret
|
||||||
|
|
|
@ -35,6 +35,7 @@ axiosInstance.interceptors.response.use(
|
||||||
if (error.config.isRetry) {
|
if (error.config.isRetry) {
|
||||||
console.log('isRetry')
|
console.log('isRetry')
|
||||||
store.dispatch(setToken({
|
store.dispatch(setToken({
|
||||||
|
staffId: '',
|
||||||
accessToken: '',
|
accessToken: '',
|
||||||
refreshToken: '',
|
refreshToken: '',
|
||||||
clientSecret: ''
|
clientSecret: ''
|
||||||
|
@ -63,6 +64,7 @@ axiosInstance.interceptors.response.use(
|
||||||
console.log('refresh error')
|
console.log('refresh error')
|
||||||
console.log(error);
|
console.log(error);
|
||||||
store.dispatch(setToken({
|
store.dispatch(setToken({
|
||||||
|
staffId: '',
|
||||||
accessToken: '',
|
accessToken: '',
|
||||||
refreshToken: '',
|
refreshToken: '',
|
||||||
clientSecret: ''
|
clientSecret: ''
|
||||||
|
|
Loading…
Reference in New Issue