UNPKG

@wufengteam/inputs

Version:

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

248 lines 11.2 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; } /* eslint-disable */ import React, { useState, useEffect } from 'react'; import { Form, Select, Modal, message, Tooltip } from 'antd'; import { wufengController } from '@wufengteam/core'; import { cssPrefixCls } from '../utils'; import "./index.css"; import { BindFieldInfo } from '../assets'; import { QuestionCircleOutlined } from '@ant-design/icons'; var Option = Select.Option; var InnerDataSelectFiled = function InnerDataSelectFiled(props) { // console.log('InnerDataSelectFiledProps', props); var onChange = props.onChange, _props$bindForm = props.bindForm, bindForm = _props$bindForm === void 0 ? {} : _props$bindForm, _props$initialValue = props.initialValue, initialValue = _props$initialValue === void 0 ? {} : _props$initialValue; // 关联表单信息 var catalogItemId = bindForm.catalogItemId, appId = bindForm.appId; var _Form$useForm = Form.useForm(), _Form$useForm2 = _slicedToArray(_Form$useForm, 1), form = _Form$useForm2[0]; var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), visible = _useState2[0], setVisible = _useState2[1]; // 主要字段和次要字段支持的表单组件类型 var compType = ['Input', 'Select', 'MultipleSelect', 'TextArea', 'InputNumber', 'Password', 'Radio', 'AddDepartment', 'AddMember']; // 字段列表 var _useState3 = useState([]), _useState4 = _slicedToArray(_useState3, 2), fieldList = _useState4[0], setFieldList = _useState4[1]; // 显示值 var _useState5 = useState('请设置'), _useState6 = _slicedToArray(_useState5, 2), showValue = _useState6[0], setShowValue = _useState6[1]; var onCancel = function onCancel() { setVisible(false); }; var onFinish = function onFinish(res) { var mainFiled = res.mainFiled, minorFiled = res.minorFiled; var mainFiledInfo = fieldList.find(function (item) { return item.attrCode === mainFiled; }); var minorFiledInfo = fieldList.find(function (item) { return item.attrCode === minorFiled; }); var result = { mainFiledInfo: { attrCode: mainFiledInfo.attrCode, attrName: mainFiledInfo.attrName, busiObjectId: mainFiledInfo.busiObjectId, staticCode: mainFiledInfo.staticCode, compType: mainFiledInfo.compType }, minorFiledInfo: { attrCode: minorFiledInfo === null || minorFiledInfo === void 0 ? void 0 : minorFiledInfo.attrCode, attrName: minorFiledInfo === null || minorFiledInfo === void 0 ? void 0 : minorFiledInfo.attrName, busiObjectId: minorFiledInfo === null || minorFiledInfo === void 0 ? void 0 : minorFiledInfo.busiObjectId, staticCode: minorFiledInfo === null || minorFiledInfo === void 0 ? void 0 : minorFiledInfo.staticCode, compType: minorFiledInfo === null || minorFiledInfo === void 0 ? void 0 : minorFiledInfo.compType } }; setShowValue(function () { return mainFiledInfo === null || mainFiledInfo === void 0 ? void 0 : mainFiledInfo.attrName; }); onChange === null || onChange === void 0 ? void 0 : onChange(result); setVisible(false); }; useEffect(function () { if (catalogItemId) { wufengController.getAction('queryFormFiledById', { catalogItemId: catalogItemId, appId: appId }).then(function (res) { var _a, _b; var _ref = res || {}, resultCode = _ref.resultCode, resultObject = _ref.resultObject; if (resultCode === '0') { if (resultObject && Array.isArray(resultObject)) { setFieldList(function () { var attrsFiltered = resultObject.filter(function (item) { return compType.includes(item.compType); }); var list = attrsFiltered.map(function (item) { return { attrCode: item.attrCode, attrName: item.attrName, busiObjectId: item.busiObjectId, staticCode: item.staticCode, compType: item.compType }; }); return list; }); var mainFiledInfo = resultObject.find(function (item) { var _a; return item.attrCode === ((_a = initialValue === null || initialValue === void 0 ? void 0 : initialValue.mainFiledInfo) === null || _a === void 0 ? void 0 : _a.attrCode); }); if (mainFiledInfo) { setShowValue(mainFiledInfo === null || mainFiledInfo === void 0 ? void 0 : mainFiledInfo.attrName); var initialFormValue = { mainFiled: (_a = initialValue === null || initialValue === void 0 ? void 0 : initialValue.mainFiledInfo) === null || _a === void 0 ? void 0 : _a.attrCode, minorFiled: (_b = initialValue === null || initialValue === void 0 ? void 0 : initialValue.minorFiledInfo) === null || _b === void 0 ? void 0 : _b.attrCode }; form.setFieldsValue(initialFormValue); } else { setShowValue(''); var _initialFormValue = { mainFiled: '', minorFiled: '' }; form.setFieldsValue(_initialFormValue); // const result = { // mainFiledInfo: { // attrCode: '', // attrName: '', // busiObjectId: '', // staticCode: '', // compType: '', // }, // minorFiledInfo: { // attrCode: '', // attrName: '', // busiObjectId: '', // staticCode: '', // compType: '', // }, // }; onChange === null || onChange === void 0 ? void 0 : onChange(''); } } } }); } }, [bindForm]); return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", { onClick: function onClick(e) { e.stopPropagation(); if (catalogItemId) { setVisible(!visible); } else { message.warn('请先关联表单'); } }, style: { display: 'flex', alignItems: 'center' } }, /*#__PURE__*/React.createElement(Select, { value: showValue, dropdownStyle: { display: 'none' }, style: { width: '100%' } }), /*#__PURE__*/React.createElement(Tooltip, { title: "\u663E\u793A\u5B57\u6BB5\uFF1A\u53D6\u5173\u8054\u8868\u5355\u4E2D\u7684\u5B57\u6BB5\u7528\u4E8E\u5728\u6B64\u9875\u9762\u505A\u6570\u636E\u5173\u8054\u7684\u5B57\u6BB5\u3002", placement: "topRight" }, /*#__PURE__*/React.createElement(QuestionCircleOutlined, { style: { marginLeft: '5px' } }))), /*#__PURE__*/React.createElement(Modal, { title: "\u663E\u793A\u5B57\u6BB5\u8BBE\u7F6E", width: 480, onCancel: onCancel, onOk: function onOk() { form.submit(); }, visible: visible, wrapClassName: "".concat(cssPrefixCls, "-dataSelectFiled") }, /*#__PURE__*/React.createElement("div", { className: "".concat(cssPrefixCls, "-dataSelectFiled-tip") }, "\u8BBE\u7F6E\u4E0B\u62C9\u9009\u9879\u4E2D\u5C55\u793A\u7684\u6570\u636E\uFF0C\u8F85\u52A9\u9009\u62E9\u5173\u8054\u6570\u636E\u3002\u4E3B\u8981\u5B57\u6BB5\uFF0C\u9009\u9879\u5217\u8868\u4E2D\u5C55\u793A\u7684\u4E3B\u8981\u5B57\u6BB5\uFF1B\u6B21\u8981\u5B57\u6BB5\uFF0C\u4F5C\u4E3A\u4E3B\u8981\u5B57\u6BB5\u7684\u8F85\u52A9\u4FE1\u606F\u3002"), /*#__PURE__*/React.createElement("div", { className: "".concat(cssPrefixCls, "-dataSelectFiled-info") }, /*#__PURE__*/React.createElement("img", { src: BindFieldInfo, alt: "", width: 412, height: 195 })), /*#__PURE__*/React.createElement(Form, { labelCol: { flex: '90px' }, form: form, onFinish: onFinish }, /*#__PURE__*/React.createElement(Form.Item, { name: "mainFiled", label: "\u4E3B\u8981\u4FE1\u606F", required: true, rules: [{ required: true, message: '请选择组要信息' }] }, /*#__PURE__*/React.createElement(Select, { allowClear: true }, fieldList.map(function (item) { var attrCode = item.attrCode, attrName = item.attrName; return /*#__PURE__*/React.createElement(Option, { value: attrCode }, attrName); }))), /*#__PURE__*/React.createElement(Form.Item, { name: "minorFiled", label: "\u6B21\u8981\u4FE1\u606F" }, /*#__PURE__*/React.createElement(Select, { allowClear: true }, fieldList.map(function (item) { var attrCode = item.attrCode, attrName = item.attrName; return /*#__PURE__*/React.createElement(Option, { value: attrCode }, attrName); })))))); }; var DataSelectFiled = function DataSelectFiled(props) { var _a; // console.log('DataSelectFiledProps', props); var name = props.name, rules = props.rules, label = props.label, DSLCore = props.DSLCore, selectedComp = props.selectedComp; var _ref2 = ((_a = DSLCore === null || DSLCore === void 0 ? void 0 : DSLCore.current) === null || _a === void 0 ? void 0 : _a.props) || {}, bindForm = _ref2.bindForm; var initialValue = (selectedComp === null || selectedComp === void 0 ? void 0 : selectedComp.props.dataSelectFiledInfo) || {}; return /*#__PURE__*/React.createElement(Form.Item, { label: label, name: name, rules: rules }, /*#__PURE__*/React.createElement(InnerDataSelectFiled, { bindForm: bindForm, initialValue: initialValue })); }; export default DataSelectFiled;