prepareShow.js 3.3 KB
Newer Older
钟是志's avatar
钟是志 committed
1
import React from 'react';
钟是志's avatar
钟是志 committed
2
import { Modal, message } from 'antd';
钟是志's avatar
钟是志 committed
3 4 5
import { isJSON } from '@/webPublic/one_stop_public/copy';
import { uaaRequest } from '@/webPublic/one_stop_public/utils/request';
import { deepCopy } from '@/webPublic/one_stop_public/utils/myutils';
钟是志's avatar
钟是志 committed
6
import moment from 'moment';
7
import { giveSmartFormGlobalProps } from '@/webPublic/one_stop_public/Table/giveSmartFormGlobalProps';
钟是志's avatar
钟是志 committed
8
import { getToken, getUserInfo } from '@/webPublic/one_stop_public/utils/token';
钟是志's avatar
钟是志 committed
9
import { getUrlInfo } from '@/webPublic/one_stop_public/DetailForAudit/utils';
10

11
const test = getUrlInfo().test;
12

13
export default function prepareShow(postData = {}, content = '', otherParams = { fromStart: false }) {
钟是志's avatar
钟是志 committed
14
  // 模板挂载前执行的公式
15

16 17
  giveSmartFormGlobalProps({
    data: postData || content,
18
    ...otherParams,
19
  });
20
  if (process.env.NODE_ENV === 'development') {
21 22
    // console.log(window.smartFormGlobalProps.data);
  }
23
  let agg = deepCopy(postData);
24 25 26 27
  window.beforeApplySubmit = undefined; // 流程发起时执行的异步回调函数 这里清空 防止泄露
  window.beforeAuditSubmit = undefined; // 流程审批时执行的异步回调函数 这里清空 防止泄露
  window.callbackApplyDataInfoZhiYong = undefined; // 流程发起时执行的同步函数 这里清空 防止泄露
  window.callbackSubmitInfoZhiYong = undefined; // 流程审批时执行的回调函数 这里清空 防止泄露
钟是志's avatar
钟是志 committed
28
  window.zdyTableTemplateWillMountProps = true;
钟是志's avatar
钟是志 committed
29 30 31
  window.message = message;
  window.Modal = Modal;
  window.moment = moment;
32
  return new Promise((resolve, reject) => {
钟是志's avatar
钟是志 committed
33 34
    console.log(agg?.unifiedServicePatternModel?.id); // 表单id;
    if (agg?.unifiedServicePatternModel?.id && localStorage.getItem('errDetail') === '1') {
钟是志's avatar
钟是志 committed
35 36
      const SystemConfig = window.specialImportantSystemConfig || {};
      console.log('%c' + `${SystemConfig?.gateWayPort}/onestop/#/admin/processServices/modelConfig/templateDetail/designById?id=${agg.unifiedServicePatternModel.id}&token=${getToken()}`, 'color: green;background: white;font-size: 14px');
37
      console.log('%c' + `${SystemConfig?.gateWayPort}/wisdomYsgz/#/designFormByUrl?id=${agg.unifiedServicePatternModel.id}&token=${getToken()}`, 'color: green;background: white;font-size: 14px');
38
    }
39
    let data = agg?.unifiedServicePatternModel?.content || content;
40 41
    let g = !!data && isJSON(data) && JSON.parse(data)?.templateWillMount;
    if (g && typeof g === 'string' && g.length > 10) {
钟是志's avatar
钟是志 committed
42 43 44 45
      let p = {
        // 函数参数
        message,
        Modal,
46
        uaaRequest,
47
        userNowInfo:
钟是志's avatar
钟是志 committed
48
          (isJSON(localStorage.getItem('user')) && JSON.parse(localStorage.getItem('user'))) || {},
49 50
        templateData: agg,
      };
51

52 53 54
      let newFunc = new Function('props', g);
      console.log('开始执行templateWillMount公式');
      try {
55
        newFunc(p) // 返回一个promise
56 57
          .then(res => {
            if (res) {
钟是志's avatar
钟是志 committed
58
              // console.log('执行templateWillMount公式完成', res);
59 60 61 62 63 64 65 66 67 68 69 70 71
              window.zdyTableTemplateWillMountProps = res;
              resolve(true);
            }
          })
          .catch(error => {
            window.zdyTableTemplateWillMountProps = undefined;
            resolve(true);
            console.log('模板挂载时公式执行失败', error);
          });
      } catch (e) {
        resolve(true);
        console.log(e);
      }
钟是志's avatar
钟是志 committed
72
    } else {
73
      resolve(true);
74 75 76
    }
  });
}
钟是志's avatar
钟是志 committed
77 78