Commit 24974163 by wufan

feat:接入状态管理

parent f251f53d
......@@ -2,7 +2,7 @@
* @Author: 吴文洁
* @Date: 2020-08-31 09:34:31
* @LastEditors: wufan
* @LastEditTime: 2020-12-01 15:25:04
* @LastEditTime: 2020-12-02 11:40:41
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -32,7 +32,7 @@ class Axios {
params: any,
options: FetchOptions = { requestType: 'json' }
): Promise<any> {
const _url = `${url}?storeId=${USER_TYPE}&token=${User.getToken()}&storeUserId=${User.getStoreUserId()}&userId=${User.getUserId()}}`;
const _url = `${url}?storeId=${USER_TYPE}&token=${User.getToken()}&storeUserId=${User.getStoreUserId()}&userId=${User.getUserId()}`;
return new Promise((resolve, reject) => {
const instance: AxiosInstance = axios.create({
......@@ -41,8 +41,8 @@ class Axios {
headers: {
storeId: User.getStoreId(),
storeUserId: User.getStoreUserId(),
userId: User.getUserId(),
token: User.getToken(),
userId: "1333700901723144193" || User.getUserId(),
token: "277c5bcc5ac441b297544c4f9fdf7420" || User.getToken(),
product: "xmCloudClass",
'Content-Type': options.requestType === 'form' ? 'application/x-www-form-urlencoded' : 'application/json; charset=UTF-8',
}
......
/*
* @Author: wufan
* @Date: 2020-12-02 10:39:36
* @LastEditors: wufan
* @LastEditTime: 2020-12-02 10:40:48
* @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
class Permission {
constructor(permissionCodes) {
this.permissionCodes = permissionCodes;
}
// 添加、编辑、删除排课
ContentClass_Schedule() {
return this.permissionCodes.includes('ContentClass_Schedule');
}
}
export default Permission;
\ No newline at end of file
......@@ -2,7 +2,7 @@
* @Author: 吴文洁
* @Date: 2020-08-31 09:34:25
* @LastEditors: wufan
* @LastEditTime: 2020-12-01 10:36:59
* @LastEditTime: 2020-12-02 16:00:39
* @Description:
* @Copyright: 杭州杰竞科技有限公司 版权所有
*/
......@@ -25,8 +25,25 @@ class User {
}
getToken() {
return Storage.get(`${PREFIX}_token`) || 'f24733242f634815a30184dfa5edf9b6';
return Storage.get(`${PREFIX}_token`);
}
setStoreId(value:any){
return Storage.set(`${PREFIX}_storeId`,value)
}
setStoreUserId(value:any){
return Storage.set(`${PREFIX}_storeUserId`,value)
}
setUserId(value:any){
return Storage.set(`${PREFIX}_userId`,value)
}
setToken(value:any) {
return Storage.set(`${PREFIX}_token`,value);
}
}
export default new User();
\ No newline at end of file
......@@ -2,7 +2,7 @@
* @Author: wufan
* @Date: 2020-12-01 17:21:21
* @LastEditors: wufan
* @LastEditTime: 2020-12-01 18:07:03
* @LastEditTime: 2020-12-02 15:56:52
* @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
......@@ -11,3 +11,7 @@ import Service from "@/common/js/service";
export function getUserStore(params: object) {
return Service.Hades("public/store/getUserStore", params);
}
export function getUserPermission(params: object) {
return Service.Hades("public/store/getPermission", params);
}
\ No newline at end of file
......@@ -7,7 +7,7 @@
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
import { getUserStore } from '@/data-source/base/request-apis';
import { getUserStore, getUserPermission } from '@/data-source/base/request-apis';
export default class StoreService {
// 获取员工列表
......@@ -15,4 +15,9 @@ export default class StoreService {
return getUserStore(params);
}
// 获取员工列表
static getUserPermission(params: any) {
return getUserPermission(params);
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
* @Author: 吴文洁
* @Date: 2020-04-27 20:35:34
* @LastEditors: wufan
* @LastEditTime: 2020-12-01 17:17:43
* @LastEditTime: 2020-12-02 11:35:12
* @Description:
*/
......
......@@ -2,10 +2,10 @@
* @Author: 吴文洁
* @Date: 2019-07-10 10:30:49
* @LastEditors: wufan
* @LastEditTime: 2020-12-01 17:30:13
* @LastEditTime: 2020-12-02 16:54:57
* @Description:
*/
import React from 'react'
import React, { useContext, useEffect } from 'react';
import { withRouter} from 'react-router-dom';
import {ConfigProvider } from 'antd';
import Header from './Header'
......@@ -16,29 +16,51 @@ import zhCN from 'antd/es/locale/zh_CN'
import User from '@/common/js/user';
import axios from 'axios';
import BaseService from "@/domains/basic-domain/baseService";
import { XMContext } from '@/store/context';
import { setStoreGroupPermission, setStorePermission, setStoreGroupList, setStoreList } from '@/store/actions/index';
declare var window: any;
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
const App: React.FC = (props: any) => {
const ctx: any = useContext(XMContext);
const userId = User.getUserId();
window.ctx = ctx;
useEffect(() => {
getStoreAndUserInfo();
},[userId])
async function getStoreAndUserInfo(){
await getUserStore();
await getUserPermission();
}
}
componentDidMount() {
this.getUserStore()
function getUserStore() {
BaseService.getUserStore({ userId }).then((res) => {
const { storeGroupVOS = [], storeVOS } = res.result;
const { id, storeUserId} = storeVOS[0];
User.setStoreId(id);
User.setStoreUserId(storeUserId);
ctx.dispatch(setStoreGroupList(storeGroupVOS))
ctx.dispatch(setStoreList(storeVOS))
});
}
getUserStore = () => {
const userId = User.getUserId();
function getUserPermission() {
const storeId = User.getStoreId();
const storeUserId = User.getStoreUserId();
BaseService.getUserStore({ userId }).then((res) => {
BaseService.getUserPermission({ storeId, storeUserId }).then((res) => {
console.log(res.result);
const { storeGroupVOS, storeVOS } = res.result;
const { storeUserPermission } = res.result;
// ctx.dispatch(setStoreGroupList(storeGroupVOS))
// ctx.dispatch(setStoreList(storeVOS))
});
}
render() {
return [
return (
<div id="home">
<Header/>
<ConfigProvider locale={zhCN}>
......@@ -46,7 +68,7 @@ class App extends React.Component {
</ConfigProvider>
<Menu/>
</div>
]
}
)
}
export default withRouter(App)
import App from '@/modules/root/App';
import React, { useReducer } from 'react';
import { basicReducer } from "@/store/reducers";
import {XMContext} from '@/store/context'
const AppContext: React.FC = (props: any) => {
const [xmState, xmDispatch] = useReducer(basicReducer, {});
return <XMContext.Provider value={{ xmState, dispatch: xmDispatch }}><App /> </XMContext.Provider>
}
export default AppContext;
\ No newline at end of file
/*
* @Author: 吴文洁
* @Date: 2020-04-28 18:05:30
* @LastEditors: 吴文洁
* @LastEditTime: 2020-08-13 11:23:36
* @LastEditors: wufan
* @LastEditTime: 2020-12-02 11:37:13
* @Description:
*/
import mainRoutes from './config/mainRoutes';
......@@ -10,6 +10,7 @@ import React from 'react'
import { Redirect,HashRouter as Router,Route ,Switch} from 'react-router-dom';
import { createHashHistory } from 'history';
import App from '../modules/root/App';
import AppContext from '@/modules/root/AppContent';
import Login from '../modules/root/Login';
import _ from 'underscore';
import { asyncComponent } from 'react-async-component'
......@@ -51,7 +52,7 @@ export const RootRouter = () => {
<Router {...history}>
<Switch>
<Route key="1" exact path="/login" render={() => <Login />} />
<Route key="2" path="/" render={() => <App />} />
<Route key="2" path="/" render={() => <AppContext />} />
</Switch>
</Router>
)
......
/*
* @Author: wufan
* @Date: 2020-12-02 10:26:59
* @LastEditors: wufan
* @LastEditTime: 2020-12-02 14:21:17
* @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
import {
STORE_GROUP_PERMISSION,
STORE_PERMISSION,
STORE_GROUP_LIST,
STORE_LIST
} from './constants'
const setStoreGroupPermission = (payload: any) => ({
type: STORE_GROUP_PERMISSION,
payload
})
const setStorePermission = (payload: any) => ({
type: STORE_PERMISSION,
payload
})
const setStoreGroupList = (payload: any) => ({
type: STORE_GROUP_LIST,
payload
})
const setStoreList = (payload: any) => ({
type: STORE_LIST,
payload
})
export {
setStoreGroupPermission,
setStorePermission,
setStoreGroupList,
setStoreList
}
/*
* @Author: wufan
* @Date: 2020-12-02 10:35:36
* @LastEditors: wufan
* @LastEditTime: 2020-12-02 13:56:13
* @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
const STORE_GROUP_PERMISSION = 'STORE_GROUP_PERMISSION';
const STORE_PERMISSION = 'STORE_PERMISSION';
const STORE_GROUP_LIST = 'STORE_GROUP_LIST';
const STORE_LIST = 'STORE_LIST';
export {
STORE_GROUP_PERMISSION,
STORE_PERMISSION,
STORE_GROUP_LIST,
STORE_LIST
}
\ No newline at end of file
import {
setStoreGroupPermission,
setStorePermission,
setStoreGroupList,
setStoreList
} from './basicAction';
export {
setStoreGroupPermission,
setStorePermission,
setStoreGroupList,
setStoreList
}
\ No newline at end of file
/*
* @Author: wufan
* @Date: 2020-12-02 10:21:50
* @LastEditors: wufan
* @LastEditTime: 2020-12-02 10:22:08
* @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
import React from 'react';
export const XMContext: any = React.createContext(null);
\ No newline at end of file
/*
* @Author: wufan
* @Date: 2020-12-02 10:27:44
* @LastEditors: wufan
* @LastEditTime: 2020-12-02 15:35:24
* @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
import {
STORE_GROUP_PERMISSION,
STORE_PERMISSION,
STORE_GROUP_LIST,
STORE_LIST
} from '@/store/actions/constants';
import _ from 'underscore';
import Permission from '@/common/js/permission';
const basicReducer = (state: any, action: any) => {
switch (action.type) {
case STORE_GROUP_PERMISSION:
// const storeGroupList: any = _.pluck(action.payload.storeGroupVOS, 'groupCode')
// return Object.assign({}, state, {
// userInfo: action.payload,
// storeGroupList,
// });
case STORE_PERMISSION:
// const storeList: any = _.pluck(action.payload.storeVOS, 'groupCode')
// return Object.assign({}, state, {
// userInfo: action.payload,
// authPermissionList: action.payload.storeVOS,
// storePermissionCodeList,
// permission: new Permission(storePermissionCodeList)
// });
case STORE_GROUP_LIST:
const storeGroupList: any = action.payload;
return Object.assign({}, state, {
storeGroupList,
});
case STORE_LIST:
const storeList: any = action.payload;
return Object.assign({}, state, {
storeList,
});
default:
return state;
}
}
export {
basicReducer
}
/*
* @Author: wufan
* @Date: 2020-12-02 10:22:50
* @LastEditors: wufan
* @LastEditTime: 2020-12-02 11:14:12
* @Description: Description
* @@Copyrigh: © 2020 杭州杰竞科技有限公司 版权所有
*/
import {
basicReducer
} from './basicReducer';
export {
basicReducer
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment