-
Notifications
You must be signed in to change notification settings - Fork 917
/
handler.js
66 lines (54 loc) · 1.92 KB
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {Handler} from "@form-create/core";
import {$set, isUndef} from "@form-create/utils";
export function parseRule(rule) {
let props = rule.props;
if (!props.type) $set(props, 'type', 'input');
if (!props.icon) $set(props, 'icon', 'el-icon-upload2');
if (!props.height) $set(props, 'height', '370px');
if (isUndef(props.spin)) $set(props, 'spin', true);
if (!props.title) $set(props, 'title', '请选择' + rule.title);
if (!props.maxLength) $set(props, 'maxLength', 0);
if (!props.okBtnText) $set(props, 'okBtnText', '确定');
if (!props.closeBtnText) $set(props, 'closeBtnText', '关闭');
if (!props.modalTitle) $set(props, 'modalTitle', '预览');
let handleIcon = props.handleIcon;
if (props.type === 'file' && props.handleIcon === undefined)
handleIcon = false;
else
handleIcon = props.handleIcon === true || props.handleIcon === undefined ? 'el-icon-view' : props.handleIcon;
$set(props, 'handleIcon', handleIcon);
if (props.allowRemove === undefined) $set(props, 'allowRemove', true);
}
export default class handler extends Handler {
init() {
parseRule(this.rule);
}
toFormValue(value) {
let parseValue, oldValue = value, isArr = Array.isArray(oldValue);
if (oldValue === '')
parseValue = [];
else if (!isArr)
parseValue = [oldValue];
else
parseValue = oldValue;
this.parseValue = parseValue;
return parseValue;
}
toValue(parseValue) {
return this.rule.props.maxLength != 1
? parseValue
: (parseValue[0] === undefined
? ''
: parseValue[0]);
}
watchValue(n) {
super.watchValue(n);
this.render.onChange(n);
this.render.sync();
}
watchFormValue(n) {
super.watchFormValue(n);
this.parseValue = n;
this.render.sync();
}
}