UNPKG

@caxa-form/core

Version:

vue动态表单,助你轻松搞定表单|form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON. Supports 3 UI frameworks, and supports the generation of any Vue components. Built-in 20

65 lines (60 loc) 1.47 kB
import mergeProps from '@caxa-form/utils/lib/mergeprops'; import unique from '@caxa-form/utils/lib/unique'; import extend from '@caxa-form/utils/lib/extend'; export function createManager(proto) { class CustomManager extends Manager { } Object.assign(CustomManager.prototype, proto); return CustomManager; } export default function Manager(handler) { extend(this, { $handle: handler, vm: handler.vm, options: {}, ref: 'fcForm', mergeOptionsRule: { normal: ['form', 'row', 'info', 'submitBtn', 'resetBtn'] } }); this.updateKey(); this.init(); } extend(Manager.prototype, { __init() { this.$render = this.$handle.$render; this.$r = (...args) => this.$render.renderRule(...args); }, updateKey() { this.key = unique(); }, //TODO interface init() { }, update() { }, beforeRender() { }, form() { return this.vm.$refs[this.ref]; }, mergeOptions(args, opt) { return mergeProps(args.map(v => this.tidyOptions(v)), opt, this.mergeOptionsRule); }, updateOptions(options) { this.options = this.mergeOptions([options], this.getDefaultOptions()); this.update(); }, tidyOptions(options) { return options; }, tidyRule(ctx) { }, mergeProp(ctx) { }, getDefaultOptions() { return {}; }, render(children) { } })