forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.js
More file actions
96 lines (82 loc) · 1.76 KB
/
shared.js
File metadata and controls
96 lines (82 loc) · 1.76 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { times } from './utils';
import { padZero } from '../utils/format/string';
import { pickerProps } from '../picker/shared';
import Picker from '../picker';
export const sharedProps = {
...pickerProps,
value: null,
filter: Function,
showToolbar: {
type: Boolean,
default: true
},
formatter: {
type: Function,
default: (type, value) => value
}
};
export const TimePickerMixin = {
data() {
return {
innerValue: this.formatValue(this.value)
};
},
computed: {
originColumns() {
return this.ranges.map(({ type, range: rangeArr }) => {
let values = times(rangeArr[1] - rangeArr[0] + 1, index => {
const value = padZero(rangeArr[0] + index);
return value;
});
if (this.filter) {
values = this.filter(type, values);
}
return {
type,
values
};
});
},
columns() {
return this.originColumns.map(column => ({
values: column.values.map(value => this.formatter(column.type, value))
}));
}
},
watch: {
columns: 'updateColumnValue',
innerValue(val) {
this.$emit('input', val);
}
},
mounted() {
this.updateColumnValue();
this.$nextTick(() => {
this.updateInnerValue();
});
},
methods: {
onConfirm() {
this.$emit('confirm', this.innerValue);
},
onCancel() {
this.$emit('cancel');
}
},
render() {
const props = {};
Object.keys(pickerProps).forEach(key => {
props[key] = this[key];
});
return (
<Picker
ref="picker"
columns={this.columns}
onChange={this.onChange}
onConfirm={this.onConfirm}
onCancel={this.onCancel}
{...{ props }}
/>
);
}
};