sadais-piui 1.2.7-beta70 → 1.2.7-beta71

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.
@@ -1,394 +1,464 @@
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', '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
- defaultValue: {
121
- type: [Number, String, Date],
122
- // ''
123
- default: datePicker.defaultValue
124
- },
125
- // 单位数组,默认值:['年', '月', '日', '时', '分', '秒']
126
- units: {
127
- type: Array,
128
- default() {
129
- return datePicker.units
130
- }
131
- },
132
- // 返回的日期格式
133
- format: {
134
- type: String,
135
- // 'YYYY-MM-DD'
136
- default: datePicker.format
137
- },
138
- // 行高
139
- itemHeight: {
140
- type: [String, Number],
141
- // 110
142
- default: datePicker.itemHeight
143
- },
144
- // 行样式
145
- itemStyle: {
146
- type: Object,
147
- default() {
148
- // {}
149
- return datePicker.itemStyle
150
- }
151
- },
152
- // 是否显示item下边框
153
- showItemBottomBorder: {
154
- type: Boolean,
155
- // true
156
- default: datePicker.showItemBottomBorder
157
- },
158
- // 弹窗选择参数设置
159
- popupSelect: {
160
- type: Object,
161
- default() {
162
- // 参照popup
163
- return datePicker.popupSelect
164
- }
165
- },
166
- // 确认按钮配置
167
- confirmBtn: {
168
- type: Object,
169
- default() {
170
- return datePicker.confirmBtn
171
- }
172
- },
173
- // 取消按钮配置
174
- cancelBtn: {
175
- type: Object,
176
- default() {
177
- return datePicker.cancelBtn
178
- }
179
- },
180
- // 弹窗参数设置
181
- popup: {
182
- type: Object,
183
- default() {
184
- // 参照popup
185
- return datePicker.popup
186
- }
187
- }
188
- },
189
- data() {
190
- const date = this.$pi.date.parseDate(this.defaultValue)
191
- return {
192
- date,
193
- scrolling: false // picker是否在滚动中,小程序在scrolling中点确定,选择的项目不正确
194
- }
195
- },
196
- computed: {
197
- getPopupSelect() {
198
- return this.$pi.lang.mergeDeep(datePicker.popupSelect, this.popupSelect)
199
- },
200
- getConfirmBtn() {
201
- const datePickerConfirmBtn = this.$pi.lang.mergeDeep(
202
- datePicker.confirmBtn,
203
- this.popupSelect.confirmBtn
204
- )
205
- const mergeConfirmBtn = this.$pi.lang.mergeDeep(datePickerConfirmBtn, this.confirmBtn)
206
- if (!mergeConfirmBtn.disabled) {
207
- mergeConfirmBtn.disabled = this.scrolling
208
- }
209
- return mergeConfirmBtn
210
- },
211
- getCancelBtn() {
212
- const datePickerCancelBtn = this.$pi.lang.mergeDeep(
213
- datePicker.cancelBtn,
214
- this.popupSelect.cancelBtn
215
- )
216
- return this.$pi.lang.mergeDeep(datePickerCancelBtn, this.cancelBtn)
217
- },
218
- getPopup() {
219
- const datePickerPopup = this.$pi.lang.mergeDeep(datePicker.popup, this.popupSelect.popup)
220
- return this.$pi.lang.mergeDeep(datePickerPopup, this.popup)
221
- },
222
- options() {
223
- const watchs = ['val', 'startYear', 'endYear', 'field', 'defaultValue']
224
- const options = watchs
225
- .filter(d => this[d])
226
- .map(d => this[d].toString())
227
- .join('-')
228
- return options
229
- },
230
- getHeight() {
231
- return this.$pi.common.addUnit(this.height)
232
- },
233
- getTitlePadding() {
234
- return this.$pi.common.addUnit(this.titlePadding)
235
- },
236
- indicatorStyle() {
237
- const itemHeight = uni.upx2px(this.itemHeight)
238
- return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
239
- },
240
- getUnits() {
241
- return this.$pi.mergeDeep(datePicker.units, this.units, {
242
- arrayMerge: (target, source, options) => {
243
- return target.map((t, index) => source[index] || t)
244
- }
245
- })
246
- },
247
- columns() {
248
- const monthDays = new Date(this.date.year, this.date.month, 0).getDate()
249
- let columns = [
250
- {
251
- field: 'year',
252
- unit: this.getUnits[0],
253
- key: 'year',
254
- setMethod: 'setYear',
255
- items: this.$pi.common.generateArray(this.startYear, this.endYear)
256
- },
257
- {
258
- field: 'month',
259
- unit: this.getUnits[1],
260
- key: 'month',
261
- setMethod: 'setMonth',
262
- items: this.$pi.common.generateArray(1, 12)
263
- },
264
- {
265
- field: 'day',
266
- unit: this.getUnits[2],
267
- key: 'date',
268
- setMethod: 'setDate',
269
- items: this.$pi.common.generateArray(1, monthDays)
270
- },
271
- {
272
- field: 'hour',
273
- unit: this.getUnits[3],
274
- key: 'hour',
275
- setMethod: 'setHours',
276
- type: 'time',
277
- items: this.$pi.common.generateArray(0, 23)
278
- },
279
- {
280
- field: 'minute',
281
- unit: this.getUnits[4],
282
- key: 'minute',
283
- setMethod: 'setMinutes',
284
- type: 'time',
285
- items: this.$pi.common.generateArray(0, 59)
286
- },
287
- {
288
- field: 'second',
289
- unit: this.getUnits[5],
290
- key: 'second',
291
- setMethod: 'setSeconds',
292
- type: 'time',
293
- items: this.$pi.common.generateArray(0, 59)
294
- }
295
- ]
296
-
297
- columns = columns.filter((col, index) => {
298
- return FIELDS.slice(index).includes(this.field)
299
- })
300
-
301
- if (this.dateType === 'time') {
302
- columns = columns.filter(col => col.type === 'time')
303
- }
304
-
305
- return columns
306
- },
307
- pickerValue() {
308
- const pickerValue = []
309
- this.columns.forEach(col => {
310
- // 当前日期字段
311
- const value = this.date[col.key]
312
- if (value !== null) {
313
- // 查找当前picker中索引对应的真实值
314
- const intValue = parseInt(value, 10)
315
- const val = col.items.findIndex(m => m === intValue)
316
- pickerValue.push(val)
317
- }
318
- })
319
- return pickerValue
320
- }
321
- },
322
- watch: {
323
- // ! 因为使用对象,在H5端watch的时候,就算没有发生改变,也会触发,这里直接监听toString后的值
324
- options(val) {
325
- this.init()
326
- }
327
- },
328
- created() {
329
- this.init()
330
- },
331
- methods: {
332
- init() {
333
- this.date = this.$pi.date.parseDate(this.defaultValue)
334
- },
335
- handlePickstart() {
336
- this.scrolling = true
337
- },
338
- // 标识滑动结束
339
- handlePickend() {
340
- this.scrolling = false
341
- },
342
- handlePopupClose() {
343
- this.val = false
344
- // 关闭
345
- this.$emit('close')
346
- this.handleEmitChange()
347
- },
348
- handleDateChange(e) {
349
- const values = e.detail.value // values 返回的数组固定是picker的数量,只返回有变化的索引值
350
- const time = this.date.time // 取出当前date的实际时间
351
- values.forEach((value, index) => {
352
- if (value !== null) {
353
- // value为picker列的索引值
354
- const col = this.columns[index]
355
- let val = col.items[value] // 取出对应picker值
356
- if (col.field === 'month') val--
357
- time[col.setMethod](val) // 调用原生date方法赋值
358
- }
359
- })
360
- // 重新解析
361
- this.date = this.$pi.date.parseDate(time)
362
- },
363
- /**
364
- * @vuese
365
- * 取消选择
366
- */
367
- handleCancel() {
368
- /**
369
- * @vuese
370
- * 点击取消按钮时触发
371
- * @arg 当前选中的值 单选为对象,多选模式为数组
372
- */
373
- this.$emit('cancel')
374
- this.onCancelClose && this.handlePopupClose()
375
- },
376
- /**
377
- * @vuese
378
- * 确认选择
379
- */
380
- handleConfirm() {
381
- // 提交
382
- const value = this.format ? this.date.format(this.format) : this.date
383
- this.$emit('confirm', value)
384
- this.onConfirmClose && this.handlePopupClose()
385
- }
386
- }
387
- }
388
- </script>
389
-
390
- <style lang="scss" scoped>
391
- .pi-date-picker {
392
- height: 50vh;
393
- }
394
- </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', '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
+ const date = this.$pi.date.parseDate(this.defaultValue)
231
+ return {
232
+ date,
233
+ scrolling: false // picker是否在滚动中,小程序在scrolling中点确定,选择的项目不正确
234
+ }
235
+ },
236
+ computed: {
237
+ getPopupSelect() {
238
+ return this.$pi.lang.mergeDeep(datePicker.popupSelect, this.popupSelect)
239
+ },
240
+ getConfirmBtn() {
241
+ const datePickerConfirmBtn = this.$pi.lang.mergeDeep(
242
+ datePicker.confirmBtn,
243
+ this.popupSelect.confirmBtn
244
+ )
245
+ const mergeConfirmBtn = this.$pi.lang.mergeDeep(datePickerConfirmBtn, this.confirmBtn)
246
+ if (!mergeConfirmBtn.disabled) {
247
+ mergeConfirmBtn.disabled = this.scrolling
248
+ }
249
+ return mergeConfirmBtn
250
+ },
251
+ getCancelBtn() {
252
+ const datePickerCancelBtn = this.$pi.lang.mergeDeep(
253
+ datePicker.cancelBtn,
254
+ this.popupSelect.cancelBtn
255
+ )
256
+ return this.$pi.lang.mergeDeep(datePickerCancelBtn, this.cancelBtn)
257
+ },
258
+ getPopup() {
259
+ const datePickerPopup = this.$pi.lang.mergeDeep(datePicker.popup, this.popupSelect.popup)
260
+ return this.$pi.lang.mergeDeep(datePickerPopup, this.popup)
261
+ },
262
+ options() {
263
+ const watchs = ['val', 'startYear', 'endYear', 'field', 'defaultValue']
264
+ const options = watchs
265
+ .filter(d => this[d])
266
+ .map(d => this[d].toString())
267
+ .join('-')
268
+ return options
269
+ },
270
+ getHeight() {
271
+ return this.$pi.common.addUnit(this.height)
272
+ },
273
+ getTitlePadding() {
274
+ return this.$pi.common.addUnit(this.titlePadding)
275
+ },
276
+ indicatorStyle() {
277
+ const itemHeight = uni.upx2px(this.itemHeight)
278
+ return `height: ${itemHeight}px;line-height: ${itemHeight}px;`
279
+ },
280
+ getUnits() {
281
+ return this.$pi.mergeDeep(datePicker.units, this.units, {
282
+ arrayMerge: (target, source, options) => {
283
+ return target.map((t, index) => source[index] || t)
284
+ }
285
+ })
286
+ },
287
+ getYearOptions() {
288
+ if (this.yearOptions && this.yearOptions.length > 0) {
289
+ return this.yearOptions
290
+ }
291
+ return this.$pi.common.generateArray(this.startYear, this.endYear)
292
+ },
293
+ getMonthOptions() {
294
+ if (this.monthOptions && this.monthOptions.length > 0) {
295
+ return this.monthOptions
296
+ }
297
+ return this.$pi.common.generateArray(1, 12)
298
+ },
299
+ getDayOptions() {
300
+ if (this.dayOptions && this.dayOptions.length > 0) {
301
+ return this.dayOptions
302
+ }
303
+ const monthDays = new Date(this.date.year, this.date.month, 0).getDate()
304
+ return this.$pi.common.generateArray(1, monthDays)
305
+ },
306
+ getHourOptions() {
307
+ if (this.hourOptions && this.hourOptions.length > 0) {
308
+ return this.hourOptions
309
+ }
310
+ return this.$pi.common.generateArray(0, 23)
311
+ },
312
+ getMinuteOptions() {
313
+ if (this.minuteOptions && this.minuteOptions.length > 0) {
314
+ return this.minuteOptions
315
+ }
316
+ return this.$pi.common.generateArray(0, 59)
317
+ },
318
+ columns() {
319
+ let columns = [
320
+ {
321
+ field: 'year',
322
+ unit: this.getUnits[0],
323
+ key: 'year',
324
+ setMethod: 'setYear',
325
+ items: this.getYearOptions
326
+ },
327
+ {
328
+ field: 'month',
329
+ unit: this.getUnits[1],
330
+ key: 'month',
331
+ setMethod: 'setMonth',
332
+ items: this.getMonthOptions
333
+ },
334
+ {
335
+ field: 'day',
336
+ unit: this.getUnits[2],
337
+ key: 'date',
338
+ setMethod: 'setDate',
339
+ items: this.getDayOptions
340
+ },
341
+ {
342
+ field: 'hour',
343
+ unit: this.getUnits[3],
344
+ key: 'hour',
345
+ setMethod: 'setHours',
346
+ type: 'time',
347
+ items: this.getHourOptions
348
+ },
349
+ {
350
+ field: 'minute',
351
+ unit: this.getUnits[4],
352
+ key: 'minute',
353
+ setMethod: 'setMinutes',
354
+ type: 'time',
355
+ items: this.getMinuteOptions
356
+ },
357
+ {
358
+ field: 'second',
359
+ unit: this.getUnits[5],
360
+ key: 'second',
361
+ setMethod: 'setSeconds',
362
+ type: 'time',
363
+ items: this.$pi.common.generateArray(0, 59)
364
+ }
365
+ ]
366
+
367
+ columns = columns.filter((col, index) => {
368
+ return FIELDS.slice(index).includes(this.field)
369
+ })
370
+
371
+ if (this.dateType === 'time') {
372
+ columns = columns.filter(col => col.type === 'time')
373
+ }
374
+
375
+ return columns
376
+ },
377
+ pickerValue() {
378
+ const pickerValue = []
379
+ this.columns.forEach(col => {
380
+ // 当前日期字段
381
+ const value = this.date[col.key]
382
+ if (value !== null) {
383
+ // 查找当前picker中索引对应的真实值
384
+ const intValue = parseInt(value, 10)
385
+ const val = col.items.findIndex(m => m === intValue)
386
+ pickerValue.push(val)
387
+ }
388
+ })
389
+ return pickerValue
390
+ }
391
+ },
392
+ watch: {
393
+ // ! 因为使用对象,在H5端watch的时候,就算没有发生改变,也会触发,这里直接监听toString后的值
394
+ options(val) {
395
+ this.init()
396
+ }
397
+ },
398
+ created() {
399
+ this.init()
400
+ },
401
+ methods: {
402
+ init() {
403
+ this.date = this.$pi.date.parseDate(this.defaultValue)
404
+ },
405
+ handlePickstart() {
406
+ this.scrolling = true
407
+ },
408
+ // 标识滑动结束
409
+ handlePickend() {
410
+ this.scrolling = false
411
+ },
412
+ handlePopupClose() {
413
+ this.val = false
414
+ // 关闭
415
+ this.$emit('close')
416
+ this.handleEmitChange()
417
+ },
418
+ handleDateChange(e) {
419
+ const values = e.detail.value // values 返回的数组固定是picker的数量,只返回有变化的索引值
420
+ const time = this.date.time // 取出当前date的实际时间
421
+ values.forEach((value, index) => {
422
+ if (value !== null) {
423
+ // value为picker列的索引值
424
+ const col = this.columns[index]
425
+ let val = col.items[value] // 取出对应picker值
426
+ if (col.field === 'month') val--
427
+ time[col.setMethod](val) // 调用原生date方法赋值
428
+ }
429
+ })
430
+ // 重新解析
431
+ this.date = this.$pi.date.parseDate(time)
432
+ },
433
+ /**
434
+ * @vuese
435
+ * 取消选择
436
+ */
437
+ handleCancel() {
438
+ /**
439
+ * @vuese
440
+ * 点击取消按钮时触发
441
+ * @arg 当前选中的值 单选为对象,多选模式为数组
442
+ */
443
+ this.$emit('cancel')
444
+ this.onCancelClose && this.handlePopupClose()
445
+ },
446
+ /**
447
+ * @vuese
448
+ * 确认选择
449
+ */
450
+ handleConfirm() {
451
+ // 提交
452
+ const value = this.format ? this.date.format(this.format) : this.date
453
+ this.$emit('confirm', value)
454
+ this.onConfirmClose && this.handlePopupClose()
455
+ }
456
+ }
457
+ }
458
+ </script>
459
+
460
+ <style lang="scss" scoped>
461
+ .pi-date-picker {
462
+ height: 50vh;
463
+ }
464
+ </style>
@@ -1,10 +1,10 @@
1
1
  <!--
2
2
  * @Author: zhangzhenfei
3
3
  * @Date: 2022-05-18 11:08:49
4
- * @LastEditTime: 2022-10-20 09:34:58
5
- * @LastEditors: zhangzhenfei
4
+ * @LastEditTime: 2023-08-03 16:19:44
5
+ * @LastEditors: liujun
6
6
  * @Description: 日历输入
7
- * @FilePath: /dt-weitibao-console/Users/feilin/workspace/piui/piui-awesome/src/piui/components/pi-date-picker-input/index.vue
7
+ * @FilePath: \dt-opt-manage-consoled:\project-liujun\piui-awesome\src\piui\components\pi-date-picker-input\index.vue
8
8
  -->
9
9
 
10
10
  <template>
@@ -55,6 +55,11 @@
55
55
  :end-year="getDatePicker.endYear"
56
56
  :field="getDatePicker.field"
57
57
  :date-type="getDatePicker.dateType"
58
+ :year-options="getDatePicker.yearOptions"
59
+ :month-options="getDatePicker.monthOptions"
60
+ :day-options="getDatePicker.dayOptions"
61
+ :hour-options="getDatePicker.hourOptions"
62
+ :minute-options="getDatePicker.minuteOptions"
58
63
  :format="dateFormat"
59
64
  :item-height="getDatePicker.itemHeight"
60
65
  :item-style="getDatePicker.itemStyle"
@@ -1,24 +1,29 @@
1
- import popupSelect from './popupSelect'
2
-
3
- const currentYear = new Date().getFullYear()
4
- const startYear = currentYear - 30
5
- const endYear = currentYear
6
-
7
- export default {
8
- customClass: '', // 自定义样式类,字符串形式('')
9
- customStyle: {}, // 自定义样式,对象形式(默认值:{})
10
- startYear, // 开始年份(默认当前年份 - 30)
11
- endYear, // 结束年份(默认当前年份)
12
- field: 'day', // 选择器的粒度 year、month、day、hour、minute、second
13
- dateType: 'datetime', // 日期类型,date、datetime、time(默认值:datetime)
14
- defaultValue: '', // 日期默认值
15
- units: ['年', '月', '日', '时', '分', '秒'], // 单位数组,默认值:['年', '月', '日', '时', '分', '秒']
16
- format: '', // 返回的日期格式,为空的时候,返回的是日期对象
17
- itemHeight: 110, // 行高(默认:'110rpx')
18
- itemStyle: {}, // 行样式(默认:{})
19
- showItemBottomBorder: true, // 是否显示底部边线
20
- popupSelect: popupSelect, // popupSelect配置
21
- popup: popupSelect.popup, // 弹窗的配置,默认选项请参照popup
22
- confirmBtn: popupSelect.confirmBtn, // 确认按钮配置
23
- cancelBtn: popupSelect.cancelBtn // 取消按钮配置
24
- }
1
+ import popupSelect from './popupSelect'
2
+
3
+ const currentYear = new Date().getFullYear()
4
+ const startYear = currentYear - 30
5
+ const endYear = currentYear
6
+
7
+ export default {
8
+ customClass: '', // 自定义样式类,字符串形式('')
9
+ customStyle: {}, // 自定义样式,对象形式(默认值:{})
10
+ startYear, // 开始年份(默认当前年份 - 30)
11
+ endYear, // 结束年份(默认当前年份)
12
+ field: 'day', // 选择器的粒度 year、month、day、hour、minute、second
13
+ dateType: 'datetime', // 日期类型,date、datetime、time(默认值:datetime)
14
+ yearOptions: [], // 年份选项(默认值:[])
15
+ monthOptions: [], // 月份选项(默认值:[])
16
+ dayOptions: [], // 日期选项(默认值:[])
17
+ hourOptions: [], // 小时选项(默认值:[])
18
+ minuteOptions: [], // 分钟选项(默认值:[])
19
+ defaultValue: '', // 日期默认值
20
+ units: ['年', '月', '日', '时', '分', '秒'], // 单位数组,默认值:['年', '月', '日', '时', '分', '秒']
21
+ format: '', // 返回的日期格式,为空的时候,返回的是日期对象
22
+ itemHeight: 110, // 行高(默认:'110rpx')
23
+ itemStyle: {}, // 行样式(默认:{})
24
+ showItemBottomBorder: true, // 是否显示底部边线
25
+ popupSelect: popupSelect, // popupSelect配置
26
+ popup: popupSelect.popup, // 弹窗的配置,默认选项请参照popup
27
+ confirmBtn: popupSelect.confirmBtn, // 确认按钮配置
28
+ cancelBtn: popupSelect.cancelBtn // 取消按钮配置
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sadais-piui",
3
- "version": "1.2.7-beta70",
3
+ "version": "1.2.7-beta71",
4
4
  "description": "piui组件库",
5
5
  "main": "index.js",
6
6
  "scripts": {