Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
col: parseCol(rule.col),
props: parseProps(rule.props),
emitEvent: parseEmit(rule.field, rule.emitPrefix, rule.emit, vm),
validate: parseArray(rule.validate),
options: parseArray(rule.options)
};
// parseRule.event = extend(rule.event, parseRule.emitEvent);
parseRule.on = parseOn(rule.on, parseRule.emitEvent);
Object.keys(parseRule).forEach(k => {
$set(rule, k, parseRule[k]);
});
if (!rule.field && !noVal) {
console.error('规则的 field 字段不能空' + errMsg());
}
return rule;
}
renderTemplate(parser) {
const {id, rule, key} = parser;
if (Vue.compile === undefined) {
console.error('使用的 Vue 版本不支持 compile' + errMsg());
return [];
}
if (!this.renderList[id]) {
let vm = rule.vm;
if (isUndef(rule.vm))
vm = new Vue;
else if (isFunction(rule.vm))
vm = rule.vm(this.$handle.getInjectData(rule));
this.renderList[id] = {
vm,
template: Vue.compile(rule.template)
};
}
if (_rule.__fc__) {
parser = _rule.__fc__;
if (parser.vm !== this.vm && !parser.deleted)
return console.error(`${_rule.type}规则正在其他的 中使用` + errMsg());
parser.update(this);
let rule = parser.rule;
this.parseOn(rule);
this.parseProps(rule);
} else {
parser = this.createParser(this.parseRule(_rule));
}
let children = parser.rule.children, rule = parser.rule;
if (!this.notField(parser.field))
return console.error(`${rule.field} 字段已存在` + errMsg());
this.setParser(parser);
if (!_rule.__fc__) {
bindParser(_rule, parser);
}
if (isValidChildren(children)) {
this.loadRule(children, true);
}
if (!child) {
this.sortList.push(parser.id);
}
if (!this.isNoVal(parser))
Object.defineProperty(parser.rule, 'value', {
append: (rule, after) => {
let fields = fc.fieldList, index = fields.indexOf(after);
if (rule.field && fields.indexOf(rule.field) !== -1)
return console.error(`${rule.field} 字段已存在` + errMsg());
if (isUndef(after)) {
index = fields.length;
} else if (index === -1)
return;
fc.rules.splice(index + 1, 0, rule);
},
prepend: (rule, after) => {
rules.map((_rule, index) => {
if (child && isString(_rule)) return;
if (!_rule.type)
return console.error('未定义生成规则的 type 字段' + errMsg());
let rule = getRule(_rule), handler;
if (_rule.__handler__) {
handler = _rule.__handler__;
if (handler.vm !== this.vm && !handler.deleted)
return console.error(`第${index + 1}条规则正在其他的 中使用` + errMsg());
handler.vm = this.vm;
handler.render.vm = this.vm;
handler.render.vNode.setVm(this.vm);
handler.refresh();
} else {
handler = getComponent(this, rule);
}
parse(form) {
let {type, rule, refName, key, noValue} = this.handler;
if (type === 'template' && rule.template) {
if (Vue.compile === undefined) {
console.error('使用的 Vue 版本不支持 compile' + errMsg());
return [];
}
if (isUndef(rule.vm)) rule.vm = new Vue;
let vn = Vue.compile(rule.template, {}).render.call(rule.vm);
if (vn.data === undefined) vn.data = {};
extend(vn.data, rule);
vn.key = key;
return [vn];
} else if (!noValue) {
return form.makeComponent(this.handler.render);
} else {
rule.ref = refName;
if (isUndef(rule.key))
valid(field) {
if (field !== this.handler.field)
throw new Error('无效的表单字段' + errMsg());
}