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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
| <template>
| <uni-datetime-picker type="daterange" v-model="displayValue" :start="start" :end="end" :returnType="returnType"
| :placeholder="placeholder" :startPlaceholder="startPlaceholder" :endPlaceholder="endPlaceholder"
| :rangeSeparator="rangeSeparator" :border="border" :disabled="disabled" :clearIcon="clearIcon"
| @change="onChange" />
| </template>
|
| <script>
| import dayjs from "dayjs";
| export default {
| name: 'OIDatePickerRange',
| props: {
| modelValue: {
| type: [String, Number, Array, Date],
| default: ''
| },
| start: {
| type: [Number, String],
| default: ''
| },
| end: {
| type: [Number, String],
| default: ''
| },
| returnType: {
| type: String,
| default: 'string'
| },
| placeholder: {
| type: String,
| default: ''
| },
| startPlaceholder: {
| type: String,
| default: ''
| },
| endPlaceholder: {
| type: String,
| default: ''
| },
| rangeSeparator: {
| type: String,
| default: '-'
| },
| border: {
| type: [Boolean],
| default: true
| },
| disabled: {
| type: [Boolean],
| default: false
| },
| clearIcon: {
| type: [Boolean],
| default: true
| },
| format: {
| type: String,
| default: ''
| }
| },
| data() {
| return {
| displayValue: "",
| }
| },
| methods: {
| toDate(t) {
| if (!t) return undefined;
| else if (typeof t == "string") {
| if (t.includes(",")) return this.toDate(t.split(","));
| else return this.toDate([t, t]);
| } else if (t instanceof Array) {
| let dt = [];
| let d0 = t[0];
| let d1 = t[1];
| if (!d0 && !d1) return undefined;
| else if (!d0) return undefined;
| else if (!d1) d1 = d0;
|
| let dt0 = new Date(dayjs(d0).format("YYYY-MM-DD"));
| let dt1 = new Date(dayjs(d1).format("YYYY-MM-DD"));
| return [dt0, dt1];
| }
| },
| onChange(val) {
| if (val instanceof Array) {
| let format = "YYYY-MM-DD";
| if (this.format)
| format = this.format
| .replace(/y/g, "Y")
| .replace(/m/g, "M")
| .replace(/d/g, "D");
| let dt = [];
| let d0 = val[0];
| let d1 = val[1];
| if (!d0 && !d1) return undefined;
| else if (!d0) return undefined;
| else if (!d1) d1 = d0;
| let dt0 = dayjs(d0).format(format);
| let dt1 = dayjs(d1).format(format);
|
| this.$emit("update:modelValue", [dt0, dt1])
| this.$emit('input', [dt0, dt1])
| this.$emit("change", [dt0, dt1])
| }
| },
| },
| watch: {
| // #ifndef VUE3
| value(val) {
| this.displayValue = this.toDate(val);
| },
| // #endif
| // #ifdef VUE3
| modelValue(val) {
| this.displayValue = this.toDate(val);
| },
| // #endif
| },
|
| }
| </script>
|
| <style>
| </style>
|
|