张延森 5 年之前
父節點
當前提交
02922546e9

+ 1
- 1
config/config.js 查看文件

474
 
474
 
475
   proxy: {
475
   proxy: {
476
     '/api/': {
476
     '/api/': {
477
-      target: 'http://192.168.0.84:8080/',
477
+      target: 'http://192.168.0.11:8080/',
478
       changeOrigin: true,
478
       changeOrigin: true,
479
       // pathRewrite: { '^/server': '' },
479
       // pathRewrite: { '^/server': '' },
480
     },
480
     },

+ 25
- 0
src/components/AuthButton/index.jsx 查看文件

1
+import React from 'react';
2
+
3
+let allBtns = [];
4
+let current = [];
5
+
6
+const AuthButton = ({ children, name, noRight }) => {
7
+  const btn = allBtns.filter(x => x.code === name)[0]
8
+
9
+  // 没维护的按钮, 或者不需要权限的按钮直接通过
10
+  if (!btn || !btn.roles || !btn.roles.length) {
11
+    return <>{children}</>
12
+  }
13
+
14
+  const hasRight = btn.roles.some(x => current.some(y => x === y))
15
+  return hasRight ? <>{children}</> : <>{noRight}</>
16
+}
17
+
18
+const setAllBtnAuth = x => allBtns = x;
19
+const setUserBtnAuth = x => current = x;
20
+
21
+export default AuthButton;
22
+export {
23
+  setAllBtnAuth,
24
+  setUserBtnAuth,
25
+};

+ 6
- 9
src/layouts/BasicLayout.jsx 查看文件

9
 import Redirect from 'umi/redirect';
9
 import Redirect from 'umi/redirect';
10
 import { connect } from 'dva';
10
 import { connect } from 'dva';
11
 import { formatMessage } from 'umi-plugin-react/locale';
11
 import { formatMessage } from 'umi-plugin-react/locale';
12
-import Authorized from '@/utils/Authorized';
12
+// import Authorized from '@/utils/Authorized';
13
 import RightContent from '@/components/GlobalHeader/RightContent';
13
 import RightContent from '@/components/GlobalHeader/RightContent';
14
+import RenderAuthorize from '@/components/Authorized';
14
 import { isAntDesignPro } from '@/utils/utils';
15
 import { isAntDesignPro } from '@/utils/utils';
15
 import logo from '../assets/logo.png';
16
 import logo from '../assets/logo.png';
16
   
17
   
33
 
34
 
34
 const BasicLayout = props => {
35
 const BasicLayout = props => {
35
   const { dispatch, children, settings } = props;
36
   const { dispatch, children, settings } = props;
36
-  /**
37
-   * constructor
38
-   */
39
-
37
+  
40
   useEffect(() => {
38
   useEffect(() => {
41
-    if (dispatch) {
39
+    if (dispatch && !props.user.currentUser.userId) {
42
       dispatch({
40
       dispatch({
43
         type: 'user/fetchCurrent',
41
         type: 'user/fetchCurrent',
44
       });
42
       });
47
       });
45
       });
48
     }
46
     }
49
   }, []);
47
   }, []);
50
-  /**
51
-   * init variables
52
-   */
48
+  
49
+  const Authorized = RenderAuthorize(props.user.currentUser.roles)
53
 
50
 
54
   const handleMenuCollapse = payload => {
51
   const handleMenuCollapse = payload => {
55
     if (dispatch) {
52
     if (dispatch) {

+ 11
- 4
src/models/login.js 查看文件

1
 import { routerRedux } from 'dva/router';
1
 import { routerRedux } from 'dva/router';
2
 import { stringify } from 'querystring';
2
 import { stringify } from 'querystring';
3
-import { fakeAccountLogin, getFakeCaptcha } from '@/services/login';
3
+// import { fakeAccountLogin, getFakeCaptcha } from '@/services/login';
4
 import { setAuthority } from '@/utils/authority';
4
 import { setAuthority } from '@/utils/authority';
5
 import { getPageQuery } from '@/utils/utils';
5
 import { getPageQuery } from '@/utils/utils';
6
+import { fetch, apis } from '@/utils/request';
7
+
8
+const signin = fetch(apis.user.signin);
9
+const signout = fetch(apis.user.signout);
10
+
6
 const Model = {
11
 const Model = {
7
   namespace: 'login',
12
   namespace: 'login',
8
   state: {
13
   state: {
10
   },
15
   },
11
   effects: {
16
   effects: {
12
     *login({ payload }, { call, put }) {
17
     *login({ payload }, { call, put }) {
13
-      const response = yield call(fakeAccountLogin, payload);
18
+      const response = yield call(signin, payload);
14
       yield put({
19
       yield put({
15
         type: 'changeLoginStatus',
20
         type: 'changeLoginStatus',
16
         payload: response,
21
         payload: response,
42
       yield call(getFakeCaptcha, payload);
47
       yield call(getFakeCaptcha, payload);
43
     },
48
     },
44
 
49
 
45
-    *logout(_, { put }) {
50
+    *logout(_, { put, call }) {
46
       const { redirect } = getPageQuery(); // redirect
51
       const { redirect } = getPageQuery(); // redirect
47
 
52
 
53
+      yield call(signout, { logout: true });
54
+
48
       if (window.location.pathname !== '/user/login' && !redirect) {
55
       if (window.location.pathname !== '/user/login' && !redirect) {
49
         yield put(
56
         yield put(
50
           routerRedux.replace({
57
           routerRedux.replace({
59
   },
66
   },
60
   reducers: {
67
   reducers: {
61
     changeLoginStatus(state, { payload }) {
68
     changeLoginStatus(state, { payload }) {
62
-      setAuthority((payload.user.roles || []).map(x => x.roleId));
69
+      // setAuthority((payload.user.roles || []).map(x => x.roleId));
63
       return { ...state, status: 'ok', type: payload.type };
70
       return { ...state, status: 'ok', type: payload.type };
64
     },
71
     },
65
   },
72
   },

+ 11
- 5
src/models/user.js 查看文件

1
-import request from '../utils/request';
2
-import apis from '../services/apis';
1
+import { fetch, apis } from '@/utils/request';
2
+import { setAllBtnAuth, setUserBtnAuth } from '@/components/AuthButton';
3
+
4
+const getCurrentUser = fetch(apis.user.current)
3
 
5
 
4
 const UserModel = {
6
 const UserModel = {
5
   namespace: 'user',
7
   namespace: 'user',
6
   state: {
8
   state: {
7
     currentUser: {},
9
     currentUser: {},
8
     menuList: [],
10
     menuList: [],
11
+    buttonList: [],
9
   },
12
   },
10
   effects: {
13
   effects: {
11
     // *fetch(_, { call, put }) {
14
     // *fetch(_, { call, put }) {
17
     // },
20
     // },
18
 
21
 
19
     *fetchCurrent(_, { call, put }) {
22
     *fetchCurrent(_, { call, put }) {
20
-      const response = yield call(request, apis.user.current);
23
+      const response = yield call(getCurrentUser);
21
 
24
 
22
       yield put({
25
       yield put({
23
         type: 'saveCurrentUser',
26
         type: 'saveCurrentUser',
27
   },
30
   },
28
   reducers: {
31
   reducers: {
29
     saveCurrentUser(state, { payload }) {
32
     saveCurrentUser(state, { payload }) {
30
-      const { taUser = {} , menuList = [] } = payload || {}
33
+      const { taUser = {} , menuList = [], buttonList = [] } = payload || {}
31
       const currentUser = { ...taUser, roles: (taUser.roles || []).map(x => x.roleId) }
34
       const currentUser = { ...taUser, roles: (taUser.roles || []).map(x => x.roleId) }
32
 
35
 
33
-      return { ...state, currentUser, menuList };
36
+      setAllBtnAuth(buttonList)
37
+      setUserBtnAuth(currentUser.roles)
38
+
39
+      return { ...state, currentUser, menuList, buttonList };
34
     },
40
     },
35
     changeNotifyCount(
41
     changeNotifyCount(
36
       state = {
42
       state = {

+ 7
- 3
src/pages/building/list/index.jsx 查看文件

5
 import apis from '../../../services/apis';
5
 import apis from '../../../services/apis';
6
 import Styles from './style.less';
6
 import Styles from './style.less';
7
 import { router } from 'umi';
7
 import { router } from 'umi';
8
+import AuthButton from '@/components/AuthButton';
8
 
9
 
9
 
10
 
10
 const { Option } = Select;
11
 const { Option } = Select;
285
           </Button>
286
           </Button>
286
         </Form.Item>
287
         </Form.Item>
287
       </Form>
288
       </Form>
288
-      <Button type="danger" className={Styles.addButton} onClick={() => toAdd()}>
289
-        新增楼盘
290
-      </Button>
289
+
290
+      <AuthButton name="building.add" noRight={null}>
291
+        <Button type="danger" className={Styles.addButton} onClick={() => toAdd()}>
292
+          新增楼盘
293
+        </Button>
294
+      </AuthButton>
291
 
295
 
292
       {/* 卡片内容,显示楼盘项目  */}
296
       {/* 卡片内容,显示楼盘项目  */}
293
       <Row style={{ padding: ' 0 10px' }}>
297
       <Row style={{ padding: ' 0 10px' }}>

+ 4
- 0
src/services/apis.js 查看文件

16
       method: 'POST',
16
       method: 'POST',
17
       url: `${prefix}/taUser/signin`,
17
       url: `${prefix}/taUser/signin`,
18
     },
18
     },
19
+    signout: {
20
+      method: 'POST',
21
+      url: `${prefix}/taUser/signout`,
22
+    },
19
   },
23
   },
20
   building: {
24
   building: {
21
     getList: {
25
     getList: {