张延森 5 years ago
parent
commit
02922546e9

+ 1
- 1
config/config.js View File

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

+ 25
- 0
src/components/AuthButton/index.jsx View File

@@ -0,0 +1,25 @@
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 View File

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

+ 11
- 4
src/models/login.js View File

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

+ 11
- 5
src/models/user.js View File

@@ -1,11 +1,14 @@
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 6
 const UserModel = {
5 7
   namespace: 'user',
6 8
   state: {
7 9
     currentUser: {},
8 10
     menuList: [],
11
+    buttonList: [],
9 12
   },
10 13
   effects: {
11 14
     // *fetch(_, { call, put }) {
@@ -17,7 +20,7 @@ const UserModel = {
17 20
     // },
18 21
 
19 22
     *fetchCurrent(_, { call, put }) {
20
-      const response = yield call(request, apis.user.current);
23
+      const response = yield call(getCurrentUser);
21 24
 
22 25
       yield put({
23 26
         type: 'saveCurrentUser',
@@ -27,10 +30,13 @@ const UserModel = {
27 30
   },
28 31
   reducers: {
29 32
     saveCurrentUser(state, { payload }) {
30
-      const { taUser = {} , menuList = [] } = payload || {}
33
+      const { taUser = {} , menuList = [], buttonList = [] } = payload || {}
31 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 41
     changeNotifyCount(
36 42
       state = {

+ 7
- 3
src/pages/building/list/index.jsx View File

@@ -5,6 +5,7 @@ import request from '../../../utils/request';
5 5
 import apis from '../../../services/apis';
6 6
 import Styles from './style.less';
7 7
 import { router } from 'umi';
8
+import AuthButton from '@/components/AuthButton';
8 9
 
9 10
 
10 11
 const { Option } = Select;
@@ -285,9 +286,12 @@ function body(props) {
285 286
           </Button>
286 287
         </Form.Item>
287 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 297
       <Row style={{ padding: ' 0 10px' }}>

+ 4
- 0
src/services/apis.js View File

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