@ecolovo/uniapp-components 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/components/aspect/aspect.vue +43 -0
  2. package/components/badge/badge.vue +88 -0
  3. package/components/button/button.vue +409 -0
  4. package/components/checkbox/checkbox.vue +183 -0
  5. package/components/checkbox-group/checkbox-group.vue +101 -0
  6. package/components/checkbox-group2/checkbox-group2.vue +138 -0
  7. package/components/checkbox-group2/checkbox.vue +103 -0
  8. package/components/data-list/data-list.vue +130 -0
  9. package/components/date-picker/date-picker-view.vue +181 -0
  10. package/components/date-picker/date-picker.vue +237 -0
  11. package/components/datetime-picker/datetime-picker-view.vue +209 -0
  12. package/components/datetime-picker/datetime-picker.vue +235 -0
  13. package/components/dialog/dialog-content.vue +162 -0
  14. package/components/dialog/dialog.vue +166 -0
  15. package/components/dropdown/dropdown.vue +145 -0
  16. package/components/empty/empty.vue +102 -0
  17. package/components/flex/flex.vue +76 -0
  18. package/components/form/form.vue +43 -0
  19. package/components/form/mixin.js +13 -0
  20. package/components/form-item/form-item.vue +141 -0
  21. package/components/icon/icon.vue +114 -0
  22. package/components/image/image.vue +61 -0
  23. package/components/input/input.vue +154 -0
  24. package/components/input/password-input.vue +95 -0
  25. package/components/list-page/list-page.js +10 -0
  26. package/components/list-page/list-page.vue +150 -0
  27. package/components/load-more/load-more.vue +97 -0
  28. package/components/loading/animations/loading-animation1.vue +92 -0
  29. package/components/loading/animations/loading-animation2.vue +28 -0
  30. package/components/loading/animations/loading-animation3.vue +81 -0
  31. package/components/loading/animations/loading-animation4.vue +74 -0
  32. package/components/loading/loading.vue +91 -0
  33. package/components/message-box/message-box.vue +60 -0
  34. package/components/number-dialog/number-dialog.vue +360 -0
  35. package/components/number-input/number-input.vue +352 -0
  36. package/components/numpad/numpad.vue +224 -0
  37. package/components/page/page-body.vue +227 -0
  38. package/components/page/page-footer.vue +75 -0
  39. package/components/page/page-header.vue +222 -0
  40. package/components/page/page.vue +128 -0
  41. package/components/picker/picker-popup.vue +295 -0
  42. package/components/picker/picker.vue +151 -0
  43. package/components/popover/popover-content.vue +255 -0
  44. package/components/popover/popover-mask.vue +113 -0
  45. package/components/popover/popover.vue +84 -0
  46. package/components/popup/popup-content.vue +162 -0
  47. package/components/popup/popup.vue +168 -0
  48. package/components/price/price.vue +104 -0
  49. package/components/search/search.vue +220 -0
  50. package/components/searching/searching.vue +86 -0
  51. package/components/selector/selector.vue +86 -0
  52. package/components/switch/switch.vue +180 -0
  53. package/components/tab/tab.vue +235 -0
  54. package/components/table/table.vue +112 -0
  55. package/components/textarea/textarea.vue +192 -0
  56. package/components/time-picker/time-picker-view.vue +127 -0
  57. package/components/time-picker/time-picker.vue +140 -0
  58. package/components/uploader/download.js +81 -0
  59. package/components/uploader/file-uploader.vue +52 -0
  60. package/components/uploader/files.js +225 -0
  61. package/components/uploader/media-uploader.vue +133 -0
  62. package/components/uploader/mixin.js +106 -0
  63. package/components/uploader/uni.js +38 -0
  64. package/components/uploader/upload-button.vue +29 -0
  65. package/components/uploader/uploader copy.vue +547 -0
  66. package/components/uploader/uploader.vue +117 -0
  67. package/configs/index.js +41 -0
  68. package/easyCom.js +25 -0
  69. package/init.js +17 -0
  70. package/mixins/componentName.js +32 -0
  71. package/mixins/listPage.js +1 -0
  72. package/mixins/windowInfo.js +1 -0
  73. package/package.json +12 -0
  74. package/resources/iconfont/uniapp_ui_icon/demo.css +539 -0
  75. package/resources/iconfont/uniapp_ui_icon/demo_index.html +555 -0
  76. package/resources/iconfont/uniapp_ui_icon/iconfont.css +78 -0
  77. package/resources/iconfont/uniapp_ui_icon/iconfont.js +1 -0
  78. package/resources/iconfont/uniapp_ui_icon/iconfont.json +121 -0
  79. package/resources/iconfont/uniapp_ui_icon/iconfont.woff2 +0 -0
  80. package/resources/image/empty.svg +13 -0
  81. package/styles/global.scss +24 -0
  82. package/styles/index.scss +2 -0
  83. package/styles/utils/css-var.scss +87 -0
  84. package/styles/utils/ellipsis.scss +26 -0
  85. package/styles/utils/global-var.scss +11 -0
  86. package/styles/utils/index.scss +5 -0
  87. package/styles/utils/selector.scss +5 -0
  88. package/styles/utils/z-index.scss +10 -0
  89. package/styles/var/component.scss +242 -0
  90. package/styles/var/index.scss +2 -0
  91. package/styles/var/theme.scss +40 -0
  92. package/utils/date.js +151 -0
  93. package/utils/floor.js +20 -0
  94. package/utils/freezeDeep.js +19 -0
  95. package/utils/price.js +32 -0
  96. package/utils/round.js +22 -0
  97. package/utils/windowInfo.js +77 -0
@@ -0,0 +1,237 @@
1
+ <template>
2
+ <view :class="componentClassNames">
3
+ <selector-cpn
4
+ :value="showText"
5
+ :readonly="isReadonly"
6
+ :disabled="disabled"
7
+ :placeholder="placeholder"
8
+ @click="showPicker"
9
+ >
10
+ <slot>{{ showText }}</slot>
11
+ </selector-cpn>
12
+
13
+ <!-- 选择器弹框 -->
14
+ <popup-cpn
15
+ v-if="isShowPopup"
16
+ ref="popup"
17
+ v-model="isShowPopup"
18
+ :cancel="false"
19
+ title="选择日期"
20
+ @click.native.stop.prevent="doNothing"
21
+ @confirm="onConfirm"
22
+ >
23
+ <view v-if="range" :class="$style['DatePicker--date-selector']">
24
+ <view
25
+ :class="[
26
+ $style['DatePicker--date-input'],
27
+ { [$style['DatePicker--date-checked']]: 'start' === checkedDateType },
28
+ ]"
29
+ @click="selectDateType('start')"
30
+ >
31
+ {{ startStr }}
32
+ </view>
33
+ <text :class="$style['DatePicker--date-separator']">至</text>
34
+ <view
35
+ :class="[
36
+ $style['DatePicker--date-input'],
37
+ { [$style['DatePicker--date-checked']]: 'end' === checkedDateType },
38
+ ]"
39
+ @click="selectDateType('end')"
40
+ >
41
+ {{ endStr }}
42
+ </view>
43
+ </view>
44
+
45
+ <view v-show="checkedDateType === 'start'">
46
+ <date-picker-view-cpn v-model="startStr" :min="min" :max="max" @change="onChangeStart" />
47
+ </view>
48
+ <view v-if="range" v-show="checkedDateType === 'end'">
49
+ <date-picker-view-cpn v-model="endStr" :min="min" :max="max" @change="onChangeEnd" />
50
+ </view>
51
+ </popup-cpn>
52
+ </view>
53
+ </template>
54
+
55
+ <script>
56
+ import componentName from '../../mixins/componentName';
57
+ import { isFormReadonly } from '../form/mixin';
58
+ import { formatDate, toDate } from '../../utils/date';
59
+ import PopupCpn from '../popup/popup.vue';
60
+ import SelectorCpn from '../selector/selector.vue';
61
+ import DatePickerViewCpn from './date-picker-view.vue';
62
+
63
+ export default {
64
+ name: 'AppDatePicker',
65
+ options: {
66
+ virtualHost: true,
67
+ styleIsolation: 'shared',
68
+ },
69
+ components: { PopupCpn, SelectorCpn, DatePickerViewCpn },
70
+ mixins: [componentName, isFormReadonly],
71
+ props: {
72
+ /** 绑定值 */
73
+ value: {
74
+ type: [String, null, Array],
75
+ default: null,
76
+ },
77
+ /** 是否禁用 */
78
+ disabled: {
79
+ type: Boolean,
80
+ default: false,
81
+ },
82
+ /** 是否只读 */
83
+ readonly: {
84
+ type: Boolean,
85
+ default: false,
86
+ },
87
+ /** 占位文本 */
88
+ placeholder: {
89
+ type: String,
90
+ default: '请选择',
91
+ },
92
+ /** 是选择日期范围 */
93
+ range: {
94
+ type: Boolean,
95
+ default: false,
96
+ },
97
+ /** 是否在选择开始日期时,同步修改结束日期,且保持时间差 */
98
+ keepDiff: {
99
+ type: Boolean,
100
+ default: false,
101
+ },
102
+ /** 结束日期是否可以与开始日期相同 */
103
+ canSame: {
104
+ type: Boolean,
105
+ default: true,
106
+ },
107
+ /** 在选择的日期后面拼接时间字符串,如果传入的是数组,会分别对应添加到范围日期值后 */
108
+ timeAppend: {
109
+ type: [String, Array],
110
+ default: '',
111
+ },
112
+ /** 最小日期 */
113
+ min: {
114
+ type: String,
115
+ default: '',
116
+ },
117
+ /** 最大日期 */
118
+ max: {
119
+ type: String,
120
+ default: '',
121
+ },
122
+ },
123
+ data() {
124
+ return {
125
+ /** 选择框是否可见 */
126
+ isShowPopup: false,
127
+ /** 开始日期 */
128
+ startStr: '',
129
+ /** 结束日期 */
130
+ endStr: '',
131
+ /** 当前选中的日期类型 */
132
+ checkedDateType: 'start',
133
+ };
134
+ },
135
+ computed: {
136
+ isReadonly() {
137
+ return this.readonly || this.isFormReadonly;
138
+ },
139
+ startDate() {
140
+ return formatDate(toDate(this.range && Array.isArray(this.value) ? this.value[0] : this.value));
141
+ },
142
+ endDate() {
143
+ return formatDate(toDate(this.range && Array.isArray(this.value) ? this.value[1] : ''));
144
+ },
145
+ showText() {
146
+ return this.range && this.startDate && this.endDate
147
+ ? `${this.startDate} 至 ${this.endDate}`
148
+ : this.startDate;
149
+ },
150
+ },
151
+ methods: {
152
+ doNothing() {},
153
+ /** 显示选择器弹出框 */
154
+ showPicker() {
155
+ if (this.disabled || this.isReadonly) {
156
+ return;
157
+ }
158
+
159
+ this.checkedDateType = 'start';
160
+
161
+ let [start, end] = [this.startDate, this.endDate];
162
+ this.startStr = start || formatDate(new Date());
163
+ this.endStr = end || formatDate(new Date(Date.now() + (this.canSame ? 0 : 8.64e7)));
164
+
165
+ this.isShowPopup = true;
166
+ this.$emit('show');
167
+ },
168
+ /** 选中日期类型 */
169
+ selectDateType(type) {
170
+ if (this.checkedDateType !== type) this.checkedDateType = type;
171
+ },
172
+ onChangeStart(dateStr) {
173
+ if (!this.range) return;
174
+
175
+ const timeDiff = toDate(this.endStr).getTime() - toDate(dateStr).getTime();
176
+ if (this.endStr <= dateStr || this.keepDiff) {
177
+ if (this.keepDiff) {
178
+ this.endStr = formatDate(new Date(toDate(dateStr).getTime() + timeDiff));
179
+ } else if (!this.canSame) {
180
+ this.endStr = formatDate(new Date(toDate(dateStr).getTime() + 8.64e7));
181
+ } else {
182
+ this.endStr = dateStr;
183
+ }
184
+ }
185
+ },
186
+ onChangeEnd(dateStr) {
187
+ if (dateStr <= this.startStr) {
188
+ if (this.canSame) {
189
+ this.endStr = this.startStr;
190
+ } else {
191
+ this.endStr = formatDate(new Date(toDate(this.startStr).getTime() + 8.64e7));
192
+ }
193
+ }
194
+ },
195
+ onConfirm() {
196
+ this.$refs.popup.close();
197
+ const startAppend = Array.isArray(this.timeAppend) ? this.timeAppend[0] : this.timeAppend;
198
+ const endAppend = Array.isArray(this.timeAppend) ? this.timeAppend[1] : this.timeAppend;
199
+ const start = startAppend ? `${this.startStr} ${startAppend}` : this.startStr;
200
+ const end = endAppend ? `${this.endStr} ${endAppend}` : this.endStr;
201
+ this.$emit('input', this.range ? [start, end] : start);
202
+ this.$emit('change', this.range ? [start, end] : start);
203
+ },
204
+ },
205
+ };
206
+ </script>
207
+
208
+ <style lang="scss" module>
209
+ @use '../../styles/index' as *;
210
+
211
+ .DatePicker {
212
+ width: 100%;
213
+ height: 100%;
214
+ }
215
+ .DatePicker--date-input {
216
+ flex: 1;
217
+ display: flex;
218
+ justify-content: center;
219
+ align-items: center;
220
+ height: 72rpx;
221
+ background: UTILS__GLOBAL_VAR(color, background);
222
+ border-radius: 12rpx;
223
+ transition: color 0.3s, background 0.3s;
224
+ &.DatePicker--date-checked {
225
+ background: UTILS__GLOBAL_VAR(theme, primary);
226
+ color: #fff;
227
+ }
228
+ }
229
+ .DatePicker--date-separator {
230
+ margin: 0 20rpx;
231
+ }
232
+ .DatePicker--date-selector {
233
+ margin-top: 20rpx;
234
+ display: flex;
235
+ align-items: center;
236
+ }
237
+ </style>
@@ -0,0 +1,209 @@
1
+ <template>
2
+ <picker-view
3
+ immediate-change
4
+ :value="pickerValue"
5
+ :class="componentClassNames"
6
+ @change="handlePickerChange"
7
+ @pickend="onPickEnd"
8
+ >
9
+ <picker-view-column>
10
+ <view v-for="item in yearOptions" :key="item" :class="$style['DatetimePickerView--option']">
11
+ {{ item }} 年
12
+ </view>
13
+ </picker-view-column>
14
+ <picker-view-column>
15
+ <view v-for="item in monthOptions" :key="item" :class="$style['DatetimePickerView--option']">
16
+ {{ item }} 月
17
+ </view>
18
+ </picker-view-column>
19
+ <picker-view-column>
20
+ <view v-for="item in dateOptions" :key="item" :class="$style['DatetimePickerView--option']">
21
+ {{ item }} 日
22
+ </view>
23
+ </picker-view-column>
24
+ <picker-view-column>
25
+ <view v-for="item in hourOptions" :key="item" :class="$style['DatetimePickerView--option']">
26
+ {{ item }} 时
27
+ </view>
28
+ </picker-view-column>
29
+ <picker-view-column v-if="minuteStep > 0">
30
+ <view v-for="item in minuteOptions" :key="item" :class="$style['DatetimePickerView--option']">
31
+ {{ item }} 分
32
+ </view>
33
+ </picker-view-column>
34
+ </picker-view>
35
+ </template>
36
+
37
+ <script>
38
+ import range from 'lodash-es/range';
39
+ import componentName from '../../mixins/componentName';
40
+ import { formatDate, toDate } from '../../utils/date';
41
+
42
+ /** 年份选项 */
43
+ const yearOptions = (function () {
44
+ const arr = [];
45
+ for (let i = 1900; i <= 2099; i++) {
46
+ arr.push(i);
47
+ }
48
+ return arr;
49
+ })();
50
+
51
+ /** 获取指定日期所在月份的日期选项列表 */
52
+ function getDateOptions(date) {
53
+ date = new Date(date);
54
+ date.setMonth(date.getMonth() + 1, 0);
55
+ const max = date.getDate();
56
+ return range(1, max + 1);
57
+ }
58
+
59
+ export default {
60
+ name: 'AppDatetimePickerView',
61
+ options: {
62
+ virtualHost: true,
63
+ styleIsolation: 'shared',
64
+ },
65
+ mixins: [componentName],
66
+ props: {
67
+ /** 绑定值 */
68
+ value: {
69
+ type: [String, null],
70
+ default: null,
71
+ },
72
+ /** 是否在选择开始日期时,同步修改结束日期,且保持时间差 */
73
+ keepDiff: {
74
+ type: Boolean,
75
+ default: false,
76
+ },
77
+ /** 结束日期是否可以与开始日期相同 */
78
+ canSame: {
79
+ type: Boolean,
80
+ default: false,
81
+ },
82
+ /** 最小日期 */
83
+ min: {
84
+ type: String,
85
+ default: '',
86
+ },
87
+ /** 最大日期 */
88
+ max: {
89
+ type: String,
90
+ default: '',
91
+ },
92
+ /** 分钟步长 */
93
+ minuteStep: {
94
+ type: Number,
95
+ default: 5,
96
+ },
97
+ },
98
+ data() {
99
+ return {
100
+ innerValue: '',
101
+ /** 年份选项列表 */
102
+ yearOptions: yearOptions,
103
+ /** 月份选项列表 */
104
+ monthOptions: range(1, 13),
105
+ /** 日期选项列表 */
106
+ dateOptions: [],
107
+ /** 小时选项列表 */
108
+ hourOptions: range(0, 24),
109
+ /** 分钟选项列表 */
110
+ minuteOptions: [],
111
+ /** picker-view 绑定值 */
112
+ pickerValue: [0, 0, 0, 0, 0],
113
+ };
114
+ },
115
+ computed: {
116
+ currentValue: {
117
+ get: function () {
118
+ return this.value === null ? this.innerValue : this.value;
119
+ },
120
+ set: function (value) {
121
+ this.$emit('input', value);
122
+ this.innerValue = value;
123
+ this.$emit('change', value);
124
+ },
125
+ },
126
+ },
127
+ created() {
128
+ this.minuteOptions = range(0, 60, this.minuteStep);
129
+ },
130
+ mounted() {
131
+ this.$nextTick(() => {
132
+ this.syncPickerValue(this.currentValue || new Date());
133
+ });
134
+ },
135
+ methods: {
136
+ /** 同步 picker-view 选中索引 */
137
+ syncPickerValue(date) {
138
+ const dateObj = toDate(date || new Date());
139
+ const [Y, M, D, h, m] = formatDate(dateObj, 'YYYY-MM-DD-HH-mm').split('-');
140
+ this.dateOptions = getDateOptions(dateObj);
141
+ const i1 = this.yearOptions.indexOf(Number(Y));
142
+ const i2 = this.monthOptions.indexOf(Number(M));
143
+ const i3 = this.dateOptions.indexOf(Number(D));
144
+ const i4 = this.hourOptions.indexOf(Number(h));
145
+ const i5 = Math.max(
146
+ this.minuteOptions.indexOf(Math.round(Number(m) / this.minuteStep) * this.minuteStep),
147
+ 0
148
+ );
149
+ this.$nextTick(() => {
150
+ this.pickerValue =
151
+ typeof this.pickerValue[0] === 'number'
152
+ ? [i1, i2, i3, i4, i5].map((item) => item.toString())
153
+ : [i1, i2, i3, i4, i5];
154
+ });
155
+ },
156
+ /** picker-view 选项值变化处理 */
157
+ handlePickerChange(e) {
158
+ const newPickerValue = e.detail.value;
159
+ /** 获取变化的列 */
160
+ const col = this.pickerValue.findIndex((item, index) => Number(item) !== Number(newPickerValue[index]));
161
+ const year = this.yearOptions[newPickerValue[0]];
162
+ const month = this.monthOptions[newPickerValue[1]];
163
+ // 如果改变的是年份或月份,需要重新获取日期列表
164
+ if (col === 0 || col === 1) {
165
+ this.dateOptions = getDateOptions(toDate(`${year}-${month}-01`));
166
+ newPickerValue[2] = Math.min(
167
+ newPickerValue[2] === -1 ? this.dateOptions.length - 1 : newPickerValue[2],
168
+ this.dateOptions.length - 1
169
+ );
170
+ }
171
+ const date = this.dateOptions[newPickerValue[2]];
172
+ const hour = this.hourOptions[newPickerValue[3]];
173
+ const minute = this.minuteStep >= 0 ? this.minuteOptions[newPickerValue[4]] : '00';
174
+
175
+ this.pickerValue = newPickerValue;
176
+ const dateValue = new Date(year, month - 1, date, hour, minute, 0, 0);
177
+ let dateStr = formatDate(dateValue, formatDate.DATE_MINUTE_WITH_YEAR);
178
+ if (this.min && dateStr < this.min) {
179
+ dateStr = this.min;
180
+ }
181
+ if (this.max && dateStr > this.max) {
182
+ dateStr = this.max;
183
+ }
184
+ this.currentValue = dateStr;
185
+ },
186
+ /** 滑动结束处理,保持选择器显示值与输入框值一致 */
187
+ onPickEnd() {
188
+ this.$nextTick(() => {
189
+ this.syncPickerValue(this.currentValue);
190
+ });
191
+ },
192
+ },
193
+ };
194
+ </script>
195
+
196
+ <style lang="scss" module>
197
+ @use '../../styles/index' as *;
198
+
199
+ .DatetimePickerView {
200
+ margin-top: 24rpx;
201
+ height: 300rpx;
202
+ }
203
+ .DatetimePickerView--option {
204
+ display: flex;
205
+ align-items: center;
206
+ justify-content: center;
207
+ white-space: nowrap;
208
+ }
209
+ </style>
@@ -0,0 +1,235 @@
1
+ <template>
2
+ <view :class="componentClassNames">
3
+ <selector-cpn
4
+ :value="showText"
5
+ :readonly="isReadonly"
6
+ :disabled="disabled"
7
+ :placeholder="placeholder"
8
+ @click="showPicker"
9
+ />
10
+
11
+ <!-- 选择器弹框 -->
12
+ <popup-cpn
13
+ v-if="isShowPopup"
14
+ ref="popup"
15
+ v-model="isShowPopup"
16
+ :cancel="false"
17
+ title="选择时间"
18
+ @click.native.stop.prevent="doNothing"
19
+ @confirm="onConfirm"
20
+ >
21
+ <view v-show="checkedDateType === 'start'">
22
+ <datetime-picker-view-cpn
23
+ v-model="startStr"
24
+ :min="min"
25
+ :max="max"
26
+ :minute-step="minuteStep"
27
+ @change="onChangeStart"
28
+ />
29
+ </view>
30
+ <view v-if="range" v-show="checkedDateType === 'end'">
31
+ <datetime-picker-view-cpn
32
+ v-model="endStr"
33
+ :min="min"
34
+ :max="max"
35
+ :minute-step="minuteStep"
36
+ @change="onChangeEnd"
37
+ />
38
+ </view>
39
+ </popup-cpn>
40
+ </view>
41
+ </template>
42
+
43
+ <script>
44
+ import componentName from '../../mixins/componentName';
45
+ import { isFormReadonly } from '../form/mixin';
46
+ import { formatDate, toDate } from '../../utils/date';
47
+ import PopupCpn from '../popup/popup.vue';
48
+ import SelectorCpn from '../selector/selector.vue';
49
+ import DatetimePickerViewCpn from './datetime-picker-view.vue';
50
+
51
+ const DATE_FORMAT = formatDate.DATE_MINUTE_WITH_YEAR;
52
+
53
+ export default {
54
+ name: 'AppDatetimePicker',
55
+ options: {
56
+ virtualHost: true,
57
+ styleIsolation: 'shared',
58
+ },
59
+ components: { PopupCpn, SelectorCpn, DatetimePickerViewCpn },
60
+ mixins: [componentName, isFormReadonly],
61
+ props: {
62
+ /** 绑定值 */
63
+ value: {
64
+ type: [String, null, Array],
65
+ default: null,
66
+ },
67
+ /** 是否禁用 */
68
+ disabled: {
69
+ type: Boolean,
70
+ default: false,
71
+ },
72
+ /** 是否只读 */
73
+ readonly: {
74
+ type: Boolean,
75
+ default: false,
76
+ },
77
+ /** 占位文本 */
78
+ placeholder: {
79
+ type: String,
80
+ default: '请选择',
81
+ },
82
+ /** 是否日期范围选择器 */
83
+ range: {
84
+ type: Boolean,
85
+ default: false,
86
+ },
87
+ /** 是否在选择开始日期时,同步修改结束日期,且保持时间差 */
88
+ keepDiff: {
89
+ type: Boolean,
90
+ default: false,
91
+ },
92
+ /** 结束日期是否可以与开始日期相同 */
93
+ canSame: {
94
+ type: Boolean,
95
+ default: true,
96
+ },
97
+ /** 在选择的日期后面拼接时间字符串,如果传入的是数组,会分别对应添加到范围日期值后 */
98
+ timeAppend: {
99
+ type: [String, Array],
100
+ default: '',
101
+ },
102
+ /** 最小日期 */
103
+ min: {
104
+ type: String,
105
+ default: '',
106
+ },
107
+ /** 最大日期 */
108
+ max: {
109
+ type: String,
110
+ default: '',
111
+ },
112
+ /** 分钟步长 */
113
+ minuteStep: {
114
+ type: Number,
115
+ default: 5,
116
+ },
117
+ },
118
+ data() {
119
+ return {
120
+ /** 选择框是否可见 */
121
+ isShowPopup: false,
122
+ /** 开始日期 */
123
+ startStr: '',
124
+ /** 结束日期 */
125
+ endStr: '',
126
+ /** 当前选中的日期类型 */
127
+ checkedDateType: 'start',
128
+ };
129
+ },
130
+ computed: {
131
+ isReadonly() {
132
+ return this.readonly || this.isFormReadonly;
133
+ },
134
+ startDate() {
135
+ return formatDate(
136
+ toDate(this.range && Array.isArray(this.value) ? this.value[0] : this.value),
137
+ DATE_FORMAT
138
+ );
139
+ },
140
+ endDate() {
141
+ return formatDate(toDate(this.range && Array.isArray(this.value) ? this.value[1] : ''), DATE_FORMAT);
142
+ },
143
+ showText() {
144
+ return this.range && this.startDate && this.endDate
145
+ ? `${this.startDate} 至 ${this.endDate}`
146
+ : this.startDate;
147
+ },
148
+ },
149
+ methods: {
150
+ doNothing() {},
151
+ /** 显示选择器弹出框 */
152
+ showPicker() {
153
+ if (this.disabled || this.isReadonly) {
154
+ return;
155
+ }
156
+
157
+ this.checkedDateType = 'start';
158
+
159
+ let [start, end] = [this.startDate, this.endDate];
160
+ this.startStr = start || formatDate(new Date(), DATE_FORMAT);
161
+ this.endStr = end || formatDate(new Date(Date.now() + (this.canSame ? 0 : 8.64e7)), DATE_FORMAT);
162
+
163
+ this.isShowPopup = true;
164
+ this.$emit('show');
165
+ },
166
+ /** 选中日期类型 */
167
+ selectDateType(type) {
168
+ if (this.checkedDateType !== type) this.checkedDateType = type;
169
+ },
170
+ onChangeStart(dateStr) {
171
+ if (!this.range) return;
172
+
173
+ const timeDiff = toDate(this.endStr).getTime() - toDate(dateStr).getTime();
174
+ if (this.endStr <= dateStr || this.keepDiff) {
175
+ if (this.keepDiff) {
176
+ this.endStr = formatDate(new Date(toDate(dateStr).getTime() + timeDiff), DATE_FORMAT);
177
+ } else if (!this.canSame) {
178
+ this.endStr = formatDate(new Date(toDate(dateStr).getTime() + 8.64e7), DATE_FORMAT);
179
+ } else {
180
+ this.endStr = dateStr;
181
+ }
182
+ }
183
+ },
184
+ onChangeEnd(dateStr) {
185
+ if (dateStr <= this.startStr) {
186
+ if (this.canSame) {
187
+ this.endStr = this.startStr;
188
+ } else {
189
+ this.endStr = formatDate(new Date(toDate(this.startStr).getTime() + 8.64e7), DATE_FORMAT);
190
+ }
191
+ }
192
+ },
193
+ onConfirm() {
194
+ this.$refs.popup.close();
195
+ const startAppend = Array.isArray(this.timeAppend) ? this.timeAppend[0] : this.timeAppend;
196
+ const endAppend = Array.isArray(this.timeAppend) ? this.timeAppend[1] : this.timeAppend;
197
+ const start = startAppend ? `${this.startStr} ${startAppend}` : this.startStr;
198
+ const end = endAppend ? `${this.endStr} ${endAppend}` : this.endStr;
199
+ this.$emit('input', this.range ? [start, end] : start);
200
+ this.$emit('change', this.range ? [start, end] : start);
201
+ },
202
+ },
203
+ };
204
+ </script>
205
+
206
+ <style lang="scss" module>
207
+ @use '../../styles/index' as *;
208
+
209
+ .DatetimePicker {
210
+ width: 100%;
211
+ height: 100%;
212
+ }
213
+ .DatetimePicker--date-input {
214
+ flex: 1;
215
+ display: flex;
216
+ justify-content: center;
217
+ align-items: center;
218
+ height: 72rpx;
219
+ background: UTILS__GLOBAL_VAR(color, background);
220
+ border-radius: 12rpx;
221
+ transition: color 0.3s, background 0.3s;
222
+ &.DatetimePicker--date-checked {
223
+ background: UTILS__GLOBAL_VAR(theme, primary);
224
+ color: #fff;
225
+ }
226
+ }
227
+ .DatetimePicker--date-separator {
228
+ margin: 0 20rpx;
229
+ }
230
+ .DatetimePicker--date-selector {
231
+ margin-top: 20rpx;
232
+ display: flex;
233
+ align-items: center;
234
+ }
235
+ </style>