UNPKG

@antdp/antdp-ui

Version:

基于antd封装的组件

160 lines 6.22 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose"; var _excluded = ["formDatas", "isView", "header", "type", "colspan", "style", "layout", "bordered", "otherDescriptions"]; import React, { forwardRef } from 'react'; import { Descriptions, Tooltip } from 'antd'; import QucikFrom from '../QuickForm'; import UploadGrid from '../UploadGrid'; import moment from 'moment'; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; // 处理TreeSelect数据 var _getTreeDataParent = function getTreeDataParent(list, current, objList) { if (list === void 0) { list = []; } if (current === void 0) { current = []; } if (objList === void 0) { objList = []; } (list || []).forEach(item => { if ((current || []).indexOf(item.value) >= 0) { objList.push(item.label || item.title || ''); } if (item.children) { _getTreeDataParent(item.children, current, objList); } }); return objList; }; var FormDetail = (props, ref) => { var { formDatas = [], isView = false, header = '', type, colspan, style, layout = 'horizontal', bordered = false, otherDescriptions = {} } = props, others = _objectWithoutPropertiesLoose(props, _excluded); return /*#__PURE__*/_jsxs("div", { style: style, children: [' ', isView ? /*#__PURE__*/_jsx(Descriptions, _extends({}, otherDescriptions, { title: header, bordered: bordered, size: "small", style: { marginBottom: 24 }, column: colspan, layout: layout, children: formDatas.map((item, idx) => { var newOptions = (item == null ? void 0 : item.options) || []; var content; if (item.type === 'UploadGrid' || type === 'uploadGrid') { content = /*#__PURE__*/_jsx(UploadGrid, _extends({ useDragHandle: true }, item.attributes)); } else if (item.type === 'radio' || item.type === 'Radio') { var value = newOptions.filter(itm => itm.value === item.initialValue); content = value && value.length > 0 && value[0].label || ''; } else if (typeof item.initialValue === 'object' && moment.isMoment(item.initialValue)) { content = item.initialValue.format('YYYY-MM-DD'); } else if (item.type === 'rangePicker' || item.type === 'RangePicker') { if (item.initialValue) { item.initialValue.forEach(date => { if (date) { content += date.format('YYYY-MM-DD HH:mm:ss'); } }); } } else if (item.type === 'checkbox' || item.type === 'Checkbox') { var values = item.initialValue || []; var arr = []; newOptions.forEach(itm => { if (values.includes(itm.value)) { arr.push(itm.label); } }); content = arr.join(','); } else if (item.type === 'cascader' || item.type === 'Cascader') { var _values = item.initialValue; content = _values ? _values.join('') : ''; } else if (item.type === 'select' || item.type === 'Select') { if (item.attributes && item.attributes.labelInValue) { content = item.initialValue && item.initialValue.label; } else { if (newOptions.length > 0) { var selObj = newOptions.find(itm => itm.value === item.initialValue); content = selObj ? selObj.label : item.initialValue; } else { content = item.initialValue; } if (item.attributes && item.attributes.mode === 'multiple') { content = item.initialValue && item.initialValue.join(' ') || ''; } } } else if (item.type === 'treeSelect' || type === 'TreeSelect') { var { attributes, initialValue } = item; var { treeData, multiple, labelInValue } = attributes || {}; // 对象 多选 if (labelInValue && multiple) { content = (initialValue || []).map(item => item.label).toString(); // 多选 } else if (multiple) { var _selObj = _getTreeDataParent(treeData, initialValue ? [initialValue] : []); content = (_selObj || []).toString(); // 单选对象 } else if (labelInValue) { content = (initialValue || {}).label || ''; // 单选 } else { var _item$attributes; var _treeData = (item == null || (_item$attributes = item.attributes) == null ? void 0 : _item$attributes.treeData) || []; var _initialValue = item.initialValue; if (_treeData.length > 0) { var _selObj2 = _getTreeDataParent(_treeData, _initialValue ? [_initialValue] : []); content = (_selObj2 || []).toString(); } } } else { content = typeof item.initialValue === 'object' ? item.initialValue && item.initialValue.label : item.initialValue; } return !item.hideInForm && /*#__PURE__*/_jsx(Descriptions.Item, { label: item.label, span: item.span, children: item.attributes && item.attributes.isTooltip ? /*#__PURE__*/_jsx(Tooltip, { title: content, children: /*#__PURE__*/_jsxs("div", { style: item.attributes && item.attributes.style, children: [' ', content, item.attributes && item.attributes.addonAfter] }) }) : /*#__PURE__*/_jsxs("div", { style: item.attributes && item.attributes.style, children: [' ', content, item.attributes && item.attributes.addonAfter] }) }, item.name + idx); }) })) : /*#__PURE__*/_jsx(QucikFrom, _extends({}, others, { size: "default", defaultFormLayout: "vertical", header: header, formDatas: formDatas, colspan: colspan, type: type, ref: ref }))] }); }; export default /*#__PURE__*/forwardRef(FormDetail);