index.js 3.7 KB
Newer Older
1
import React, { useEffect, useState, useRef } from 'react';
王绍森's avatar
王绍森 committed
2 3 4
import ZdyTable from '@/webPublic/one_stop_public/Table';
import styles from './index.less';
import { fetchTemplateByCode, fetchTableItem } from '@/webPublic/Services';
5
import { isJSON } from '@/webPublic/zyd_public/utils/utils';
6
import SelectPerson from '@/webPublic/FormInsertDiy/ExportComponent/SelectPerson/Index';
7
import Detail from '@/webPublic/FormInsertDiy/AffairPage/Detail';
王绍森's avatar
王绍森 committed
8

9 10 11 12 13 14 15 16 17 18 19

const showDiv = () => {
  document.getElementById('listZdyTable').style.position = 'static';
  document.getElementById('listZdyTable').style.zIndex = 'auto';
};

const hideDiv = () => {
  document.getElementById('listZdyTable').style.position = 'absolute';
  document.getElementById('listZdyTable').style.zIndex = '-10';
};

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
export default function RenderForm({ get = 'web', isCg = 'yes', style, ...rest }) {
	let content = rest?.postData?.unifiedServicePatternModel?.content;
	if (isJSON(content)) {
		content = JSON.parse(content);
	}
	const tableRoot = useRef();
	const [showPageType, setShowPageType] = useState(0);
	const [pageProps, setPageProps] = useState({});
	useEffect(() => {
		const timerId = setTimeout(() => {
			// 修改样式
			const div = tableRoot.current && tableRoot.current.root;
			if (div) {
				div.style.overflow = 'unset';
			}
			let new_element = document.createElement('style');
			new_element.innerHTML = `main>div>#web_table .login-form>div>div>div{
37 38
      overflow: inherit !important;
      }`;
39 40
			document.body.appendChild(new_element);
		}, 0);
41

42 43 44 45
		window.keepAliveCheckRecord = {
			showList: (props) => {
        setShowPageType(0);
        setPageProps({});
46
        showDiv();
47 48 49 50 51 52 53 54
      },
			showDetail: (p) => {
        setPageProps({
          ...p,
          history: {...p},
        });
        setShowPageType(1);
				console.log(p);
55
        hideDiv();
56 57 58 59 60 61 62 63 64 65 66
			},
		};

		return () => {
			clearTimeout(timerId);
		};
	}, []);
	if (!content) {
		return null;
	}

67
	// console.log(showPageType);
68 69 70 71 72 73 74 75 76 77 78 79 80 81

	return (
		<>
			<div className={styles.zyd_onestop_style_class} style={style} id={'listZdyTable'}>
				<ZdyTable
					ref={tableRoot}
					get={get}
					{...rest}
					isQuery={true}
					init={undefined}
					{...content}
				/>
				<SelectPerson />
			</div>
82 83
			{showPageType === 1 && <Detail fromCheckRecord={true}
                                     {...pageProps} />}
84 85
		</>
	);
王绍森's avatar
王绍森 committed
86 87 88 89 90 91 92
}

/**
 * 根据表单code渲染表单
 * @param {Object} content 表单内容,传入对象
 * @param {String} templateCode 表单模板
 */
93 94 95 96 97 98 99 100 101 102 103 104
export function RenderFormByContent({ content, templateCode, form, get, isCg }) {
	const [formTemplate, setFormTemplate] = useState();
	useEffect(
		() => {
			fetchTemplateByCode(templateCode).then((res) => {
				if (res) {
					setFormTemplate(res);
				}
			});
		},
		[templateCode],
	);
王绍森's avatar
王绍森 committed
105

106 107 108 109 110 111 112 113 114 115 116
	return formTemplate ? (
		<RenderForm
			get={get}
			isCg={isCg}
			postData={{
				content: JSON.stringify(content),
				unifiedServicePatternModel: formTemplate,
			}}
			form={form}
		/>
	) : null;
王绍森's avatar
王绍森 committed
117 118 119 120 121 122 123 124 125 126
}

/**
 *渲染元数据库中的某条数据
 * @param {Object} objId 元数据库id
 * @param {String} dataTypeKey 元数据库表格键
 * @param {String} dataTypeValue 键对应的值
 * @param {Function} onLoad 数据加载的回调函数
 */
export function RenderFormByObjId({
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	objId,
	dataTypeKey,
	dataTypeValue,
	onLoad,
	templateCode,
	form,
	get,
	isCg,
}) {
	const [content, setContent] = useState({});
	useEffect(
		() => {
			fetchTableItem({
				dataObjId: objId,
				key: dataTypeKey,
				value: dataTypeValue,
			}).then((res) => {
				setContent(res || {});
				if (onLoad) {
					onLoad(res);
				}
			});
		},
		[objId, dataTypeKey, dataTypeValue],
	);
王绍森's avatar
王绍森 committed
152

153 154 155 156 157 158 159 160 161
	return (
		<RenderFormByContent
			get={get}
			isCg={isCg}
			content={content}
			templateCode={templateCode}
			form={form}
		/>
	);
王绍森's avatar
王绍森 committed
162
}