@pi-form-create/component-subform
Version:
@pi-form-create 内置组件
117 lines (110 loc) • 3.8 kB
JavaScript
/*!
* @pi-form-create/component-subform v3.0.0-alpha.1
* (c) 2018-2025 xaboy
* Github https://github.com/xaboy/form-create with subform
* Released under the Apache-2.0 License.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('@pi-form-create/utils/lib/toline'), require('@pi-form-create/utils/lib/type')) :
typeof define === 'function' && define.amd ? define(['exports', 'vue', '@pi-form-create/utils/lib/toline', '@pi-form-create/utils/lib/type'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.FcSubForm = {}, global.Vue, null, global.is));
})(this, (function (exports, vue, toline, is) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var is__default = /*#__PURE__*/_interopDefaultLegacy(is);
const NAME = 'fcSubForm';
var Sub = vue.defineComponent({
name: NAME,
props: {
rule: Array,
options: {
type: Object,
default: () => vue.reactive({
submitBtn: false,
resetBtn: false
})
},
modelValue: {
type: Object,
default: () => ({})
},
disabled: {
type: [Boolean, undefined],
default: undefined
},
syncDisabled: {
type: Boolean,
default: true
},
formCreateInject: Object
},
data() {
return {
cacheValue: {},
subApi: {},
form: vue.markRaw(this.formCreateInject.form.$form())
};
},
emits: ['fc:subform', 'update:modelValue', 'change', 'itemMounted'],
watch: {
disabled(n) {
if (is__default["default"].Boolean(n)) {
this.syncDisabled && this.subApi.disabled(n);
}
},
modelValue(n) {
this.setValue(n);
}
},
methods: {
formData(value) {
this.cacheValue = JSON.stringify(value);
this.$emit('update:modelValue', value);
this.$emit('change', value);
},
setValue(value) {
const str = JSON.stringify(value);
if (this.cacheValue === str) {
return;
}
this.cacheValue = str;
this.subApi.coverValue(value || {});
},
add$f(api) {
this.subApi = api;
vue.nextTick(() => {
if (is__default["default"].Boolean(this.disabled)) {
this.syncDisabled && api.disabled(this.disabled);
}
this.$emit('itemMounted', api);
});
}
// emitEvent(name, ...args) {
// const {field, api} = this.formCreateInject
// const fieldKey = toLine(`${field}-${name}`);
// api.emit(fieldKey, ...args);
// },
// submit(...args){
// const {field, api} = this.formCreateInject
// const submitKey = toLine(`${field}-submit`);
// api.emit(submitKey, ...args);
// }
},
render() {
const Type = this.form;
return vue.createVNode(Type, {
"disabled": this.disabled,
"onUpdate:modelValue": this.formData,
"modelValue": this.modelValue,
"onEmit-event": this.$emit,
"onUpdate:api": this.add$f,
"rule": this.rule,
"option": this.options,
"extendOption": true,
"dataScope": this.formCreateInject.dataScope,
"utils": this.formCreateInject.utils
}, null);
}
});
exports["default"] = Sub;
Object.defineProperty(exports, '__esModule', { value: true });
}));