prepareShow.js 3.2 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';
8
import { getToken } from '@/webPublic/one_stop_public/utils/token';
钟是志's avatar
钟是志 committed
9
import { getUrlInfo } from '@/webPublic/one_stop_public/DetailForAudit/utils';
10
const test = getUrlInfo().test;
11

钟是志's avatar
钟是志 committed
12 13
export default function prepareShow(postData = {}, content = '') {
  // 模板挂载前执行的公式
14 15 16
  giveSmartFormGlobalProps({
    data: postData || content,
  });
17
  let agg = deepCopy(postData);
18 19 20 21
  window.beforeApplySubmit = undefined; // 流程发起时执行的异步回调函数 这里清空 防止泄露
  window.beforeAuditSubmit = undefined; // 流程审批时执行的异步回调函数 这里清空 防止泄露
  window.callbackApplyDataInfoZhiYong = undefined; // 流程发起时执行的同步函数 这里清空 防止泄露
  window.callbackSubmitInfoZhiYong = undefined; // 流程审批时执行的回调函数 这里清空 防止泄露
钟是志's avatar
钟是志 committed
22
  window.zdyTableTemplateWillMountProps = true;
钟是志's avatar
钟是志 committed
23 24 25
  window.message = message;
  window.Modal = Modal;
  window.moment = moment;
26
  return new Promise((resolve, reject) => {
钟是志's avatar
钟是志 committed
27
    console.log(agg?.unifiedServicePatternModel?.id); // 表单id;
28
    if (agg?.unifiedServicePatternModel?.id && (window.location.href.indexOf('localhost') > -1 || test)) {
钟是志's avatar
钟是志 committed
29 30 31
      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');
      console.log('%c' + `${SystemConfig?.gateWayPort}/wisdomSchool/#/designFormByUrl?id=${agg.unifiedServicePatternModel.id}&token=${getToken()}`, 'color: green;background: white;font-size: 14px');
32
    }
33
    let data = agg?.unifiedServicePatternModel?.content || content;
34 35
    let g = !!data && isJSON(data) && JSON.parse(data)?.templateWillMount;
    if (g && typeof g === 'string' && g.length > 10) {
钟是志's avatar
钟是志 committed
36 37 38 39
      let p = {
        // 函数参数
        message,
        Modal,
40
        uaaRequest,
41
        userNowInfo:
钟是志's avatar
钟是志 committed
42
          (isJSON(localStorage.getItem('user')) && JSON.parse(localStorage.getItem('user'))) || {},
43 44 45 46 47
        templateData: agg,
      };
      let newFunc = new Function('props', g);
      console.log('开始执行templateWillMount公式');
      try {
48
        newFunc(p) // 返回一个promise
49 50
          .then(res => {
            if (res) {
钟是志's avatar
钟是志 committed
51
              // console.log('执行templateWillMount公式完成', res);
52 53 54 55 56 57 58 59 60 61 62 63 64
              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
65
    } else {
66
      resolve(true);
67 68 69
    }
  });
}
钟是志's avatar
钟是志 committed
70 71