@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.
- package/lib/parser.js +1 -1
- package/lib/platform/json/wx/index.js +21 -8
- package/lib/platform/style/wx/index.js +51 -54
- package/lib/platform/template/wx/component-config/fix-component-name.js +15 -12
- package/lib/platform/template/wx/component-config/index.js +1 -1
- package/lib/platform/template/wx/component-config/input.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +8 -0
- package/lib/platform/template/wx/component-config/swiper.js +1 -1
- package/lib/platform/template/wx/component-config/textarea.js +1 -1
- package/lib/platform/template/wx/component-config/unsupported.js +1 -1
- package/lib/react/processTemplate.js +3 -0
- package/lib/runtime/components/react/context.ts +4 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.js +24 -24
- package/lib/runtime/components/react/dist/getInnerListeners.js +183 -166
- package/lib/runtime/components/react/dist/mpx-button.jsx +35 -42
- package/lib/runtime/components/react/dist/mpx-canvas/html.js +2 -4
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +35 -13
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +13 -19
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +29 -38
- package/lib/runtime/components/react/dist/mpx-form.jsx +16 -19
- package/lib/runtime/components/react/dist/mpx-icon.jsx +8 -16
- package/lib/runtime/components/react/dist/mpx-image.jsx +291 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +54 -27
- package/lib/runtime/components/react/dist/mpx-label.jsx +15 -22
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +13 -16
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +13 -13
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +2 -4
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +6 -2
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +10 -15
- package/lib/runtime/components/react/dist/mpx-picker-view-column.jsx +3 -1
- package/lib/runtime/components/react/dist/mpx-picker-view.jsx +5 -3
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +11 -19
- package/lib/runtime/components/react/dist/mpx-radio.jsx +27 -42
- package/lib/runtime/components/react/dist/mpx-rich-text/html.js +39 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +63 -0
- package/lib/runtime/components/react/dist/mpx-root-portal.jsx +6 -4
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +47 -41
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-swiper/carouse.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -2
- package/lib/runtime/components/react/dist/mpx-switch.jsx +20 -10
- package/lib/runtime/components/react/dist/mpx-text.jsx +11 -10
- package/lib/runtime/components/react/dist/mpx-textarea.jsx +8 -3
- package/lib/runtime/components/react/dist/mpx-view.jsx +34 -46
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +105 -42
- package/lib/runtime/components/react/dist/useAnimationHooks.js +35 -10
- package/lib/runtime/components/react/dist/utils.jsx +107 -82
- package/lib/runtime/components/react/event.config.ts +25 -26
- package/lib/runtime/components/react/getInnerListeners.ts +238 -188
- package/lib/runtime/components/react/mpx-button.tsx +64 -50
- package/lib/runtime/components/react/mpx-canvas/html.ts +2 -4
- package/lib/runtime/components/react/mpx-canvas/index.tsx +46 -48
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +28 -25
- package/lib/runtime/components/react/mpx-checkbox.tsx +48 -49
- package/lib/runtime/components/react/mpx-form.tsx +25 -28
- package/lib/runtime/components/react/mpx-icon.tsx +12 -17
- package/lib/runtime/components/react/mpx-image.tsx +436 -0
- package/lib/runtime/components/react/mpx-input.tsx +77 -57
- package/lib/runtime/components/react/mpx-label.tsx +26 -27
- package/lib/runtime/components/react/mpx-movable-area.tsx +18 -23
- package/lib/runtime/components/react/mpx-movable-view.tsx +21 -25
- package/lib/runtime/components/react/mpx-navigator.tsx +2 -8
- package/lib/runtime/components/react/mpx-picker/date.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/index.tsx +3 -2
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/region.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/selector.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker/time.tsx +10 -15
- package/lib/runtime/components/react/mpx-picker/type.ts +48 -43
- package/lib/runtime/components/react/mpx-picker-view-column.tsx +4 -1
- package/lib/runtime/components/react/mpx-picker-view.tsx +7 -1
- package/lib/runtime/components/react/mpx-radio-group.tsx +24 -27
- package/lib/runtime/components/react/mpx-radio.tsx +45 -54
- package/lib/runtime/components/react/mpx-rich-text/html.ts +40 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +121 -0
- package/lib/runtime/components/react/mpx-root-portal.tsx +3 -5
- package/lib/runtime/components/react/mpx-scroll-view.tsx +72 -71
- package/lib/runtime/components/react/mpx-simple-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-swiper/carouse.tsx +4 -2
- package/lib/runtime/components/react/mpx-swiper-item.tsx +3 -2
- package/lib/runtime/components/react/mpx-switch.tsx +29 -23
- package/lib/runtime/components/react/mpx-text.tsx +14 -18
- package/lib/runtime/components/react/mpx-textarea.tsx +11 -10
- package/lib/runtime/components/react/mpx-view.tsx +55 -65
- package/lib/runtime/components/react/mpx-web-view.tsx +108 -63
- package/lib/runtime/components/react/types/global.d.ts +3 -17
- package/lib/runtime/components/react/useAnimationHooks.ts +36 -12
- package/lib/runtime/components/react/utils.tsx +113 -82
- package/lib/runtime/components/web/getInnerListeners.js +6 -6
- package/lib/runtime/components/web/mpx-movable-view.vue +334 -344
- package/lib/runtime/components/web/mpx-picker-view-column.vue +75 -75
- package/lib/runtime/components/web/mpx-picker.vue +382 -385
- package/lib/runtime/components/web/mpx-web-view.vue +175 -161
- package/lib/runtime/optionProcessor.js +7 -38
- package/lib/runtime/utils.js +2 -0
- package/lib/style-compiler/plugins/scope-id.js +30 -2
- package/lib/template-compiler/bind-this.js +7 -2
- package/lib/template-compiler/compiler.js +77 -46
- package/lib/template-compiler/gen-node-react.js +2 -2
- package/lib/utils/pre-process-json.js +9 -5
- package/package.json +5 -4
- package/lib/runtime/components/react/dist/mpx-image/index.jsx +0 -226
- package/lib/runtime/components/react/dist/mpx-image/svg.jsx +0 -7
- package/lib/runtime/components/react/mpx-image/index.tsx +0 -345
- package/lib/runtime/components/react/mpx-image/svg.tsx +0 -22
- package/lib/runtime/components/web/event.js +0 -105
|
@@ -7,379 +7,369 @@
|
|
|
7
7
|
</template>
|
|
8
8
|
|
|
9
9
|
<script type="text/ecmascript-6">
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
import { getCustomEvent, extendEvent } from './getInnerListeners'
|
|
11
|
+
import { extend } from '../../utils'
|
|
12
|
+
import BScroll from '@better-scroll/core'
|
|
13
|
+
import Movable from '@better-scroll/movable'
|
|
14
|
+
import ObserveDOM from '@better-scroll/observe-dom'
|
|
15
|
+
import Zoom from '@better-scroll/zoom'
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
BScroll.use(Movable)
|
|
18
|
+
BScroll.use(Zoom)
|
|
19
|
+
BScroll.use(ObserveDOM)
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
export default {
|
|
22
|
+
data () {
|
|
23
|
+
return {
|
|
24
|
+
directions: ['none', 'all', 'vertical', 'horizontal'],
|
|
25
|
+
minScrollX: 0,
|
|
26
|
+
maxScrollX: 0,
|
|
27
|
+
minScrollY: 0,
|
|
28
|
+
maxScrollY: 0,
|
|
29
|
+
currentX: this.x,
|
|
30
|
+
currentY: this.y,
|
|
31
|
+
lastestX: 0,
|
|
32
|
+
lastestY: 0,
|
|
33
|
+
lastestScale: 1,
|
|
34
|
+
bsOptions: {},
|
|
35
|
+
isZooming: false,
|
|
36
|
+
isFirstTouch: true,
|
|
37
|
+
source: '',
|
|
38
|
+
touchEvent: '',
|
|
39
|
+
isInited: false,
|
|
40
|
+
deactivatedX: 0,
|
|
41
|
+
deactivatedY: 0
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
props: {
|
|
45
|
+
direction: {
|
|
46
|
+
type: String,
|
|
47
|
+
default: 'none'
|
|
48
|
+
},
|
|
49
|
+
inertia: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: false
|
|
52
|
+
},
|
|
53
|
+
outOfBounds: {
|
|
54
|
+
type: Boolean,
|
|
55
|
+
default: false
|
|
56
|
+
},
|
|
57
|
+
x: {
|
|
58
|
+
type: Number,
|
|
59
|
+
default: 0
|
|
60
|
+
},
|
|
61
|
+
y: {
|
|
62
|
+
type: Number,
|
|
63
|
+
default: 0
|
|
64
|
+
},
|
|
65
|
+
damping: {
|
|
66
|
+
type: Number,
|
|
67
|
+
default: 20
|
|
68
|
+
},
|
|
69
|
+
friction: {
|
|
70
|
+
type: Number,
|
|
71
|
+
default: 2
|
|
72
|
+
},
|
|
73
|
+
disabled: {
|
|
74
|
+
type: Boolean,
|
|
75
|
+
default: false
|
|
76
|
+
},
|
|
77
|
+
scale: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
default: false
|
|
80
|
+
},
|
|
81
|
+
scaleMin: {
|
|
82
|
+
type: Number,
|
|
83
|
+
default: 0.5
|
|
84
|
+
},
|
|
85
|
+
scaleMax: {
|
|
86
|
+
type: Number,
|
|
87
|
+
default: 10
|
|
88
|
+
},
|
|
89
|
+
scaleValue: {
|
|
90
|
+
type: Number,
|
|
91
|
+
default: 1
|
|
92
|
+
},
|
|
93
|
+
animation: {
|
|
94
|
+
type: Boolean,
|
|
95
|
+
default: true
|
|
96
|
+
},
|
|
97
|
+
speed: {
|
|
98
|
+
type: Number,
|
|
99
|
+
default: 500
|
|
100
|
+
},
|
|
101
|
+
scrollOptions: {
|
|
102
|
+
type: Object,
|
|
103
|
+
default: () => {
|
|
104
|
+
return {}
|
|
41
105
|
}
|
|
42
106
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
},
|
|
56
|
-
x: {
|
|
57
|
-
type: Number,
|
|
58
|
-
default: 0
|
|
59
|
-
},
|
|
60
|
-
y: {
|
|
61
|
-
type: Number,
|
|
62
|
-
default: 0
|
|
63
|
-
},
|
|
64
|
-
damping: {
|
|
65
|
-
type: Number,
|
|
66
|
-
default: 20
|
|
67
|
-
},
|
|
68
|
-
friction: {
|
|
69
|
-
type: Number,
|
|
70
|
-
default: 2
|
|
71
|
-
},
|
|
72
|
-
disabled: {
|
|
73
|
-
type: Boolean,
|
|
74
|
-
default: false
|
|
75
|
-
},
|
|
76
|
-
scale: {
|
|
77
|
-
type: Boolean,
|
|
78
|
-
default: false
|
|
79
|
-
},
|
|
80
|
-
scaleMin: {
|
|
81
|
-
type: Number,
|
|
82
|
-
default: 0.5
|
|
83
|
-
},
|
|
84
|
-
scaleMax: {
|
|
85
|
-
type: Number,
|
|
86
|
-
default: 10
|
|
87
|
-
},
|
|
88
|
-
scaleValue: {
|
|
89
|
-
type: Number,
|
|
90
|
-
default: 1
|
|
91
|
-
},
|
|
92
|
-
animation: {
|
|
93
|
-
type: Boolean,
|
|
94
|
-
default: true
|
|
95
|
-
},
|
|
96
|
-
speed: {
|
|
97
|
-
type: Number,
|
|
98
|
-
default: 500
|
|
99
|
-
},
|
|
100
|
-
scrollOptions: {
|
|
101
|
-
type: Object,
|
|
102
|
-
default: () => {
|
|
103
|
-
return {}
|
|
104
|
-
}
|
|
105
|
-
},
|
|
107
|
+
},
|
|
108
|
+
watch: {
|
|
109
|
+
x (newVal) {
|
|
110
|
+
this.source = ''
|
|
111
|
+
if (newVal > this.bs.minScrollX) {
|
|
112
|
+
newVal = this.bs.minScrollX
|
|
113
|
+
}
|
|
114
|
+
if (newVal < this.bs.maxScrollX) {
|
|
115
|
+
newVal = this.bs.maxScrollX
|
|
116
|
+
}
|
|
117
|
+
this.currentX = newVal
|
|
118
|
+
this.bs.scrollTo(newVal, this.bs.y, this.speed)
|
|
106
119
|
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
newVal = this.bs.maxScrollX
|
|
115
|
-
}
|
|
116
|
-
this.currentX = newVal
|
|
117
|
-
this.bs.scrollTo(newVal, this.bs.y, this.speed)
|
|
118
|
-
},
|
|
119
|
-
y (newVal) {
|
|
120
|
-
this.source = ''
|
|
121
|
-
if (newVal > this.bs.minScrollY) {
|
|
122
|
-
newVal = this.bs.minScrollY
|
|
123
|
-
}
|
|
124
|
-
if (newVal < this.bs.maxScrollY) {
|
|
125
|
-
newVal = this.bs.maxScrollY
|
|
126
|
-
}
|
|
127
|
-
this.currentY = newVal
|
|
128
|
-
this.bs.scrollTo(this.bs.x, newVal, this.speed)
|
|
129
|
-
},
|
|
130
|
-
scaleValue (newVal) {
|
|
131
|
-
this.isZooming = true
|
|
132
|
-
if (newVal > 10) {
|
|
133
|
-
newVal = 10
|
|
134
|
-
}
|
|
135
|
-
if (newVal < 0.5) {
|
|
136
|
-
newVal = 0.5
|
|
137
|
-
}
|
|
138
|
-
this.bs.zoomTo(newVal, 'center', 'center')
|
|
139
|
-
},
|
|
140
|
-
disabled () {
|
|
141
|
-
this.init()
|
|
120
|
+
y (newVal) {
|
|
121
|
+
this.source = ''
|
|
122
|
+
if (newVal > this.bs.minScrollY) {
|
|
123
|
+
newVal = this.bs.minScrollY
|
|
124
|
+
}
|
|
125
|
+
if (newVal < this.bs.maxScrollY) {
|
|
126
|
+
newVal = this.bs.maxScrollY
|
|
142
127
|
}
|
|
128
|
+
this.currentY = newVal
|
|
129
|
+
this.bs.scrollTo(this.bs.x, newVal, this.speed)
|
|
143
130
|
},
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
131
|
+
scaleValue (newVal) {
|
|
132
|
+
this.isZooming = true
|
|
133
|
+
if (newVal > 10) {
|
|
134
|
+
newVal = 10
|
|
147
135
|
}
|
|
148
|
-
|
|
136
|
+
if (newVal < 0.5) {
|
|
137
|
+
newVal = 0.5
|
|
138
|
+
}
|
|
139
|
+
this.bs.zoomTo(newVal, 'center', 'center')
|
|
149
140
|
},
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
141
|
+
disabled () {
|
|
142
|
+
this.init()
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
mounted () {
|
|
146
|
+
if (!this.scrollOptions.closeResizeObserver) {
|
|
147
|
+
this.createResizeObserver()
|
|
148
|
+
}
|
|
149
|
+
this.init()
|
|
150
|
+
},
|
|
151
|
+
activated () {
|
|
152
|
+
if (this.deactivatedX || this.deactivatedY) {
|
|
153
|
+
this.refresh()
|
|
154
|
+
this.bs.putAt(this.deactivatedX, this.deactivatedY, 0)
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
deactivated () {
|
|
158
|
+
// when the hook is triggered
|
|
159
|
+
// bs will recalculate the boundary of movable to 0
|
|
160
|
+
// so record the position of the movable
|
|
161
|
+
this.deactivatedX = this.bs.x
|
|
162
|
+
this.deactivatedY = this.bs.y
|
|
163
|
+
},
|
|
164
|
+
beforeDestroy () {
|
|
165
|
+
this.destroyBs()
|
|
166
|
+
if (this.resizeObserver) {
|
|
167
|
+
this.resizeObserver.disconnect()
|
|
168
|
+
this.resizeObserver = null
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
methods: {
|
|
172
|
+
createResizeObserver () {
|
|
173
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
174
|
+
this.resizeObserver = new ResizeObserver(entries => {
|
|
175
|
+
if (!this.isInited) {
|
|
176
|
+
this.isInited = true
|
|
177
|
+
return
|
|
178
|
+
}
|
|
179
|
+
this.refresh()
|
|
180
|
+
})
|
|
181
|
+
const elementToObserve = document.querySelector('.mpx-movable-scroll-content')
|
|
182
|
+
elementToObserve && this.resizeObserver.observe(elementToObserve)
|
|
154
183
|
}
|
|
155
184
|
},
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.
|
|
185
|
+
refresh () {
|
|
186
|
+
this.bs && this.bs.refresh()
|
|
187
|
+
},
|
|
188
|
+
destroyBs () {
|
|
189
|
+
if (!this.bs) return
|
|
190
|
+
this.bs.destroy()
|
|
191
|
+
delete this.bs
|
|
162
192
|
},
|
|
163
|
-
|
|
193
|
+
init () {
|
|
164
194
|
this.destroyBs()
|
|
165
|
-
if (this.
|
|
166
|
-
|
|
167
|
-
this.resizeObserver = null
|
|
195
|
+
if (!this.$refs.scrollContent.parentNode || (this.$refs.scrollContent.parentNode && this.$refs.scrollContent.parentNode.className !== 'mpx-movable-scroll-wrapper')) {
|
|
196
|
+
return
|
|
168
197
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
this.initOptions()
|
|
199
|
+
const el = this.$refs.scrollContent
|
|
200
|
+
this.bs = new BScroll(this.$parent.$refs.scroll, extend({
|
|
201
|
+
specifiedIndexAsContent: [].indexOf.call(el.parentElement.children, el) || 0,
|
|
202
|
+
bindToTarget: true,
|
|
203
|
+
freeScroll: false,
|
|
204
|
+
scrollX: false,
|
|
205
|
+
scrollY: false,
|
|
206
|
+
movable: true,
|
|
207
|
+
startX: this.currentX,
|
|
208
|
+
startY: this.currentY,
|
|
209
|
+
bounce: this.outOfBounds,
|
|
210
|
+
bounceTime: 800 / (this.damping / 20),
|
|
211
|
+
probeType: 3
|
|
212
|
+
}, this.bsOptions))
|
|
213
|
+
const BehaviorHooks = this.bs.scroller.scrollBehaviorY.hooks
|
|
214
|
+
const actionsHandlerHooks = this.bs.scroller.actionsHandler.hooks
|
|
215
|
+
const scrollerHooks = this.bs.scroller.hooks
|
|
216
|
+
this.bs.putAt(this.currentX, this.currentY, 0)
|
|
217
|
+
this.lastestX = this.roundFun(this.x)
|
|
218
|
+
this.lastestY = this.roundFun(this.y)
|
|
219
|
+
this.lastestScale = this.roundFun(this.scaleValue)
|
|
220
|
+
this.minScrollX = this.bs.minScrollX
|
|
221
|
+
this.maxScrollX = this.bs.maxScrollX
|
|
222
|
+
this.minScrollY = this.bs.minScrollY
|
|
223
|
+
this.maxScrollY = this.bs.maxScrollY
|
|
224
|
+
scrollerHooks.on('beforeScrollStart', (position) => {
|
|
225
|
+
this.source = 'touch'
|
|
226
|
+
})
|
|
227
|
+
scrollerHooks.on('scroll', (position) => {
|
|
228
|
+
if (position.x > this.minScrollX && this.bs.movingDirectionX === -1 ||
|
|
229
|
+
(position.x < this.maxScrollX && this.bs.movingDirectionX === 1) ||
|
|
230
|
+
(position.y > this.minScrollY && this.bs.movingDirectionY === -1) ||
|
|
231
|
+
(position.y < this.maxScrollY && this.bs.movingDirectionY === 1)) {
|
|
232
|
+
this.source = 'touch-out-of-bounds'
|
|
196
233
|
}
|
|
197
|
-
this.
|
|
198
|
-
|
|
199
|
-
this.bs = new BScroll(this.$parent.$refs.scroll, {
|
|
200
|
-
specifiedIndexAsContent: [].indexOf.call(el.parentElement.children, el) || 0,
|
|
201
|
-
bindToTarget: true,
|
|
202
|
-
freeScroll: false,
|
|
203
|
-
scrollX: false,
|
|
204
|
-
scrollY: false,
|
|
205
|
-
movable: true,
|
|
206
|
-
startX: this.currentX,
|
|
207
|
-
startY: this.currentY,
|
|
208
|
-
bounce: this.outOfBounds,
|
|
209
|
-
bounceTime: 800 / (this.damping / 20),
|
|
210
|
-
probeType: 3,
|
|
211
|
-
...this.bsOptions
|
|
212
|
-
})
|
|
213
|
-
const BehaviorHooks = this.bs.scroller.scrollBehaviorY.hooks
|
|
214
|
-
const actionsHandlerHooks = this.bs.scroller.actionsHandler.hooks
|
|
215
|
-
const scrollerHooks = this.bs.scroller.hooks
|
|
216
|
-
this.bs.putAt(this.currentX, this.currentY, 0)
|
|
217
|
-
this.lastestX = this.roundFun(this.x)
|
|
218
|
-
this.lastestY = this.roundFun(this.y)
|
|
219
|
-
this.lastestScale = this.roundFun(this.scaleValue)
|
|
220
|
-
this.minScrollX = this.bs.minScrollX
|
|
221
|
-
this.maxScrollX = this.bs.maxScrollX
|
|
222
|
-
this.minScrollY = this.bs.minScrollY
|
|
223
|
-
this.maxScrollY = this.bs.maxScrollY
|
|
224
|
-
scrollerHooks.on('beforeScrollStart', (position) => {
|
|
225
|
-
this.source = 'touch'
|
|
226
|
-
})
|
|
227
|
-
scrollerHooks.on('scroll', (position) => {
|
|
228
|
-
if (position.x > this.minScrollX && this.bs.movingDirectionX === -1 ||
|
|
229
|
-
(position.x < this.maxScrollX && this.bs.movingDirectionX === 1) ||
|
|
230
|
-
(position.y > this.minScrollY && this.bs.movingDirectionY === -1) ||
|
|
231
|
-
(position.y < this.maxScrollY && this.bs.movingDirectionY === 1)) {
|
|
232
|
-
this.source = 'touch-out-of-bounds'
|
|
233
|
-
}
|
|
234
|
-
if (this.direction !== 'none' && (this.directions.indexOf(this.direction) >= 0)) {
|
|
235
|
-
if (this.isZooming || (this.roundFun(position.x) === this.lastestX && this.roundFun(position.y) === this.lastestY)) {
|
|
236
|
-
return
|
|
237
|
-
}
|
|
238
|
-
this.$emit('change', getCustomEvent('change', {
|
|
239
|
-
x: this.roundFun(position.x) ? this.roundFun(position.x) : 0,
|
|
240
|
-
y: this.roundFun(position.y) ? this.roundFun(position.y) : 0,
|
|
241
|
-
source: this.source
|
|
242
|
-
}, this))
|
|
243
|
-
}
|
|
244
|
-
this.lastestX = this.roundFun(position.x)
|
|
245
|
-
this.lastestY = this.roundFun(position.y)
|
|
246
|
-
})
|
|
247
|
-
scrollerHooks.on('scrollEnd', (position) =>{
|
|
248
|
-
this.currentX = this.bs.x
|
|
249
|
-
this.currentY = this.bs.y
|
|
250
|
-
})
|
|
251
|
-
scrollerHooks.on('touchEnd', (position) => {
|
|
252
|
-
this.isFirstTouch = true
|
|
253
|
-
if (position.x > this.minScrollX || position.x < this.maxScrollX ||
|
|
254
|
-
position.y > this.minScrollY || position.y < this.maxScrollY
|
|
255
|
-
) {
|
|
256
|
-
this.source = 'out-of-bounds'
|
|
257
|
-
}
|
|
258
|
-
if (position.x > this.minScrollX) {
|
|
259
|
-
this.bs.movingDirectionX = 1
|
|
260
|
-
}
|
|
261
|
-
if (position.x < this.maxScrollX) {
|
|
262
|
-
this.bs.movingDirectionX = -1
|
|
263
|
-
}
|
|
264
|
-
if (position.y > this.minScrollY) {
|
|
265
|
-
this.bs.movingDirectionY = 1
|
|
266
|
-
}
|
|
267
|
-
if (position.y < this.maxScrollY) {
|
|
268
|
-
this.bs.movingDirectionY = -1
|
|
269
|
-
}
|
|
270
|
-
})
|
|
271
|
-
actionsHandlerHooks.on('start', (e) => {
|
|
272
|
-
extendEvent(e, { detail: Object.assign({}, e.detail) })
|
|
273
|
-
this.$emit('touchstart', e)
|
|
274
|
-
})
|
|
275
|
-
actionsHandlerHooks.on('end', (e) => {
|
|
276
|
-
extendEvent(e, { detail: Object.assign({}, e.detail) })
|
|
277
|
-
this.$emit('touchend', e)
|
|
278
|
-
})
|
|
279
|
-
actionsHandlerHooks.on('move', ({ deltaX, deltaY, e }) => {
|
|
280
|
-
if (this.isZooming) {
|
|
234
|
+
if (this.direction !== 'none' && (this.directions.indexOf(this.direction) >= 0)) {
|
|
235
|
+
if (this.isZooming || (this.roundFun(position.x) === this.lastestX && this.roundFun(position.y) === this.lastestY)) {
|
|
281
236
|
return
|
|
282
237
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
extendEvent(e, { detail: Object.assign({}, e.detail), currentTarget: e.target })
|
|
291
|
-
this.$emit(this.touchEvent, e)
|
|
292
|
-
this.$emit('touchmove', e)
|
|
293
|
-
this.isFirstTouch = false
|
|
294
|
-
})
|
|
295
|
-
if (this.inertia) { // movable-view是否带有惯性
|
|
296
|
-
BehaviorHooks.on('momentum', (momentumData, distance) => {
|
|
297
|
-
this.source = 'friction'
|
|
298
|
-
})
|
|
238
|
+
this.$emit('change', getCustomEvent('change', {
|
|
239
|
+
x: this.roundFun(position.x) ? this.roundFun(position.x) : 0,
|
|
240
|
+
y: this.roundFun(position.y) ? this.roundFun(position.y) : 0,
|
|
241
|
+
source: this.source
|
|
242
|
+
}, this))
|
|
299
243
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
this.bs.on('zoomEnd', ({ scale }) => {
|
|
314
|
-
this.isZooming = false
|
|
315
|
-
})
|
|
244
|
+
this.lastestX = this.roundFun(position.x)
|
|
245
|
+
this.lastestY = this.roundFun(position.y)
|
|
246
|
+
})
|
|
247
|
+
scrollerHooks.on('scrollEnd', (position) => {
|
|
248
|
+
this.currentX = this.bs.x
|
|
249
|
+
this.currentY = this.bs.y
|
|
250
|
+
})
|
|
251
|
+
scrollerHooks.on('touchEnd', (position) => {
|
|
252
|
+
this.isFirstTouch = true
|
|
253
|
+
if (position.x > this.minScrollX || position.x < this.maxScrollX ||
|
|
254
|
+
position.y > this.minScrollY || position.y < this.maxScrollY
|
|
255
|
+
) {
|
|
256
|
+
this.source = 'out-of-bounds'
|
|
316
257
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
if (!this.friction || this.friction < 0) {
|
|
320
|
-
this.friction = 2
|
|
258
|
+
if (position.x > this.minScrollX) {
|
|
259
|
+
this.bs.movingDirectionX = 1
|
|
321
260
|
}
|
|
322
|
-
if (
|
|
323
|
-
this.
|
|
324
|
-
...this.bsOptions,
|
|
325
|
-
bindToTarget: !this.scale
|
|
326
|
-
}
|
|
261
|
+
if (position.x < this.maxScrollX) {
|
|
262
|
+
this.bs.movingDirectionX = -1
|
|
327
263
|
}
|
|
328
|
-
if (this.
|
|
329
|
-
this.
|
|
330
|
-
...this.bsOptions,
|
|
331
|
-
zoom: { // for zoom plugin
|
|
332
|
-
start: this.scaleValue,
|
|
333
|
-
min: this.scaleMin < 0.5 ? 0.5 : this.scaleMin,
|
|
334
|
-
max: this.scaleMax > 10 ? 10 : this.scaleMax
|
|
335
|
-
}
|
|
336
|
-
}
|
|
264
|
+
if (position.y > this.minScrollY) {
|
|
265
|
+
this.bs.movingDirectionY = 1
|
|
337
266
|
}
|
|
338
|
-
if (this.
|
|
339
|
-
this.
|
|
340
|
-
...this.bsOptions,
|
|
341
|
-
momentum: true,
|
|
342
|
-
momentumLimitDistance: 30,
|
|
343
|
-
deceleration: this.friction / 2 * 0.05,
|
|
344
|
-
swipeTime: 50
|
|
345
|
-
}
|
|
267
|
+
if (position.y < this.maxScrollY) {
|
|
268
|
+
this.bs.movingDirectionY = -1
|
|
346
269
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
270
|
+
})
|
|
271
|
+
actionsHandlerHooks.on('start', (e) => {
|
|
272
|
+
extendEvent(e, { detail: Object.assign({}, e.detail) })
|
|
273
|
+
this.$emit('touchstart', e)
|
|
274
|
+
})
|
|
275
|
+
actionsHandlerHooks.on('end', (e) => {
|
|
276
|
+
extendEvent(e, { detail: Object.assign({}, e.detail) })
|
|
277
|
+
this.$emit('touchend', e)
|
|
278
|
+
})
|
|
279
|
+
actionsHandlerHooks.on('move', ({ deltaX, deltaY, e }) => {
|
|
280
|
+
if (this.isZooming) {
|
|
281
|
+
return
|
|
282
|
+
}
|
|
283
|
+
if (this.isFirstTouch) {
|
|
284
|
+
if (Math.abs(deltaX) - Math.abs(deltaY) > 0) {
|
|
285
|
+
this.touchEvent = 'htouchmove'
|
|
286
|
+
} else {
|
|
287
|
+
this.touchEvent = 'vtouchmove'
|
|
358
288
|
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
289
|
+
}
|
|
290
|
+
extendEvent(e, { detail: Object.assign({}, e.detail), currentTarget: e.target })
|
|
291
|
+
this.$emit(this.touchEvent, e)
|
|
292
|
+
this.$emit('touchmove', e)
|
|
293
|
+
this.isFirstTouch = false
|
|
294
|
+
})
|
|
295
|
+
if (this.inertia) { // movable-view是否带有惯性
|
|
296
|
+
BehaviorHooks.on('momentum', (momentumData, distance) => {
|
|
297
|
+
this.source = 'friction'
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
if (this.scale) { // 支持双指缩放
|
|
301
|
+
this.bs.on('zooming', ({ scale }) => {
|
|
302
|
+
if (this.lastestScale === this.roundFun(scale)) {
|
|
303
|
+
return
|
|
363
304
|
}
|
|
364
|
-
|
|
365
|
-
this
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
305
|
+
this.isZooming = true
|
|
306
|
+
this.$emit('scale', getCustomEvent('change', {
|
|
307
|
+
x: this.roundFun(this.bs.x),
|
|
308
|
+
y: this.roundFun(this.bs.y),
|
|
309
|
+
scale: this.roundFun(scale)
|
|
310
|
+
}, this))
|
|
311
|
+
this.lastestScale = this.roundFun(scale)
|
|
312
|
+
})
|
|
313
|
+
this.bs.on('zoomEnd', ({ scale }) => {
|
|
314
|
+
this.isZooming = false
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
initOptions () {
|
|
319
|
+
if (!this.friction || this.friction < 0) {
|
|
320
|
+
this.friction = 2
|
|
321
|
+
}
|
|
322
|
+
if (this.$parent.$attrs && this.$parent.$attrs['scale-area'] === "true") {
|
|
323
|
+
extend(this.bsOptions, {
|
|
324
|
+
bindToTarget: !this.scale
|
|
325
|
+
})
|
|
326
|
+
}
|
|
327
|
+
if (this.scale) {
|
|
328
|
+
extend(this.bsOptions, {
|
|
329
|
+
zoom: { // for zoom plugin
|
|
330
|
+
start: this.scaleValue,
|
|
331
|
+
min: this.scaleMin < 0.5 ? 0.5 : this.scaleMin,
|
|
332
|
+
max: this.scaleMax > 10 ? 10 : this.scaleMax
|
|
370
333
|
}
|
|
371
|
-
}
|
|
372
|
-
this.bsOptions = {
|
|
373
|
-
...this.bsOptions,
|
|
374
|
-
...this.scrollOptions
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
// 处理小数点,四舍五入,默认保留一位小数
|
|
378
|
-
roundFun(value, n = 1) {
|
|
379
|
-
return Math.round(value * Math.pow(10, n)) / Math.pow(10, n)
|
|
334
|
+
})
|
|
380
335
|
}
|
|
336
|
+
if (this.inertia) {
|
|
337
|
+
extend(this.bsOptions, {
|
|
338
|
+
momentum: true,
|
|
339
|
+
momentumLimitDistance: 30,
|
|
340
|
+
deceleration: this.friction / 2 * 0.05,
|
|
341
|
+
swipeTime: 50
|
|
342
|
+
})
|
|
343
|
+
}
|
|
344
|
+
if (this.disabled) {
|
|
345
|
+
extend(this.bsOptions, {
|
|
346
|
+
freeScroll: false,
|
|
347
|
+
scrollY: false,
|
|
348
|
+
scrollX: false
|
|
349
|
+
})
|
|
350
|
+
} else if (this.direction === 'vertical') {
|
|
351
|
+
extend(this.bsOptions, {
|
|
352
|
+
scrollY: true
|
|
353
|
+
})
|
|
354
|
+
} else if (this.direction === 'horizontal') {
|
|
355
|
+
extend(this.bsOptions, {
|
|
356
|
+
scrollX: true
|
|
357
|
+
})
|
|
358
|
+
} else if (this.direction === 'all') {
|
|
359
|
+
extend(this.bsOptions, {
|
|
360
|
+
freeScroll: true,
|
|
361
|
+
scrollX: true,
|
|
362
|
+
scrollY: true
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
extend(this.bsOptions, this.scrollOptions)
|
|
366
|
+
},
|
|
367
|
+
// 处理小数点,四舍五入,默认保留一位小数
|
|
368
|
+
roundFun (value, n = 1) {
|
|
369
|
+
return Math.round(value * Math.pow(10, n)) / Math.pow(10, n)
|
|
381
370
|
}
|
|
382
371
|
}
|
|
372
|
+
}
|
|
383
373
|
</script>
|
|
384
374
|
<style lang="stylus" rel="stylesheet/stylus" scoped>
|
|
385
375
|
.mpx-movable-scroll-content
|