| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- /*!
- * FormCreate 低代码表单渲染器
- * @form-create/component-elm-group v2.6.3
- * (c) 2018-2024 xaboy
- * Github https://github.com/xaboy/form-create
- * Site https://form-create.com/
- * Released under the MIT License.
- */
- (function(){"use strict";try{if(typeof document!="undefined"){var o=document.createElement("style");o.appendChild(document.createTextNode('._fc-group{display:flex;min-height:42px;justify-content:center;flex-direction:column}._fc-group-disabled ._fc-group-btn,._fc-group-disabled ._fc-group-add{cursor:not-allowed}._fc-group-handle{display:flex;flex-direction:row;position:absolute;bottom:-15px;right:30px;border-radius:15px;border:1px dashed #d9d9d9;padding:3px 8px;background-color:#fff}._fc-group-btn{cursor:pointer}._fc-group-idx{position:absolute;bottom:-15px;left:10px;width:30px;height:30px;display:flex;align-items:center;justify-content:center;background:#eee;border-radius:15px;font-weight:700}._fc-group-handle ._fc-group-btn+._fc-group-btn{margin-left:7px}._fc-group-container{position:relative;display:flex;flex-direction:column;border:1px dashed #d9d9d9;padding:20px 20px 25px;margin:5px 5px 25px;border-radius:5px}._fc-group-arrow{position:relative;width:20px;height:20px}._fc-group-arrow:before{content:"";position:absolute;top:8px;left:5px;width:9px;height:9px;border-left:2px solid #999;border-top:2px solid #999}._fc-group-arrow:before{transform:rotate(45deg)}._fc-group-arrow._fc-group-down{transform:rotate(180deg)}._fc-group-plus-minus{width:20px;height:20px;position:relative;cursor:pointer}._fc-group-plus-minus:before,._fc-group-plus-minus:after{content:"";position:absolute;top:50%;left:50%;width:60%;height:2px;background-color:#409eff;transform:translate(-50%,-50%)}._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{cursor:pointer;width:25px;height:25px;border:1px solid rgb(64 158 255 / 50%);border-radius:15px}._fc-group-add._fc-group-plus-minus:before,._fc-group-add._fc-group-plus-minus:after{width:50%}')),document.head.appendChild(o)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})();
- var O = Object.defineProperty;
- var g = Object.getOwnPropertySymbols;
- var R = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
- var _ = (e, t, r) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, d = (e, t) => {
- for (var r in t || (t = {}))
- R.call(t, r) && _(e, r, t[r]);
- if (g)
- for (var r of g(t))
- j.call(t, r) && _(e, r, t[r]);
- return e;
- };
- import A from "vue";
- function V(e) {
- return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
- }
- function p() {
- return p = Object.assign ? Object.assign.bind() : function(e) {
- for (var t, r = 1; r < arguments.length; r++) for (var s in t = arguments[r], t) Object.prototype.hasOwnProperty.call(t, s) && (e[s] = t[s]);
- return e;
- }, p.apply(this, arguments);
- }
- var S = ["attrs", "props", "domProps"], B = ["class", "style", "directives"], D = ["on", "nativeOn"], E = function(e) {
- return e.reduce(function(t, r) {
- for (var s in r) if (!t[s]) t[s] = r[s];
- else if (S.indexOf(s) !== -1) t[s] = p({}, t[s], r[s]);
- else if (B.indexOf(s) !== -1) {
- var i = t[s] instanceof Array ? t[s] : [t[s]], n = r[s] instanceof Array ? r[s] : [r[s]];
- t[s] = [].concat(i, n);
- } else if (D.indexOf(s) !== -1)
- for (var o in r[s]) if (t[s][o]) {
- var l = t[s][o] instanceof Array ? t[s][o] : [t[s][o]], f = r[s][o] instanceof Array ? r[s][o] : [r[s][o]];
- t[s][o] = [].concat(l, f);
- } else t[s][o] = r[s][o];
- else if (s === "hook") for (var u in r[s]) t[s][u] = t[s][u] ? I(t[s][u], r[s][u]) : r[s][u];
- else t[s] = r[s];
- return t;
- }, {});
- }, I = function(e, t) {
- return function() {
- e && e.apply(this, arguments), t && t.apply(this, arguments);
- };
- }, b = E;
- const k = /* @__PURE__ */ V(b), a = {
- type(e, t) {
- return Object.prototype.toString.call(e) === "[object " + t + "]";
- },
- Undef(e) {
- return e == null;
- },
- Element(e) {
- return typeof e == "object" && e !== null && e.nodeType === 1 && !a.Object(e);
- },
- trueArray(e) {
- return Array.isArray(e) && e.length > 0;
- },
- Function(e) {
- const t = this.getType(e);
- return t === "Function" || t === "AsyncFunction";
- },
- getType(e) {
- const t = Object.prototype.toString.call(e);
- return /^\[object (.*)\]$/.exec(t)[1];
- },
- empty(e) {
- return e == null || Array.isArray(e) && Array.isArray(e) && !e.length ? !0 : typeof e == "string" && !e;
- }
- };
- ["Date", "Object", "String", "Boolean", "Array", "Number"].forEach((e) => {
- a[e] = function(t) {
- return a.type(t, e);
- };
- });
- function w(e, t) {
- return {}.hasOwnProperty.call(e, t);
- }
- function h(e, t, r) {
- A.set(e, t, r);
- }
- function m(e, t = {}, r) {
- let s = !1;
- for (let i in t)
- if (Object.prototype.hasOwnProperty.call(t, i)) {
- let n = t[i];
- if ((s = Array.isArray(n)) || a.Object(n)) {
- let o = e[i] === void 0;
- if (s)
- s = !1, o && h(e, i, []);
- else if (n._clone && r !== void 0) {
- h(e, i, n._clone());
- continue;
- } else
- o && h(e, i, {});
- e[i] = m(e[i], n, r);
- } else
- h(e, i, n), a.Undef(n) || (a.Undef(n.__json) || (e[i].__json = n.__json), a.Undef(n.__origin) || (e[i].__origin = n.__origin));
- }
- return e;
- }
- function v(e) {
- return m({}, { value: e }).value;
- }
- const x = Object.assign || function(e) {
- for (let t, r = 1; r < arguments.length; r++)
- for (let s in t = arguments[r], t)
- Object.prototype.hasOwnProperty.call(t, s) && h(e, s, t[s]);
- return e;
- };
- function F() {
- return x.apply(this, arguments);
- }
- const P = "fcGroup", M = {
- name: P,
- props: {
- field: String,
- rule: [Array, Object],
- rules: Array,
- expand: Number,
- options: Object,
- formCreateInject: {
- type: Object,
- required: !0
- },
- button: {
- type: Boolean,
- default: !0
- },
- max: {
- type: Number,
- default: 0
- },
- min: {
- type: Number,
- default: 0
- },
- value: {
- type: Array,
- default: () => []
- },
- sortBtn: {
- type: Boolean,
- default: !0
- },
- defaultValue: Object,
- disabled: {
- type: Boolean,
- default: !1
- },
- syncDisabled: {
- type: Boolean,
- default: !0
- },
- onBeforeRemove: {
- type: Function,
- default: () => {
- }
- },
- onBeforeAdd: {
- type: Function,
- default: () => {
- }
- },
- parse: Function
- },
- data() {
- return {
- len: 0,
- cacheRule: {},
- cacheValue: {},
- sort: [],
- type: void 0
- };
- },
- computed: {
- formRule() {
- return this.rules ? this.rules : this.rule ? Array.isArray(this.rule) ? this.rule : [this.rule] : [];
- }
- },
- watch: {
- cacheRule: {
- handler(e) {
- this.sort = Object.keys(e);
- },
- immediate: !0
- },
- formRule: {
- handler(e, t) {
- Object.keys(this.cacheRule).forEach((r) => {
- const s = this.cacheRule[r];
- if (s.$f) {
- const i = s.$f.formData();
- if (e === t)
- s.$f.deferSyncValue(() => {
- m(s.rule, e), s.$f.setValue(i);
- }, !0);
- else {
- const n = s.$f.formData();
- s.$f.once("reloading", () => {
- s.$f.setValue(n);
- }), s.rule = v(e);
- }
- }
- });
- },
- deep: !0
- },
- expand(e) {
- let t = e - this.value.length;
- t > 0 && this.expandRule(t);
- },
- value(e, t) {
- e = e || [];
- let r = this.sort, s = r.length, i = s - e.length;
- if (i < 0) {
- for (let n = i; n < 0; n++)
- this.addRule(e.length + n);
- this.sort = Object.keys(this.cacheRule);
- for (let n = 0; n < s; n++)
- this.setValue(r[n], e[n]);
- } else {
- if (i > 0) {
- for (let n = 0; n < i; n++)
- this.removeRule(r[s - n - 1]);
- this.sort = Object.keys(this.cacheRule);
- }
- e.forEach((n, o) => {
- this.setValue(r[o], e[o]);
- });
- }
- }
- },
- methods: {
- _value(e) {
- return e && w(e, this.field) ? e[this.field] : e;
- },
- cache(e, t) {
- this.cacheValue[e] = JSON.stringify(t);
- },
- input(e) {
- this.$emit("input", e), this.$emit("change", e);
- },
- formData(e, t) {
- const r = this.cacheRule, s = this.sort;
- if (s.filter((n) => r[n].$f).length !== s.length)
- return;
- const i = s.map((n) => {
- const o = e === n ? t : d({}, this.cacheRule[n].$f.form), l = this.field ? o[this.field] || null : o;
- return this.cache(n, l), l;
- });
- this.input(i);
- },
- setValue(e, t) {
- const r = this.field, s = this.cacheRule[e].$f;
- r && (t = {
- [r]: this._value(t)
- }), this.cacheValue[e] !== JSON.stringify(r ? t[r] : t) && (this.cache(e, t), s && s.coverValue(t || {}));
- },
- addRule(e, t) {
- const r = this.formCreateInject.form.copyRules(this.formRule), s = this.options ? d({}, this.options) : {
- submitBtn: !1,
- resetBtn: !1
- };
- if (this.defaultValue) {
- s.formData || (s.formData = {});
- const i = v(this.defaultValue);
- F(s.formData, this.field ? {
- [this.field]: i
- } : i);
- }
- this.parse && this.parse({
- rule: r,
- options: s,
- index: this.sort.length
- }), this.$set(this.cacheRule, ++this.len, {
- rule: r,
- options: s
- }), t && this.$nextTick(() => this.$emit("add", r, Object.keys(this.cacheRule).length - 1));
- },
- add$f(e, t, r) {
- this.cacheRule[t].$f = r, this.$nextTick(() => {
- this.$emit("itemMounted", r, Object.keys(this.cacheRule).indexOf(t));
- });
- },
- removeRule(e, t) {
- const r = Object.keys(this.cacheRule).indexOf(e);
- this.$delete(this.cacheRule, e), this.$delete(this.cacheValue, e), t && this.$nextTick(() => this.$emit("remove", r));
- },
- add(e) {
- this.disabled || this.onBeforeAdd(this.value) === !1 || this.addRule(e, !0);
- },
- del(e, t) {
- if (this.disabled || this.onBeforeRemove(this.value, e) === !1)
- return;
- this.removeRule(t, !0);
- const r = [...this.value];
- r.splice(e, 1), this.input(r);
- },
- addIcon(e) {
- const t = this.$createElement;
- return t("div", {
- class: "_fc-group-btn _fc-group-plus-minus",
- on: {
- click: this.add
- }
- });
- },
- delIcon(e, t) {
- const r = this.$createElement;
- return r("div", {
- class: "_fc-group-btn _fc-group-plus-minus _fc-group-minus",
- on: {
- click: () => this.del(e, t)
- }
- });
- },
- sortUpIcon(e) {
- const t = this.$createElement;
- return t("div", {
- class: "_fc-group-btn _fc-group-arrow _fc-group-up",
- on: {
- click: () => this.changeSort(e, -1)
- }
- });
- },
- sortDownIcon(e) {
- const t = this.$createElement;
- return t("div", {
- class: "_fc-group-btn _fc-group-arrow _fc-group-down",
- on: {
- click: () => this.changeSort(e, 1)
- }
- });
- },
- changeSort(e, t) {
- const r = this.sort[e];
- this.$set(this.sort, e, this.sort[e + t]), this.sort[e + t] = r, this.formData(0);
- },
- makeIcon(e, t, r) {
- if (this.$scopedSlots.button)
- return this.$scopedSlots.button({
- total: e,
- index: t,
- vm: this,
- key: r,
- del: () => this.del(t, r),
- add: this.add
- });
- const s = [];
- return (!this.max || e < this.max) && e === t + 1 && s.push(this.addIcon(r)), e > this.min && s.push(this.delIcon(t, r)), this.sortBtn && t && s.push(this.sortUpIcon(t)), this.sortBtn && t !== e - 1 && s.push(this.sortDownIcon(t)), s;
- },
- emitEvent(e, t, r, s) {
- this.$emit(e, ...t, this.cacheRule[s].$f, r);
- },
- expandRule(e) {
- for (let t = 0; t < e; t++)
- this.value.push(this.field ? null : {});
- }
- },
- created() {
- this.type = this.formCreateInject.form.$form();
- const e = (this.expand || 0) - this.value.length;
- e > 0 && this.expandRule(e);
- for (let t = 0; t < this.value.length; t++)
- this.addRule(t);
- },
- render() {
- const e = arguments[0], t = this.sort, r = this.button, s = this.type, i = this.disabled, n = t.length === 0 ? this.$scopedSlots.default ? this.$scopedSlots.default({
- vm: this,
- add: this.add
- }) : e("div", {
- key: "a_def",
- class: "_fc-group-plus-minus _fc-group-add",
- on: {
- click: this.add
- }
- }) : t.map((o, l) => {
- const {
- rule: f,
- options: u
- } = this.cacheRule[o], y = r && !i ? this.makeIcon(t.length, l, o) : [];
- return e("div", {
- class: "_fc-group-container",
- key: o
- }, [e(s, k([{
- key: o
- }, {
- on: {
- "update:value": (c) => this.formData(o, c),
- "emit-event": (c, ...$) => this.emitEvent(c, $, l, o),
- input: (c) => this.add$f(l, o, c)
- }
- }, {}, {
- props: {
- disabled: i,
- inFor: !0,
- value: this.field ? {
- [this.field]: this._value(this.value[l])
- } : this.value[l],
- rule: f,
- option: u,
- extendOption: !0
- }
- }])), e("div", {
- class: "_fc-group-idx"
- }, [l + 1]), y.length ? e("div", {
- class: "_fc-group-handle"
- }, [y]) : null]);
- });
- return e("div", {
- key: "con",
- class: "_fc-group " + (i ? "_fc-group-disabled" : "")
- }, [n]);
- }
- };
- export {
- M as default
- };
|