@mpxjs/webpack-plugin 2.9.69 → 2.9.70

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 (111) hide show
  1. package/lib/parser.js +1 -1
  2. package/lib/platform/json/wx/index.js +21 -8
  3. package/lib/platform/style/wx/index.js +51 -54
  4. package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
  5. package/lib/platform/template/wx/component-config/index.js +1 -1
  6. package/lib/platform/template/wx/component-config/input.js +1 -1
  7. package/lib/platform/template/wx/component-config/rich-text.js +8 -0
  8. package/lib/platform/template/wx/component-config/swiper.js +1 -1
  9. package/lib/platform/template/wx/component-config/textarea.js +1 -1
  10. package/lib/platform/template/wx/component-config/unsupported.js +1 -1
  11. package/lib/react/processTemplate.js +3 -0
  12. package/lib/runtime/components/react/context.ts +4 -0
  13. package/lib/runtime/components/react/dist/context.js +1 -0
  14. package/lib/runtime/components/react/dist/event.config.js +24 -24
  15. package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
  16. package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
  17. package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
  18. package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
  19. package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
  20. package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
  21. package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
  22. package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
  23. package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
  24. package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
  25. package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
  26. package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
  27. package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
  28. package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
  29. package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
  30. package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
  31. package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
  32. package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
  33. package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
  34. package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
  35. package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
  36. package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
  37. package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
  38. package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
  39. package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
  40. package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
  41. package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
  42. package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
  43. package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
  44. package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
  45. package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
  46. package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
  47. package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
  48. package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
  49. package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
  50. package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
  51. package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
  52. package/lib/runtime/components/react/dist/utils.jsx +107 -82
  53. package/lib/runtime/components/react/event.config.ts +25 -26
  54. package/lib/runtime/components/react/getInnerListeners.ts +238 -188
  55. package/lib/runtime/components/react/mpx-button.tsx +64 -50
  56. package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
  57. package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
  58. package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
  59. package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
  60. package/lib/runtime/components/react/mpx-form.tsx +25 -28
  61. package/lib/runtime/components/react/mpx-icon.tsx +12 -17
  62. package/lib/runtime/components/react/mpx-image.tsx +436 -0
  63. package/lib/runtime/components/react/mpx-input.tsx +77 -57
  64. package/lib/runtime/components/react/mpx-label.tsx +26 -27
  65. package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
  66. package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
  67. package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
  68. package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
  69. package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
  70. package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
  71. package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
  72. package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
  73. package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
  74. package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
  75. package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
  76. package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
  77. package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
  78. package/lib/runtime/components/react/mpx-radio.tsx +45 -54
  79. package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
  80. package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
  81. package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
  82. package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
  83. package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
  84. package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
  85. package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
  86. package/lib/runtime/components/react/mpx-switch.tsx +29 -23
  87. package/lib/runtime/components/react/mpx-text.tsx +14 -18
  88. package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
  89. package/lib/runtime/components/react/mpx-view.tsx +55 -65
  90. package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
  91. package/lib/runtime/components/react/types/global.d.ts +3 -17
  92. package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
  93. package/lib/runtime/components/react/utils.tsx +113 -82
  94. package/lib/runtime/components/web/getInnerListeners.js +6 -6
  95. package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
  96. package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
  97. package/lib/runtime/components/web/mpx-picker.vue +382 -385
  98. package/lib/runtime/components/web/mpx-web-view.vue +175 -161
  99. package/lib/runtime/optionProcessor.js +7 -38
  100. package/lib/runtime/utils.js +2 -0
  101. package/lib/style-compiler/plugins/scope-id.js +30 -2
  102. package/lib/template-compiler/bind-this.js +7 -2
  103. package/lib/template-compiler/compiler.js +77 -46
  104. package/lib/template-compiler/gen-node-react.js +2 -2
  105. package/lib/utils/pre-process-json.js +9 -5
  106. package/package.json +5 -4
  107. package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
  108. package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
  109. package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
  110. package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
  111. package/lib/runtime/components/web/event.js +0 -105
@@ -17,9 +17,7 @@
17
17
  <div class="wheel-wrapper" ref="wheelWrapper">
18
18
  <div class="wheel" v-for="(data, index) in pickerData" :key="index">
19
19
  <ul class="wheel-scroll">
20
- <li
21
- v-for="item in data" :key="item"
22
- class="wheel-item">{{item}}
20
+ <li v-for="item in data" :key="item" class="wheel-item">{{ item }}
23
21
  </li>
24
22
  </ul>
25
23
  </div>
@@ -34,453 +32,451 @@
34
32
 
35
33
 
36
34
  <script type="text/ecmascript-6">
37
- import BScroll from '@better-scroll/core'
38
- import Wheel from '@better-scroll/wheel'
39
- import { type } from '../../utils'
40
- import { getCustomEvent } from './getInnerListeners'
41
-
42
- const startYear = 1900
43
- const modeOptions = {
44
- time: [23, 59],
45
- date: [200, 11, 30]
35
+ import BScroll from '@better-scroll/core'
36
+ import Wheel from '@better-scroll/wheel'
37
+ import { type, extend } from '../../utils'
38
+ import { getCustomEvent } from './getInnerListeners'
39
+
40
+ const startYear = 1900
41
+ const modeOptions = {
42
+ time: [23, 59],
43
+ date: [200, 11, 30]
44
+ }
45
+
46
+ BScroll.use(Wheel)
47
+
48
+ function getPickerData (range, rangeKey) {
49
+ if (range) {
50
+ return range.map((item) => {
51
+ if (rangeKey && type(item) === 'Object') {
52
+ return item[rangeKey]
53
+ }
54
+ return item
55
+ })
56
+ }
57
+ return range
58
+ }
59
+
60
+ function getTimePickerData () {
61
+ let list = []
62
+ for (let i = 0; i < 60; i++) {
63
+ let temp = i < 10 ? `0${i}` : i
64
+ list.push(temp)
46
65
  }
66
+ return [list.slice(0, 24), list]
67
+ }
47
68
 
48
- BScroll.use(Wheel)
69
+ function getDatePickerData (fields) {
70
+ let years = []
71
+ let months = []
72
+ let days = []
49
73
 
50
- function getPickerData (range, rangeKey) {
51
- if (range) {
52
- return range.map((item) => {
53
- if (rangeKey && type(item) === 'Object') {
54
- return item[rangeKey]
55
- }
56
- return item
57
- })
58
- }
59
- return range
74
+ for (let i = 0; i <= 200; i++) {
75
+ years.push(`${startYear + i}年`)
60
76
  }
61
-
62
- function getTimePickerData () {
63
- let list = []
64
- for (let i = 0; i < 60; i++) {
65
- let temp = i < 10 ? `0${i}` : i
66
- list.push(temp)
67
- }
68
- return [list.slice(0, 24), list]
77
+ if (fields === 'year') {
78
+ return [years]
69
79
  }
70
80
 
71
- function getDatePickerData (fields) {
72
- let years = []
73
- let months = []
74
- let days = []
75
-
76
- for (let i = 0; i <= 200; i++) {
77
- years.push(`${startYear + i}年`)
78
- }
79
- if (fields === 'year') {
80
- return [years]
81
- }
82
-
83
- for (let i = 1; i <= 12; i++) {
84
- let temp = i < 10 ? `0${i}` : i
85
- months.push(`${temp}月`)
86
- }
87
- if (fields === 'month') {
88
- return [years, months]
89
- }
90
-
91
- for (let i = 1; i <= 31; i++) {
92
- let temp = i < 10 ? `0${i}` : i
93
- days.push(`${temp}日`)
94
- }
95
- return [years, months, days]
81
+ for (let i = 1; i <= 12; i++) {
82
+ let temp = i < 10 ? `0${i}` : i
83
+ months.push(`${temp}月`)
84
+ }
85
+ if (fields === 'month') {
86
+ return [years, months]
96
87
  }
97
88
 
98
- export default {
99
- name: 'mpx-picker',
100
- props: {
101
- mode: {
102
- type: String,
103
- default: 'selector'
104
- },
105
- disabled: Boolean,
106
- range: {
107
- type: Array,
108
- default () {
109
- return []
110
- }
111
- },
112
- rangeKey: String,
113
- value: {
114
- type: [Number, String, Array],
115
- default () {
116
- switch (this.mode) {
117
- case 'selector':
118
- return 0
119
- case 'multiSelector':
120
- return []
121
- case 'time':
122
- return ''
123
- case 'date':
124
- return ''
125
- default:
126
- return ''
127
- }
128
- }
129
- },
130
- start: {
131
- type: String,
132
- default: '1970-01-01'
133
- },
134
- end: {
135
- type: String,
136
- default: '2100-01-01'
137
- },
138
- fields: {
139
- type: String,
140
- default: 'day'
141
- },
142
- scrollOptions: {
143
- type: Object,
144
- default: () => {
145
- return {}
146
- }
147
- }
89
+ for (let i = 1; i <= 31; i++) {
90
+ let temp = i < 10 ? `0${i}` : i
91
+ days.push(`${temp}日`)
92
+ }
93
+ return [years, months, days]
94
+ }
95
+
96
+ export default {
97
+ name: 'mpx-picker',
98
+ props: {
99
+ mode: {
100
+ type: String,
101
+ default: 'selector'
148
102
  },
149
- data () {
150
- return {
151
- isShow: false,
152
- startIndex: [0, 0, 0],
153
- endIndex: [0, 0, 0],
154
- itemHeight: 0
103
+ disabled: Boolean,
104
+ range: {
105
+ type: Array,
106
+ default () {
107
+ return []
155
108
  }
156
109
  },
157
- computed: {
158
- pickerData () {
110
+ rangeKey: String,
111
+ value: {
112
+ type: [Number, String, Array],
113
+ default () {
159
114
  switch (this.mode) {
160
115
  case 'selector':
161
- return [getPickerData(this.range, this.rangeKey)]
116
+ return 0
162
117
  case 'multiSelector':
163
- return this.range.map((item) => {
164
- return getPickerData(item, this.rangeKey)
165
- })
118
+ return []
166
119
  case 'time':
167
- return getTimePickerData()
120
+ return ''
168
121
  case 'date':
169
- return getDatePickerData(this.fields)
122
+ return ''
170
123
  default:
171
- return []
124
+ return ''
172
125
  }
173
126
  }
174
127
  },
175
- watch: {
176
- pickerData () {
177
- this.refresh()
178
- },
179
- value: {
180
- handler () {
181
- let valueTemp = []
182
- switch (this.mode) {
183
- case 'selector':
184
- this.selectedIndex = [this.value]
185
- break
186
- case 'multiSelector':
187
- this.selectedIndex = []
188
- for (let i = 0; i < this.range.length; i++) {
189
- this.selectedIndex[i] = this.value[i] || 0
190
- }
191
- break
192
- case 'time':
193
- this.selectedIndex = []
194
- if (!this.value) {
195
- valueTemp = [new Date().getHours(), new Date().getMinutes()]
196
- } else {
197
- valueTemp = this.value && this.value.split(':')
198
- }
199
- for (let i = 0; i < valueTemp.length; i++) {
200
- this.selectedIndex[i] = valueTemp[i] || 0
201
- }
202
- break
203
- case 'date':
204
- this.selectedIndex = []
205
- if (!this.value) {
206
- valueTemp = [new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()]
207
- } else {
208
- valueTemp = this.value && this.value.split('-')
209
- }
210
- let result = Object.keys(this.pickerData[0]).filter(item => startYear + Number(item) === Number(valueTemp[0]))
211
- this.selectedIndex[0] = Number(result[0])
212
- for (let i = 1; i < valueTemp.length; i++) {
213
- this.selectedIndex[i] = valueTemp[i] - 1
214
- }
215
- break
216
- default:
217
- this.selectedIndex = [0]
218
- }
219
- this.refresh()
220
- },
221
- immediate: true
222
- }
128
+ start: {
129
+ type: String,
130
+ default: '1970-01-01'
223
131
  },
224
- mounted () {
225
- this.wheels = []
226
- this.refresh()
227
- this.initRangeIndex()
132
+ end: {
133
+ type: String,
134
+ default: '2100-01-01'
228
135
  },
229
- beforeDestroy () {
230
- this.wheels.forEach((wheel) => {
231
- wheel.destroy()
232
- })
233
- this.wheels = []
136
+ fields: {
137
+ type: String,
138
+ default: 'day'
234
139
  },
235
- methods: {
236
- _confirm () {
237
- if (this._isMoving()) {
238
- return
239
- }
240
- this.hide()
241
- let value = ''
140
+ scrollOptions: {
141
+ type: Object,
142
+ default: () => {
143
+ return {}
144
+ }
145
+ }
146
+ },
147
+ data () {
148
+ return {
149
+ isShow: false,
150
+ startIndex: [0, 0, 0],
151
+ endIndex: [0, 0, 0],
152
+ itemHeight: 0
153
+ }
154
+ },
155
+ computed: {
156
+ pickerData () {
157
+ switch (this.mode) {
158
+ case 'selector':
159
+ return [getPickerData(this.range, this.rangeKey)]
160
+ case 'multiSelector':
161
+ return this.range.map((item) => {
162
+ return getPickerData(item, this.rangeKey)
163
+ })
164
+ case 'time':
165
+ return getTimePickerData()
166
+ case 'date':
167
+ return getDatePickerData(this.fields)
168
+ default:
169
+ return []
170
+ }
171
+ }
172
+ },
173
+ watch: {
174
+ pickerData () {
175
+ this.refresh()
176
+ },
177
+ value: {
178
+ handler () {
242
179
  let valueTemp = []
243
180
  switch (this.mode) {
244
181
  case 'selector':
245
- value = this.selectedIndex[0]
182
+ this.selectedIndex = [this.value]
246
183
  break
247
184
  case 'multiSelector':
248
- value = this.selectedIndex.slice()
185
+ this.selectedIndex = []
186
+ for (let i = 0; i < this.range.length; i++) {
187
+ this.selectedIndex[i] = this.value[i] || 0
188
+ }
249
189
  break
250
190
  case 'time':
251
- for (let i = 0; i < this.selectedIndex.length; i++) {
252
- valueTemp[i] = this.selectedIndex[i] < 10 ? `0${Number(this.selectedIndex[i])}` : `${this.selectedIndex[i]}`
191
+ this.selectedIndex = []
192
+ if (!this.value) {
193
+ valueTemp = [new Date().getHours(), new Date().getMinutes()]
194
+ } else {
195
+ valueTemp = this.value && this.value.split(':')
196
+ }
197
+ for (let i = 0; i < valueTemp.length; i++) {
198
+ this.selectedIndex[i] = valueTemp[i] || 0
253
199
  }
254
- value = `${valueTemp[0]}:${valueTemp[1]}`
255
200
  break
256
201
  case 'date':
257
- let year = this.pickerData[0][this.selectedIndex[0]].replace('年', '')
258
- if (this.fields === 'year') {
259
- value = `${year}`
260
- break
202
+ this.selectedIndex = []
203
+ if (!this.value) {
204
+ valueTemp = [new Date().getFullYear(), new Date().getMonth() + 1, new Date().getDate()]
205
+ } else {
206
+ valueTemp = this.value && this.value.split('-')
261
207
  }
262
-
263
- let month = this.selectedIndex[1] < 9 ? `0${this.selectedIndex[1] + 1}` : this.selectedIndex[1] + 1
264
- if (this.fields === 'month') {
265
- value = `${year}-${month}`
266
- break
208
+ let result = Object.keys(this.pickerData[0]).filter(item => startYear + Number(item) === Number(valueTemp[0]))
209
+ this.selectedIndex[0] = Number(result[0])
210
+ for (let i = 1; i < valueTemp.length; i++) {
211
+ this.selectedIndex[i] = valueTemp[i] - 1
267
212
  }
268
-
269
- let day = this.selectedIndex[2] < 9 ? `0${this.selectedIndex[2] + 1}` : this.selectedIndex[2] + 1
270
- value = `${year}-${month}-${day}`
271
213
  break
272
214
  default:
273
- value = this.selectedIndex[0]
215
+ this.selectedIndex = [0]
274
216
  }
275
- this.$emit('change', getCustomEvent('change', {value}, this))
276
- },
277
- _cancel () {
278
- this.hide()
279
- this.$emit('cancel', getCustomEvent('cancel', {}, this))
280
- },
281
- _isMoving () {
282
- return this.wheels.some((wheel) => {
283
- return wheel.pending
284
- })
285
- },
286
- show () {
287
- this.isShow = true
288
- if (this.needRefresh) {
289
- this.needRefresh = false
290
- this.refresh()
291
- }
292
- },
293
- hide () {
294
- this.isShow = false
217
+ this.refresh()
295
218
  },
296
- refresh () {
297
- if (this.isShow) {
298
- if (this.refreshing) return
299
- this.refreshing = true
300
- this.$nextTick(() => {
301
- let i = 0
302
- const wheelWrapper = this.$refs.wheelWrapper
303
- for (; i < this.pickerData.length; i++) {
304
- this.selectedIndex[i] = +this.selectedIndex[i] || 0
305
- if (this.selectedIndex[i] >= this.pickerData[i].length) {
306
- this.selectedIndex[i] = 0
219
+ immediate: true
220
+ }
221
+ },
222
+ mounted () {
223
+ this.wheels = []
224
+ this.refresh()
225
+ this.initRangeIndex()
226
+ },
227
+ beforeDestroy () {
228
+ this.wheels.forEach((wheel) => {
229
+ wheel.destroy()
230
+ })
231
+ this.wheels = []
232
+ },
233
+ methods: {
234
+ _confirm () {
235
+ if (this._isMoving()) {
236
+ return
237
+ }
238
+ this.hide()
239
+ let value = ''
240
+ let valueTemp = []
241
+ switch (this.mode) {
242
+ case 'selector':
243
+ value = this.selectedIndex[0]
244
+ break
245
+ case 'multiSelector':
246
+ value = this.selectedIndex.slice()
247
+ break
248
+ case 'time':
249
+ for (let i = 0; i < this.selectedIndex.length; i++) {
250
+ valueTemp[i] = this.selectedIndex[i] < 10 ? `0${Number(this.selectedIndex[i])}` : `${this.selectedIndex[i]}`
251
+ }
252
+ value = `${valueTemp[0]}:${valueTemp[1]}`
253
+ break
254
+ case 'date':
255
+ let year = this.pickerData[0][this.selectedIndex[0]].replace('年', '')
256
+ if (this.fields === 'year') {
257
+ value = `${year}`
258
+ break
259
+ }
260
+
261
+ let month = this.selectedIndex[1] < 9 ? `0${this.selectedIndex[1] + 1}` : this.selectedIndex[1] + 1
262
+ if (this.fields === 'month') {
263
+ value = `${year}-${month}`
264
+ break
265
+ }
266
+
267
+ let day = this.selectedIndex[2] < 9 ? `0${this.selectedIndex[2] + 1}` : this.selectedIndex[2] + 1
268
+ value = `${year}-${month}-${day}`
269
+ break
270
+ default:
271
+ value = this.selectedIndex[0]
272
+ }
273
+ this.$emit('change', getCustomEvent('change', { value }, this))
274
+ },
275
+ _cancel () {
276
+ this.hide()
277
+ this.$emit('cancel', getCustomEvent('cancel', {}, this))
278
+ },
279
+ _isMoving () {
280
+ return this.wheels.some((wheel) => {
281
+ return wheel.pending
282
+ })
283
+ },
284
+ show () {
285
+ this.isShow = true
286
+ if (this.needRefresh) {
287
+ this.needRefresh = false
288
+ this.refresh()
289
+ }
290
+ },
291
+ hide () {
292
+ this.isShow = false
293
+ },
294
+ refresh () {
295
+ if (this.isShow) {
296
+ if (this.refreshing) return
297
+ this.refreshing = true
298
+ this.$nextTick(() => {
299
+ let i = 0
300
+ const wheelWrapper = this.$refs.wheelWrapper
301
+ for (; i < this.pickerData.length; i++) {
302
+ this.selectedIndex[i] = +this.selectedIndex[i] || 0
303
+ if (this.selectedIndex[i] >= this.pickerData[i].length) {
304
+ this.selectedIndex[i] = 0
305
+ }
306
+ if (this.wheels[i]) {
307
+ this.wheels[i].refresh()
308
+ if (this.wheels[i].getSelectedIndex() !== this.selectedIndex[i]) {
309
+ this.wheels[i].wheelTo(this.selectedIndex[i])
310
+ }
311
+ } else {
312
+ this.wheels[i] = new BScroll(wheelWrapper.children[i], extend({
313
+ wheel: {
314
+ selectedIndex: this.selectedIndex[i],
315
+ wheelWrapperClass: 'wheel-scroll',
316
+ wheelItemClass: 'wheel-item'
317
+ },
318
+ probeType: 3,
319
+ bindToWrapper: true
320
+ }, this.scrollOptions))
321
+ if (this.mode === 'time' || this.mode === 'date') {
322
+ this.wheels[i].on('scrollStart', function (i) {
323
+ this.handleScrollStart()
324
+ }.bind(this, i))
307
325
  }
308
- if (this.wheels[i]) {
309
- this.wheels[i].refresh()
310
- if (this.wheels[i].getSelectedIndex() !== this.selectedIndex[i]) {
311
- this.wheels[i].wheelTo(this.selectedIndex[i])
326
+ this.wheels[i].on('scrollEnd', function (i) {
327
+ if (this.refreshing) return
328
+ const currentIndex = this.wheels[i].getSelectedIndex()
329
+ if (this.selectedIndex[i] !== currentIndex) {
330
+ this.selectedIndex[i] = currentIndex
331
+ if (this.mode === 'multiSelector') {
332
+ this.$emit('columnchange', getCustomEvent('columnchange', {
333
+ column: i,
334
+ value: currentIndex
335
+ }, this))
336
+ }
312
337
  }
313
- } else {
314
- this.wheels[i] = new BScroll(wheelWrapper.children[i], {
315
- wheel: {
316
- selectedIndex: this.selectedIndex[i],
317
- wheelWrapperClass: 'wheel-scroll',
318
- wheelItemClass: 'wheel-item'
319
- },
320
- probeType: 3,
321
- bindToWrapper: true,
322
- ...this.scrollOptions
323
- })
324
338
  if (this.mode === 'time' || this.mode === 'date') {
325
- this.wheels[i].on('scrollStart', function (i) {
326
- this.handleScrollStart()
327
- }.bind(this, i))
339
+ this.handleScrollEnd()
328
340
  }
329
- this.wheels[i].on('scrollEnd', function (i) {
330
- if (this.refreshing) return
331
- const currentIndex = this.wheels[i].getSelectedIndex()
332
- if (this.selectedIndex[i] !== currentIndex) {
333
- this.selectedIndex[i] = currentIndex
334
- if (this.mode === 'multiSelector') {
335
- this.$emit('columnchange', getCustomEvent('columnchange', {
336
- column: i,
337
- value: currentIndex
338
- }, this))
339
- }
340
- }
341
- if (this.mode === 'time' || this.mode === 'date') {
342
- this.handleScrollEnd()
343
- }
344
- }.bind(this, i))
345
- }
341
+ }.bind(this, i))
346
342
  }
347
- if (this.mode === 'time' || this.mode === 'date') {
348
- this.initWheelPosition()
349
- }
350
- for (; i < this.wheels.length; i++) {
351
- if (this.wheels[i]) {
352
- this.wheels[i].destroy()
353
- }
343
+ }
344
+ if (this.mode === 'time' || this.mode === 'date') {
345
+ this.initWheelPosition()
346
+ }
347
+ for (; i < this.wheels.length; i++) {
348
+ if (this.wheels[i]) {
349
+ this.wheels[i].destroy()
354
350
  }
355
- this.wheels.length = this.pickerData.length
356
- this.selectedIndex.length = this.pickerData.length
357
- this.refreshing = false
358
- })
359
- } else {
360
- this.needRefresh = true
361
- }
362
- },
363
- initRangeIndex () {
364
- if (this.mode !== 'time' && this.mode !== 'date') {
365
- return
366
- }
351
+ }
352
+ this.wheels.length = this.pickerData.length
353
+ this.selectedIndex.length = this.pickerData.length
354
+ this.refreshing = false
355
+ })
356
+ } else {
357
+ this.needRefresh = true
358
+ }
359
+ },
360
+ initRangeIndex () {
361
+ if (this.mode !== 'time' && this.mode !== 'date') {
362
+ return
363
+ }
364
+
365
+ this.itemHeight = window.getComputedStyle(document.getElementsByClassName('wheel-item')[0]).height.replace(/px/g, '')
366
+ if (this.mode === 'time') {
367
+ this.startIndex = [this.getIndex('start', 0, ':'), this.getIndex('start', 1, ':')]
368
+ this.endIndex = [this.getIndex('end', 0, ':'), this.getIndex('end', 1, ':')]
369
+ }
370
+ if (this.mode === 'date') {
371
+ this.startIndex = [this.getIndex('start', 0, '-') - startYear, this.getIndex('start', 1, '-') - 1, this.getIndex('start', 2, '-') - 1]
372
+ this.endIndex = [this.getIndex('end', 0, '-') - startYear, this.getIndex('end', 1, '-') - 1, this.getIndex('end', 2, '-') - 1]
373
+ }
374
+ },
375
+ getIndex (type, i, delimiter) {
376
+ return this[type] && Number(this[type].split(delimiter)[i])
377
+ },
378
+ handleScrollStart () {
379
+ // 重置可滚动距离
380
+ for (let i = 0; i < this.wheels.length; i++) {
381
+ this.wheels[i].minScrollY = 0
382
+ this.wheels[i].maxScrollY = -(modeOptions[this.mode][i] * this.itemHeight)
383
+ }
384
+ //开始滚动 判断最多可滚动距离
385
+ if (this.start) {
386
+ this.wheels[0].minScrollY = -(this.startIndex[0] * this.itemHeight)
367
387
 
368
- this.itemHeight = window.getComputedStyle(document.getElementsByClassName('wheel-item')[0]).height.replace(/px/g, '')
369
- if (this.mode === 'time') {
370
- this.startIndex = [this.getIndex('start', 0, ':'), this.getIndex('start', 1, ':')]
371
- this.endIndex = [this.getIndex('end', 0, ':'), this.getIndex('end', 1, ':')]
372
- }
373
- if (this.mode === 'date') {
374
- this.startIndex = [this.getIndex('start', 0, '-') - startYear, this.getIndex('start', 1, '-') - 1, this.getIndex('start', 2, '-') - 1]
375
- this.endIndex = [this.getIndex('end', 0, '-') - startYear, this.getIndex('end', 1, '-') - 1, this.getIndex('end', 2, '-') - 1]
376
- }
377
- },
378
- getIndex (type, i, delimiter) {
379
- return this[type] && Number(this[type].split(delimiter)[i])
380
- },
381
- handleScrollStart () {
382
- // 重置可滚动距离
383
388
  for (let i = 0; i < this.wheels.length; i++) {
384
- this.wheels[i].minScrollY = 0
385
- this.wheels[i].maxScrollY = -(modeOptions[this.mode][i] * this.itemHeight)
389
+ if (!(this.wheels[i + 1] && this.wheels[i].getSelectedIndex() === this.startIndex[i])) {
390
+ break
391
+ }
392
+ this.wheels[i + 1].minScrollY = -(this.startIndex[i + 1] * this.itemHeight)
393
+ this.wheels[i + 1].maxScrollY = -(modeOptions[this.mode][i + 1] * this.itemHeight)
386
394
  }
387
- //开始滚动 判断最多可滚动距离
388
- if (this.start) {
389
- this.wheels[0].minScrollY = -(this.startIndex[0] * this.itemHeight)
395
+ }
396
+ if (this.end) {
397
+ this.wheels[0].maxScrollY = -(this.endIndex[0] * this.itemHeight)
390
398
 
391
- for (let i = 0; i < this.wheels.length; i++) {
392
- if (!(this.wheels[i + 1] && this.wheels[i].getSelectedIndex() === this.startIndex[i])) {
393
- break
394
- }
395
- this.wheels[i + 1].minScrollY = -(this.startIndex[i + 1] * this.itemHeight)
399
+ for (let i = 0; i < this.wheels.length; i++) {
400
+ if (!(this.wheels[i + 1] && this.wheels[i].getSelectedIndex() === this.endIndex[i])) {
401
+ break
402
+ }
403
+ this.wheels[i + 1].minScrollY = 0
404
+ this.wheels[i + 1].maxScrollY = -(this.endIndex[i + 1] * this.itemHeight)
405
+ }
406
+ }
407
+ },
408
+ handleScrollEnd () {
409
+ const solarMonths = [1, 3, 5, 7, 8, 10, 12]
410
+ if (this.start) {
411
+ for (let i = 0; i < this.wheels.length; i++) {
412
+ if (!(this.wheels[i].getSelectedIndex() === this.startIndex[i]) || !(this.wheels[i + 1])) {
413
+ break
414
+ }
415
+ if (this.wheels[i + 1].getSelectedIndex() < this.startIndex[i + 1]) {
416
+ this.wheels[i + 1].minScrollY = 0
396
417
  this.wheels[i + 1].maxScrollY = -(modeOptions[this.mode][i + 1] * this.itemHeight)
418
+ this.wheels[i + 1].wheelTo([this.startIndex[i + 1]])
397
419
  }
398
420
  }
399
- if (this.end) {
400
- this.wheels[0].maxScrollY = -(this.endIndex[0] * this.itemHeight)
401
-
402
- for (let i = 0; i < this.wheels.length; i++) {
403
- if (!(this.wheels[i + 1] && this.wheels[i].getSelectedIndex() === this.endIndex[i])) {
404
- break
405
- }
421
+ }
422
+ if (this.end) {
423
+ for (let i = 0; i < this.wheels.length; i++) {
424
+ if (!(this.wheels[i].getSelectedIndex() === this.endIndex[i]) || !(this.wheels[i + 1])) {
425
+ break
426
+ }
427
+ if (this.wheels[i + 1].getSelectedIndex() > this.endIndex[i + 1]) {
406
428
  this.wheels[i + 1].minScrollY = 0
407
- this.wheels[i + 1].maxScrollY = -(this.endIndex[i + 1] * this.itemHeight)
429
+ this.wheels[i + 1].maxScrollY = -(modeOptions[this.mode][i + 1] * this.itemHeight)
430
+ this.wheels[i + 1].wheelTo([this.endIndex[i + 1]])
408
431
  }
409
432
  }
410
- },
411
- handleScrollEnd () {
412
- const solarMonths = [1, 3, 5, 7, 8, 10, 12]
413
- if (this.start) {
433
+ }
434
+ // 单独处理小月30天,2月28天或29天情况
435
+ if (this.mode === 'date' && this.fields === 'day' && !solarMonths.includes(this.wheels[1].getSelectedIndex() + 1)) {
436
+ const currentYear = this.wheels[0].getSelectedIndex() + startYear
437
+ const isFebruary = this.wheels[1].getSelectedIndex() === 1
438
+ const isLeapYear = (currentYear % 4 === 0 && (currentYear % 100 !== 0)) || (currentYear % 400 === 0)
439
+ const day = isFebruary && (isLeapYear ? 28 : 27) || 29
440
+ this.wheels[2].getSelectedIndex() > day && this.wheels[2].wheelTo([0])
441
+ }
442
+
443
+ },
444
+ initWheelPosition () {
445
+ if (this.start) {
446
+ if (this.wheels[0].getSelectedIndex() < this.startIndex[0]) {
414
447
  for (let i = 0; i < this.wheels.length; i++) {
415
- if (!(this.wheels[i].getSelectedIndex() === this.startIndex[i]) || !(this.wheels[i + 1])) {
416
- break
417
- }
418
- if (this.wheels[i + 1].getSelectedIndex() < this.startIndex[i + 1]) {
419
- this.wheels[i + 1].minScrollY = 0
420
- this.wheels[i + 1].maxScrollY = -(modeOptions[this.mode][i+1] * this.itemHeight)
421
- this.wheels[i + 1].wheelTo([this.startIndex[i + 1]])
422
- }
448
+ this.wheels[i].wheelTo([this.startIndex[i]])
449
+ this.selectedIndex[i] = this.startIndex[i] || 0
423
450
  }
424
- }
425
- if (this.end) {
451
+ } else {
426
452
  for (let i = 0; i < this.wheels.length; i++) {
427
- if (!(this.wheels[i].getSelectedIndex() === this.endIndex[i]) || !(this.wheels[i + 1])) {
453
+ if (this.wheels[i].getSelectedIndex() !== this.startIndex[i]) {
428
454
  break
429
455
  }
430
- if (this.wheels[i + 1].getSelectedIndex() > this.endIndex[i + 1]) {
431
- this.wheels[i + 1].minScrollY = 0
432
- this.wheels[i + 1].maxScrollY = -(modeOptions[this.mode][i+1] * this.itemHeight)
433
- this.wheels[i + 1].wheelTo([this.endIndex[i + 1]])
434
- }
435
- }
436
- }
437
- // 单独处理小月30天,2月28天或29天情况
438
- if (this.mode === 'date' && this.fields === 'day' && !solarMonths.includes(this.wheels[1].getSelectedIndex() + 1)) {
439
- const currentYear = this.wheels[0].getSelectedIndex() + startYear
440
- const isFebruary = this.wheels[1].getSelectedIndex() === 1
441
- const isLeapYear = (currentYear % 4 === 0 && (currentYear % 100 !== 0)) || (currentYear % 400 === 0)
442
- const day = isFebruary && (isLeapYear ? 28 : 27) || 29
443
- this.wheels[2].getSelectedIndex() > day && this.wheels[2].wheelTo([0])
444
- }
445
-
446
- },
447
- initWheelPosition () {
448
- if (this.start) {
449
- if (this.wheels[0].getSelectedIndex() < this.startIndex[0]) {
450
- for (let i = 0; i < this.wheels.length; i++) {
451
- this.wheels[i].wheelTo([this.startIndex[i]])
452
- this.selectedIndex[i] = this.startIndex[i] || 0
453
- }
454
- } else {
455
- for (let i = 0; i < this.wheels.length; i++) {
456
- if (this.wheels[i].getSelectedIndex() !== this.startIndex[i]) {
457
- break
458
- }
459
- if (this.wheels[i+1] && this.wheels[i+1].getSelectedIndex() < this.startIndex[i+1]) {
460
- for (let j = i+1; j < this.wheels.length; j++) {
461
- this.wheels[j].wheelTo([this.startIndex[j]])
462
- this.selectedIndex[j] = this.startIndex[j] || 0
463
- }
456
+ if (this.wheels[i + 1] && this.wheels[i + 1].getSelectedIndex() < this.startIndex[i + 1]) {
457
+ for (let j = i + 1; j < this.wheels.length; j++) {
458
+ this.wheels[j].wheelTo([this.startIndex[j]])
459
+ this.selectedIndex[j] = this.startIndex[j] || 0
464
460
  }
465
461
  }
466
462
  }
467
463
  }
468
- if (this.end) {
469
- if (this.wheels[0].getSelectedIndex() > this.endIndex[0]) {
470
- for (let i = 0; i < this.wheels.length; i++) {
471
- this.wheels[i].wheelTo([this.endIndex[i]])
472
- this.selectedIndex[i] = this.endIndex[i] || 0
464
+ }
465
+ if (this.end) {
466
+ if (this.wheels[0].getSelectedIndex() > this.endIndex[0]) {
467
+ for (let i = 0; i < this.wheels.length; i++) {
468
+ this.wheels[i].wheelTo([this.endIndex[i]])
469
+ this.selectedIndex[i] = this.endIndex[i] || 0
470
+ }
471
+ } else {
472
+ for (let i = 0; i < this.wheels.length; i++) {
473
+ if (this.wheels[i].getSelectedIndex() !== this.endIndex[i]) {
474
+ break
473
475
  }
474
- } else {
475
- for (let i = 0; i < this.wheels.length; i++) {
476
- if (this.wheels[i].getSelectedIndex() !== this.endIndex[i]) {
477
- break
478
- }
479
- if (this.wheels[i+1] && this.wheels[i+1].getSelectedIndex() > this.endIndex[i+1]) {
480
- for (let j = i+1; j < this.wheels.length; j++) {
481
- this.wheels[j].wheelTo([this.endIndex[j]])
482
- this.selectedIndex[j] = this.endIndex[j] || 0
483
- }
476
+ if (this.wheels[i + 1] && this.wheels[i + 1].getSelectedIndex() > this.endIndex[i + 1]) {
477
+ for (let j = i + 1; j < this.wheels.length; j++) {
478
+ this.wheels[j].wheelTo([this.endIndex[j]])
479
+ this.selectedIndex[j] = this.endIndex[j] || 0
484
480
  }
485
481
  }
486
482
  }
@@ -488,6 +484,7 @@
488
484
  }
489
485
  }
490
486
  }
487
+ }
491
488
  </script>
492
489
 
493
490
  <style scoped lang="stylus" rel="stylesheet/stylus">