sadais-piui 1.2.7-beta15 → 1.2.7-beta151

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 (75) hide show
  1. package/.prettierrc +8 -0
  2. package/components/pi-action-sheet/index.vue +260 -247
  3. package/components/pi-badge/index.vue +11 -1
  4. package/components/pi-bottom-bar/index.vue +1 -1
  5. package/components/pi-calendar/index.vue +207 -182
  6. package/components/pi-calendar-input/index.vue +61 -30
  7. package/components/pi-calendar-panel/components/calendar-days/index.vue +91 -52
  8. package/components/pi-calendar-panel/index.vue +28 -12
  9. package/components/pi-canvas/index.vue +8 -1
  10. package/components/pi-cascader/index.vue +601 -0
  11. package/components/pi-checkbox/index.vue +8 -4
  12. package/components/pi-checkbox-group/index.vue +12 -11
  13. package/components/pi-circle-progress/index.vue +53 -16
  14. package/components/pi-code-input/index.vue +11 -3
  15. package/components/pi-collapse/index.vue +16 -6
  16. package/components/pi-collapse-item/index.vue +35 -22
  17. package/components/pi-date-picker/index.vue +512 -391
  18. package/components/pi-date-picker-input/index.vue +61 -30
  19. package/components/pi-dropdown/components/dropdown-tab.vue +33 -23
  20. package/components/pi-dropdown/index.vue +34 -19
  21. package/components/pi-dropdown-item/index.vue +70 -58
  22. package/components/pi-form-item/index.vue +98 -20
  23. package/components/pi-grid/index.vue +1 -1
  24. package/components/pi-grid-item/index.vue +4 -4
  25. package/components/pi-img/index.vue +275 -267
  26. package/components/pi-img-cropper/index.vue +6 -3
  27. package/components/pi-input/index.vue +97 -36
  28. package/components/pi-list-item/index.vue +1 -1
  29. package/components/pi-marquee/index.vue +322 -310
  30. package/components/pi-marquee-pure-css/index.vue +267 -0
  31. package/components/pi-mask/index.vue +3 -1
  32. package/components/pi-modal/index.vue +311 -303
  33. package/components/pi-pagination/index.vue +13 -0
  34. package/components/pi-picker/index.vue +332 -317
  35. package/components/pi-popup/index.vue +4 -1
  36. package/components/pi-popup-select/index.vue +13 -4
  37. package/components/pi-radio/index.vue +12 -11
  38. package/components/pi-radio-group/index.vue +25 -5
  39. package/components/pi-regions-select/index.vue +6 -1
  40. package/components/pi-regions-select-input/index.vue +69 -31
  41. package/components/pi-search/index.vue +37 -2
  42. package/components/pi-section/index.vue +1 -1
  43. package/components/pi-select/index.vue +237 -22
  44. package/components/pi-select-input/index.vue +106 -41
  45. package/components/pi-stepper/index.vue +135 -121
  46. package/components/pi-steps/index.vue +115 -36
  47. package/components/pi-swiper/index.vue +22 -7
  48. package/components/pi-switch/index.vue +5 -1
  49. package/components/pi-table/index.vue +351 -0
  50. package/components/pi-tabs/index.vue +46 -10
  51. package/components/pi-upload-img/index.vue +895 -44
  52. package/components/pi-webview/index.vue +95 -82
  53. package/config/actionSheet.js +0 -1
  54. package/config/calendarInput.js +2 -1
  55. package/config/calendarPanel.js +2 -1
  56. package/config/cascader.js +22 -0
  57. package/config/circleProgress.js +12 -4
  58. package/config/codeInput.js +2 -1
  59. package/config/datePicker.js +29 -24
  60. package/config/datePickerInput.js +2 -1
  61. package/config/dropdown.js +3 -1
  62. package/config/input.js +5 -3
  63. package/config/marqueePureCss.js +18 -0
  64. package/config/regionsSelectInput.js +2 -1
  65. package/config/select.js +13 -1
  66. package/config/selectInput.js +2 -1
  67. package/config/steps.js +1 -1
  68. package/config/table.js +9 -0
  69. package/config/uploadImg.js +33 -11
  70. package/mixin/emitter.js +8 -1
  71. package/mixin/value-sync.js +5 -0
  72. package/package.json +5 -2
  73. package/scss/common.scss +11 -14
  74. package/scss/icon/icon.scss +2 -1
  75. package/scss/mixin.scss +5 -5
@@ -1,391 +1,512 @@
1
- <template>
2
- <pi-popup-select
3
- :value="val"
4
- :custom-style="getPopupSelect.customStyle"
5
- :custom-class="getPopupSelect.customClass"
6
- :height="getPopupSelect.height"
7
- :show-title="getPopupSelect.showTitle"
8
- :title="getPopupSelect.title"
9
- :title-padding="getPopupSelect.titlePadding"
10
- :toolbar-position="getPopupSelect.toolbarPosition"
11
- :on-confirm-close="getPopupSelect.onConfirmClose"
12
- :on-cancel-close="getPopupSelect.onCancelClose"
13
- :confirm-btn="getConfirmBtn"
14
- :cancel-btn="getCancelBtn"
15
- :popup="getPopup"
16
- @close="handlePopupClose"
17
- @cancel="handleCancel"
18
- @confirm="handleConfirm"
19
- >
20
- <slot name="header" />
21
- <picker-view
22
- v-if="val"
23
- class="pi-text-center pi-h-100P"
24
- :style="[customStyle]"
25
- :class="[customClass]"
26
- :indicator-style="indicatorStyle"
27
- :value="pickerValue"
28
- @pickstart="handlePickstart"
29
- @pickend="handlePickend"
30
- @change="handleDateChange"
31
- >
32
- <picker-view-column v-for="col in columns" :key="col.field">
33
- <view v-for="item in col.items" :key="item" :style="indicatorStyle">
34
- {{ item }}{{ col.unit }}
35
- </view>
36
- </picker-view-column>
37
- </picker-view>
38
- <slot name="footer" />
39
- </pi-popup-select>
40
- </template>
41
-
42
- <script>
43
- import ValueSync from '../../mixin/value-sync'
44
- import { getConfig } from '../../config'
45
-
46
- const TAG = 'PiDatePicker'
47
- const { datePicker } = getConfig()
48
- const FIELDS = ['year', 'month', 'day', 'hour', 'minute', 'second']
49
-
50
- export default {
51
- name: 'PiDatePicker',
52
- // 混入v-model
53
- mixins: [ValueSync],
54
- props: {
55
- // 是否显示弹窗
56
- value: {
57
- required: false
58
- },
59
- // 自定义样式
60
- customStyle: {
61
- type: Object,
62
- default() {
63
- // {}
64
- return datePicker.customStyle
65
- }
66
- },
67
- // 自定义样式类
68
- customClass: {
69
- type: String,
70
- default() {
71
- // ''
72
- return datePicker.customClass
73
- }
74
- },
75
- // 开始年份
76
- startYear: {
77
- type: [String, Number],
78
- default() {
79
- // 当前年份 - 30
80
- return datePicker.startYear
81
- }
82
- },
83
- // 结束年份
84
- endYear: {
85
- type: [String, Number],
86
- default() {
87
- // 当前年份
88
- return datePicker.endYear
89
- }
90
- },
91
- // 选择器的粒度
92
- field: {
93
- // `'year'` `'month'` `'day'` `'hour'` `'minute'` `'second'`
94
- type: String,
95
- validator: function(value) {
96
- // 这个值必须匹配下列字符串中的一个
97
- return FIELDS.includes(value)
98
- },
99
- // 'day'
100
- default() {
101
- return datePicker.field
102
- }
103
- },
104
- // 日期类型,date、datetime、time
105
- dateType: {
106
- // `'date'` `'datetime'` `'time'`
107
- type: String,
108
- validator: function(value) {
109
- return ['date', 'datetime', 'time'].includes(value)
110
- },
111
- // 'datetime'
112
- default() {
113
- return datePicker.dateType
114
- }
115
- },
116
- // 日期默认值
117
- defaultValue: {
118
- type: [Number, String, Date],
119
- // ''
120
- default: datePicker.defaultValue
121
- },
122
- // 单位数组,默认值:['年', '月', '日', '时', '分', '秒']
123
- units: {
124
- type: Array,
125
- default() {
126
- return datePicker.units
127
- }
128
- },
129
- // 返回的日期格式
130
- format: {
131
- type: String,
132
- // 'YYYY-MM-DD'
133
- default: datePicker.format
134
- },
135
- // 行高
136
- itemHeight: {
137
- type: [String, Number],
138
- // 110
139
- default: datePicker.itemHeight
140
- },
141
- // 行样式
142
- itemStyle: {
143
- type: Object,
144
- default() {
145
- // {}
146
- return datePicker.itemStyle
147
- }
148
- },
149
- // 是否显示item下边框
150
- showItemBottomBorder: {
151
- type: Boolean,
152
- // true
153
- default: datePicker.showItemBottomBorder
154
- },
155
- // 弹窗选择参数设置
156
- popupSelect: {
157
- type: Object,
158
- default() {
159
- // 参照popup
160
- return datePicker.popupSelect
161
- }
162
- },
163
- // 确认按钮配置
164
- confirmBtn: {
165
- type: Object,
166
- default() {
167
- return datePicker.confirmBtn
168
- }
169
- },
170
- // 取消按钮配置
171
- cancelBtn: {
172
- type: Object,
173
- default() {
174
- return datePicker.cancelBtn
175
- }
176
- },
177
- // 弹窗参数设置
178
- popup: {
179
- type: Object,
180
- default() {
181
- // 参照popup
182
- return datePicker.popup
183
- }
184
- }
185
- },
186
- data() {
187
- const date = this.$pi.date.parseDate(this.defaultValue)
188
- return {
189
- date,
190
- scrolling: false // picker是否在滚动中,小程序在scrolling中点确定,选择的项目不正确
191
- }
192
- },
193
- computed: {
194
- getPopupSelect() {
195
- return this.$pi.lang.mergeDeep(datePicker.popupSelect, this.popupSelect)
196
- },
197
- getConfirmBtn() {
198
- const datePickerConfirmBtn = this.$pi.lang.mergeDeep(
199
- datePicker.confirmBtn,
200
- this.popupSelect.confirmBtn
201
- )
202
- const mergeConfirmBtn = this.$pi.lang.mergeDeep(datePickerConfirmBtn, this.confirmBtn)
203
- if (!mergeConfirmBtn.disabled) {
204
- mergeConfirmBtn.disabled = this.scrolling
205
- }
206
- return mergeConfirmBtn
207
- },
208
- getCancelBtn() {
209
- const datePickerCancelBtn = this.$pi.lang.mergeDeep(
210
- datePicker.cancelBtn,
211
- this.popupSelect.cancelBtn
212
- )
213
- return this.$pi.lang.mergeDeep(datePickerCancelBtn, this.cancelBtn)
214
- },
215
- getPopup() {
216
- const datePickerPopup = this.$pi.lang.mergeDeep(datePicker.popup, this.popupSelect.popup)
217
- return this.$pi.lang.mergeDeep(datePickerPopup, this.popup)
218
- },
219
- options() {
220
- const watchs = ['startYear', 'endYear', 'field', 'defaultValue']
221
- const options = watchs
222
- .filter(d => this[d])
223
- .map(d => this[d].toString())
224
- .join('-')
225
- return options
226
- },
227
- getHeight() {
228
- return this.$pi.common.addUnit(this.height)
229
- },
230
- getTitlePadding() {
231
- return this.$pi.common.addUnit(this.titlePadding)
232
- },
233
- indicatorStyle() {
234
- const itemHeight = uni.upx2px(this.itemHeight)
235
- return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
236
- },
237
- getUnits() {
238
- return this.$pi.mergeDeep(datePicker.units, this.units, {
239
- arrayMerge: (target, source, options) => {
240
- return target.map((t, index) => source[index] || t)
241
- }
242
- })
243
- },
244
- columns() {
245
- const monthDays = new Date(this.date.year, this.date.month, 0).getDate()
246
- let columns = [
247
- {
248
- field: 'year',
249
- unit: this.getUnits[0],
250
- key: 'year',
251
- setMethod: 'setYear',
252
- items: this.$pi.common.generateArray(this.startYear, this.endYear)
253
- },
254
- {
255
- field: 'month',
256
- unit: this.getUnits[1],
257
- key: 'month',
258
- setMethod: 'setMonth',
259
- items: this.$pi.common.generateArray(1, 12)
260
- },
261
- {
262
- field: 'day',
263
- unit: this.getUnits[2],
264
- key: 'date',
265
- setMethod: 'setDate',
266
- items: this.$pi.common.generateArray(1, monthDays)
267
- },
268
- {
269
- field: 'hour',
270
- unit: this.getUnits[3],
271
- key: 'hour',
272
- setMethod: 'setHours',
273
- type: 'time',
274
- items: this.$pi.common.generateArray(0, 23)
275
- },
276
- {
277
- field: 'minute',
278
- unit: this.getUnits[4],
279
- key: 'minute',
280
- setMethod: 'setMinutes',
281
- type: 'time',
282
- items: this.$pi.common.generateArray(0, 59)
283
- },
284
- {
285
- field: 'second',
286
- unit: this.getUnits[5],
287
- key: 'second',
288
- setMethod: 'setSeconds',
289
- type: 'time',
290
- items: this.$pi.common.generateArray(0, 59)
291
- }
292
- ]
293
-
294
- columns = columns.filter((col, index) => {
295
- return FIELDS.slice(index).includes(this.field)
296
- })
297
-
298
- if (this.dateType === 'time') {
299
- columns = columns.filter(col => col.type === 'time')
300
- }
301
-
302
- return columns
303
- },
304
- pickerValue() {
305
- const pickerValue = []
306
- this.columns.forEach(col => {
307
- // 当前日期字段
308
- const value = this.date[col.key]
309
- if (value !== null) {
310
- // 查找当前picker中索引对应的真实值
311
- const intValue = parseInt(value, 10)
312
- const val = col.items.findIndex(m => m === intValue)
313
- pickerValue.push(val)
314
- }
315
- })
316
- return pickerValue
317
- }
318
- },
319
- watch: {
320
- // ! 因为使用对象,在H5端watch的时候,就算没有发生改变,也会触发,这里直接监听toString后的值
321
- options(val) {
322
- this.init()
323
- }
324
- },
325
- created() {
326
- this.init()
327
- },
328
- methods: {
329
- init() {
330
- this.date = this.$pi.date.parseDate(this.defaultValue)
331
- },
332
- handlePickstart() {
333
- this.scrolling = true
334
- },
335
- // 标识滑动结束
336
- handlePickend() {
337
- this.scrolling = false
338
- },
339
- handlePopupClose() {
340
- this.val = false
341
- // 关闭
342
- this.$emit('close')
343
- this.handleEmitChange()
344
- },
345
- handleDateChange(e) {
346
- const values = e.detail.value // values 返回的数组固定是picker的数量,只返回有变化的索引值
347
- const time = this.date.time // 取出当前date的实际时间
348
- values.forEach((value, index) => {
349
- if (value !== null) {
350
- // value为picker列的索引值
351
- const col = this.columns[index]
352
- let val = col.items[value] // 取出对应picker值
353
- if (col.field === 'month') val--
354
- time[col.setMethod](val) // 调用原生date方法赋值
355
- }
356
- })
357
- // 重新解析
358
- this.date = this.$pi.date.parseDate(time)
359
- },
360
- /**
361
- * @vuese
362
- * 取消选择
363
- */
364
- handleCancel() {
365
- /**
366
- * @vuese
367
- * 点击取消按钮时触发
368
- * @arg 当前选中的值 单选为对象,多选模式为数组
369
- */
370
- this.$emit('cancel')
371
- this.onCancelClose && this.handlePopupClose()
372
- },
373
- /**
374
- * @vuese
375
- * 确认选择
376
- */
377
- handleConfirm() {
378
- // 提交
379
- const value = this.format ? this.date.format(this.format) : this.date
380
- this.$emit('confirm', value)
381
- this.onConfirmClose && this.handlePopupClose()
382
- }
383
- }
384
- }
385
- </script>
386
-
387
- <style lang="scss" scoped>
388
- .pi-date-picker {
389
- height: 50vh;
390
- }
391
- </style>
1
+ <template>
2
+ <pi-popup-select
3
+ :value="val"
4
+ :custom-style="getPopupSelect.customStyle"
5
+ :custom-class="getPopupSelect.customClass"
6
+ :height="getPopupSelect.height"
7
+ :show-title="getPopupSelect.showTitle"
8
+ :title="getPopupSelect.title"
9
+ :title-padding="getPopupSelect.titlePadding"
10
+ :toolbar-position="getPopupSelect.toolbarPosition"
11
+ :on-confirm-close="getPopupSelect.onConfirmClose"
12
+ :on-cancel-close="getPopupSelect.onCancelClose"
13
+ :confirm-btn="getConfirmBtn"
14
+ :cancel-btn="getCancelBtn"
15
+ :popup="getPopup"
16
+ @close="handlePopupClose"
17
+ @cancel="handleCancel"
18
+ @confirm="handleConfirm"
19
+ @closed="$emit('closed', $event)"
20
+ @show="$emit('show', $event)"
21
+ @showed="$emit('showed', $event)"
22
+ >
23
+ <slot name="header" />
24
+ <picker-view
25
+ v-if="val"
26
+ class="pi-text-center pi-h-100P"
27
+ :style="[customStyle]"
28
+ :class="[customClass]"
29
+ :indicator-style="indicatorStyle"
30
+ :value="pickerValue"
31
+ @pickstart="handlePickstart"
32
+ @pickend="handlePickend"
33
+ @change="handleDateChange"
34
+ >
35
+ <picker-view-column v-for="col in columns" :key="col.field">
36
+ <view v-for="item in col.items" :key="item" :style="indicatorStyle">
37
+ {{ item }}{{ col.unit }}
38
+ </view>
39
+ </picker-view-column>
40
+ </picker-view>
41
+ <slot name="footer" />
42
+ </pi-popup-select>
43
+ </template>
44
+
45
+ <script>
46
+ import ValueSync from '../../mixin/value-sync'
47
+ import { getConfig } from '../../config'
48
+
49
+ const TAG = 'PiDatePicker'
50
+ const { datePicker } = getConfig()
51
+ const FIELDS = ['year', 'month', 'day', 'halfday', 'hour', 'minute', 'second']
52
+
53
+ export default {
54
+ name: 'PiDatePicker',
55
+ // 混入v-model
56
+ mixins: [ValueSync],
57
+ props: {
58
+ // 是否显示弹窗
59
+ value: {
60
+ required: false
61
+ },
62
+ // 自定义样式
63
+ customStyle: {
64
+ type: Object,
65
+ default() {
66
+ // {}
67
+ return datePicker.customStyle
68
+ }
69
+ },
70
+ // 自定义样式类
71
+ customClass: {
72
+ type: String,
73
+ default() {
74
+ // ''
75
+ return datePicker.customClass
76
+ }
77
+ },
78
+ // 开始年份
79
+ startYear: {
80
+ type: [String, Number],
81
+ default() {
82
+ // 当前年份 - 30
83
+ return datePicker.startYear
84
+ }
85
+ },
86
+ // 结束年份
87
+ endYear: {
88
+ type: [String, Number],
89
+ default() {
90
+ // 当前年份
91
+ return datePicker.endYear
92
+ }
93
+ },
94
+ // 选择器的粒度
95
+ field: {
96
+ // `'year'` `'month'` `'day'` `'hour'` `'minute'` `'second'`
97
+ type: String,
98
+ validator: function(value) {
99
+ // 这个值必须匹配下列字符串中的一个
100
+ return FIELDS.includes(value)
101
+ },
102
+ // 'day'
103
+ default() {
104
+ return datePicker.field
105
+ }
106
+ },
107
+ // 日期类型,date、datetime、time
108
+ dateType: {
109
+ // `'date'` `'datetime'` `'time'`
110
+ type: String,
111
+ validator: function(value) {
112
+ return ['date', 'datetime', 'time'].includes(value)
113
+ },
114
+ // 'datetime'
115
+ default() {
116
+ return datePicker.dateType
117
+ }
118
+ },
119
+ // 年份选项
120
+ yearOptions: {
121
+ type: Array,
122
+ default() {
123
+ // []
124
+ return datePicker.yearOptions
125
+ }
126
+ },
127
+ // 月份选项
128
+ monthOptions: {
129
+ type: Array,
130
+ default() {
131
+ // []
132
+ return datePicker.monthOptions
133
+ }
134
+ },
135
+ // 日期选项
136
+ dayOptions: {
137
+ type: Array,
138
+ default() {
139
+ // []
140
+ return datePicker.dayOptions
141
+ }
142
+ },
143
+ // 小时选项
144
+ hourOptions: {
145
+ type: Array,
146
+ default() {
147
+ // []
148
+ return datePicker.hourOptions
149
+ }
150
+ },
151
+ // 分钟选项
152
+ minuteOptions: {
153
+ type: Array,
154
+ default() {
155
+ // []
156
+ return datePicker.minuteOptions
157
+ }
158
+ },
159
+ // 日期默认值
160
+ defaultValue: {
161
+ type: [Number, String, Date],
162
+ // ''
163
+ default: datePicker.defaultValue
164
+ },
165
+ // 单位数组,默认值:['年', '月', '日', '时', '分', '秒']
166
+ units: {
167
+ type: Array,
168
+ default() {
169
+ return datePicker.units
170
+ }
171
+ },
172
+ // 返回的日期格式
173
+ format: {
174
+ type: String,
175
+ // 'YYYY-MM-DD'
176
+ default: datePicker.format
177
+ },
178
+ // 行高
179
+ itemHeight: {
180
+ type: [String, Number],
181
+ // 110
182
+ default: datePicker.itemHeight
183
+ },
184
+ // 行样式
185
+ itemStyle: {
186
+ type: Object,
187
+ default() {
188
+ // {}
189
+ return datePicker.itemStyle
190
+ }
191
+ },
192
+ // 是否显示item下边框
193
+ showItemBottomBorder: {
194
+ type: Boolean,
195
+ // true
196
+ default: datePicker.showItemBottomBorder
197
+ },
198
+ // 弹窗选择参数设置
199
+ popupSelect: {
200
+ type: Object,
201
+ default() {
202
+ // 参照popup
203
+ return datePicker.popupSelect
204
+ }
205
+ },
206
+ // 确认按钮配置
207
+ confirmBtn: {
208
+ type: Object,
209
+ default() {
210
+ return datePicker.confirmBtn
211
+ }
212
+ },
213
+ // 取消按钮配置
214
+ cancelBtn: {
215
+ type: Object,
216
+ default() {
217
+ return datePicker.cancelBtn
218
+ }
219
+ },
220
+ // 弹窗参数设置
221
+ popup: {
222
+ type: Object,
223
+ default() {
224
+ // 参照popup
225
+ return datePicker.popup
226
+ }
227
+ }
228
+ },
229
+ data() {
230
+ let date = this.$pi.date.parseDate(this.defaultValue)
231
+ if (this.field === 'halfday') {
232
+ const time = date.time
233
+ if (date.hour < 12) {
234
+ time.setHours(0)
235
+ } else {
236
+ time.setHours(12)
237
+ }
238
+ date = this.$pi.date.parseDate(time)
239
+ }
240
+ return {
241
+ date,
242
+ scrolling: false // picker是否在滚动中,小程序在scrolling中点确定,选择的项目不正确
243
+ }
244
+ },
245
+ computed: {
246
+ getPopupSelect() {
247
+ return this.$pi.lang.mergeDeep(datePicker.popupSelect, this.popupSelect)
248
+ },
249
+ getConfirmBtn() {
250
+ const datePickerConfirmBtn = this.$pi.lang.mergeDeep(
251
+ datePicker.confirmBtn,
252
+ this.popupSelect.confirmBtn
253
+ )
254
+ const mergeConfirmBtn = this.$pi.lang.mergeDeep(
255
+ datePickerConfirmBtn,
256
+ this.confirmBtn
257
+ )
258
+ if (!mergeConfirmBtn.disabled) {
259
+ mergeConfirmBtn.disabled = this.scrolling
260
+ }
261
+ return mergeConfirmBtn
262
+ },
263
+ getCancelBtn() {
264
+ const datePickerCancelBtn = this.$pi.lang.mergeDeep(
265
+ datePicker.cancelBtn,
266
+ this.popupSelect.cancelBtn
267
+ )
268
+ return this.$pi.lang.mergeDeep(datePickerCancelBtn, this.cancelBtn)
269
+ },
270
+ getPopup() {
271
+ const datePickerPopup = this.$pi.lang.mergeDeep(
272
+ datePicker.popup,
273
+ this.popupSelect.popup
274
+ )
275
+ return this.$pi.lang.mergeDeep(datePickerPopup, this.popup)
276
+ },
277
+ options() {
278
+ const watchs = ['val', 'startYear', 'endYear', 'field', 'defaultValue']
279
+ const options = watchs
280
+ .filter(d => this[d])
281
+ .map(d => this[d].toString())
282
+ .join('-')
283
+ return options
284
+ },
285
+ getHeight() {
286
+ return this.$pi.common.addUnit(this.height)
287
+ },
288
+ getTitlePadding() {
289
+ return this.$pi.common.addUnit(this.titlePadding)
290
+ },
291
+ indicatorStyle() {
292
+ const itemHeight = uni.upx2px(this.itemHeight)
293
+ return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
294
+ },
295
+ getUnits() {
296
+ return this.$pi.mergeDeep(datePicker.units, this.units, {
297
+ arrayMerge: (target, source, options) => {
298
+ return target.map((t, index) => source[index] || t)
299
+ }
300
+ })
301
+ },
302
+ getYearOptions() {
303
+ if (this.yearOptions && this.yearOptions.length > 0) {
304
+ return this.yearOptions
305
+ }
306
+ return this.$pi.common.generateArray(this.startYear, this.endYear)
307
+ },
308
+ getMonthOptions() {
309
+ if (this.monthOptions && this.monthOptions.length > 0) {
310
+ return this.monthOptions
311
+ }
312
+ return this.$pi.common.generateArray(1, 12)
313
+ },
314
+ getDayOptions() {
315
+ if (this.dayOptions && this.dayOptions.length > 0) {
316
+ return this.dayOptions
317
+ }
318
+ const monthDays = new Date(this.date.year, this.date.month, 0).getDate()
319
+ return this.$pi.common.generateArray(1, monthDays)
320
+ },
321
+ getHourOptions() {
322
+ if (this.hourOptions && this.hourOptions.length > 0) {
323
+ return this.hourOptions
324
+ }
325
+ return this.$pi.common.generateArray(0, 23)
326
+ },
327
+ getMinuteOptions() {
328
+ if (this.minuteOptions && this.minuteOptions.length > 0) {
329
+ return this.minuteOptions
330
+ }
331
+ return this.$pi.common.generateArray(0, 59)
332
+ },
333
+ columns() {
334
+ let columns = [
335
+ {
336
+ field: 'year',
337
+ unit: this.getUnits[0],
338
+ key: 'year',
339
+ setMethod: 'setYear',
340
+ items: this.getYearOptions
341
+ },
342
+ {
343
+ field: 'month',
344
+ unit: this.getUnits[1],
345
+ key: 'month',
346
+ setMethod: 'setMonth',
347
+ items: this.getMonthOptions
348
+ },
349
+ {
350
+ field: 'day',
351
+ unit: this.getUnits[2],
352
+ key: 'date',
353
+ setMethod: 'setDate',
354
+ items: this.getDayOptions
355
+ },
356
+ {
357
+ field: 'halfday',
358
+ unit: '',
359
+ key: 'hour',
360
+ setMethod: 'setHours',
361
+ items: ['上午', '下午']
362
+ },
363
+ {
364
+ field: 'hour',
365
+ unit: this.getUnits[3],
366
+ key: 'hour',
367
+ setMethod: 'setHours',
368
+ type: 'time',
369
+ items: this.getHourOptions
370
+ },
371
+ {
372
+ field: 'minute',
373
+ unit: this.getUnits[4],
374
+ key: 'minute',
375
+ setMethod: 'setMinutes',
376
+ type: 'time',
377
+ items: this.getMinuteOptions
378
+ },
379
+ {
380
+ field: 'second',
381
+ unit: this.getUnits[5],
382
+ key: 'second',
383
+ setMethod: 'setSeconds',
384
+ type: 'time',
385
+ items: this.$pi.common.generateArray(0, 59)
386
+ }
387
+ ]
388
+
389
+ columns = columns.filter((col, index) => {
390
+ return FIELDS.slice(index).includes(this.field)
391
+ })
392
+ if (this.field !== 'halfday') {
393
+ columns = columns.filter(col => col.field !== 'halfday')
394
+ }
395
+ if (this.dateType === 'time') {
396
+ columns = columns.filter(col => col.type === 'time')
397
+ }
398
+
399
+ return columns
400
+ },
401
+ pickerValue() {
402
+ const pickerValue = []
403
+ this.columns.forEach(col => {
404
+ // 当前日期字段
405
+ const value = this.date[col.key]
406
+ if (value !== null) {
407
+ // 查找当前picker中索引对应的真实值
408
+ if (col.field === 'halfday') {
409
+ const val = value < 12 ? 0 : 1
410
+ pickerValue.push(val)
411
+ } else {
412
+ const intValue = parseInt(value, 10)
413
+ const val = col.items.findIndex(m => m === intValue)
414
+ pickerValue.push(val)
415
+ }
416
+ }
417
+ })
418
+ return pickerValue
419
+ }
420
+ },
421
+ watch: {
422
+ // ! 因为使用对象,在H5端watch的时候,就算没有发生改变,也会触发,这里直接监听toString后的值
423
+ options(val) {
424
+ this.init()
425
+ }
426
+ },
427
+ created() {
428
+ this.init()
429
+ },
430
+ methods: {
431
+ init() {
432
+ this.date = this.$pi.date.parseDate(this.defaultValue)
433
+ if (this.field === 'halfday') {
434
+ const time = this.date.time
435
+ if (this.date.hour < 12) {
436
+ time.setHours(0)
437
+ } else {
438
+ time.setHours(12)
439
+ }
440
+ this.date = this.$pi.date.parseDate(time)
441
+ }
442
+ },
443
+ handlePickstart() {
444
+ this.scrolling = true
445
+ },
446
+ // 标识滑动结束
447
+ handlePickend() {
448
+ this.scrolling = false
449
+ },
450
+ handlePopupClose() {
451
+ this.val = false
452
+ // 关闭
453
+ this.$emit('close')
454
+ this.handleEmitChange()
455
+ },
456
+ handleDateChange(e) {
457
+ const values = e.detail.value // values 返回的数组固定是picker的数量,只返回有变化的索引值
458
+ const time = this.date.time // 取出当前date的实际时间
459
+ values.forEach((value, index) => {
460
+ if (value !== null) {
461
+ // value为picker列的索引值
462
+ const col = this.columns[index]
463
+ let val = col.items[value] // 取出对应picker值
464
+ if (col.field === 'month') val--
465
+ if (col.field === 'halfday') val = value === 0 ? 0 : 12
466
+ time[col.setMethod](val) // 调用原生date方法赋值
467
+ }
468
+ })
469
+ // 重新解析
470
+ this.date = this.$pi.date.parseDate(time)
471
+
472
+ this.$emit('scrollend', this.date)
473
+ },
474
+ /**
475
+ * @vuese
476
+ * 取消选择
477
+ */
478
+ handleCancel() {
479
+ /**
480
+ * @vuese
481
+ * 点击取消按钮时触发
482
+ * @arg 当前选中的值 单选为对象,多选模式为数组
483
+ */
484
+ this.$emit('cancel')
485
+ this.onCancelClose && this.handlePopupClose()
486
+ },
487
+ /**
488
+ * @vuese
489
+ * 确认选择
490
+ */
491
+ handleConfirm() {
492
+ // 提交
493
+ if (this.field === 'halfday') {
494
+ const time = this.date.time
495
+ time.setMinutes(0)
496
+ time.setSeconds(0)
497
+ time.setMilliseconds(0)
498
+ this.date = this.$pi.date.parseDate(time)
499
+ }
500
+ const value = this.format ? this.date.format(this.format) : this.date
501
+ this.$emit('confirm', value)
502
+ this.onConfirmClose && this.handlePopupClose()
503
+ }
504
+ }
505
+ }
506
+ </script>
507
+
508
+ <style lang="scss" scoped>
509
+ .pi-date-picker {
510
+ height: 50vh;
511
+ }
512
+ </style>