import React from "react"; import { Badge, Input, Tooltip } from "antd"; import loadable from "@loadable/component"; import { ControlHolderType, FieldConfig, ViewOrEdit } from "../tmpl/interface"; import ControlTypeSupportor from "../tmpl/control-type-supportor"; import EnumTags from "./enum-tag"; import EnumBadge from "./enum-badge"; import Steps from "./steps"; import Units from "./../units"; import Rfield from "./rfield"; import dayjs from "dayjs"; import Progress from "./progress"; import EllipsisText from "./text/ellipsis-text"; import { ProgramConfig, useLocale } from "../index"; import FieldHistory from "./field-history"; import MultiFileView from "./file-view/multi-file-view"; import DirectFileView from "./direct-file-view"; import QRCode from "./qr-code"; import RichEditor from "./html-editor"; // 更换富文本插件 // 暂时先这样, 异步组件国际化有问题 const Loading = <>loading; const Signature = loadable(() => import("./signature"), { fallback: Loading }); const ChemStruc = loadable(() => import("./chemstruc/graph"), { fallback: Loading, }); const SqlCodeEditor = loadable(() => import("./code-editor/sql-code-editor"), { fallback: Loading, }); const ColorPicker = loadable(() => import("./color-picker"), { fallback: Loading, }); const FileView = loadable(() => import("../controls/file-view"), { fallback: Loading, }); interface FieldViewControlProps { serverKey?: string; value?: any; fieldConfig: FieldConfig; holderType: ControlHolderType; style?: any; dataCode?: string; } function renderControl( fieldConfig: FieldConfig, fieldValue: any, pHolderType: ControlHolderType, width: any, other: any ) { const { translate } = useLocale(); let itemType = ControlTypeSupportor.getControlType(fieldConfig, fieldValue); let holderType: ControlHolderType = pHolderType; if (!holderType) { holderType = "descriptions"; } const colSpan = fieldConfig.colSpan; let scalableWidth = width; if (colSpan == 2) { scalableWidth = width * colSpan * 1.52; } let viewControl = undefined; let placeholder = !fieldConfig.disabled ? translate("${请输入}${" + fieldConfig.title + "}") : translate("${无需输入}"); let disabled: boolean = fieldConfig.disabled; let value = fieldValue || fieldValue == 0 ? fieldValue : fieldConfig.defaultValue && !Units.isConfigDefaultValue(fieldConfig.defaultValue) ? fieldConfig.defaultValue : ""; let viewOrEdit: ViewOrEdit = "view"; let controlProps = { fieldConfig, itemType, value, viewOrEdit, ...other, }; //自定义组件为先 if (ProgramConfig.getCustomEditControl(itemType)) { return React.createElement( ProgramConfig.getCustomViewControl(itemType), controlProps ); } const unSupportControl = ( {translate("${暂未完成}-${" + itemType + "}")} ); if (value != 0 && (!value || value == "null" || value.toString().includes("@R@null"))) { viewControl = <>; } else { switch (itemType) { case "int": case "decimal": case "float": case "double": case "intrange": case "decimalrange": case "range": viewControl = {value}; break; case "date-YY": case "date-M1": case "date": case "datetime-HH": case "datetime-mm": case "datetime": case "time-HH": case "time-mm": case "time": viewControl = ( {value ? dayjs(value).format(Units.getDayjsFormat(itemType)) == "Invalid Date" ? value : dayjs(value).format(Units.getDayjsFormat(itemType)) : undefined} ); break; case "daterange-YY": case "daterange-M1": case "daterange": case "datetimerange-HH": case "datetimerange-mm": case "datetimerange": case "timerange-HH": case "timerange-mm": case "timerange": viewControl = {value}; break; case "text": case "textarea": case "text-view": case "preselect": case "QRCode": if (holderType == "table") { viewControl = ( ); } else { viewControl = {value}; } break; case "select": case "radio": case "yes-no-switch": viewControl = ; break; case "yes-no-radio": viewControl = ( {value ? ( ) : null} ); break; case "multiselect": case "checkbox": viewControl = ; break; case "html": if (holderType == "table") { viewControl = ( ); } else { // viewControl =
; viewControl = ; } break; case "steps": viewControl = ; break; case "password": if (value) { viewControl = ( ******** ); } else { viewControl = null; } break; case "caselect": viewControl = {value}; break; case "relation": viewControl = unSupportControl; break; case "file": case "picture": case "video": viewControl = ; break; case "direct-file": viewControl = ; break; case "relfile": case "relimage": //只是配置了,内部未做开发 viewControl = ; break; case "non-download-file": viewControl = ( ); break; case "chemstruc": viewControl = ; //viewControl = unSupportControl break; case "sql-code-editor": viewControl = ( ); break; case "relselect": case "refselect": case "entity-select": case "table-entity-select": case "tree-entity-select": case "relselect-extdis": viewControl = ; break; case "progress": viewControl = ; break; case "signature": viewControl = ; break; case "color": viewControl = ; break; case "url": viewControl = ( {translate("${网址}")} ); break; case "hidden": // viewControl = ( ); break; case "field-history": // viewControl = ; break; case "QRCode": // viewControl = ; break; default: viewControl = unSupportControl; break; } } return viewControl; } const ViewControl: React.FC = (props) => { const { fieldConfig, value, holderType, ...other } = props; return renderControl(fieldConfig, value, holderType, null, other); }; export default ViewControl;