UNPKG

@wufengteam/inputs

Version:

平台提供的右侧属性编辑器,需要在主工程中注册

452 lines (451 loc) 22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _antd = require("antd"); var _util = require("./util"); var _utils = require("../utils"); require("./index.css"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } // import { SERVICE_KEY } from '../ApiObject/constant'; var ObjectFormItem = function ObjectFormItem(_ref) { var key1 = _ref.key1, value = _ref.value, options = _ref.options, _onChange = _ref.onChange, root = _ref.root, n = _ref.n, _ref$usedComponents = _ref.usedComponents, usedComponents = _ref$usedComponents === void 0 ? [] : _ref$usedComponents; return /*#__PURE__*/_react.default.createElement(_antd.Space, { key: key1, align: "baseline", size: "middle" }, !!n && /*#__PURE__*/_react.default.createElement("div", { style: { width: "".concat(10 * n, "px") } }), /*#__PURE__*/_react.default.createElement(_antd.Form.Item, null, /*#__PURE__*/_react.default.createElement(_antd.Input, { style: { width: "".concat(n ? 210 - 10 * n - 16 : 210, "px") }, disabled: true, value: key1 })), /*#__PURE__*/_react.default.createElement(_antd.Form.Item, null, /*#__PURE__*/_react.default.createElement(_antd.Select, { style: { width: '210px' }, value: value, onChange: function onChange(newValue) { _onChange === null || _onChange === void 0 ? void 0 : _onChange({ key1: "".concat(root, ".").concat(key1), value: newValue, root: root, n: n }); }, allowClear: true }, options.filter(function (option) { return option.attrCode === value || !usedComponents.includes(option.attrCode); }).map(function (item) { return /*#__PURE__*/_react.default.createElement(_antd.Select.Option, { value: item.attrCode, key: item.attrCode }, item.attrName); })))); }; var ObjectForm = function ObjectForm(_ref2) { var options = _ref2.options, data = _ref2.data, onChange = _ref2.onChange, root = _ref2.root, n = _ref2.n, values = _ref2.values, _ref2$isArray = _ref2.isArray, isArray = _ref2$isArray === void 0 ? false : _ref2$isArray, _ref2$usedComponents = _ref2.usedComponents, usedComponents = _ref2$usedComponents === void 0 ? [] : _ref2$usedComponents; return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_antd.Space, { style: { width: '435px', color: 'black', backgroundColor: '#f5f5f5', borderColor: '#d9d9d9', boxShadow: 'none', cursor: 'not-allowed', opacity: 1, marginBottom: '12px', padding: '4px 11px' } }, !!n && /*#__PURE__*/_react.default.createElement("div", { style: { width: "".concat(10 * n, "px") } }), /*#__PURE__*/_react.default.createElement("div", null, "- ", root, isArray ? '(数组)' : '', ":")), data && Object.keys(data).map(function (key) { if (!data[key] || _typeof(data[key]) !== 'object') { return /*#__PURE__*/_react.default.createElement(ObjectFormItem, { key1: key, options: options, usedComponents: usedComponents, value: (values === null || values === void 0 ? void 0 : values["".concat(root, ".").concat(key)]) || '', onChange: onChange, root: root, n: n }); } if (Array.isArray(data[key])) { // 数组绑定子表,暂不支持 return null; // return ( // <ObjectForm // options={options} // data={data?.[key]?.[0]} // onChange={onChange} // isArray // root={`${root}.${key}`} // n={n + 1} // values={values} // /> // ); } return /*#__PURE__*/_react.default.createElement(ObjectForm, { options: options, usedComponents: usedComponents, data: data[key], onChange: onChange, root: "".concat(root, ".").concat(key), n: n + 1, values: values }); })); }; var RespondModal = function RespondModal(_ref3) { var apiObject = _ref3.apiObject, apiParams = _ref3.apiParams, value = _ref3.value, onChange = _ref3.onChange, DSLCore = _ref3.DSLCore, respond = _ref3.respond, busiServiceId = _ref3.busiServiceId; var _a, _b, _c, _d; var _useState = (0, _react.useState)(false), _useState2 = _slicedToArray(_useState, 2), visible = _useState2[0], setVisible = _useState2[1]; var _useState3 = (0, _react.useState)(undefined), _useState4 = _slicedToArray(_useState3, 2), root = _useState4[0], setRoot = _useState4[1]; var _useState5 = (0, _react.useState)(), _useState6 = _slicedToArray(_useState5, 2), currentValue = _useState6[0], setCurrentValue = _useState6[1]; var _useState7 = (0, _react.useState)([]), _useState8 = _slicedToArray(_useState7, 2), treeData = _useState8[0], setTreeData = _useState8[1]; var onRootChange = function onRootChange(newValue) { var _a; setRoot(newValue); onChange === null || onChange === void 0 ? void 0 : onChange(Object.assign(Object.assign({}, value), { root: newValue, respond: {}, rootIsArray: (_a = newValue === null || newValue === void 0 ? void 0 : newValue.label) === null || _a === void 0 ? void 0 : _a.includes('数组') })); setUsedComponents([]); }; // 本地表单的字段列表 var _useState9 = (0, _react.useState)([]), _useState10 = _slicedToArray(_useState9, 2), localFieldList = _useState10[0], setLocalFieldList = _useState10[1]; // 已用的组件 var _useState11 = (0, _react.useState)([]), _useState12 = _slicedToArray(_useState11, 2), usedComponents = _useState12[0], setUsedComponents = _useState12[1]; var _ref4 = ((_a = DSLCore === null || DSLCore === void 0 ? void 0 : DSLCore.current) === null || _a === void 0 ? void 0 : _a.props) || {}, apiRespond = _ref4.apiRespond; (0, _react.useEffect)(function () { if (busiServiceId !== (apiRespond === null || apiRespond === void 0 ? void 0 : apiRespond.busiServiceId)) { onChange === null || onChange === void 0 ? void 0 : onChange({ busiServiceId: busiServiceId, respond: null }); setUsedComponents([]); setRoot(undefined); } else if (apiRespond === null || apiRespond === void 0 ? void 0 : apiRespond.root) { setRoot(apiRespond === null || apiRespond === void 0 ? void 0 : apiRespond.root); } // 初始值 value 有异常 }, [apiRespond, busiServiceId]); (0, _react.useEffect)(function () { setCurrentValue(value); }, [value]); (0, _react.useEffect)(function () { // eslint-disable-next-line @typescript-eslint/no-shadow var getTreeNode = function getTreeNode(data, parent) { var tree = []; if (!data) return tree; // eslint-disable-next-line array-callback-return Object.keys(data).map(function (i) { if (Array.isArray(data[i])) { tree.push({ value: "".concat(parent ? "".concat(parent, ".") : '').concat(i), title: "".concat(i, " (\u6570\u7EC4)") }); } else if (data[i] && _typeof(data[i]) === 'object') { tree.push({ value: "".concat(parent ? "".concat(parent, ".") : '').concat(i), title: "".concat(i, " (\u5BF9\u8C61)"), children: getTreeNode(data[i], "".concat(parent ? "".concat(parent, ".") : '').concat(i)) }); } // else { // tree.push({ title: `${i} (字符串)`, value: `${parent ? `${parent}.` : ''}${i}` }); // } }); return tree; }; // 仅适配sql 中 根节点返回为数组的情况。 setTreeData([{ value: '', title: "".concat(apiObject === null || apiObject === void 0 ? void 0 : apiObject.scriptResultType) === '3' ? '根节点(数组)' : '根节点', children: getTreeNode(respond) }]); }, [respond]); (0, _react.useEffect)(function () { if (visible) { setLocalFieldList(function () { // 1、对于输入参数不支持:附件/图片/视频/表格/签名/关联表单/数据联动/附件下载; // 2、对于输出参数不支持:附件/图片/视频/签名/关联表单/数据联动/附件下载; var fillterList = ['Upload', 'Image', 'Video', 'EditableTable', 'Autograph', 'BindTable', 'DataLinkage', 'Download', 'Attachments', 'Api', 'ImgUpload', 'StdUpload', 'VideoUpload', 'SubForm', 'ImageShow']; var components = DSLCore.querySelectAll('[compType=2]') || []; var filterList = components.filter(function (item) { var _a, _b; return "".concat((_b = (_a = item === null || item === void 0 ? void 0 : item.attribute) === null || _a === void 0 ? void 0 : _a.props) === null || _b === void 0 ? void 0 : _b.isInSubForm) !== 'true'; }) // 过滤子表单下的组件 .filter(function (item) { var _a; return !fillterList.includes((_a = item === null || item === void 0 ? void 0 : item.attribute) === null || _a === void 0 ? void 0 : _a.compName); }); // const components = DSLCore.querySelectAll('[compType=2]') || []; // const filterList = components.filter((item: any) => { // return item?.attribute?.compName !== 'Api'; // }); var list = filterList.map(function (item) { var _a, _b, _c, _d, _e; var compType = (_a = item === null || item === void 0 ? void 0 : item.attribute) === null || _a === void 0 ? void 0 : _a.compName; var attrCode = (_c = (_b = item === null || item === void 0 ? void 0 : item.attribute) === null || _b === void 0 ? void 0 : _b.props) === null || _c === void 0 ? void 0 : _c.fieldName; var attrName = (_e = (_d = item === null || item === void 0 ? void 0 : item.attribute) === null || _d === void 0 ? void 0 : _d.props) === null || _e === void 0 ? void 0 : _e.name; return { compType: compType, attrCode: attrCode, attrName: attrName }; }); // 过滤输入参数选择的组件 var paramsComponents = []; if (apiParams && (apiParams === null || apiParams === void 0 ? void 0 : apiParams.params)) { var bean = apiParams === null || apiParams === void 0 ? void 0 : apiParams.params; Object.keys(bean).forEach(function (key) { if (bean[key] && Array.isArray(bean[key])) { bean[key].forEach(function (item1) { var _a; if ((item1 === null || item1 === void 0 ? void 0 : item1.dataValue) && item1.dataType === '2') { paramsComponents.push(item1 === null || item1 === void 0 ? void 0 : item1.dataValue); } if ((item1 === null || item1 === void 0 ? void 0 : item1.children) && Array.isArray(item1.children)) { (_a = item1.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) { if ((child === null || child === void 0 ? void 0 : child.dataValue) && child.dataType === '2') { paramsComponents.push(child === null || child === void 0 ? void 0 : child.dataValue); } }); } }); } }); } var resultList = list.filter(function (item) { return !paramsComponents.includes(item === null || item === void 0 ? void 0 : item.attrCode); }); return resultList; }); // 初始化 设置已经设置的组件 if (apiRespond && (apiRespond === null || apiRespond === void 0 ? void 0 : apiRespond.respond)) { var usedComponentsTemp = []; Object.keys(apiRespond === null || apiRespond === void 0 ? void 0 : apiRespond.respond).forEach(function (item) { usedComponentsTemp.push(apiRespond === null || apiRespond === void 0 ? void 0 : apiRespond.respond[item]); }); setUsedComponents(usedComponentsTemp); } } }, [visible]); var keys = []; var getDataKeys = function getDataKeys(data) { Object.keys(data).forEach(function (key) { if (_typeof(data[key]) === 'object') { getDataKeys(data[key]); } else { keys.push(key); } }); return keys; }; return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_antd.Button, { disabled: !!(apiObject && (apiObject === null || apiObject === void 0 ? void 0 : apiObject.busiServiceId) ? ((_b = Object.keys(respond)) === null || _b === void 0 ? void 0 : _b.length) > 0 ? value && value.respond ? false : false : true : true), onClick: function onClick() { setVisible(true); }, style: { fontSize: '12px', lineHeight: 'unset', height: 'unset', padding: '0 15px' } }, apiObject && (apiObject === null || apiObject === void 0 ? void 0 : apiObject.busiServiceId) ? ((_c = Object.keys(respond)) === null || _c === void 0 ? void 0 : _c.length) > 0 ? value && (value === null || value === void 0 ? void 0 : value.respond) && Object.values(value === null || value === void 0 ? void 0 : value.respond).some(function (v) { return v; }) ? '已配置' : '配置参数' : '无需配置' : '请先选择API'), visible && ( /*#__PURE__*/_react.default.createElement(_antd.Modal, { visible: visible, title: "\u8F93\u51FA\u53C2\u6570\u8BBE\u7F6E", key: busiServiceId, wrapClassName: "".concat(_utils.cssPrefixCls, "-respond-modalWrap"), bodyStyle: { maxHeight: '500px', overflow: 'auto', display: 'flex', flexDirection: 'column', alignItems: 'center' }, onOk: function onOk() { var _a; // 删除未在当前列表的出参数 var data = (0, _util.getRespondData)(respond, root === null || root === void 0 ? void 0 : root.value); if (currentValue && currentValue.respond && JSON.stringify(currentValue.respond) !== '{}') { Object.keys(currentValue.respond).forEach(function (key) { if (JSON.stringify(data) !== '{}') { var arr = key.split('.'); var lastVal = arr.pop(); // 先清空数组数据 keys.length = 0; var currentKeys = getDataKeys(data); if (lastVal && !currentKeys.includes(lastVal)) { delete currentValue.respond[key]; } } }); } onChange === null || onChange === void 0 ? void 0 : onChange(Object.assign(Object.assign({}, currentValue), { root: root, rootIsArray: (_a = root === null || root === void 0 ? void 0 : root.label) === null || _a === void 0 ? void 0 : _a.includes('数组') })); setVisible(false); }, onCancel: function onCancel() { return setVisible(false); } }, /*#__PURE__*/_react.default.createElement("p", { style: { alignSelf: 'flex-start', marginLeft: '14px' } }, "\u8BF7\u9009\u62E9\u5F53\u524D\u8868\u5355\u7ED1\u5B9A\u8282\u70B9\uFF1A"), /*#__PURE__*/_react.default.createElement(_antd.Space, { align: "baseline", size: "middle", style: { marginBottom: '10px' } }, /*#__PURE__*/_react.default.createElement(_antd.TreeSelect, { style: { width: '435px' }, value: root, dropdownStyle: { maxHeight: 400, overflow: 'auto' }, placeholder: "".concat(apiObject === null || apiObject === void 0 ? void 0 : apiObject.scriptResultType) === '3' ? '根节点(数组)' : '根节点', allowClear: true, labelInValue: true, treeDefaultExpandAll: true, onChange: onRootChange, treeData: treeData })), /*#__PURE__*/_react.default.createElement(_antd.Space, { align: "baseline", size: "middle", style: { marginBottom: '10px' } }, /*#__PURE__*/_react.default.createElement("div", { style: { width: '210px' } }, "\u53C2\u6570\u540D"), /*#__PURE__*/_react.default.createElement("div", { style: { width: '210px' } }, "\u8868\u5355\u5B57\u6BB5")), /*#__PURE__*/_react.default.createElement(ObjectForm, { options: localFieldList, usedComponents: usedComponents, data: (0, _util.getRespondData)(respond, root === null || root === void 0 ? void 0 : root.value), onChange: function onChange(_ref5) { var key1 = _ref5.key1, val = _ref5.value; var newValue = Object.assign(Object.assign({}, value), { respond: Object.assign(Object.assign({}, (currentValue === null || currentValue === void 0 ? void 0 : currentValue.respond) || {}), _defineProperty({}, key1, val)) }); setUsedComponents(Object.values(newValue.respond)); // onChange?.(newValue); setCurrentValue(newValue); }, values: currentValue === null || currentValue === void 0 ? void 0 : currentValue.respond, root: "root", isArray: (_d = root === null || root === void 0 ? void 0 : root.label) === null || _d === void 0 ? void 0 : _d.includes('数组'), n: 0 })))); }; var Test = function Test(_ref6) { var name = _ref6.name, rules = _ref6.rules, label = _ref6.label, DSLCore = _ref6.DSLCore; var _a; var _ref7 = ((_a = DSLCore === null || DSLCore === void 0 ? void 0 : DSLCore.current) === null || _a === void 0 ? void 0 : _a.props) || {}, apiObject = _ref7.apiObject, apiParams = _ref7.apiParams; var respond = {}; if (apiObject === null || apiObject === void 0 ? void 0 : apiObject.responseJson) { // if (apiObject?.tabKey === SERVICE_KEY.RHIN) { // respond = apiObject?.responseJson; // } else if ((apiObject === null || apiObject === void 0 ? void 0 : apiObject.responseJson) && Array.isArray(apiObject === null || apiObject === void 0 ? void 0 : apiObject.responseJson) && (apiObject === null || apiObject === void 0 ? void 0 : apiObject.responseJson.length) > 0) { apiObject === null || apiObject === void 0 ? void 0 : apiObject.responseJson.forEach(function (item) { respond = (0, _util.getNoRiinRep)(respond, item); }); } } return /*#__PURE__*/_react.default.createElement(_antd.Form.Item, { label: label, name: name, rules: rules }, /*#__PURE__*/_react.default.createElement(RespondModal, { apiObject: apiObject, apiParams: apiParams, DSLCore: DSLCore, respond: respond, busiServiceId: apiObject === null || apiObject === void 0 ? void 0 : apiObject.busiServiceId })); }; var _default = exports.default = Test;