소스 검색

Merge branch 'develop'

xjj 2 년 전
부모
커밋
33e630a094
5개의 변경된 파일94개의 추가작업 그리고 21개의 파일을 삭제
  1. 32 14
      src/components/FileViewer/index.js
  2. 37 2
      src/pages/Index.js
  3. 16 1
      src/pages/Login/Login.js
  4. 5 1
      src/pages/Login/models/login.js
  5. 4 3
      src/utils/request.js

+ 32 - 14
src/components/FileViewer/index.js

@@ -1,21 +1,25 @@
 import FileViewer from 'react-file-viewer';
 import { Modal, Spin } from 'antd';
-import { memo } from 'react';
+import { memo, useMemo } from 'react';
 
 const FileViewerModal = ({ data, visible, onCancel, downloadFile }) => {
-  const type = data?.url?.split('.')[data?.url?.split('.').length - 1];
+  const type = useMemo(() => {
+    if (!data || !data.url) return '';
+    let url = data.url || '';
+    let arr = url.split('.');
 
-  return (
-    <Modal
-      destroyOnClose
-      title="预览"
-      visible={visible}
-      width={1000}
-      footer={null}
-      onCancel={onCancel}
-      bodyStyle={{ height: '680px', overflowY: 'hidden' }}
-    >
-      {data?.url && (
+    return arr[arr.length - 1];
+  }, [data?.url]);
+
+  const renderContent = () => {
+    if (type == 'xlsx') {
+      return (
+        <div>
+          不支持的文件格式点击<a onClick={() => downloadFile(data)}>下载</a>
+        </div>
+      );
+    } else if (data?.url) {
+      return (
         <FileViewer
           key={data?.name}
           fileType={type}
@@ -32,7 +36,21 @@ const FileViewerModal = ({ data, visible, onCancel, downloadFile }) => {
             </div>
           )}
         />
-      )}
+      );
+    }
+  };
+
+  return (
+    <Modal
+      destroyOnClose
+      title="预览"
+      visible={visible}
+      width={1000}
+      footer={null}
+      onCancel={onCancel}
+      bodyStyle={{ height: '680px', overflowY: 'hidden' }}
+    >
+      {renderContent()}
     </Modal>
   );
 };

+ 37 - 2
src/pages/Index.js

@@ -8,7 +8,7 @@ import styles from './Index.less';
 const { Header, Content, Footer } = Layout;
 const { SubMenu } = Menu;
 let timer;
-
+const isMobile = isMobileDevice();
 // 布局
 function LayoutDetail(props) {
   const { currentUser, permission, dispatch, authList } = props;
@@ -21,15 +21,22 @@ function LayoutDetail(props) {
     marginRight: 60,
     width: 120,
   };
+
   useEffect(() => {
+    if (isMobile) return;
     // 查询用户信息
-    props.dispatch({
+    dispatch({
       type: 'user/fetchCurrent',
     });
   }, []);
 
   useEffect(() => {
+    if (isMobile) return;
     if (!currentUser.ID) return;
+    dispatch({
+      type: 'authList/queryAuthList',
+      payload: { user_id: currentUser.ID },
+    });
     clearInterval(timer);
     timer = setInterval(() => {
       dispatch({
@@ -41,6 +48,30 @@ function LayoutDetail(props) {
     return () => clearInterval(timer);
   }, [currentUser.ID]);
 
+  // 不支持移动端使用,做判断
+  if (isMobile) {
+    return (
+      <Layout>
+        <Header>
+          <div style={{ display: 'flex', height: '100%', justifyContent: 'space-between' }}>
+            <div style={{ display: 'flex', width: '70%' }}>
+              <div style={logoStyle}>金科环境</div>
+            </div>
+          </div>
+        </Header>
+        <Content
+          style={{
+            padding: '50px 0',
+            minHeight: 'calc(100vh - 64px)',
+            textAlign: 'center',
+            fontSize: 24,
+          }}
+        >
+          请使用PC端进行审批
+        </Content>
+      </Layout>
+    );
+  }
   return (
     <Layout>
       <Header>
@@ -78,6 +109,10 @@ function LayoutDetail(props) {
     </Layout>
   );
 }
+
+function isMobileDevice() {
+  return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
+}
 export default connect(({ user, authList }) => ({
   currentUser: user.currentUser,
   permission: user.currentUser.Permission,

+ 16 - 1
src/pages/Login/Login.js

@@ -79,6 +79,13 @@ class LoginPage extends Component {
   };
   handleSubmit = (err, values) => {
     const { type, depId } = this.state;
+    const {
+      login,
+      submitting,
+      location: {
+        query: { referrer },
+      },
+    } = this.props;
     if (!depId) {
       message.error('请选择部门');
       return;
@@ -91,6 +98,7 @@ class LoginPage extends Component {
           ...values,
           type,
           DepId: depId + '',
+          referrer: referrer && decodeURIComponent(decodeURIComponent(referrer)),
         },
       });
     }
@@ -111,8 +119,15 @@ class LoginPage extends Component {
   );
 
   render() {
-    const { login, submitting } = this.props;
+    const {
+      login,
+      submitting,
+      location: {
+        query: { referrer },
+      },
+    } = this.props;
     const { type, autoLogin, depList, depId, loginType } = this.state;
+    console.log(referrer);
     return (
       <DocumentTitle title={`登录-${loginType == 'bom' ? '采购清单' : '人日'}`}>
         <div className={styles.container}>

+ 5 - 1
src/pages/Login/models/login.js

@@ -25,7 +25,11 @@ export default {
         type: 'changeLoginStatus',
         payload: response,
       });
-      yield put(routerRedux.replace('/home'));
+      if(payload.referrer) {
+        location.href = payload.referrer
+      } else {
+        yield put(routerRedux.replace('/home'));
+      }
     },
     *logout(_, { call, put }) {
       yield call(Logout);

+ 4 - 3
src/utils/request.js

@@ -174,7 +174,7 @@ export default function request(url, option, jwt) {
             message: '错误',
             description: 'token失效,请重新登录',
           });
-          router.push('/login');
+          router.push(`/login?referrer=${encodeURIComponent(encodeURIComponent(location.href))}`);
         } else {
           message.error(response.msg);
         }
@@ -192,9 +192,10 @@ export default function request(url, option, jwt) {
           message: '错误',
           description: 'token失效,请重新登录',
         });
-        router.push('/login');
+        router.push(`/login?referrer=${encodeURIComponent(encodeURIComponent(location.href))}`);
         return;
-      } else if (status == 'AbortError') { // 中止的ajax 不做额外处理
+      } else if (status == 'AbortError') {
+        // 中止的ajax 不做额外处理
         return e;
       }
       // if (status <= 504 && status > 500 && status !== 600) {