prepareShow.js 1.8 KB
Newer Older
1 2 3
import React, {useEffect, useState, useRef, memo} from 'react';
import {isJSON} from '@/webPublic/one_stop_public/copy';
import {uaaRequest} from '@/webPublic/one_stop_public/utils/request';
钟是志's avatar
钟是志 committed
4
import { Spin } from 'antd';
5
import {deepCopy} from "@/webPublic/one_stop_public/utils/myutils";
钟是志's avatar
钟是志 committed
6 7 8
import { getMessage, getModal } from '@/webPublic/one_stop_public/utils/utils';
const Modal = getModal();
const message = getMessage();
9

10
export default function prepareShow(postData = {} , content = '') { // 模板挂载前执行的公式
11 12
  let agg = deepCopy(postData);
  return new Promise((resolve, reject) => {
13
    let data = agg?.unifiedServicePatternModel?.content || content;
14 15
    let g = !!data && isJSON(data) && JSON.parse(data)?.templateWillMount;
    if (g && typeof g === 'string' && g.length > 10) {
16
      let p = { // 函数参数
17 18
        message,
        Modal,
19
        uaaRequest,
20 21 22 23 24 25 26 27 28
        userNowInfo:
          (isJSON(localStorage.getItem('user')) && JSON.parse(localStorage.getItem('user'))) ||
          {},
        templateData: agg,
      };
      let newFunc = new Function('props', g);
      console.log('开始执行templateWillMount公式');
      window.zdyTableTemplateWillMountInit = true;
      try {
29
        newFunc(p) // 返回一个promise
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
          .then(res => {
            if (res) {
              console.log('执行templateWillMount公式完成', res);
              window.zdyTableTemplateWillMountProps = res;
              resolve(true);
            }
          })
          .catch(error => {
            window.zdyTableTemplateWillMountProps = undefined;
            resolve(true);
            console.log('模板挂载时公式执行失败', error);
          });
      } catch (e) {
        resolve(true);
        console.log(e);
      }
46 47
    }else{
      resolve(true);
48 49 50
    }
  });
}