UNPKG

@wufengteam/inputs

Version:

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

214 lines 11.7 kB
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); } 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; } import React, { useEffect, useState } from 'react'; import { Empty, Table, Select, Tooltip } from 'antd'; import { QuestionCircleOutlined } from '@ant-design/icons'; import "./index.css"; import { ARRAY_LIST } from '../../../constant'; // 输出参数配置 var OutParams = function OutParams(props) { var _a; var nodes = props.nodes, value = props.value, onValuesChange = props.onValuesChange; var _useState = useState(value === null || value === void 0 ? void 0 : value.selectNode), _useState2 = _slicedToArray(_useState, 2), selectNode = _useState2[0], setSelectNode = _useState2[1]; var _useState3 = useState([]), _useState4 = _slicedToArray(_useState3, 2), selectParams = _useState4[0], setSelectParams = _useState4[1]; var _useState5 = useState([{ fieldName: 'selectNode', name: '-', paramValue: value === null || value === void 0 ? void 0 : value.selectNode }, // { fieldName: 'vRowId', name: '序列号(导入数据的行号)', paramValue: value?.vRowId }, { fieldName: 'reasonForFail', name: '不通过原因(有设置时,下载异常数据时可查看校验不通过的原因)', paramValue: value === null || value === void 0 ? void 0 : value.failedReason }]), _useState6 = _slicedToArray(_useState5, 2), dataSource = _useState6[0], setDataSource = _useState6[1]; useEffect(function () { var dataSourceTemp = JSON.parse(JSON.stringify(dataSource)); var selectParamsTemp = []; Object.keys(value).forEach(function (key) { var cur = dataSourceTemp.find(function (it) { return it.fieldName === key; }); if (cur) { cur.paramValue = value[key]; } if (key !== 'selectNode') { selectParamsTemp.push({ key: key, value: value[key] }); } }); setSelectNode(value === null || value === void 0 ? void 0 : value.selectNode); setDataSource(dataSourceTemp); setSelectParams(selectParamsTemp); if (JSON.stringify(value) === '{}') { setDataSource(dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (it) { return Object.assign(Object.assign({}, it), { paramValue: undefined }); })); } }, [value]); var getTitle = function getTitle() { return { title: '校验不通过的节点', tip: '此处仅支持选择数组类型的参数,校验不通过的数据将不会导入处理,但支持下载重新加工。' }; }; var columns = [{ title: '表单字段', width: '30%', dataIndex: 'name', key: 'name', render: function render(_, row) { return /*#__PURE__*/React.createElement("span", { className: "paramNameWrap" }, /*#__PURE__*/React.createElement("span", { className: "redWrap" }, " ", (row === null || row === void 0 ? void 0 : row.fieldName) === 'reasonForFail' ? '*' : '', " "), (row === null || row === void 0 ? void 0 : row.name) || (row === null || row === void 0 ? void 0 : row.paramName)); } }, { title: '参数名称', width: '30%', dataIndex: 'paramValue', key: 'paramValue', render: function render(_, row) { var _a, _b; if ((row === null || row === void 0 ? void 0 : row.fieldName) === 'selectNode') { return selectNode || 'root'; } var paramsList = ((_b = (_a = nodes === null || nodes === void 0 ? void 0 : nodes.find(function (it) { return (it === null || it === void 0 ? void 0 : it.code) === selectNode; })) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.filter(function (it) { return !ARRAY_LIST.includes(it === null || it === void 0 ? void 0 : it.attrType); })) || []; return /*#__PURE__*/React.createElement(Select, { allowClear: true, style: { width: '100%' }, showSearch: true, value: row === null || row === void 0 ? void 0 : row.paramValue, onClear: function onClear() { var _a; // 清空回调 var selectParamsTemp = (_a = JSON.parse(JSON.stringify(selectParams))) === null || _a === void 0 ? void 0 : _a.filter(function (i) { return i.key !== (row === null || row === void 0 ? void 0 : row.fieldName); }); setSelectParams(selectParamsTemp); }, onChange: function onChange(e) { if (e) { // 选中的节点 var selectParamsTemp = JSON.parse(JSON.stringify(selectParams)); var beanTemp = selectParamsTemp === null || selectParamsTemp === void 0 ? void 0 : selectParamsTemp.find(function (it) { return (it === null || it === void 0 ? void 0 : it.key) === (row === null || row === void 0 ? void 0 : row.fieldName); }); if (beanTemp) { beanTemp.value = e; } else { selectParamsTemp.push({ key: row === null || row === void 0 ? void 0 : row.fieldName, value: e }); } setSelectParams(selectParamsTemp); } setDataSource(dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (it) { if (it.fieldName === (row === null || row === void 0 ? void 0 : row.fieldName)) { return Object.assign(Object.assign({}, it), { paramValue: e }); } return it; })); onValuesChange('out', _defineProperty({}, row === null || row === void 0 ? void 0 : row.fieldName, e)); }, filterOption: function filterOption(input, option) { return "".concat((option === null || option === void 0 ? void 0 : option.children) || '').toLowerCase().includes(input === null || input === void 0 ? void 0 : input.toLowerCase()) || "".concat((option === null || option === void 0 ? void 0 : option.value) || '').toLowerCase().includes(input === null || input === void 0 ? void 0 : input.toLowerCase()); }, placeholder: "\u8BF7\u9009\u62E9\u53C2\u6570\u540D\u79F0" }, paramsList === null || paramsList === void 0 ? void 0 : paramsList // ?.filter((it: any) => !selectParams?.includes(it?.code)) .map(function (it) { var _a; return /*#__PURE__*/React.createElement(Select.Option // 其他表单字段选中的值不可编辑 , { // 其他表单字段选中的值不可编辑 disabled: (_a = selectParams === null || selectParams === void 0 ? void 0 : selectParams // eslint-disable-next-line consistent-return .map(function (i) { if ((i === null || i === void 0 ? void 0 : i.key) !== (row === null || row === void 0 ? void 0 : row.fieldName)) { return i === null || i === void 0 ? void 0 : i.value; } })) === null || _a === void 0 ? void 0 : _a.includes(it === null || it === void 0 ? void 0 : it.code), value: it === null || it === void 0 ? void 0 : it.code }, it === null || it === void 0 ? void 0 : it.name); })); } }]; return /*#__PURE__*/React.createElement("div", { className: "outParamsWrap" }, (nodes === null || nodes === void 0 ? void 0 : nodes.length) !== 0 ? ( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { className: "selectNode" }, /*#__PURE__*/React.createElement("div", { className: "selectNodeWrap" }, getTitle().title), /*#__PURE__*/React.createElement(Tooltip, { title: getTitle().tip }, /*#__PURE__*/React.createElement(QuestionCircleOutlined, null)), /*#__PURE__*/React.createElement(Select, { className: "selectWrap", placeholder: "\u8BF7\u9009\u62E9", value: selectNode, onChange: function onChange(e) { setSelectNode(e); // 清空dataSource的paramValue setDataSource(dataSource === null || dataSource === void 0 ? void 0 : dataSource.map(function (it) { return Object.assign(Object.assign({}, it), { paramValue: undefined }); })); onValuesChange('out', { selectNode: e }); } }, (_a = nodes || []) === null || _a === void 0 ? void 0 : _a.map(function (item) { return /*#__PURE__*/React.createElement(Select.Option, { value: item === null || item === void 0 ? void 0 : item.code }, item === null || item === void 0 ? void 0 : item.name); }))), /*#__PURE__*/React.createElement("div", { className: "hint" }, "\u670D\u52A1\u53C2\u6570\u4E0E\u5F53\u524D\u8868\u5355\u5B57\u6BB5\u7684\u5173\u7CFB\u6620\u5C04\u8BBE\u7F6E"), /*#__PURE__*/React.createElement(Table, { rowKey: "key", pagination: false, defaultExpandAllRows: true, expandable: { defaultExpandAllRows: true }, columns: columns, dataSource: JSON.parse(JSON.stringify(dataSource)) }))) : ( /*#__PURE__*/React.createElement(Empty, { description: "\u5982\u9700\u670D\u52A1\u6821\u9A8C\uFF0C\u8BF7\u5148\u9009\u62E9\u5BF9\u5E94\u670D\u52A1" }))); }; export default OutParams;