-
Notifications
You must be signed in to change notification settings - Fork 917
/
handler.js
40 lines (33 loc) · 1.14 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
import {Handler} from "@form-create/core";
import {$set, dateFormat, isDate, isUndef, timeStampToDate} from "@form-create/utils";
export function getTime(date) {
return isDate(date)
? dateFormat('hh:mm:ss', date)
: date;
}
export default class handler extends Handler {
init() {
let props = this.rule.props;
if (!props.type) $set(props, 'type', 'time');
if (isUndef(props.confirm)) $set(props, 'confirm', true);
}
toFormValue(value) {
let parseValue, isArr = Array.isArray(value);
if ('timerange' === this.rule.props.type) {
if (isArr) {
parseValue = value.map((time) => !time ? '' : getTime(timeStampToDate(time)));
} else {
parseValue = ['', ''];
}
} else {
isArr && (value = value[0]);
parseValue = !value ? '' : getTime(timeStampToDate(value));
}
return parseValue;
}
mounted() {
super.mounted();
this.rule.value = this.el.publicStringValue;
this.vm._changeFormData(this.field, this.toFormValue(this.el.publicStringValue));
}
}