UNPKG

@wufengteam/inputs

Version:

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

411 lines 18.4 kB
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; } var __rest = this && this.__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; /* eslint-disable */ import React, { useEffect, useMemo, useRef, useState } from 'react'; import { Form, Button, Modal, Select } from 'antd'; import { PlusOutlined } from '@ant-design/icons'; import { cssPrefixCls } from '../utils'; import "./index.css"; var cssCls = "".concat(cssPrefixCls, "-data-statistics-rules-set"); var InnerDataStatisticsRules = function InnerDataStatisticsRules(props) { var value = props.value, onChange = props.onChange, selectedComp = props.selectedComp, DSLCore = props.DSLCore; var _Form$useForm = Form.useForm(), _Form$useForm2 = _slicedToArray(_Form$useForm, 1), form = _Form$useForm2[0]; var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), isModalOpen = _useState2[0], setIsModalOpen = _useState2[1]; var statisticalFieldSource = useRef({}); var currentFormFieldSource = useRef({}); var _useState3 = useState([]), _useState4 = _slicedToArray(_useState3, 2), currentFormFieldList = _useState4[0], setCurrentFormFieldList = _useState4[1]; var _useState5 = useState([]), _useState6 = _slicedToArray(_useState5, 2), calculationMethodList = _useState6[0], setCalculationMethodList = _useState6[1]; var errorResult = useRef(); var statisticalFieldList = useMemo(function () { var _ref = (selectedComp === null || selectedComp === void 0 ? void 0 : selectedComp.props) || {}, subFormFields = _ref.subFormFields; var statisticalFieldListVal = []; if (Array.isArray(subFormFields)) { subFormFields.forEach(function (item) { var _ref2 = item || {}, id = _ref2.id, compName = _ref2.compName; var _ref3 = (item === null || item === void 0 ? void 0 : item.props) || {}, fieldNameAlias = _ref3.fieldNameAlias, name = _ref3.name; statisticalFieldSource.current[id] = { id: id, fieldName: fieldNameAlias, label: name, compName: compName }; statisticalFieldListVal.push({ value: id, label: name }); }); } return statisticalFieldListVal; }, [JSON.stringify(selectedComp)]); useEffect(function () { if (isModalOpen) { var InputNumberNodeList = DSLCore.querySelectAll('.InputNumber'); var InputNumberFieldList = []; if (Array.isArray(InputNumberNodeList)) { InputNumberNodeList.forEach(function (item) { var _ref4 = item || {}, id = _ref4.id, compName = _ref4.compName, parentId = _ref4.parentId; if (!parentId.startsWith('SubForm_')) { var _ref5 = (item === null || item === void 0 ? void 0 : item.props) || {}, fieldNameAlias = _ref5.fieldNameAlias, name = _ref5.name; currentFormFieldSource.current[id] = { id: id, fieldName: fieldNameAlias, label: name, compName: compName }; InputNumberFieldList.push({ value: id, label: name }); } }); } var InputNumberSelectEdFieldList = []; var SubFormNodeList = DSLCore.querySelectAll('.SubForm'); if (Array.isArray(SubFormNodeList)) { SubFormNodeList.forEach(function (item) { if (item.id !== (selectedComp === null || selectedComp === void 0 ? void 0 : selectedComp.id)) { var _ref6 = (item === null || item === void 0 ? void 0 : item.props) || {}, dataStatisticsRules = _ref6.dataStatisticsRules; if (Array.isArray(dataStatisticsRules)) { dataStatisticsRules.forEach(function (item) { var _a; if ((_a = item === null || item === void 0 ? void 0 : item.currentFormFieldInfo) === null || _a === void 0 ? void 0 : _a.id) { InputNumberSelectEdFieldList.push(item.currentFormFieldInfo.id); } }); } } }); } var currentFormFieldListVal = InputNumberFieldList.filter(function (item) { return !InputNumberSelectEdFieldList.includes(item === null || item === void 0 ? void 0 : item.value); }); setCurrentFormFieldList(currentFormFieldListVal); if (Array.isArray(value) && value.length > 0) { var calculationMethodListVal = []; var innerDataStatisticsRules = []; var filterResult = value.filter(function (item) { var _a; var _ref7 = item || {}, statisticalFieldInfo = _ref7.statisticalFieldInfo; if ((statisticalFieldInfo === null || statisticalFieldInfo === void 0 ? void 0 : statisticalFieldInfo.id) && ((_a = statisticalFieldSource === null || statisticalFieldSource === void 0 ? void 0 : statisticalFieldSource.current) === null || _a === void 0 ? void 0 : _a[statisticalFieldInfo.id])) { return true; } return false; }); if (Array.isArray(filterResult)) { onChange === null || onChange === void 0 ? void 0 : onChange(filterResult); } else { onChange === null || onChange === void 0 ? void 0 : onChange([]); } filterResult.forEach(function (item) { var _a, _b; var _ref8 = item || {}, statisticalFieldInfo = _ref8.statisticalFieldInfo, currentFormFieldInfo = _ref8.currentFormFieldInfo, calculationMethod = _ref8.calculationMethod; if ((statisticalFieldInfo === null || statisticalFieldInfo === void 0 ? void 0 : statisticalFieldInfo.id) && ((_a = statisticalFieldSource === null || statisticalFieldSource === void 0 ? void 0 : statisticalFieldSource.current) === null || _a === void 0 ? void 0 : _a[statisticalFieldInfo.id])) { if ((statisticalFieldInfo === null || statisticalFieldInfo === void 0 ? void 0 : statisticalFieldInfo.compName) === 'InputNumber') { calculationMethodListVal.push([{ value: 'sum', label: '求和' }, { value: 'average', label: '平均值' }, { value: 'maximum', label: '最大值' }, { value: 'minimum', label: '最小值' }, { value: 'filledCount', label: '计数' }, { value: 'alreadyFilledCount', label: '已填数量' }, { value: 'notFilledCount', label: '未填数量' }]); } else { calculationMethodListVal.push([{ value: 'filledCount', label: '计数' }, { value: 'alreadyFilledCount', label: '已填数量' }, { value: 'notFilledCount', label: '未填数量' }]); } var currentFormField = ''; if ((currentFormFieldInfo === null || currentFormFieldInfo === void 0 ? void 0 : currentFormFieldInfo.id) && ((_b = currentFormFieldSource.current) === null || _b === void 0 ? void 0 : _b[currentFormFieldInfo.id])) { currentFormField = currentFormFieldInfo.id; } innerDataStatisticsRules.push({ statisticalField: statisticalFieldInfo.id, calculationMethod: calculationMethod, currentFormField: currentFormField }); } }); setCalculationMethodList(calculationMethodListVal); form.setFieldsValue({ innerDataStatisticsRules: innerDataStatisticsRules }); } } }, [isModalOpen, JSON.stringify(statisticalFieldSource), JSON.stringify(currentFormFieldSource)]); var handleOk = function handleOk() { form.validateFields().then(function (res) { var result = []; if (Array.isArray(res.innerDataStatisticsRules)) { result = res.innerDataStatisticsRules.map(function (item) { var _a, _b; var statisticalField = item.statisticalField, calculationMethod = item.calculationMethod, currentFormField = item.currentFormField; return { statisticalFieldInfo: (_a = statisticalFieldSource.current) === null || _a === void 0 ? void 0 : _a[statisticalField], currentFormFieldInfo: (_b = currentFormFieldSource.current) === null || _b === void 0 ? void 0 : _b[currentFormField], calculationMethod: calculationMethod }; }); } errorResult.current = null; onChange === null || onChange === void 0 ? void 0 : onChange(result); setIsModalOpen(false); }).catch(function (err) { var _a, _b; console.log(err); if (Array.isArray(err === null || err === void 0 ? void 0 : err.errorFields) && err.errorFields.length > 0) { var name = (_a = err.errorFields[0]) === null || _a === void 0 ? void 0 : _a.name; if (name) { form.scrollToField(err.errorFields[0].name); } } if (Array.isArray((_b = err === null || err === void 0 ? void 0 : err.values) === null || _b === void 0 ? void 0 : _b.innerDataStatisticsRules)) { errorResult.current = err.values.innerDataStatisticsRules.map(function (item) { var _a, _b; var statisticalField = item.statisticalField, calculationMethod = item.calculationMethod, currentFormField = item.currentFormField; return { statisticalFieldInfo: (_a = statisticalFieldSource.current) === null || _a === void 0 ? void 0 : _a[statisticalField], currentFormFieldInfo: (_b = currentFormFieldSource.current) === null || _b === void 0 ? void 0 : _b[currentFormField], calculationMethod: calculationMethod }; }); } }); }; var handleCancel = function handleCancel() { if (Array.isArray(errorResult.current)) { onChange === null || onChange === void 0 ? void 0 : onChange(errorResult.current); } setIsModalOpen(false); }; var handleOpenModal = function handleOpenModal() { setIsModalOpen(true); }; var onValuesChange = function onValuesChange(_, allValues) { if (Array.isArray(allValues.innerDataStatisticsRules) && allValues.innerDataStatisticsRules.length > 0) { var calculationMethodListVal = allValues.innerDataStatisticsRules.map(function (item) { var _a; if (item && item.statisticalField) { var _ref9 = ((_a = statisticalFieldSource.current) === null || _a === void 0 ? void 0 : _a[item.statisticalField]) || {}, compName = _ref9.compName; if (compName === 'InputNumber') { return [{ value: 'sum', label: '求和' }, { value: 'average', label: '平均值' }, { value: 'maximum', label: '最大值' }, { value: 'minimum', label: '最小值' }, { value: 'filledCount', label: '计数' }, { value: 'alreadyFilledCount', label: '已填数量' }, { value: 'notFilledCount', label: '未填数量' }]; } else if (compName) { return [{ value: 'filledCount', label: '计数' }, { value: 'alreadyFilledCount', label: '已填数量' }, { value: 'notFilledCount', label: '未填数量' }]; } return []; } return []; }); if (Array.isArray(calculationMethodListVal)) { setCalculationMethodList(calculationMethodListVal); } } }; return /*#__PURE__*/React.createElement(React.Fragment, null, isModalOpen && /*#__PURE__*/React.createElement(Modal, { title: "\u6570\u636E\u7EDF\u8BA1", open: isModalOpen, onOk: handleOk, onCancel: handleCancel, width: '660px', maskClosable: false, wrapClassName: "".concat(cssCls) }, /*#__PURE__*/React.createElement(Form, { form: form, onValuesChange: onValuesChange }, /*#__PURE__*/React.createElement(Form.List, { name: "innerDataStatisticsRules" }, function (fields, _ref10) { var add = _ref10.add, remove = _ref10.remove; return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { className: "".concat(cssCls, "-head") }, /*#__PURE__*/React.createElement("div", { className: "".concat(cssCls, "-head-statistical-filed") }, "\u7EDF\u8BA1\u5B57\u6BB5"), /*#__PURE__*/React.createElement("div", { className: "".concat(cssCls, "-head-calculation-method") }, "\u8BA1\u7B97\u65B9\u5F0F"), /*#__PURE__*/React.createElement("div", { className: "".concat(cssCls, "-head-current-form-field") }, "\u586B\u5145\u5230\u5F53\u524D\u8868\u5355\u5B57\u6BB5"), /*#__PURE__*/React.createElement("div", { className: "".concat(cssCls, "-head-delete") }, "\u5220\u9664")), /*#__PURE__*/React.createElement("div", { className: "".concat(cssCls, "-content") }, fields.map(function (_a, index) { var key = _a.key, name = _a.name, restField = __rest(_a, ["key", "name"]); return /*#__PURE__*/React.createElement("div", { key: key, className: "".concat(cssCls, "-row") }, /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, restField, { name: [name, 'statisticalField'], rules: [{ required: true, message: '请选择统计字段' }], className: "".concat(cssCls, "-row-statistical-filed") }), /*#__PURE__*/React.createElement(Select, { size: "small", placeholder: "\u8BF7\u9009\u62E9\u7EDF\u8BA1\u5B57\u6BB5", options: statisticalFieldList, style: { width: '120px' } })), /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, restField, { name: [name, 'calculationMethod'], rules: [{ required: true, message: '请选择计算方式' }], className: "".concat(cssCls, "-row-calculation-method") }), /*#__PURE__*/React.createElement(Select, { size: "small", placeholder: "\u8BF7\u9009\u62E9\u8BA1\u7B97\u65B9\u5F0F", options: calculationMethodList[index], style: { width: '120px' } })), /*#__PURE__*/React.createElement(Form.Item, Object.assign({}, restField, { name: [name, 'currentFormField'], rules: [{ required: true, message: '请选择当前表单字段' }], className: "".concat(cssCls, "-row-current-form-field") }), /*#__PURE__*/React.createElement(Select, { size: "small", placeholder: "\u8BF7\u9009\u62E9\u5F53\u524D\u8868\u5355\u5B57\u6BB5", options: currentFormFieldList, style: { width: '206px' } })), /*#__PURE__*/React.createElement("div", { onClick: function onClick() { return remove(name); }, className: "".concat(cssCls, "-row-delete") }, "\u5220\u9664")); })), /*#__PURE__*/React.createElement("div", { className: "".concat(cssCls, "-footer") }, /*#__PURE__*/React.createElement(Button, { shape: "round", size: "small", onClick: function onClick() { return add(); }, icon: /*#__PURE__*/React.createElement(PlusOutlined, null) }, "\u6DFB\u52A0\u4E00\u884C"))); }))), /*#__PURE__*/React.createElement(Button, { block: true, onClick: handleOpenModal, style: { fontSize: '12px' } }, Array.isArray(value) && (value === null || value === void 0 ? void 0 : value.length) > 0 ? '已设置' : '去设置')); }; var DataStatisticsRules = function DataStatisticsRules(props) { var name = props.name, label = props.label, rules = props.rules; return /*#__PURE__*/React.createElement(Form.Item, { label: label, name: name, rules: rules }, /*#__PURE__*/React.createElement(InnerDataStatisticsRules, Object.assign({}, props))); }; export default DataStatisticsRules;