@mpxjs/webpack-plugin 2.6.113 → 2.6.114-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/lib/config.js +14 -0
  2. package/lib/dependency/AddEntryDependency.js +24 -0
  3. package/lib/dependency/ResolveDependency.js +4 -0
  4. package/lib/index.js +44 -3
  5. package/lib/json-compiler/index.js +3 -0
  6. package/lib/loader.js +43 -2
  7. package/lib/path-loader.js +4 -1
  8. package/lib/platform/template/wx/component-config/button.js +14 -2
  9. package/lib/platform/template/wx/component-config/image.js +4 -0
  10. package/lib/platform/template/wx/component-config/input.js +4 -0
  11. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  12. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  13. package/lib/platform/template/wx/component-config/switch.js +4 -0
  14. package/lib/platform/template/wx/component-config/text.js +4 -0
  15. package/lib/platform/template/wx/component-config/textarea.js +5 -0
  16. package/lib/platform/template/wx/component-config/view.js +4 -0
  17. package/lib/platform/template/wx/index.js +114 -1
  18. package/lib/runtime/components/tenon/filterTag.js +402 -0
  19. package/lib/runtime/components/tenon/getInnerListeners.js +292 -0
  20. package/lib/runtime/components/tenon/tenon-button.vue +305 -0
  21. package/lib/runtime/components/tenon/tenon-image.vue +61 -0
  22. package/lib/runtime/components/tenon/tenon-input.vue +95 -0
  23. package/lib/runtime/components/tenon/tenon-rich-text.vue +30 -0
  24. package/lib/runtime/components/tenon/tenon-scroll-view.vue +118 -0
  25. package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
  26. package/lib/runtime/components/tenon/tenon-text-area.vue +64 -0
  27. package/lib/runtime/components/tenon/tenon-text.vue +64 -0
  28. package/lib/runtime/components/tenon/tenon-view.vue +89 -0
  29. package/lib/runtime/components/tenon/util.js +44 -0
  30. package/lib/runtime/optionProcessor.tenon.js +386 -0
  31. package/lib/template-compiler/compiler.js +11 -2
  32. package/lib/template-compiler/trans-dynamic-class-expr.js +1 -1
  33. package/lib/tenon/index.js +108 -0
  34. package/lib/tenon/processJSON.js +361 -0
  35. package/lib/tenon/processScript.js +260 -0
  36. package/lib/tenon/processStyles.js +21 -0
  37. package/lib/tenon/processTemplate.js +133 -0
  38. package/lib/utils/get-relative-path.js +24 -0
  39. package/package.json +7 -3
@@ -0,0 +1,305 @@
1
+ <script>
2
+ import { h } from "@hummer/tenon-vue";
3
+ import getInnerListeners from "./getInnerListeners";
4
+
5
+ // 获取当前小程序样式版本配置
6
+ const styleVersion = global.__style || "";
7
+ const sizeClassMap = {
8
+ default: "",
9
+ mini: "mpx-button-size-mini",
10
+ };
11
+ const typeClassMap = {
12
+ primary: "mpx-button-type-primary",
13
+ warn: "mpx-button-type-warn",
14
+ };
15
+ const plainClassMap = {
16
+ false: "",
17
+ true: "mpx-button-plain",
18
+ };
19
+ const disabledClassMap = {
20
+ false: "",
21
+ true: "mpx-button-disabled",
22
+ };
23
+ const clickDisabledClassMap = {
24
+ false: "",
25
+ true: "mpx-button-click-disabled",
26
+ };
27
+ export default (function(){
28
+ return {
29
+ name: "mpx-button",
30
+ data() {
31
+ return {
32
+ hover: false,
33
+ };
34
+ },
35
+ props: {
36
+ name: String,
37
+ size: {
38
+ type: String,
39
+ default: "default",
40
+ },
41
+ type: {
42
+ type: String,
43
+ default: "default",
44
+ },
45
+ plain: Boolean,
46
+ disabled: Boolean,
47
+ loading: Boolean,
48
+ formType: String,
49
+ hoverClass: {
50
+ type: String,
51
+ default: "button-hover",
52
+ },
53
+ hoverStopPropagation: {
54
+ type: Boolean,
55
+ default: false,
56
+ },
57
+ hoverStartTime: {
58
+ type: Number,
59
+ default: 20,
60
+ },
61
+ hoverStayTime: {
62
+ type: Number,
63
+ default: 70,
64
+ },
65
+ },
66
+ computed: {
67
+ className() {
68
+ if (this.hoverClass && this.hoverClass !== "none" && this.hover) {
69
+ return this.hoverClass;
70
+ }
71
+ return "";
72
+ },
73
+ classNameList() {
74
+ let classArr = [];
75
+ if (this.hoverClass && this.hoverClass !== "none" && this.hover) {
76
+ classArr.push(this.hoverClass);
77
+ }
78
+ if (styleVersion === "v2") {
79
+ classArr.push(`${sizeClassMap[this.size]}${styleVersion}`);
80
+ classArr.push(`${typeClassMap[this.type]}${styleVersion}`);
81
+ classArr.push(`mpx-button-version${styleVersion}`);
82
+ } else {
83
+ classArr.push(sizeClassMap[this.size]);
84
+ classArr.push(typeClassMap[this.type]);
85
+ classArr.push(`mpx-button-version`);
86
+ }
87
+ classArr.push(plainClassMap[this.plain]);
88
+ classArr.push(disabledClassMap["" + !!this.disabled]);
89
+ // 禁用click
90
+ classArr.push(clickDisabledClassMap["" + !!this.disabled]);
91
+ return classArr;
92
+ },
93
+ },
94
+ render() {
95
+ let mergeAfter;
96
+ if (this.hoverClass && this.hoverClass !== "none") {
97
+ mergeAfter = {
98
+ listeners: {
99
+ onTouchstart: this.handleTouchstart,
100
+ onTouchend: this.handleTouchend,
101
+ },
102
+ force: true,
103
+ };
104
+ }
105
+ const domProps = {
106
+ disabled: this.disabled,
107
+ plain: this.plain,
108
+ type: this.type,
109
+ };
110
+ const data = {
111
+ class: ["mpx-button", ...this.classNameList],
112
+ ...domProps,
113
+ ...getInnerListeners(this, {
114
+ mergeAfter,
115
+ // 由于当前机制下tap事件只有存在tap监听才会触发,为了确保该组件能够触发tap,传递一个包含tap的defaultListeners用于模拟存在tap监听
116
+ defaultListeners: ["onTap"],
117
+ }),
118
+ };
119
+
120
+ let text = "";
121
+ const nodes = this.$slots.default();
122
+ nodes.forEach((item) => {
123
+ if (item.shapeFlag === 8 && item.children) {
124
+ text += item.children;
125
+ }
126
+ });
127
+ return h("button", data, text);
128
+ },
129
+ methods: {
130
+ handleTouchstart(e) {
131
+ if (e.__hoverStopPropagation) {
132
+ return;
133
+ }
134
+ e.__hoverStopPropagation = this.hoverStopPropagation;
135
+ clearTimeout(this.startTimer);
136
+ this.startTimer = setTimeout(() => {
137
+ this.hover = true;
138
+ }, this.hoverStartTime);
139
+ },
140
+ handleTouchend() {
141
+ clearTimeout(this.endTimer);
142
+ this.endTimer = setTimeout(() => {
143
+ this.hover = false;
144
+ }, this.hoverStayTime);
145
+ },
146
+ },
147
+ }
148
+ })()
149
+ </script>
150
+
151
+
152
+
153
+ <style lang="stylus">
154
+ .mpx-button-versionv2
155
+ width: 184px
156
+ line-height 1.41176471
157
+ font-weight: 700;
158
+ padding-top 8px
159
+ padding-bottom 8px
160
+ .mpx-button-version
161
+ width: 100%
162
+ line-height 2.55555556
163
+ cursor: pointer
164
+ &:after
165
+ border 1px solid rgba(0,0,0,.2)
166
+
167
+ .mpx-button
168
+ padding-left: 14px
169
+ padding-right: 14px
170
+ border none
171
+ outline: none
172
+ position relative
173
+ display block
174
+ margin-left auto
175
+ margin-right auto
176
+ margin-bottom 10px
177
+ box-sizing border-box
178
+ font-size 18px
179
+ text-align center
180
+ text-decoration none
181
+ border-radius 5px
182
+ -webkit-tap-highlight-color transparent
183
+ overflow hidden
184
+ color #000
185
+ background-color #f8f8f8
186
+ &:after
187
+ content " "
188
+ width 200%
189
+ height 200%
190
+ position absolute
191
+ top 0
192
+ left 0
193
+ -webkit-transform scale(.5)
194
+ transform scale(.5)
195
+ -webkit-transform-origin 0 0
196
+ transform-origin 0 0
197
+ box-sizing border-box
198
+ border-radius 10px
199
+
200
+ &.button-hover
201
+ background-color #dedede
202
+
203
+ /* 默认版本 size=mini style */
204
+ &.mpx-button-size-mini
205
+ display inline-block
206
+ line-height 2.3
207
+ font-size 13px
208
+ padding 0 1.34em
209
+ width auto
210
+ /* v2 size=mini style */
211
+ &.mpx-button-size-miniv2
212
+ width auto
213
+ padding 0 0.75em
214
+ line-height 2
215
+ font-size 16px
216
+ display inline-block
217
+ &.mpx-button-plain
218
+ color #353535
219
+ border 1px solid #353535
220
+ background-color transparent
221
+ &.mpx-button-plain.button-hover
222
+ background-color rgba(0, 0, 0, 0)
223
+ color #828282
224
+ border 1px solid #828282
225
+
226
+ /* 默认版本 type=primary style */
227
+ &.mpx-button-type-primary
228
+ background-color #1aad19
229
+ color #fff
230
+ &.mpx-button-type-primary.mpx-button-plain
231
+ color #1aad19
232
+ border-color #1aad19
233
+ background-color #fff
234
+ /* v2 type=primary style */
235
+ &.mpx-button-type-primaryv2
236
+ background-color #07c160
237
+ color #fff
238
+ &.mpx-button-type-primaryv2.button-hover
239
+ color #fff
240
+ background-color #06ad56
241
+ &.mpx-button-type-primaryv2.mpx-button-plain
242
+ color #06ae56
243
+ border-color #179c16
244
+ background-color #fff
245
+ &.mpx-button-type-primaryv2.button-hover.mpx-button-plain
246
+ color #06ae56
247
+ background-color rgba(0, 0, 0, .1)
248
+
249
+ /* 默认版本 type=warn style */
250
+ &.mpx-button-type-warn
251
+ color #fff
252
+ background-color #e64340
253
+ &.mpx-button-type-warn.mpx-button-plain
254
+ color #e64340
255
+ background-color transparent
256
+ border 1px solid #e64340
257
+ /* v2 type=warn style */
258
+ &.mpx-button-type-warnv2
259
+ color #fa5151
260
+ background-color #f2f2f2
261
+ &.mpx-button-type-warnv2.button-hover
262
+ background-color #d9d9d9
263
+ &.mpx-button-type-warnv2.mpx-button-plain
264
+ color #fa5151
265
+ background-color #fff
266
+ border 1px solid #e64340
267
+ &.mpx-button-type-warnv2.button-hover.mpx-button-plain
268
+ color: #f58c8d
269
+ border 1px solid #f58a8b
270
+ background-color #fff
271
+
272
+ &.mpx-button-disabled
273
+ color rgba(0, 0, 0, 0.18) !important
274
+ background-color #fafafa !important
275
+ border 1px solid rgba(0, 0, 0, .2) !important
276
+ &.mpx-button-click-disabled
277
+ pointer-events none
278
+ &.mpx-button-loading
279
+ &.mpx-button-type-warn
280
+ color rgba(255,255,255,.6)
281
+ background-color #ce3c39
282
+ &.mpx-button-type-warnv2
283
+ background-color #d9d9d9
284
+ color #fa5151
285
+ &.mpx-button-type-primary
286
+ color: rgba(255,255,255,.6);
287
+ background-color: #179b16;
288
+ &:before
289
+ content: " "
290
+ display: inline-block
291
+ width: 18px
292
+ height: 18px
293
+ vertical-align: middle
294
+ -webkit-animation: mpxButton 1s steps(12,end) infinite
295
+ animation: mpxButton 1s steps(12,end) infinite
296
+ background transparent url('data:image/svg+xml;base64,PHN2ZyBjbGFzcz0iciIgd2lkdGg9JzEyMHB4JyBoZWlnaHQ9JzEyMHB4JyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj4KICAgIDxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJub25lIiBjbGFzcz0iYmsiPjwvcmVjdD4KICAgIDxyZWN0IHg9JzQ2LjUnIHk9JzQwJyB3aWR0aD0nNycgaGVpZ2h0PScyMCcgcng9JzUnIHJ5PSc1JyBmaWxsPScjRTlFOUU5JwogICAgICAgICAgdHJhbnNmb3JtPSdyb3RhdGUoMCA1MCA1MCkgdHJhbnNsYXRlKDAgLTMwKSc+CiAgICA8L3JlY3Q+CiAgICA8cmVjdCB4PSc0Ni41JyB5PSc0MCcgd2lkdGg9JzcnIGhlaWdodD0nMjAnIHJ4PSc1JyByeT0nNScgZmlsbD0nIzk4OTY5NycKICAgICAgICAgIHRyYW5zZm9ybT0ncm90YXRlKDMwIDUwIDUwKSB0cmFuc2xhdGUoMCAtMzApJz4KICAgICAgICAgICAgICAgICByZXBlYXRDb3VudD0naW5kZWZpbml0ZScvPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyM5Qjk5OUEnCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSg2MCA1MCA1MCkgdHJhbnNsYXRlKDAgLTMwKSc+CiAgICAgICAgICAgICAgICAgcmVwZWF0Q291bnQ9J2luZGVmaW5pdGUnLz4KICAgIDwvcmVjdD4KICAgIDxyZWN0IHg9JzQ2LjUnIHk9JzQwJyB3aWR0aD0nNycgaGVpZ2h0PScyMCcgcng9JzUnIHJ5PSc1JyBmaWxsPScjQTNBMUEyJwogICAgICAgICAgdHJhbnNmb3JtPSdyb3RhdGUoOTAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNBQkE5QUEnCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgxMjAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNCMkIyQjInCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgxNTAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNCQUI4QjknCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgxODAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNDMkMwQzEnCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgyMTAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNDQkNCQ0InCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgyNDAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNEMkQyRDInCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgyNzAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNEQURBREEnCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgzMDAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0PgogICAgPHJlY3QgeD0nNDYuNScgeT0nNDAnIHdpZHRoPSc3JyBoZWlnaHQ9JzIwJyByeD0nNScgcnk9JzUnIGZpbGw9JyNFMkUyRTInCiAgICAgICAgICB0cmFuc2Zvcm09J3JvdGF0ZSgzMzAgNTAgNTApIHRyYW5zbGF0ZSgwIC0zMCknPgogICAgPC9yZWN0Pgo8L3N2Zz4=') no-repeat
297
+ background-size: 100%
298
+ margin -0.2em 0.34em 0 0
299
+
300
+ @keyframes mpxButton
301
+ 0%
302
+ transform: rotate3d(0, 0, 1, 0deg)
303
+ 100%
304
+ transform: rotate3d(0, 0, 1, 360deg)
305
+ </style>
@@ -0,0 +1,61 @@
1
+ <script>
2
+ import { h } from "@hummer/tenon-vue";
3
+ import getInnerListeners from "./getInnerListeners";
4
+
5
+ export default {
6
+ name: "mpx-image",
7
+ props: {
8
+ src: {
9
+ type: String,
10
+ },
11
+ mode: {
12
+ type: String,
13
+ default: "scaleToFill",
14
+ },
15
+ lazyLoad: {
16
+ type: Boolean,
17
+ default: false,
18
+ },
19
+ showMenuByLongpress: {
20
+ type: Boolean,
21
+ default: false,
22
+ },
23
+ },
24
+ render() {
25
+ let resize = "";
26
+ switch (this.mode) {
27
+ case "scaleToFill":
28
+ resize = "stretch";
29
+ break;
30
+ case "aspectFit":
31
+ resize = "contain";
32
+ break;
33
+ case "aspectFill":
34
+ resize = "cover";
35
+ break;
36
+ default:
37
+ resize = "stretch";
38
+ }
39
+ return h("image", {
40
+ class: "mpx-image",
41
+ src: this.src,
42
+ resize,
43
+ ...getInnerListeners(this)
44
+ });
45
+ },
46
+ data() {
47
+ return {};
48
+ },
49
+ pageConfig: {
50
+ canScroll: false,
51
+ },
52
+ methods: {
53
+ },
54
+ };
55
+ </script>
56
+ <style lang="stylus">
57
+ .mpx-image
58
+ width 300px
59
+ height 225px
60
+ display inline-block
61
+ </style>
@@ -0,0 +1,95 @@
1
+ <script>
2
+ import { h } from "@hummer/tenon-vue";
3
+ import getInnerListeners from "./getInnerListeners";
4
+ export default {
5
+ name: "mpx-input",
6
+ props: {
7
+ name: String,
8
+ value: {
9
+ type: String,
10
+ default: "",
11
+ },
12
+ type: {
13
+ type: String,
14
+ default: "text",
15
+ },
16
+ password: Boolean,
17
+ placeholder: String,
18
+ disabled: Boolean,
19
+ maxlength: {
20
+ type: Number,
21
+ default: 140,
22
+ },
23
+ autoFocus: Boolean,
24
+ focus: {
25
+ type: Boolean,
26
+ default: false,
27
+ },
28
+ cursor: {
29
+ type: Number,
30
+ default: -1,
31
+ },
32
+ selectionStart: {
33
+ type: Number,
34
+ default: -1,
35
+ },
36
+ selectionEnd: {
37
+ type: Number,
38
+ default: -1,
39
+ },
40
+ },
41
+ render() {
42
+ let inputType = "";
43
+ if (this.password) {
44
+ inputType = "password";
45
+ } else {
46
+ switch (this.type) {
47
+ case "text":
48
+ inputType = "default";
49
+ break;
50
+ case "number":
51
+ inputType = "number";
52
+ break;
53
+ default:
54
+ inputType = "text";
55
+ }
56
+ }
57
+
58
+ const data = {
59
+ class: "mpx-input",
60
+ value: this.value,
61
+ focus: this.focus,
62
+ placeholder: this.placeholder,
63
+ maxLength: this.maxLength,
64
+ type: inputType,
65
+ disabled: this.disabled,
66
+ ...getInnerListeners(this),
67
+ };
68
+ return h("input", data, []);
69
+ // return '123'
70
+ },
71
+ data() {
72
+ return {};
73
+ },
74
+ pageConfig: {
75
+ canScroll: false,
76
+ },
77
+ methods: {},
78
+ };
79
+ </script>
80
+ <style lang="stylus">
81
+ .mpx-input
82
+ cursor auto
83
+ width 100%
84
+ padding 0
85
+ border 0
86
+ font inherit
87
+ display block
88
+ height 1.4rem
89
+ text-overflow clip
90
+ overflow hidden
91
+ white-space nowrap
92
+ font-family UICTFontTextStyleBody
93
+ min-height 1.4rem
94
+
95
+ </style>
@@ -0,0 +1,30 @@
1
+ <script>
2
+ import { parse, htmlTranStr } from './filterTag.js'
3
+ import getInnerListeners from './getInnerListeners'
4
+ import { h } from '@hummer/tenon-vue'
5
+ export default {
6
+ name: 'mpx-rich-text',
7
+ props: {
8
+ nodes: [Array, String],
9
+ space: {
10
+ type: String
11
+ }
12
+ },
13
+ render () {
14
+ let nodes = this.nodes
15
+ let html = ''
16
+ if (typeof this.nodes === 'string') {
17
+ nodes = parse(this.nodes)
18
+ }
19
+ if (Array.isArray(nodes)) {
20
+ html = htmlTranStr(nodes, this.space)
21
+ }
22
+ console.log('html--------', html)
23
+ const data = {
24
+ richText: html,
25
+ ...getInnerListeners(this)
26
+ }
27
+ return h('text', data)
28
+ }
29
+ }
30
+ </script>
@@ -0,0 +1,118 @@
1
+ <script>
2
+ import getInnerListeners, { getCustomEvent } from "./getInnerListeners";
3
+ import { processSize } from "./util";
4
+ import { h } from "@hummer/tenon-vue";
5
+ export default {
6
+ name: "mpx-scroll-view",
7
+ props: {
8
+ // 允许横向滚动
9
+ scrollX: Boolean,
10
+ // 允许纵向滚动
11
+ scrollY: Boolean,
12
+ // 距顶部/左边多远时,触发 scrolltoupper 事件
13
+ upperThreshold: {
14
+ type: [Number, String],
15
+ default: 50,
16
+ },
17
+ // 距底部/右边多远时,触发 scrolltolower 事件
18
+ lowerThreshold: {
19
+ type: [Number, String],
20
+ default: 50,
21
+ },
22
+ // 设置竖向滚动条位置
23
+ scrollTop: {
24
+ type: [Number, String],
25
+ default: 0,
26
+ },
27
+ // 设置横向滚动条位置
28
+ scrollLeft: {
29
+ type: [Number, String],
30
+ default: 0,
31
+ },
32
+ scrollOptions: Object,
33
+ // 更新refresh
34
+ updateRefresh: {
35
+ type: Boolean,
36
+ default: true,
37
+ },
38
+ // 值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素
39
+ scrollIntoView: String,
40
+ // 在设置滚动条位置时使用动画过渡
41
+ scrollWithAnimation: Boolean,
42
+ // 启用 flexbox 布局。开启后,当前节点声明了 display: flex 就会成为 flex container,并作用于其孩子节点。
43
+ enableFlex: Boolean,
44
+ // 启用 scroll-view 增强特性,启用后可通过 ScrollViewContext 操作 scroll-view
45
+ enhanced: Boolean,
46
+ // 开启自定义下拉刷新
47
+ refresherEnabled: Boolean,
48
+ // 设置当前下拉刷新状态,true 表示下拉刷新已经被触发,false 表示下拉刷新未被触发
49
+ refresherTriggered: Boolean,
50
+ // 设置自定义下拉刷新阈值
51
+ refresherThreshold: {
52
+ type: Number,
53
+ default: 45,
54
+ },
55
+ // 设置自定义下拉刷新默认样式,支持设置 black | white | none, none 表示不使用默认样式
56
+ refresherDefaultStyle: {
57
+ type: String,
58
+ default: "black",
59
+ },
60
+ // 设置自定义下拉刷新区域背景颜色
61
+ refresherBackground: {
62
+ type: String,
63
+ default: "",
64
+ },
65
+ },
66
+ data() {
67
+ return {};
68
+ },
69
+ computed: {
70
+ _scrollTop() {
71
+ // return 1
72
+ return processSize(this.scrollTop);
73
+ },
74
+ _scrollLeft() {
75
+ // return 1
76
+ return processSize(this.scrollLeft);
77
+ },
78
+ },
79
+ mounted() {
80
+ if (this.scrollTop) {
81
+ setTimeout(() => {
82
+ this.$refs.scroll && this.$refs.scroll.scrollTo(0, this._scrollTop);
83
+ }, 100);
84
+
85
+ }
86
+ if (this.scrollLeft) {
87
+ setTimeout(() => {
88
+ this.$refs.scroll && this.$refs.scroll.scrollTo(this._scrollLeft, 0);
89
+ }, 100);
90
+ }
91
+ },
92
+ watch: {
93
+ _scrollTop(val) {
94
+ console.log('触发')
95
+ this.$refs.scroll && this.$refs.scroll.scrollTo(0, val);
96
+ },
97
+ _scrollLeft(val) {
98
+ this.$refs.scroll && this.$refs.scroll.scrollTo(val, 0);
99
+ },
100
+ },
101
+ methods: {},
102
+ render() {
103
+ let scrollDirection = "vertical";
104
+ if (!this.scrollY && this.scrollX) {
105
+ scrollDirection = "horizontal";
106
+ }
107
+ return h(
108
+ "scroller",
109
+ {
110
+ ref: "scroll",
111
+ scrollDirection,
112
+ showScrollBar: true,
113
+ },
114
+ this.$slots.default()
115
+ );
116
+ },
117
+ };
118
+ </script>
@@ -0,0 +1,91 @@
1
+ <script>
2
+ import { getCustomEvent } from "./getInnerListeners";
3
+ import { h } from "@hummer/tenon-vue";
4
+ export default {
5
+ name: "mpx-switch",
6
+ props: {
7
+ name: String,
8
+ type: {
9
+ type: String,
10
+ default: "switch",
11
+ },
12
+ checked: {
13
+ type: Boolean,
14
+ default: false,
15
+ },
16
+ disabled: {
17
+ type: Boolean,
18
+ default: false,
19
+ },
20
+ color: {
21
+ type: String,
22
+ default: "#04BE02",
23
+ },
24
+ },
25
+ watch: {
26
+ checked(newVal) {
27
+ this.switchChecked = newVal;
28
+ },
29
+ },
30
+ data() {
31
+ return {
32
+ switchChecked: this.checked,
33
+ };
34
+ },
35
+ render() {
36
+ let children = [];
37
+
38
+ const switchElem = h("switch", {
39
+ value: this.switchChecked,
40
+ class: [
41
+ "mpx-switch-label",
42
+ this.switchChecked ? "checked-switch-label" : "uncheck-switch-label",
43
+ ],
44
+ });
45
+ children.push(switchElem);
46
+
47
+ // children.push(...(this.$slots.default() || []));
48
+ const data = {
49
+ class: ["mpx-switch-wrap"],
50
+ ref: "switch",
51
+ onClick: (e) => {
52
+ if (this.disabled) {
53
+ return;
54
+ }
55
+ this.switchChecked = !this.switchChecked;
56
+ this.notifyChange();
57
+ },
58
+ };
59
+ return h("view", data, children);
60
+ },
61
+ methods: {
62
+ getValue() {
63
+ return this.switchChecked;
64
+ },
65
+ setValue(value) {
66
+ this.switchChecked = value;
67
+ },
68
+ notifyChange(value) {
69
+ if (value !== undefined) {
70
+ this.setValue(value);
71
+ } else {
72
+ value = this.getValue();
73
+ }
74
+ this.$emit(
75
+ "change",
76
+ getCustomEvent("change", { value }, this.$refs.switch)
77
+ );
78
+ },
79
+ },
80
+ };
81
+ </script>
82
+
83
+ <style lang="stylus">
84
+ .mpx-switch-wrap
85
+ .mpx-switch-label
86
+ border-radius 16hm
87
+ width 52hm
88
+ height 32hm
89
+ border none
90
+
91
+ </style>