@form-create/tdesign
Version:
tdesign动态表单|form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON. Supports 5 UI frameworks, and supports the generation of any Vue components. Built-in 20 kinds
1,633 lines (1,459 loc) • 195 kB
JavaScript
/*!
* @form-create/tdesign v3.1.29
* (c) 2018-2024 xaboy
* Github https://github.com/xaboy/form-create
* Released under the MIT License.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue')) :
typeof define === 'function' && define.amd ? define(['exports', 'vue'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.formCreate = {}, global.Vue));
})(this, (function (exports, vue) { 'use strict';
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 _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
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 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__*/vue.createElementVNode("path", {
d: "M26 20h-2v4h-4v2h4v4h2v-4h4v-2h-4z",
fill: "currentColor"
}, null, -1);
var _hoisted_3$3 = /*#__PURE__*/vue.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 vue.openBlock(), vue.createElementBlock("svg", _hoisted_1$3, _hoisted_4$1);
}
script$3.render = render$3;
var IconFile = vue.defineComponent({
name: 'IconFile',
render: function render() {
return vue.h('svg', {
style: {
width: '20px',
fontSize: '20px'
},
viewBox: '0 0 24 24',
version: '1.1',
xmlns: 'http://www.w3.org/2000/svg'
}, vue.h('g', {
fill: 'none',
stroke: 'currentColor',
'stroke-width': '2',
'stroke-linecap': 'round',
'stroke-linejoin': 'round'
}, vue.h('path', {
d: 'M14 3v4a1 1 0 0 0 1 1h4'
}), vue.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__*/vue.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 vue.openBlock(), vue.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__*/vue.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 vue.openBlock(), vue.createElementBlock("svg", _hoisted_1$1, _hoisted_3$1);
}
script$1.render = render$1;
function _isSlot(s) {
return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
var NAME$5 = 'fcFrame';
var Frame = vue.defineComponent({
name: NAME$5,
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 = vue.resolveComponent(this.icon);
return vue.createVNode(vue.resolveComponent("t-input-adornment"), {
"append": function append() {
return vue.createVNode(Type, {
"onClick": _this.showModal,
"class": "_fc-frame-icon"
}, null);
}
}, {
"default": function _default() {
return [vue.createVNode(vue.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 vue.createVNode("div", {
"key": 2
}, [children]);
},
makeItem: function makeItem(index, children) {
return vue.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 vue.createVNode("div", {
"class": "_fc-upload-cover",
"key": 4
}, [icons]);
}
},
makeHandleIcon: function makeHandleIcon(val, index) {
var _this2 = this;
var Type = vue.resolveComponent(this.handleIcon === true || this.handleIcon === undefined ? 'EyeOutlined' : this.handleIcon);
return vue.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 vue.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, [vue.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, [vue.createVNode("img", {
"src": _this5.getSrc(src)
}, null), _this5.makeIcons(src, index)]);
}));
},
makeBtn: function makeBtn() {
var _this6 = this;
var Type = vue.resolveComponent(this.icon);
return vue.createVNode("div", {
"class": "_fc-upload-btn",
"onClick": function onClick() {
return _this6.showModal();
},
"key": 7
}, [vue.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(vue.createVNode(vue.resolveComponent("TButton"), {
"onClick": function onClick() {
return _this8.onCancel() !== false && _this8.closeModal(true);
}
}, _isSlot(closeBtnText) ? closeBtnText : {
"default": function _default() {
return [closeBtnText];
}
}));
if (okBtn) node.push(vue.createVNode(vue.resolveComponent("TButton"), {
"theme": "primary",
"onClick": function onClick() {
return _this8.onOk() !== false && _this8.closeModal();
}
}, _isSlot(okBtnText) ? okBtnText : {
"default": function _default() {
return [okBtnText];
}
}));
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;
vue.nextTick(function () {
if (_this9.$refs.frame) {
_this9.frameLoad(_this9.$refs.frame.contentWindow || {});
}
});
return vue.createVNode("div", {
"class": {
'_fc-frame': true,
'_fc-disabled': this.disabled
}
}, [Node, vue.createVNode(vue.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 [vue.createVNode("img", {
"style": "width: 100%",
"src": _this9.previewImage,
"key": 1
}, null)];
}
}), vue.createVNode(vue.resolveComponent("TDialog"), vue.mergeProps(_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 ? vue.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$4 = 'fcUpload';
function parseFile(file, i) {
return {
url: file,
name: getFileName(file),
status: 'success',
uid: i
};
}
function getFileName(file) {
return ('' + file).split('/').pop();
}
var Upload = vue.defineComponent({
name: NAME$4,
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,
"default": []
},
onSuccess: {
type: Function
},
onRemove: {
type: Function
}
},
emits: ['update:modelValue', 'fc.el'],
data: function data() {
return {
uploadList: toArray(this.modelValue).map(parseFile)
};
},
watch: {
modelValue: function modelValue(n) {
this.uploadList = toArray(n).map(parseFile);
}
},
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.url;
}));
}
},
render: function render() {
var uploadList = this.uploadList,
handleSuccess = this.handleSuccess,
handleRemove = this.handleRemove,
$slots = this.$slots;
return vue.createVNode(vue.Fragment, null, [vue.createVNode(vue.resolveComponent("t-upload"), vue.mergeProps({
"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%}";
styleInject(css_248z$1);
var NAME$3 = 'fcGroup';
var Group = vue.defineComponent({
name: NAME$3,
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
},
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: vue.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
},
disabled: function disabled(n) {
if (this.syncDisabled) {
var lst = this.cacheRule;
Object.keys(lst).forEach(function (k) {
lst[k].$f.disabled(n);
});
}
},
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 = Object.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].$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.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
};
if (emit) {
vue.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;
vue.nextTick(function () {
if (_this5.syncDisabled) {
$f.disabled(_this5.disabled);
}
_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];
if (emit) {
vue.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) {
if (this.disabled || false === this.onBeforeRemove(this.modelValue, index)) {
return;
}
this.removeRule(key, true);
var value = _toConsumableArray(this.modelValue);
value.splice(index, 1);
this.input(value);
},
addIcon: function addIcon(key) {
return vue.createVNode("div", {
"class": "_fc-group-btn _fc-group-plus-minus",
"onClick": this.add
}, null);
},
delIcon: function delIcon(index, key) {
var _this7 = this;
return vue.createVNode("div", {
"class": "_fc-group-btn _fc-group-plus-minus _fc-group-minus",
"onClick": function onClick() {
return _this7.del(index, key);
}
}, null);
},
sortUpIcon: function sortUpIcon(index) {
var _this8 = this;
return vue.createVNode("div", {
"class": "_fc-group-btn _fc-group-arrow _fc-group-up",
"onClick": function onClick() {
return _this8.changeSort(index, -1);
}
}, null);
},
sortDownIcon: function sortDownIcon(index) {
var _this9 = this;
return vue.createVNode("div", {
"class": "_fc-group-btn _fc-group-arrow _fc-group-down",
"onClick": function onClick() {
return _this9.changeSort(index, 1);
}
}, null);
},
changeSort: function changeSort(index, sort) {
var a = this.sort[index];
this.sort[index] = this.sort[index + sort];
this.sort[index + sort] = a;
this.formData(0);
},
makeIcon: function makeIcon(total, index, key) {
var _this10 = this;
if (this.$slots.button) {
return this.$slots.button({
total: total,
index: index,
vm: this,
key: key,
del: function del() {
return _this10.del(index, key);
},
add: this.add
});
}
var btn = [];
if ((!this.max || total < this.max) && total === index + 1) {
btn.push(this.addIcon(key));
}
if (total > this.min) {
btn.push(this.delIcon(index, key));
}
if (this.sortBtn && index) {
btn.push(this.sortUpIcon(index));
}
if (this.sortBtn && index !== total - 1) {
btn.push(this.sortDownIcon(index));
}
return btn;
},
emitEvent: function emitEvent(name, args, index, key) {
this.$emit.apply(this, [name].concat(_toConsumableArray(args), [this.cacheRule[key].$f, index]));
},
expandRule: function expandRule(n) {
for (var i = 0; i < n; i++) {
this.addRule(i);
}
}
},
created: function created() {
var _this11 = this;
vue.watch(function () {
return _objectSpread2({}, _this11.cacheRule);
}, function (n) {
_this11.sort = Object.keys(n);
}, {
immediate: true
});
var d = (this.expand || 0) - this.modelValue.length;
for (var i = 0; i < this.modelValue.length; i++) {
this.addRule(i);
}
if (d > 0) {
this.expandRule(d);
}
},
render: function render() {
var _this12 = this;
var keys = this.sort;
var button = this.button;
var Type = this.form;
var disabled = this.disabled;
var children = keys.length === 0 ? this.$slots["default"] ? this.$slots["default"]({
vm: this,
add: this.add
}) : vue.createVNode("div", {
"key": 'a_def',
"class": "_fc-group-plus-minus _fc-group-add fc-clock",
"onClick": this.add
}, null) : keys.map(function (key, index) {
var _this12$cacheRule$key = _this12.cacheRule[key],
rule = _this12$cacheRule$key.rule,
options = _this12$cacheRule$key.options;
var btn = button && !disabled ? _this12.makeIcon(keys.length, index, key) : [];
return vue.createVNode("div", {
"class": "_fc-group-container",
"key": key
}, [vue.createVNode(Type, vue.mergeProps({
"key": key
}, {
'onUpdate:modelValue': function onUpdateModelValue(formData) {
return _this12.formData(key, formData);
},
'onEmit-event': function onEmitEvent(name) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return _this12.emitEvent(name, args, index, key);
},
'onUpdate:api': function onUpdateApi($f) {
return _this12.add$f(index, key, $f);
},
inFor: true,
modelValue: _this12.field ? _defineProperty({}, _this12.field, _this12._value(_this12.modelValue[index])) : _this12.modelValue[index],
rule: rule,
option: options,
extendOption: true
}), null), vue.createVNode("div", {
"class": "_fc-group-idx"
}, [index + 1]), btn.length ? vue.createVNode("div", {
"class": "_fc-group-handle fc-clock"
}, [btn]) : null]);
});
return vue.createVNode("div", {
"key": 'con',
"class": '_fc-group ' + (disabled ? '_fc-group-disabled' : '')
}, [children]);
}
});
var NAME$2 = 'fcSubForm';
var Sub = vue.defineComponent({
name: NAME$2,
props: {
rule: Array,
options: {
type: Object,
"default": function _default() {
return vue.reactive({
submitBtn: false,
resetBtn: false
});
}
},
modelValue: {
type: Object,
"default": function _default() {
return {};
}
},
disabled: {
type: Boolean,
"default": false
},
syncDisabled: {
type: Boolean,
"default": true
},
formCreateInject: Object
},
data: function data() {
return {
cacheValue: {},
subApi: {},
form: vue.markRaw(this.formCreateInject.form.$form())
};
},
emits: ['fc:subform', 'update:modelValue', 'change', 'itemMounted'],
watch: {
disabled: function disabled(n) {
this.syncDisabled && this.subApi.disabled(n);
},
modelValue: function modelValue(n) {
this.setValue(n);
}
},
methods: {
formData: function formData(value) {
this.cacheValue = JSON.stringify(value);
this.$emit('update:modelValue', value);
this.$emit('change', value);
},
setValue: function setValue(value) {
var str = JSON.stringify(value);
if (this.cacheValue === str) {
return;
}
this.cacheValue = str;
this.subApi.coverValue(value || {});
},
add$f: function add$f(api) {
var _this = this;
this.subApi = api;
vue.nextTick(function () {
_this.syncDisabled && api.disabled(_this.disabled);
_this.$emit('itemMounted', api);
});
}
},
render: function render() {
var Type = this.form;
return vue.createVNode(Type, {
"onUpdate:modelValue": this.formData,
"modelValue": this.modelValue,
"onEmit-event": this.$emit,
"onUpdate:api": this.add$f,
"rule": this.rule,
"option": this.options,
"extendOption": true
}, null);
}
});
var script = {
name: 'QuestionCircleOutlined'
};
var _hoisted_1 = {
height: "1em",
width: "1em",
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 1024 1024"
};
var _hoisted_2 = /*#__PURE__*/vue.createElementVNode("path", {
d: "M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448s448-200.6 448-448S759.4 64 512 64zm0 820c-205.4 0-372-166.6-372-372s166.6-372 372-372s372 166.6 372 372s-166.6 372-372 372z",
fill: "currentColor"
}, null, -1);
var _hoisted_3 = /*#__PURE__*/vue.createElementVNode("path", {
d: "M623.6 316.7C593.6 290.4 554 276 512 276s-81.6 14.5-111.6 40.7C369.2 344 352 380.7 352 420v7.6c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V420c0-44.1 43.1-80 96-80s96 35.9 96 80c0 31.1-22 59.6-56.1 72.7c-21.2 8.1-39.2 22.3-52.1 40.9c-13.1 19-19.9 41.8-19.9 64.9V620c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8v-22.7a48.3 48.3 0 0 1 30.9-44.8c59-22.7 97.1-74.7 97.1-132.5c.1-39.3-17.1-76-48.3-103.3zM472 732a40 40 0 1 0 80 0a40 40 0 1 0-80 0z",
fill: "currentColor"
}, null, -1);
var _hoisted_4 = [_hoisted_2, _hoisted_3];
function render(_ctx, _cache, $props, $setup, $data, $options) {
return vue.openBlock(), vue.createElementBlock("svg", _hoisted_1, _hoisted_4);
}
script.render = render;
var components = [Frame, Upload, Group, Sub, script];
var NAME$1 = 'FormCreate';
var getRuleInject = function getRuleInject(vm, parent) {
if (!vm || vm === parent) {
return;
}
if (vm.props.formCreateInject) {
return vm.props.formCreateInject;
}
if (vm.parent) {
return getRuleInject(vm.parent, parent);
}
};
function $FormCreate(FormCreate, components, directives) {
return vue.defineComponent({
name: NAME$1,
components: components,
directives: directives,
props: {
rule: {
type: Array,
required: true,
"default": function _default() {
ret