UNPKG

@form-create/tdesign

Version:

TDesign版本低代码表单|FormCreate 是一个可以通过 JSON 生成具有动态渲染、数据收集、验证和提交功能的低代码表单生成组件。支持6个UI框架,适配移动端,并且支持生成任何 Vue 组件。内置20种常用表单组件和自定义组件,再复杂的表单都可以轻松搞定。

1,578 lines (1,393 loc) 261 kB
/*! * @form-create/tdesign v3.2.35 * (c) 2018-2025 xaboy * Github https://github.com/xaboy/form-create * Released under the MIT License. */ import { openBlock, createElementBlock, createElementVNode, defineComponent, h, resolveComponent, createVNode, nextTick, mergeProps as mergeProps$1, Fragment, markRaw, reactive, isVNode, getCurrentInstance, provide, inject, toRefs, onBeforeMount, watchEffect, onMounted, onBeforeUnmount, onUpdated, watch, computed, toRef, withDirectives, resolveDirective, createApp, ref } from 'vue'; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; } function _objectSpread2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function (obj) { return typeof obj; }; } else { _typeof = function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } 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 _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } 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 toArray(value) { return Array.isArray(value) ? value : [null, undefined, ''].indexOf(value) > -1 ? [] : [value]; } // https://github.com/developit/mitt function Mitt(all) { all = all || new Map(); var mitt = { $on: function $on(type, handler) { var handlers = all.get(type); var added = handlers && handlers.push(handler); if (!added) { all.set(type, [handler]); } }, $once: function $once(type, handler) { handler._once = true; mitt.$on(type, handler); }, $off: function $off(type, handler) { var handlers = all.get(type); if (handlers) { handlers.splice(handlers.indexOf(handler) >>> 0, 1); } }, $emit: function $emit(type) { for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } (all.get(type) || []).slice().map(function (handler) { if (handler._once) { mitt.$off(type, handler); delete handler._once; } handler.apply(void 0, args); }); (all.get('*') || []).slice().map(function (handler) { handler(type, args); }); } }; return mitt; } function styleInject(css, ref) { if ( ref === void 0 ) ref = {}; var insertAt = ref.insertAt; if (!css || typeof document === 'undefined') { return; } var head = document.head || document.getElementsByTagName('head')[0]; var style = document.createElement('style'); style.type = 'text/css'; if (insertAt === 'top') { if (head.firstChild) { head.insertBefore(style, head.firstChild); } else { head.appendChild(style); } } else { head.appendChild(style); } if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } } var css_248z$2 = "._fc-frame ._fc-files img{display:inline-block;height:100%;vertical-align:top;width:100%}._fc-frame ._fc-upload-cover{background:rgba(0,0,0,.6);bottom:0;left:0;opacity:0;position:absolute;right:0;top:0;transition:opacity .3s}._fc-frame ._fc-upload-cover ._fc-frame-icon{color:#fff;font-size:20px;margin:0 2px}._fc-frame ._fc-files:hover ._fc-upload-cover{opacity:1}._fc-frame .t-upload{display:block}._fc-frame ._fc-frame-icon,._fc-frame ._fc-upload-btn{cursor:pointer;font-size:20px;width:20px}._fc-frame._fc-disabled ._fc-frame-icon,._fc-frame._fc-disabled ._fc-upload-btn{color:#999;cursor:not-allowed!important}._fc-frame .t-input-adornment__append ._fc-frame-icon{margin:5px 12px 0}._fc-files,._fc-frame ._fc-upload-btn{background:#fff;border:1px solid #c0ccda;box-shadow:2px 2px 5px rgba(0,0,0,.1);box-sizing:border-box;display:inline-block;height:112px;line-height:112px;margin-right:4px;overflow:hidden;position:relative;text-align:center;width:112px}"; styleInject(css_248z$2); var script$3 = { name: 'IconFolder' }; var _hoisted_1$3 = { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 32 32" }; var _hoisted_2$3 = /*#__PURE__*/createElementVNode("path", { d: "M26 20h-2v4h-4v2h4v4h2v-4h4v-2h-4z", fill: "currentColor" }, null, -1); var _hoisted_3$3 = /*#__PURE__*/createElementVNode("path", { d: "M28 8H16l-3.4-3.4c-.4-.4-.9-.6-1.4-.6H4c-1.1 0-2 .9-2 2v20c0 1.1.9 2 2 2h14v-2H4V6h7.2l3.4 3.4l.6.6H28v8h2v-8c0-1.1-.9-2-2-2z", fill: "currentColor" }, null, -1); var _hoisted_4$1 = [_hoisted_2$3, _hoisted_3$3]; function render$3(_ctx, _cache, $props, $setup, $data, $options) { return openBlock(), createElementBlock("svg", _hoisted_1$3, _hoisted_4$1); } script$3.render = render$3; var IconFile = defineComponent({ name: 'IconFile', render: function render() { return h('svg', { style: { width: '20px', fontSize: '20px' }, viewBox: '0 0 24 24', version: '1.1', xmlns: 'http://www.w3.org/2000/svg' }, h('g', { fill: 'none', stroke: 'currentColor', 'stroke-width': '2', 'stroke-linecap': 'round', 'stroke-linejoin': 'round' }, h('path', { d: 'M14 3v4a1 1 0 0 0 1 1h4' }), h('path', { d: 'M17 21H7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7l5 5v11a2 2 0 0 1-2 2z' }))); } }); var script$2 = { name: 'DeleteOutlined' }; var _hoisted_1$2 = { height: "1em", width: "1em", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 1024 1024" }; var _hoisted_2$2 = /*#__PURE__*/createElementVNode("path", { d: "M360 184h-8c4.4 0 8-3.6 8-8v8h304v-8c0 4.4 3.6 8 8 8h-8v72h72v-80c0-35.3-28.7-64-64-64H352c-35.3 0-64 28.7-64 64v80h72v-72zm504 72H160c-17.7 0-32 14.3-32 32v32c0 4.4 3.6 8 8 8h60.4l24.7 523c1.6 34.1 29.8 61 63.9 61h454c34.2 0 62.3-26.8 63.9-61l24.7-523H888c4.4 0 8-3.6 8-8v-32c0-17.7-14.3-32-32-32zM731.3 840H292.7l-24.2-512h487l-24.2 512z", fill: "currentColor" }, null, -1); var _hoisted_3$2 = [_hoisted_2$2]; function render$2(_ctx, _cache, $props, $setup, $data, $options) { return openBlock(), createElementBlock("svg", _hoisted_1$2, _hoisted_3$2); } script$2.render = render$2; var script$1 = { name: 'EyeOutlined' }; var _hoisted_1$1 = { height: "1em", width: "1em", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 1024 1024" }; var _hoisted_2$1 = /*#__PURE__*/createElementVNode("path", { d: "M942.2 486.2C847.4 286.5 704.1 186 512 186c-192.2 0-335.4 100.5-430.2 300.3a60.3 60.3 0 0 0 0 51.5C176.6 737.5 319.9 838 512 838c192.2 0 335.4-100.5 430.2-300.3c7.7-16.2 7.7-35 0-51.5zM512 766c-161.3 0-279.4-81.8-362.7-254C232.6 339.8 350.7 258 512 258c161.3 0 279.4 81.8 362.7 254C791.5 684.2 673.4 766 512 766zm-4-430c-97.2 0-176 78.8-176 176s78.8 176 176 176s176-78.8 176-176s-78.8-176-176-176zm0 288c-61.9 0-112-50.1-112-112s50.1-112 112-112s112 50.1 112 112s-50.1 112-112 112z", fill: "currentColor" }, null, -1); var _hoisted_3$1 = [_hoisted_2$1]; function render$1(_ctx, _cache, $props, $setup, $data, $options) { return openBlock(), createElementBlock("svg", _hoisted_1$1, _hoisted_3$1); } script$1.render = render$1; var NAME$4 = 'fcFrame'; var Frame = defineComponent({ name: NAME$4, props: { type: { type: String, "default": 'input' }, field: String, helper: { type: Boolean, "default": true }, disabled: { type: Boolean, "default": false }, src: { type: String, required: true }, icon: { type: String, "default": 'icon-folder' }, width: { type: [Number, String], "default": '500px' }, height: { type: [Number, String], "default": '370px' }, maxLength: { type: Number, "default": 0 }, okBtnText: { type: String, "default": '' }, closeBtnText: { type: String, "default": '' }, modalTitle: String, handleIcon: { type: [String, Boolean], "default": undefined }, title: String, allowRemove: { type: Boolean, "default": true }, onOpen: { type: Function, "default": function _default() {} }, onOk: { type: Function, "default": function _default() {} }, onCancel: { type: Function, "default": function _default() {} }, onLoad: { type: Function, "default": function _default() {} }, onBeforeRemove: { type: Function, "default": function _default() {} }, onRemove: { type: Function, "default": function _default() {} }, onHandle: Function, modal: { type: Object, "default": function _default() { return {}; } }, srcKey: [String, Number], modelValue: [Array, String, Number, Object], previewMask: undefined, footer: { type: Boolean, "default": true }, reload: { type: Boolean, "default": true }, closeBtn: { type: Boolean, "default": true }, okBtn: { type: Boolean, "default": true }, formCreateInject: Object }, emits: ['update:modelValue', 'change'], components: { IconFolder: script$3, EyeOutlined: script$1 }, data: function data() { return { fileList: toArray(this.modelValue), previewVisible: false, frameVisible: false, previewImage: '', bus: new Mitt() }; }, watch: { modelValue: function modelValue(n) { this.fileList = toArray(n); } }, methods: { key: function key(unique) { return unique; }, close: function close() { this.closeModal(true); }, closeModal: function closeModal(close) { this.bus.$emit(close ? '$close' : '$ok'); if (this.reload) { this.bus.$off('$ok'); this.bus.$off('$close'); } this.frameVisible = false; }, handleCancel: function handleCancel() { this.previewVisible = false; }, showModal: function showModal() { if (this.disabled || false === this.onOpen()) { return; } this.frameVisible = true; }, input: function input() { var n = this.fileList; var val = this.maxLength === 1 ? n[0] || '' : n; this.$emit('update:modelValue', val); this.$emit('change', val); }, makeInput: function makeInput() { var _this = this; var Type = resolveComponent(this.icon); return createVNode(resolveComponent("t-input-adornment"), { "append": function append() { return createVNode(Type, { "onClick": _this.showModal, "class": "_fc-frame-icon" }, null); } }, { "default": function _default() { return [createVNode(resolveComponent("TInput"), { "readonly": true, "clearable": !_this.disabled, "showClearIconOnEmpty": !_this.disabled, "value": _this.fileList.map(function (v) { return _this.getSrc(v); }).toString(), "onClear": function onClear() { _this.fileList = []; _this.input(); }, "key": 1 }, null)]; } }); }, makeGroup: function makeGroup(children) { if (!this.maxLength || this.fileList.length < this.maxLength) children.push(this.makeBtn()); return createVNode("div", { "key": 2 }, [children]); }, makeItem: function makeItem(index, children) { return createVNode("div", { "class": "_fc-files", "key": '3' + index }, [children]); }, valid: function valid(f) { var field = this.formCreateInject.field || this.field; if (field && f !== field) { throw new Error('[frame]无效的字段值'); } }, makeIcons: function makeIcons(val, index) { if (this.handleIcon !== false || this.allowRemove === true) { var icons = []; if (this.type !== 'file' && this.handleIcon !== false || this.type === 'file' && this.handleIcon) icons.push(this.makeHandleIcon(val, index)); if (this.allowRemove) icons.push(this.makeRemoveIcon(val, index)); return createVNode("div", { "class": "_fc-upload-cover", "key": 4 }, [icons]); } }, makeHandleIcon: function makeHandleIcon(val, index) { var _this2 = this; var Type = resolveComponent(this.handleIcon === true || this.handleIcon === undefined ? 'EyeOutlined' : this.handleIcon); return createVNode(Type, { "class": "_fc-frame-icon", "onClick": function onClick() { return _this2.handleClick(val); }, "key": '5' + index }, null); }, makeRemoveIcon: function makeRemoveIcon(val, index) { var _this3 = this; return createVNode(script$2, { "class": "_fc-frame-icon", "onClick": function onClick() { return _this3.handleRemove(val); }, "key": '6' + index }, null); }, makeFiles: function makeFiles() { var _this4 = this; return this.makeGroup(this.fileList.map(function (src, index) { return _this4.makeItem(index, [createVNode(IconFile, { "size": "20", "onClick": function onClick() { return _this4.handleClick(src); } }, null), _this4.makeIcons(src, index)]); })); }, makeImages: function makeImages() { var _this5 = this; return this.makeGroup(this.fileList.map(function (src, index) { return _this5.makeItem(index, [createVNode("img", { "src": _this5.getSrc(src) }, null), _this5.makeIcons(src, index)]); })); }, makeBtn: function makeBtn() { var _this6 = this; var Type = resolveComponent(this.icon); return createVNode("div", { "class": "_fc-upload-btn", "onClick": function onClick() { return _this6.showModal(); }, "key": 7 }, [createVNode(Type, { "class": "_fc-frame-icon" }, null)]); }, handleClick: function handleClick(src) { if (this.onHandle) { return this.onHandle(src); } else { this.previewImage = this.getSrc(src); this.previewVisible = true; } }, handleRemove: function handleRemove(src) { if (this.disabled) return; if (false !== this.onBeforeRemove(src)) { this.fileList.splice(this.fileList.indexOf(src), 1); this.input(); this.onRemove(src); } }, getSrc: function getSrc(src) { return !this.srcKey ? src : src[this.srcKey]; }, frameLoad: function frameLoad(iframe) { var _this7 = this; this.onLoad(iframe); try { if (this.helper === true) { iframe['form_create_helper'] = { api: this.formCreateInject.api, close: function close(field) { _this7.valid(field); _this7.closeModal(); }, set: function set(field, value) { _this7.valid(field); if (!_this7.disabled) { _this7.$emit('update:modelValue', value); _this7.$emit('change', value); } }, get: function get(field) { _this7.valid(field); return _this7.modelValue; }, onOk: function onOk(fn) { return _this7.bus.$on('$ok', fn); }, onClose: function onClose(fn) { return _this7.bus.$on('$close', fn); } }; } } catch (e) { console.error(e); } }, makeFooter: function makeFooter() { var _this8 = this; var _this$$props = this.$props, okBtnText = _this$$props.okBtnText, closeBtnText = _this$$props.closeBtnText, closeBtn = _this$$props.closeBtn, okBtn = _this$$props.okBtn, footer = _this$$props.footer; var node = []; if (!footer) return node; if (closeBtn) node.push(createVNode(resolveComponent("TButton"), { "onClick": function onClick() { return _this8.onCancel() !== false && _this8.closeModal(true); } }, { "default": function _default() { return [closeBtnText || _this8.formCreateInject.t('close') || '关闭']; } })); if (okBtn) node.push(createVNode(resolveComponent("TButton"), { "theme": "primary", "onClick": function onClick() { return _this8.onOk() !== false && _this8.closeModal(); } }, { "default": function _default() { return [okBtnText || _this8.formCreateInject.t('ok') || '确定']; } })); return node; } }, render: function render() { var _this9 = this; var type = this.type; var Node; if (type === 'input') Node = this.makeInput();else if (type === 'image') Node = this.makeImages();else Node = this.makeFiles(); var _this$$props2 = this.$props, _this$$props2$width = _this$$props2.width, width = _this$$props2$width === void 0 ? '30%' : _this$$props2$width, height = _this$$props2.height, src = _this$$props2.src, title = _this$$props2.title, modalTitle = _this$$props2.modalTitle; nextTick(function () { if (_this9.$refs.frame) { _this9.frameLoad(_this9.$refs.frame.contentWindow || {}); } }); return createVNode("div", { "class": { '_fc-frame': true, '_fc-disabled': this.disabled } }, [Node, createVNode(resolveComponent("TDialog"), { "mask": this.previewMask, "header": modalTitle, "visible": this.previewVisible, "style": "width: 600px;", "attach": "body", "onUpdate:visible": function onUpdateVisible(n) { return _this9.previewVisible = n; }, "footer": false }, { "default": function _default() { return [createVNode("img", { "style": "width: 100%", "src": _this9.previewImage, "key": 1 }, null)]; } }), createVNode(resolveComponent("TDialog"), mergeProps$1(_objectSpread2({ width: width, header: title }, this.modal), { "visible": this.frameVisible, "attach": "body", "style": { width: width }, "onClose": function onClose() { return _this9.frameVisible = false; }, "onConfirm": function onConfirm() { return _this9.closeModal(true); }, "key": 2 }), { "default": function _default() { return [_this9.frameVisible || !_this9.reload ? createVNode("iframe", { "ref": "frame", "src": src, "frameborder": "0", "style": { height: height, 'border': '0 none', 'width': '100%' } }, null) : null]; }, action: function action() { return _this9.makeFooter(); } })]); }, beforeMount: function beforeMount() { var _this$formCreateInjec = this.formCreateInject, name = _this$formCreateInjec.name, field = _this$formCreateInjec.field, api = _this$formCreateInjec.api; name && api.on('fc:closeModal:' + name, this.close); field && api.on('fc:closeModal:' + field, this.close); }, beforeUnmount: function beforeUnmount() { var _this$formCreateInjec2 = this.formCreateInject, name = _this$formCreateInjec2.name, field = _this$formCreateInjec2.field, api = _this$formCreateInjec2.api; name && api.off('fc:closeModal:' + name, this.close); field && api.off('fc:closeModal:' + field, this.close); } }); var NAME$3 = 'fcUpload'; function parseFile(file, i) { if (_typeof(file) === 'object') { return file; } return { url: file, is_string: true, name: getFileName(file), status: 'success', uid: i }; } function parseUpload(file) { return _objectSpread2(_objectSpread2({}, file), {}, { file: file, value: file }); } function getFileName(file) { return ('' + file).split('/').pop(); } var Upload = defineComponent({ name: NAME$3, inheritAttrs: false, formCreateParser: { toFormValue: function toFormValue(value) { return toArray(value); }, toValue: function toValue(formValue, ctx) { return ctx.prop.props.limit === 1 ? formValue[0] || '' : formValue; } }, props: { limit: { type: Number, "default": 0 }, formCreateInject: Object, modelValue: { type: [Array, String, Object], "default": [] }, onSuccess: { type: Function }, onRemove: { type: Function } }, emits: ['update:modelValue', 'fc.el'], data: function data() { return { uploadList: toArray(this.modelValue).map(parseFile).map(parseUpload) }; }, watch: { modelValue: function modelValue(n) { this.uploadList = toArray(n).map(parseFile).map(parseUpload); } }, methods: { handleRemove: function handleRemove(_ref) { var index = _ref.index; this.uploadList.splice(index, 1); this.onRemove && this.onRemove.apply(this, arguments); this.input(); }, handleSuccess: function handleSuccess(_ref2) { var file = _ref2.file, fileList = _ref2.fileList; this.uploadList = fileList; if (file.status === 'success') { this.onSuccess && this.onSuccess.apply(this, arguments); } this.input(); }, input: function input() { this.$emit('update:modelValue', this.uploadList.map(function (v) { return v.is_string ? v.url : v.value || v.url; }).filter(function (url) { return url !== undefined; })); } }, render: function render() { var uploadList = this.uploadList, handleSuccess = this.handleSuccess, handleRemove = this.handleRemove, $slots = this.$slots; return createVNode(Fragment, null, [createVNode(resolveComponent("t-upload"), mergeProps$1({ "max": this.limit, "theme": "image", "accept": "image/*", "modelValue": uploadList }, this.$attrs, { "onSuccess": handleSuccess, "onRemove": handleRemove, "ref": "el" }), $slots)]); }, mounted: function mounted() { this.$emit('fc.el', this.$refs.el); } }); var is = { type: function type(arg, _type) { return Object.prototype.toString.call(arg) === '[object ' + _type + ']'; }, Undef: function Undef(v) { return v === undefined || v === null; }, Element: function Element(arg) { return _typeof(arg) === 'object' && arg !== null && arg.nodeType === 1 && !is.Object(arg); }, trueArray: function trueArray(data) { return Array.isArray(data) && data.length > 0; }, Function: function Function(v) { var type = this.getType(v); return type === 'Function' || type === 'AsyncFunction'; }, getType: function getType(v) { var str = Object.prototype.toString.call(v); return /^\[object (.*)\]$/.exec(str)[1]; }, empty: function empty(value) { if (value === undefined || value === null) { return true; } if (Array.isArray(value) && Array.isArray(value) && !value.length) { return true; } return typeof value === 'string' && !value; } }; ['Date', 'Object', 'String', 'Boolean', 'Array', 'Number'].forEach(function (t) { is[t] = function (arg) { return is.type(arg, t); }; }); function hasProperty(rule, k) { return {}.hasOwnProperty.call(rule, k); } function $set(target, field, value) { target[field] = value; } function $del(target, field) { delete target[field]; } function deepExtend(origin) { var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; var mode = arguments.length > 2 ? arguments[2] : undefined; var isArr = false; for (var key in target) { if (Object.prototype.hasOwnProperty.call(target, key)) { var clone = target[key]; if ((isArr = Array.isArray(clone)) || is.Object(clone)) { var nst = origin[key] === undefined; if (isArr) { isArr = false; nst && $set(origin, key, []); } else if (clone._clone && mode !== undefined) { if (mode) { clone = clone.getRule(); nst && $set(origin, key, {}); } else { $set(origin, key, clone._clone()); continue; } } else { nst && $set(origin, key, {}); } origin[key] = deepExtend(origin[key], clone, mode); } else { $set(origin, key, clone); if (!is.Undef(clone)) { if (!is.Undef(clone.__json)) { origin[key].__json = clone.__json; } if (!is.Undef(clone.__origin)) { origin[key].__origin = clone.__origin; } } } } } return mode !== undefined && Array.isArray(origin) ? origin.filter(function (v) { return !v || !v.__ctrl; }) : origin; } function deepCopy(value) { return deepExtend({}, { value: value }).value; } var _extends = Object.assign || function (a) { for (var b, c = 1; c < arguments.length; c++) { for (var d in b = arguments[c], b) { Object.prototype.hasOwnProperty.call(b, d) && $set(a, d, b[d]); } } return a; }; function extend() { return _extends.apply(this, arguments); } function copy$1(obj) { if (_typeof(obj) !== 'object' || obj === null) return obj; return obj instanceof Array ? _toConsumableArray(obj) : _objectSpread2({}, obj); } var css_248z$1 = "._fc-group{display:flex;flex-direction:column;justify-content:center;min-height:38px;width:100%}._fc-group-disabled ._fc-group-add,._fc-group-disabled ._fc-group-btn{cursor:not-allowed}._fc-group-handle{background-color:#fff;border:1px dashed #d9d9d9;border-radius:15px;bottom:-15px;display:flex;flex-direction:row;padding:3px 8px;position:absolute;right:30px}._fc-group-btn{cursor:pointer}._fc-group-idx{align-items:center;background:#eee;border-radius:15px;bottom:-15px;display:flex;font-weight:700;height:30px;justify-content:center;left:10px;position:absolute;width:30px}._fc-group-handle ._fc-group-btn+._fc-group-btn{margin-left:7px}._fc-group-container{border:1px dashed #d9d9d9;border-radius:5px;display:flex;flex-direction:column;margin:5px 5px 25px;padding:20px 20px 25px;position:relative}._fc-group-arrow{height:20px;position:relative;width:20px}._fc-group-arrow:before{border-left:2px solid #999;border-top:2px solid #999;content:\"\";height:9px;left:5px;position:absolute;top:8px;transform:rotate(45deg);width:9px}._fc-group-arrow._fc-group-down{transform:rotate(180deg)}._fc-group-plus-minus{cursor:pointer;height:20px;position:relative;width:20px}._fc-group-plus-minus:after,._fc-group-plus-minus:before{background-color:#409eff;content:\"\";height:2px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);width:60%}._fc-group-plus-minus:before{transform:translate(-50%,-50%) rotate(90deg)}._fc-group-plus-minus._fc-group-minus:before{display:none}._fc-group-plus-minus._fc-group-minus:after{background-color:#f56c6c}._fc-group-add{border:1px solid rgba(64,158,255,.5);border-radius:15px;cursor:pointer;height:25px;width:25px}._fc-group-add._fc-group-plus-minus:after,._fc-group-add._fc-group-plus-minus:before{width:50%}._fc-group._fc-group-card{display:flex;flex-direction:column;gap:16px;width:100%}._fc-group._fc-group-card._fc-group-disabled ._fc-group-add,._fc-group._fc-group-card._fc-group-disabled ._fc-group-btn{cursor:not-allowed;opacity:.5}._fc-group._fc-group-card ._fc-group-container{background:#fff;border:1px solid #f0f0f0;border-radius:6px;display:flex;flex-direction:column;margin:0;overflow:hidden;padding:0;position:relative}._fc-group._fc-group-card ._fc-group-header{align-items:center;background:#fafafa;border-bottom:1px solid #f0f0f0;display:flex;justify-content:space-between;padding:16px 20px 12px}._fc-group._fc-group-card ._fc-group-idx{align-items:center;background:#f0f0f0;border:1px solid #e0e0e0;border-radius:6px;color:#666;display:flex;flex-shrink:0;font-size:12px;font-weight:500;height:24px;justify-content:center;margin-right:12px;position:static;width:24px}._fc-group._fc-group-card ._fc-group-title{color:rgba(0,0,0,.85);flex:1;font-size:14px;font-weight:500;line-height:1.5715}._fc-group._fc-group-card ._fc-group-handle{align-items:center;background-color:transparent;border:none;border-radius:0;bottom:auto;display:flex;flex-direction:row;flex-shrink:0;gap:4px;margin-left:12px;padding:0;position:static;right:auto}._fc-group._fc-group-card ._fc-group-btn{align-items:center;background:#fff;border:1px solid #d9d9d9;border-radius:4px;color:rgba(0,0,0,.45);cursor:pointer;display:flex;height:24px;justify-content:center;position:relative;width:24px}._fc-group._fc-group-card ._fc-group-btn:hover{background:#f0f8ff;border-color:#1890ff;color:#1890ff}._fc-group._fc-group-card ._fc-group-btn:active{border-color:#096dd9;color:#096dd9}._fc-group._fc-group-card ._fc-group-arrow{position:relative}._fc-group._fc-group-card ._fc-group-arrow:before{border-left:1px solid;border-top:1px solid;content:\"\";height:5px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%) rotate(45deg);width:5px}._fc-group._fc-group-card ._fc-group-arrow._fc-group-down{transform:rotate(180deg)}._fc-group._fc-group-card ._fc-group-sort{align-items:center;display:flex;flex-direction:column;height:24px;justify-content:center;position:relative}._fc-group._fc-group-card ._fc-group-sort:after,._fc-group._fc-group-card ._fc-group-sort:before{border-left:1px solid;border-top:1px solid;content:\"\";height:4px;left:50%;position:absolute;transform:translateX(-50%);width:4px}._fc-group._fc-group-card ._fc-group-sort:before{top:6px;transform:translateX(-50%) rotate(45deg)}._fc-group._fc-group-card ._fc-group-sort:after{bottom:6px;transform:translateX(-50%) rotate(225deg)}._fc-group._fc-group-card ._fc-group-sort-down,._fc-group._fc-group-card ._fc-group-sort-up{cursor:pointer;height:12px;left:0;position:absolute;right:0;z-index:1}._fc-group._fc-group-card ._fc-group-sort-up{top:0}._fc-group._fc-group-card ._fc-group-sort-down{bottom:0}._fc-group._fc-group-card ._fc-group-sort-down:hover,._fc-group._fc-group-card ._fc-group-sort-up:hover{background:rgba(24,144,255,.1)}._fc-group._fc-group-card ._fc-group-plus-minus{background:#409eff;border-color:#409eff;color:#fff;height:24px;position:relative;width:24px}._fc-group._fc-group-card ._fc-group-plus-minus:hover{background:#66b1ff;border-color:#66b1ff;color:#fff}._fc-group._fc-group-card ._fc-group-plus-minus:after,._fc-group._fc-group-card ._fc-group-plus-minus:before{background-color:currentColor;content:\"\";height:1px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);width:8px}._fc-group._fc-group-card ._fc-group-plus-minus:before{transform:translate(-50%,-50%) rotate(90deg)}._fc-group._fc-group-card ._fc-group-plus-minus._fc-group-minus{background:#f56c6c;border-color:#f56c6c}._fc-group._fc-group-card ._fc-group-plus-minus._fc-group-minus:hover{background:#f78989;border-color:#f78989}._fc-group._fc-group-card ._fc-group-plus-minus._fc-group-minus:before{display:none}._fc-group._fc-group-card ._fc-group-content{padding:20px}._fc-group._fc-group-card ._fc-group-add{align-items:center;background:#fff;border:1px solid #d9d9d9;border-radius:4px;color:rgba(0,0,0,.45);cursor:pointer;display:flex;height:24px;justify-content:center;position:relative;width:24px}._fc-group._fc-group-card ._fc-group-add:hover{background:#f0f8ff;border-color:#409eff;color:#409eff}._fc-group._fc-group-card ._fc-group-add._fc-group-plus-minus{background:#409eff;border-color:#409eff;color:#fff;height:24px;width:24px}._fc-group._fc-group-card ._fc-group-add._fc-group-plus-minus:hover{background:#66b1ff;border-color:#66b1ff;color:#fff}._fc-group._fc-group-card ._fc-group-add._fc-group-plus-minus:after,._fc-group._fc-group-card ._fc-group-add._fc-group-plus-minus:before{background-color:currentColor;content:\"\";height:1px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);width:8px}._fc-group._fc-group-card ._fc-group-add._fc-group-plus-minus:before{transform:translate(-50%,-50%) rotate(90deg)}._fc-group._fc-group-card ._fc-group-empty{color:rgba(0,0,0,.45);font-size:14px;padding:40px 20px;text-align:center}@media (max-width:768px){._fc-group._fc-group-card ._fc-group-container{border-left:none;border-radius:0;border-right:none;margin:0 -8px}._fc-group._fc-group-card ._fc-group-header{padding:12px 16px 8px}._fc-group._fc-group-card ._fc-group-content{padding:16px}._fc-group._fc-group-card ._fc-group-handle{gap:2px}._fc-group._fc-group-card ._fc-group-btn{height:22px;width:22px}}"; styleInject(css_248z$1); function debounce(fn, wait) { var timeout = null; return function () { var _this = this; for (var _len = arguments.length, arg = new Array(_len), _key = 0; _key < _len; _key++) { arg[_key] = arguments[_key]; } if (timeout !== null) clearTimeout(timeout); timeout = setTimeout(function () { return fn.call.apply(fn, [_this].concat(arg)); }, wait); }; } function toString(val) { return val == null ? '' : _typeof(val) === 'object' ? JSON.stringify(val, null, 2) : String(val); } function isPromise(value) { return value && _typeof(value) === 'object' && typeof value.then === 'function'; } function toPromise(value) { if (isPromise(value)) { return value; } return Promise.resolve(value); } function toLine(name) { var line = name.replace(/([A-Z])/g, '-$1').toLocaleLowerCase(); if (line.indexOf('-') === 0) line = line.substr(1); return line; } function upper(str) { return str.replace(str[0], str[0].toLocaleUpperCase()); } function format(type, msg, rule) { return "[form-create ".concat(type, "]: ").concat(msg) + (rule ? '\n\nrule: ' + JSON.stringify(rule.getRule ? rule.getRule() : rule) : ''); } function err(msg, rule) { console.error(format('err', msg, rule)); } function logError(e) { err(e.toString()); console.error(e); } var PREFIX = '[[FORM-CREATE-PREFIX-'; var SUFFIX = '-FORM-CREATE-SUFFIX]]'; function toJson(obj, space) { return JSON.stringify(deepExtend(Array.isArray(obj) ? [] : {}, obj, true), function (key, val) { if (val && val._isVue === true) return undefined; if (typeof val !== 'function') { return val; } if (val.__json) { return val.__json; } if (val.__origin) val = val.__origin; if (val.__emit) return undefined; return PREFIX + val + SUFFIX; }, space); } function makeFn(fn) { return new Function('return ' + fn)(); } function parseFn(fn, mode) { if (fn && is.String(fn) && fn.length > 4) { var v = fn.trim(); var flag = false; try { if (v.indexOf(SUFFIX) > 0 && v.indexOf(PREFIX) === 0) { v = v.replace(SUFFIX, '').replace(PREFIX, ''); flag = true; } else if (v.indexOf('$FN:') === 0) { v = v.substring(4); flag = true; } else if (v.indexOf('$EXEC:') === 0) { v = v.substring(6); flag = true; } else if (v.indexOf('$GLOBAL:') === 0) { var name = v.substring(8); v = function v() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var callback = args[0].api.getGlobalEvent(name); if (callback) { return callback.call.apply(callback, [this].concat(args)); } return undefined; }; v.__json = fn; v.__inject = true; return v; } else if (v.indexOf('$FNX:') === 0) { v = makeFn('function($inject){\n' + v.substring(5) + '\n}'); v.__json = fn; v.__inject = true; return v; } else if (!mode && v.indexOf('function ') === 0 && v !== 'function ') { flag = true; } else if (!mode && v.indexOf('function(') === 0 && v !== 'function(') { flag = true; } if (!flag) return fn; var val; try { val = makeFn(v); } catch (e) { val = makeFn('function ' + v); } val.__json = fn; return val; } catch (e) { err("\u89E3\u6790\u5931\u8D25:".concat(v, "\n\nerr: ").concat(e)); return undefined; } } return fn; } function parseJson(json, mode) { return JSON.parse(json, function (k, v) { if (is.Undef(v) || !v.indexOf) return v; return parseFn(v, mode); }); } var id$2 = 0; function uniqueId() { var num = 370 + ++id$2; return 'F' + Math.random().toString(36).substr(3, 3) + Number("".concat(Date.now())).toString(36) + num.toString(36) + 'c'; } function deepSet(data, idx, val) { var _data = data, to; (idx || '').split('.').forEach(function (v) { if (to) { if (!_data[to] || _typeof(_data[to]) != 'object') { _data[to] = {}; } _data = _data[to]; } to = v; }); _data[to] = val; return _data; } var NAME$2 = 'fcGroup'; var Group = defineComponent({ name: NAME$2, props: { field: String, rule: Array, expand: Number, options: Object, button: { type: Boolean, "default": true }, max: { type: Number, "default": 0 }, min: { type: Number, "default": 0 }, modelValue: { type: Array, "default": function _default() { return []; } }, defaultValue: Object, sortBtn: { type: Boolean, "default": true }, disabled: { type: Boolean, "default": false }, syncDisabled: { type: Boolean, "default": true }, title: { type: [String, Function], "default": null }, type: { type: String, "default": 'default' }, onBeforeRemove: { type: Function, "default": function _default() {} }, onBeforeAdd: { type: Function, "default": function _default() {} }, formCreateInject: Object, parse: Function }, data: function data() { return { len: 0, cacheRule: {}, cacheValue: {}, sort: [], form: markRaw(this.formCreateInject.form.$form()) }; }, emits: ['update:modelValue', 'change', 'itemMounted', 'remove', 'add'], watch: { rule: { handler: function handler(n, o) { var _this = this; Object.keys(this.cacheRule).forEach(function (v) { var item = _this.cacheRule[v]; if (item.$f) { var val = item.$f.formData(); if (n === o) { item.$f.deferSyncValue(function () { deepExtend(item.rule, n); item.$f.setValue(val); }, true); } else { var _val = item.$f.formData(); item.$f.once('reloading', function () { item.$f.setValue(_val); }); item.rule = deepCopy(n); } } }); }, deep: true }, expand: function expand(n) { var d = n - this.modelValue.length; if (d > 0) { this.expandRule(d); } }, modelValue: { handler: function handler(n) { var _this2 = this; n = n || []; var keys = this.sort, total = keys.length, len = total - n.length; if (len < 0) { for (var i = len; i < 0; i++) { this.addRule(n.length + i, true); } for (var _i = 0; _i < total; _i++) { this.setValue(keys[_i], n[_i]); } } else { if (len > 0) { for (var _i2 = 0; _i2 < len; _i2++) { this.removeRule(keys[total - _i2 - 1]); } } n.forEach(function (val, i) { _this2.setValue(keys[i], n[i]); }); } }, deep: true } }, methods: { _value: function _value(v) { return v && hasProperty(v, this.field) ? v[this.field] : v; }, cache: function cache(k, val) { this.cacheValue[k] = JSON.stringify(val); }, input: function input(value) { this.$emit('update:modelValue', value); this.$emit('change', value); }, formData: function formData(key, _formData) { var _this3 = this; var cacheRule = this.cacheRule; var keys = this.sort; if (keys.filter(function (k) { return cacheRule[k] && cacheRule[k].$f; }).length !== keys.length) { return; } var value = keys.map(function (k) { var data = key === k ? _formData : _objectSpread2({}, _this3.cacheRule[k].$f.form); var value = _this3.field ? data[_this3.field] || null : data; _this3.cache(k, value); return value; }); this.input(value); }, setValue: function setValue(key, value) { var field = this.field; if (field) { value = _defineProperty({}, field, this._value(value)); } if (this.cacheValue[key] === JSON.stringify(field ? value[field] : value)) { return; } this.cacheRule[key].$f && this.cacheRule[key].$f.coverValue(value); this.cache(key, value); }, addRule: function addRule(i, emit) { var _this4 = this; var rule = this.formCreateInject.form.copyRules(this.rule || []); var options = this.options ? _objectSpread2({}, this.options) : { submitBtn: false, resetBtn: false }; if (this.defaultValue) { if (!options.formData) options.formData = {}; var defVal = deepCopy(this.defaultValue); extend(options.formData, this.field ? _defineProperty({}, this.field, defVal) : defVal); } this.parse && this.parse({ rule: rule, options: options, index: this.sort.length }); this.cacheRule[++this.len] = { rule: rule, options: options }; this.sort = Object.keys(this.cacheRule); if (emit) { nextTick(function () { return _this4.$emit('add', rule, Object.keys(_this4.cacheRule).length - 1); }); } }, add$f: function add$f(i, key, $f) { var _this5 = this; this.cacheRule[key].$f = $f; nextTick(function () { _this5.$emit('itemMounted', $f, Object.keys(_this5.cacheRule).indexOf(key)); }); }, removeRule: function removeRule(key, emit) { var _this6 = this; var index = Object.keys(this.cacheRule).indexOf(key); delete this.cacheRule[key]; delete this.cacheValue[key]; this.sort = Object.keys(this.cacheRule); if (emit) { nextTick(function () { return _this6.$emit('remove', index); }); } }, add: function add(i) { if (this.disabled || false === this.onBeforeAdd(this.modelValue)) { return; } var value = _toConsumableArray(this.modelValue); value.push(this.defaultValue ? deepCopy(this.defaultValue) : this.field ? null : {}); this.input(value); }, del: function del(index, key) { var _this7 = this; if (this.disabled) { return; } var del = function del() { _this7.removeRule(key, true); var value = _toConsumableArray(_this7.modelValue); value.splice(index, 1); _this7.input(value); }; toPromise(this.onBeforeRemove(this.modelValue, index)).then(function (res) { if (false !== res) { del(); } }); }, addIcon: function addIcon(key) { return createVNode("div", { "class": "_fc-group-btn _fc-group-plus-minus", "onClick": this.add }, null); }, delIcon: function delIcon(index, key) { var _this8 = this; return createVNode("div", { "class": "_fc-group-btn _fc-group-plus-minus _fc-group-minus", "onClick": function onClick() { return _this8.del(index, key); } }, null); }, sortUpIcon: function sortUpIcon(index) { var _this9 = this; return createVNode("div", { "class": "_fc-group-btn _fc-group-arrow _fc-group-up", "onClick": function