李志伟 3 years ago
parent
commit
0cb8f26395

+ 8
- 0
config/routes.js View File

@@ -11,6 +11,11 @@ export default [
11 11
             path: '/user/login',
12 12
             component: '@/pages/user/Login',
13 13
           },
14
+          {
15
+            name: 'orgLogin',
16
+            path: '/user/orgLogin',
17
+            component: '@/pages/user/orgLogin',
18
+          },
14 19
         ],
15 20
       },
16 21
       {
@@ -21,6 +26,7 @@ export default [
21 26
   {
22 27
     path: '/dashboard',
23 28
     name: '工作台',
29
+    access:'admin',
24 30
     icon: 'DashboardOutlined',
25 31
     component: './dashboard',
26 32
   },
@@ -33,6 +39,7 @@ export default [
33 39
   {
34 40
     path: '/org',
35 41
     name: '企业管理',
42
+    access:'admin',
36 43
     icon: 'apartment',
37 44
     component: '@/layouts/BasicLayout',
38 45
     routes: [
@@ -71,6 +78,7 @@ export default [
71 78
   {
72 79
     path: '/deleteLog',
73 80
     name: '删除日志',
81
+    access:'admin',
74 82
     icon: 'ProfileOutlined',
75 83
     component: '@/pages/deleteLog',    
76 84
   },

+ 12
- 1
src/access.js View File

@@ -2,7 +2,18 @@
2 2
  * @see https://umijs.org/zh-CN/plugins/plugin-access
3 3
  * */
4 4
 export default function access(initialState) {
5
-  const { menuAccess } = initialState || {};
5
+  const { menuAccess,roleAlias } = initialState || {};
6
+  if(roleAlias=='org'){
7
+    return {
8
+      admin:false,
9
+      org:true
10
+    }
11
+  }else if(roleAlias=='admin'){
12
+    return {
13
+      admin:true,
14
+      org:false
15
+    }
16
+  }
6 17
   return (menuAccess || []).reduce((acc, item) => {
7 18
     const { permission, canAccess } = item;
8 19
     return {

+ 5
- 2
src/app.jsx View File

@@ -32,7 +32,8 @@ export async function getInitialState() {
32 32
       fetchUserInfo,
33 33
       currentUser: res.user,
34 34
       menuAccess: res.menu,
35
-      report_url:res.report_url,
35
+      report_url: res.report_url,
36
+      roleAlias:res.roleAlias,
36 37
       settings: {},
37 38
     };
38 39
   }
@@ -52,7 +53,9 @@ export const layout = ({ initialState }) => {
52 53
     onPageChange: () => {
53 54
       const { location } = history; // 如果没有登录,重定向到 login
54 55
 
55
-      if (!initialState?.currentUser && location.pathname !== loginPath) {
56
+      if (!initialState?.currentUser &&
57
+        (location.pathname !== loginPath &&
58
+          location.pathname !== '/user/orgLogin')) {
56 59
         history.push(loginPath);
57 60
       }
58 61
     },

+ 22
- 10
src/components/RightContent/AvatarDropdown.jsx View File

@@ -10,18 +10,26 @@ import styles from './index.less';
10 10
 /**
11 11
  * 退出登录,并且将当前的 url 保存
12 12
  */
13
-const loginOut = async () => {
13
+const loginOut = async (val) => {
14 14
   localStorage.removeItem('token');
15 15
   const { query = {}, pathname } = history.location;
16
-  const { redirect } = query; // Note: There may be security issues, please note
17
-
16
+  const { redirect } = query;
18 17
   if (window.location.pathname !== '/user/login' && !redirect) {
19
-    history.replace({
20
-      pathname: '/user/login',
21
-      search: stringify({
22
-        redirect: pathname,
23
-      }),
24
-    });
18
+    if (val == 'org') {
19
+      history.replace({
20
+        pathname: '/user/orgLogin',
21
+        search: stringify({
22
+          redirect: pathname,
23
+        }),
24
+      });
25
+    } else {
26
+      history.replace({
27
+        pathname: '/user/login',
28
+        search: stringify({
29
+          redirect: pathname,
30
+        }),
31
+      });
32
+    }
25 33
   }
26 34
 };
27 35
 
@@ -35,7 +43,11 @@ const AvatarDropdown = ({ menu }) => {
35 43
 
36 44
       if (key === 'logout') {
37 45
         setInitialState((s) => ({ ...s, currentUser: undefined }));
38
-        loginOut();
46
+        if (initialState.roleAlias == 'org') {
47
+          loginOut('org');
48
+        } else {
49
+          loginOut('admin');
50
+        }
39 51
         return;
40 52
       }
41 53
 

+ 28
- 10
src/pages/resumework/form/index.jsx View File

@@ -1,11 +1,12 @@
1
-
2
-import React, { useRef } from 'react'
1
+import React, { useRef,useEffect,useState } from 'react'
2
+import { useModel } from 'umi';
3 3
 import moment from 'moment';
4
-import { Badge, Image, DatePicker,Button,Popconfirm,message } from 'antd';
4
+import { Badge, Image, DatePicker,Button,Popconfirm,message,Input } from 'antd';
5 5
 import { PageHeaderWrapper } from '@ant-design/pro-layout';
6 6
 import PageTable from '@/components/PageTable'
7 7
 import OrgSearch from '@/components/OrgSearch';
8 8
 import { getList, exportList,deleteworkForm } from '@/services/work'
9
+import { getDetail } from '@/services/org';
9 10
 
10 11
 const { RangePicker } = DatePicker;
11 12
 
@@ -16,11 +17,14 @@ const formatterTime = (val) => {
16 17
 export default (props) => {
17 18
   const initDate = useRef(moment())
18 19
   const actionRef = useRef();
20
+  const { initialState } = useModel('@@initialState');
21
+  const isorg=useRef(false)
22
+  const [orgName,setOrgName]=useState()
19 23
 
20 24
   const handleBeforSearch = (params) => {
21 25
     const { createDate, ...others } = params;
22 26
 
23
-    let start, end;
27
+    let start, end,orgId;
24 28
     if (!createDate || createDate.length < 1) {
25 29
       // 默认时间是今天
26 30
       start = moment().format('YYYY-MM-DD')
@@ -29,7 +33,10 @@ export default (props) => {
29 33
       start = moment(createDate[0]).format('YYYY-MM-DD')
30 34
       end = moment(createDate[1]).format('YYYY-MM-DD')
31 35
     }
32
-
36
+    if (isorg.current) {
37
+      orgId=initialState.currentUser.orgId
38
+      return { ...others, start, end,orgId };
39
+    }
33 40
     return { ...others, start, end };
34 41
   }
35 42
 
@@ -41,6 +48,16 @@ export default (props) => {
41 48
       message.error(err.message || err);
42 49
     })
43 50
   }
51
+  useEffect(()=>{
52
+    if (initialState.roleAlias == 'org') {
53
+      isorg.current=true
54
+      getDetail(initialState.currentUser.orgId).then((res)=>{
55
+        setOrgName(res.orgName);
56
+      })
57
+    }else{
58
+      setOrgName('');
59
+    }
60
+  },[initialState.currentUser.orgId, initialState.roleAlias])
44 61
 
45 62
   const columns = [
46 63
     {
@@ -50,16 +67,17 @@ export default (props) => {
50 67
       search: true,
51 68
       hideInTable:true,
52 69
       renderFormItem: () => (
53
-        <OrgSearch placeholder='请输入企业名称' />
70
+        !isorg.current?
71
+        <OrgSearch placeholder='请输入企业名称' />:<Input readOnly value={orgName} />
54 72
       ),
55
-      formItemProps: {
56
-        rules: [
73
+      formItemProps: !isorg.current?{
74
+        rules: [          
57 75
           {
58 76
             required: true,
59 77
             message: '请输入企业名称',
60
-          },
78
+          }
61 79
         ],
62
-      },
80
+      }:false,
63 81
     },
64 82
     {
65 83
       title: '企业名称',

+ 2
- 2
src/pages/user/Login/index.jsx View File

@@ -17,9 +17,9 @@ const Login = () => {
17 17
     setSubmitting(true);
18 18
     try {
19 19
       // 登录
20
-      const { user, menu,report_url } = await login({ ...values, password: md5(values.password) });
20
+      const { user, menu,report_url,roleAlias } = await login({ ...values, password: md5(values.password) });
21 21
 
22
-      await setInitialState((s) => ({ ...s, currentUser: user, menuAccess: menu,report_url:report_url }));
22
+      await setInitialState((s) => ({ ...s, currentUser: user, menuAccess: menu,report_url:report_url,roleAlias:roleAlias }));
23 23
       message.success('登录成功!');
24 24
       /** 此方法会跳转到 redirect 参数所在的位置 */
25 25
       if (!history) return;

+ 127
- 0
src/pages/user/orgLogin/index.jsx View File

@@ -0,0 +1,127 @@
1
+import { LockOutlined, UserOutlined } from '@ant-design/icons';
2
+import { message } from 'antd';
3
+import React, { useState } from 'react';
4
+import md5 from 'md5';
5
+import ProForm, { ProFormText } from '@ant-design/pro-form';
6
+import { useIntl, Link, history, FormattedMessage, useModel } from 'umi';
7
+import Footer from '@/components/Footer';
8
+import { orgLogin } from '@/services/user';
9
+import styles from './index.less';
10
+
11
+const Login = () => {
12
+  const [submitting, setSubmitting] = useState(false);
13
+  const { setInitialState } = useModel('@@initialState');
14
+  const intl = useIntl();
15
+
16
+  const handleSubmit = async (values) => {
17
+    setSubmitting(true);
18
+    try {
19
+      // 登录
20
+      const { user, menu,report_url,roleAlias } = await orgLogin({ ...values, password: md5(values.password) });
21
+
22
+      await setInitialState((s) => ({ ...s, currentUser: user, menuAccess: menu,report_url:report_url,roleAlias:roleAlias }));
23
+      message.success('登录成功!');
24
+      /** 此方法会跳转到 redirect 参数所在的位置 */
25
+      if (!history) return;
26
+      const { query } = history.location;
27
+      const { redirect } = query;
28
+      history.push(redirect || '/');
29
+      return;
30
+    } catch (error) {
31
+      console.error(error);
32
+    }
33
+    setSubmitting(false);
34
+  };
35
+
36
+  return (
37
+    <div className={styles.container}>
38
+      <div className={styles.leftback} />
39
+      <div className={styles.rightSide} >
40
+        <div>
41
+          <div className={styles.content}>
42
+            <div className={styles.top}>
43
+              <div className={styles.header}>
44
+                <Link to="/">
45
+                  {/* <img alt="logo" className={styles.logo} src="/logo.svg" /> */}
46
+                  <span className={styles.title}>复工复产申报系统-企业子系统</span>
47
+                </Link>
48
+              </div>
49
+              <div className={styles.desc}> </div>
50
+            </div>
51
+
52
+            <div className={styles.main}>
53
+              <ProForm
54
+                isKeyPressSubmit
55
+                initialValues={{
56
+                  autoLogin: true,
57
+                }}
58
+                submitter={{
59
+                  searchConfig: {
60
+                    submitText: intl.formatMessage({
61
+                      id: 'pages.login.submit',
62
+                      defaultMessage: '登录',
63
+                    }),
64
+                  },
65
+                  render: (_, dom) => dom.pop(),
66
+                  submitButtonProps: {
67
+                    loading: submitting,
68
+                    size: 'large',
69
+                    style: {
70
+                      width: '100%',
71
+                    },
72
+                  },
73
+                }}
74
+                onFinish={async (values) => {
75
+                  handleSubmit(values);
76
+                }}
77
+              >
78
+                <ProFormText
79
+                  name="userName"
80
+                  fieldProps={{
81
+                    size: 'large',
82
+                    prefix: <UserOutlined className={styles.prefixIcon} />,
83
+                  }}
84
+                  placeholder="用户名"
85
+                  rules={[
86
+                    {
87
+                      required: true,
88
+                      message: (
89
+                        <FormattedMessage
90
+                          id="pages.login.username.required"
91
+                          defaultMessage="请输入用户名!"
92
+                        />
93
+                      ),
94
+                    },
95
+                  ]}
96
+                />
97
+                <ProFormText.Password
98
+                  name="password"
99
+                  fieldProps={{
100
+                    size: 'large',
101
+                    prefix: <LockOutlined className={styles.prefixIcon} />,
102
+                  }}
103
+                  placeholder="密码"
104
+                  rules={[
105
+                    {
106
+                      required: true,
107
+                      message: (
108
+                        <FormattedMessage
109
+                          id="pages.login.password.required"
110
+                          defaultMessage="请输入密码!"
111
+                        />
112
+                      ),
113
+                    },
114
+                  ]}
115
+
116
+                />
117
+              </ProForm>
118
+            </div>
119
+          </div>
120
+          <Footer />
121
+        </div>
122
+      </div>
123
+    </div>
124
+  );
125
+};
126
+
127
+export default Login;

+ 138
- 0
src/pages/user/orgLogin/index.less View File

@@ -0,0 +1,138 @@
1
+@import '~antd/es/style/themes/default.less';
2
+
3
+.container {
4
+  display: flex;
5
+  flex-direction: column;
6
+  height: 100vh;
7
+  overflow: auto;
8
+  background: @layout-body-background;
9
+}
10
+
11
+.leftback {
12
+  position: absolute;
13
+  left: 0;
14
+  top: 0;
15
+  z-index: 0;
16
+  width: 50vw;
17
+  height: 100vh;
18
+  background-image: url('../../../../public/back.png');
19
+  background-repeat: no-repeat;
20
+  background-position:left top;
21
+  background-size: cover;
22
+}
23
+
24
+.rightSide {
25
+  position: absolute;
26
+  right: 0;
27
+  top: 0;
28
+  width: 50vw;
29
+  height: 100vh;
30
+  display: flex;
31
+  justify-content: center;
32
+  align-items: center;
33
+}
34
+
35
+.lang {
36
+  width: 100%;
37
+  height: 40px;
38
+  line-height: 44px;
39
+  text-align: right;
40
+  :global(.ant-dropdown-trigger) {
41
+    margin-right: 24px;
42
+  }
43
+}
44
+
45
+.content {
46
+  flex: 1;
47
+  padding: 32px 0;
48
+}
49
+
50
+@media (min-width: @screen-md-min) {
51
+  .container {
52
+    // background-image: url('/back.png');
53
+    // background-repeat: no-repeat;
54
+    // background-position: center 110px;
55
+    // background-size: 100%;
56
+  }
57
+
58
+  .content {
59
+    padding: 32px 0 24px;
60
+  }
61
+}
62
+
63
+.top {
64
+  text-align: center;
65
+}
66
+
67
+.header {
68
+  height: 44px;
69
+  line-height: 44px;
70
+  a {
71
+    text-decoration: none;
72
+  }
73
+}
74
+
75
+.logo {
76
+  height: 44px;
77
+  margin-right: 16px;
78
+  vertical-align: top;
79
+}
80
+
81
+.title {
82
+  position: relative;
83
+  top: 2px;
84
+  color: @heading-color;
85
+  font-weight: 600;
86
+  font-size: 33px;
87
+  font-family: Avenir, 'Helvetica Neue', Arial, Helvetica, sans-serif;
88
+}
89
+
90
+.desc {
91
+  margin-top: 12px;
92
+  margin-bottom: 40px;
93
+  color: @text-color-secondary;
94
+  font-size: @font-size-base;
95
+}
96
+
97
+.main {
98
+  width: 328px;
99
+  margin: 0 auto;
100
+  @media screen and (max-width: @screen-sm) {
101
+    width: 95%;
102
+    max-width: 328px;
103
+  }
104
+
105
+  :global {
106
+    .@{ant-prefix}-tabs-nav-list {
107
+      margin: auto;
108
+      font-size: 16px;
109
+    }
110
+  }
111
+
112
+  .icon {
113
+    margin-left: 16px;
114
+    color: rgba(0, 0, 0, 0.2);
115
+    font-size: 24px;
116
+    vertical-align: middle;
117
+    cursor: pointer;
118
+    transition: color 0.3s;
119
+
120
+    &:hover {
121
+      color: @primary-color;
122
+    }
123
+  }
124
+
125
+  .other {
126
+    margin-top: 24px;
127
+    line-height: 22px;
128
+    text-align: left;
129
+    .register {
130
+      float: right;
131
+    }
132
+  }
133
+
134
+  .prefixIcon {
135
+    color: @primary-color;
136
+    font-size: @font-size-base;
137
+  }
138
+}

+ 5
- 1
src/services/user.js View File

@@ -7,4 +7,8 @@ export const login = (data) => request('/login', { method: 'post', data });
7 7
 export const currentUser = () => request('/currentUser', { showType: 0 });
8 8
 
9 9
 // 修改密码
10
-export const changePassword = (data) => request('/change-password', { data, method: 'PUT' });
10
+export const changePassword = (data) => request('/change-password', { data, method: 'PUT' });
11
+
12
+
13
+// 企业登录
14
+export const orgLogin = (data) => request('/org/login', { method: 'post', data });

+ 16
- 0
src/utils/hooks/useFetchState.js View File

@@ -0,0 +1,16 @@
1
+import { useCallback, useEffect, useRef, useState } from 'react';
2
+
3
+function useFetchState(...props) {
4
+  const focus = useRef();
5
+  const [state, setState] = useState(...props);
6
+  useEffect(() => {
7
+    focus.current = true;
8
+    return () => (focus.current = false);
9
+  }, []);
10
+  const setFetchState = useCallback((...params) => {
11
+    focus.current && setState(...params);
12
+  }, []);
13
+  return [state, setFetchState];
14
+}
15
+
16
+export default useFetchState;