xujunjie 2 år sedan
förälder
incheckning
c2695d3f52

+ 2 - 2
config/config.js

@@ -140,8 +140,8 @@ export default {
   chainWebpack: webpackPlugin,
   proxy: {
     '/api': {
-      target: 'http://192.168.20.152:8888/',
-      // target: 'http://47.96.12.136:8888/',
+      // target: 'http://192.168.20.152:8888/',
+      target: 'http://47.96.12.136:8896/',
       // target: 'http://oraysmart.com:8889/',
       // target: 'http://oraysmart.com:8888/api',
       // changeOrigin: true,

+ 1 - 1
config/router.config.js

@@ -75,7 +75,7 @@ export default [
         ],
       },
       {
-        path: '/dd-login',
+        path: '/dd-login/:dingUserId',
         component: './DDLogin/index',
       },
       {

+ 9 - 3
src/components/DDComponents/DDCode/index.js

@@ -1,10 +1,15 @@
 import QRCode from 'qrcode.react';
 import React, { useEffect, useState } from 'react';
 import { Spin } from 'antd';
+import { connect } from 'dva';
 
 let timer;
 function DDCode(props) {
-  const { value, onChange } = props;
+  const {
+    value,
+    onChange,
+    currentUser: { DingUserId },
+  } = props;
   const [loading, setLoading] = useState(false);
   const [time, setTime] = useState(0);
 
@@ -30,6 +35,7 @@ function DDCode(props) {
       });
     }, second * 1000);
   };
+  if (!DingUserId) return <div>未知用户,请联系管理员。</div>;
   return (
     <div>
       {time > 0 ? (
@@ -40,7 +46,7 @@ function DDCode(props) {
         </div>
       ) : (
         <Spin spinning={loading}>
-          <QRCode size={128} value={'http://192.168.20.80:8000/bom/#/bom/dd-login'} />
+          <QRCode size={128} value={`http://192.168.20.80:8000/bom/#/bom/dd-login/${DingUserId}`} />
           请使用钉钉扫码授权<a onClick={queryCode}>刷新</a>
         </Spin>
       )}
@@ -48,4 +54,4 @@ function DDCode(props) {
   );
 }
 
-export default DDCode;
+export default connect(({ user }) => ({ currentUser: user.currentUser }))(DDCode);

+ 14 - 4
src/pages/DDLogin/index.js

@@ -2,18 +2,27 @@ import React, { useEffect, useState } from 'react';
 import * as dd from 'dingtalk-jsapi';
 import { message } from 'antd';
 import { LoadingOutlined, CheckOutlined } from '@ant-design/icons';
+import { bindDDCode } from '@/services/boom';
 
-function DDLogin() {
+function DDLogin(props) {
+  const {
+    match: {
+      params: { dingUserId },
+    },
+  } = props;
   const [info, setInfo] = useState('');
   useEffect(() => {
     if (dd.env.platform != 'notInDingTalk') {
       dd.ready(function() {
         dd.runtime.permission.requestAuthCode({
           corpId: 'ding0cdce2d5dbf986d9', // 企业id
-          onSuccess: function(info) {
+          onSuccess: async function(info) {
             setTimeout(() => {
-              setInfo(JSON.stringify(info));
-            }, 1000);
+              setInfo(info.code);
+            }, 500);
+            let res = await bindDDCode(dingUserId, info.code);
+            console.log(res);
+
             // 通过该免登授权码可以获取用户身份
           },
           onFail: error => {
@@ -40,6 +49,7 @@ function DDLogin() {
         <>
           <CheckOutlined style={{ fontSize: 40, color: '#52c41a' }} />
           <div>授权成功</div>
+          <div>{info}</div>
         </>
       ) : (
         <>

+ 41 - 8
src/pages/PurchaseAdmin/PurchaseList/Detail/CommitAuditModal.js

@@ -1,6 +1,6 @@
 import React, { useEffect, useState, useRef, useMemo } from 'react';
 import '@ant-design/compatible/assets/index.css';
-import { Modal, Input, Select, message, Cascader, Form, Tabs, Row, Col, Empty } from 'antd';
+import { Modal, Input, Select, message, Cascader, Form, Tabs, Row, Col, Empty, Button } from 'antd';
 import { connect } from 'dva';
 import { isArray, result } from 'lodash';
 import { useForm } from 'rc-field-form';
@@ -11,6 +11,7 @@ import { queryDingSchema } from '@/services/boom';
 import { Form as Form3x } from '@ant-design/compatible';
 import { getCurrentUser } from '@/utils/authority';
 import DDCode from '@/components/DDComponents/DDCode';
+import { uploadFile } from '@/services/boom';
 
 const { TextArea } = Input;
 const { Option } = Select;
@@ -18,7 +19,17 @@ const { TabPane } = Tabs;
 
 // 提交
 function CommitAuditModal(props) {
-  const { visible, onClose, onOk, loading, version, versionList, flowDetail, currentUser } = props;
+  const {
+    visible,
+    onClose,
+    onOk,
+    loading,
+    version,
+    versionList,
+    flowDetail,
+    currentUser,
+    luckysheet,
+  } = props;
   const [auditId, setAuditId] = useState();
   const [data, setData] = useState([]);
   const [length, setLength] = useState(1);
@@ -185,7 +196,7 @@ function CommitAuditModal(props) {
     setAuditList(addAuditList);
   };
 
-  const getFromData = idList => {
+  const getFromData = async idList => {
     const data = formComponentValues;
     const result = [];
     //获取流转节点的层级关系
@@ -210,14 +221,16 @@ function CommitAuditModal(props) {
     //     }
     //   });
     // }
+    let attachment = await upload();
     firstList.forEach(id => {
       let approvalNode = flowDetail.nodes.find?.(item => item.Id == id);
+      let values = data[approvalNode.Id] || [];
       const formItem = {
         processCode: approvalNode.process_code,
         originatorUserId: currentUser.DingUserId || getCurrentUser()?.DingUserId, //'16569001414345099',
         deptId: '14237557', //currentUser.DingDepId || getCurrentUser()?.DingDepId,
         template_node_id: `${approvalNode.Id}`,
-        formComponentValues: data[approvalNode.Id] || [],
+        formComponentValues: [...values, { name: '附件', value: JSON.stringify(attachment) }],
       };
       result.push(JSON.stringify(formItem));
     });
@@ -266,7 +279,7 @@ function CommitAuditModal(props) {
     }
 
     const flowPath = result.map(item => getFlowPath(item));
-    const formList = getFromData(result);
+    const formList = await getFromData(result);
     let params = {
       desc: fieldsValue.desc,
       // 审核流程id
@@ -323,6 +336,28 @@ function CommitAuditModal(props) {
       </Form.Item>
     );
   };
+  const upload = async () => {
+    let blob = await luckysheet.current.getExcelBolb();
+    let formData = new FormData();
+    formData.append('userid', currentUser.DingUserId);
+    formData.append('file', new File([blob], `${version.version_name}_${version.version_no}.xlsx`));
+
+    let res = await uploadFile(formData);
+    let data;
+    try {
+      debugger;
+      data = JSON.parse(res.dentry);
+      return [{
+        spaceId: String(data.spaceId),
+        fileName: data.name,
+        fileSize: String(data.spaceId),
+        fileType: data.extension,
+        fileId: data.id,
+      }];
+    } catch (error) {
+      message.error('附件上传失败');
+    }
+  };
 
   return (
     <Modal
@@ -356,13 +391,11 @@ function CommitAuditModal(props) {
         </Form.Item>
         <Form.Item labelCol={{ span: 7 }} wrapperCol={{ span: 15 }} label="授权码" name="ddCode">
           <DDCode />
+          {/* <Button onClick={upload}>上传文件</Button> */}
         </Form.Item>
       </Form>
       <Tabs defaultActiveKey="1">
         {auditList.map((item, idx) => (
-          // <TabPane tab={item.label} key={`${item.Id}_${item.label}`}>
-          //   <AuditDetailed />
-          // </TabPane>
           <TabPane tab={item.name} key={`${idx}_${item.title}`}>
             <Row>
               <Col span={17}>{item.FormComponents}</Col>

+ 1 - 0
src/pages/PurchaseAdmin/PurchaseList/Detail/Index.js

@@ -1104,6 +1104,7 @@ function Detail(props) {
         version={version}
         onClose={() => setCommitAuditVisible(false)}
         onOk={onSubmitNextNode}
+        luckysheet={sheetRef}
       />
     </Spin>
   );

+ 1 - 1
src/pages/PurchaseAdmin/PurchaseList/Detail/LuckySheet.js

@@ -487,7 +487,7 @@ class LuckySheet extends React.Component {
   }
 
   getExcelBolb() {
-    let currentData = this.getExcelData(checkValue);
+    let currentData = this.getExcelData();
     return getExcelBolob(currentData);
   }
 

+ 18 - 0
src/services/boom.js

@@ -330,3 +330,21 @@ export async function queryDDProcessesForecast(data) {
   }
   return res.data.result;
 }
+
+export async function uploadFile(data) {
+  let res = await request(`/api/v1/purchase/bom/ding/upload-file`, {
+    method: 'POST',
+    body: data,
+    headers: {
+      ContentType: 'application/x-www-form-urlencoded',
+    },
+  });
+  return res.data;
+}
+
+export async function bindDDCode(userId, code) {
+  let res = await request(`/api/v1/purchase/bom/ding/set-ding-user-code?ucode=${userId}:${code}`, {
+    method: 'GET',
+  });
+  return res.data;
+}