@cloudbase/framework-plugin-low-code 0.6.32 → 0.6.33

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 (79) hide show
  1. package/lib/builder/config/index.js +2 -5
  2. package/lib/builder/core/copy.d.ts.map +1 -1
  3. package/lib/builder/mp/materials.d.ts.map +1 -1
  4. package/lib/builder/mp/materials.js +21 -5
  5. package/package.json +5 -3
  6. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/cookie.js +0 -286
  7. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/history.js +0 -133
  8. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/local-storage.js +0 -103
  9. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/location.js +0 -588
  10. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/miniprogram.js +0 -101
  11. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/navigator.js +0 -80
  12. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/performance.js +0 -28
  13. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/screen.js +0 -31
  14. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/session-storage.js +0 -96
  15. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/xml-http-request.js +0 -290
  16. package/template/dist/mp/miniprogram_npm/miniprogram-render/document.js +0 -396
  17. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/custom-event.js +0 -12
  18. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event-target.js +0 -389
  19. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event.js +0 -186
  20. package/template/dist/mp/miniprogram_npm/miniprogram-render/index.js +0 -41
  21. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/attribute.js +0 -226
  22. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/class-list.js +0 -153
  23. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/comment.js +0 -80
  24. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/a.js +0 -165
  25. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/canvas.js +0 -138
  26. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/image.js +0 -177
  27. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/input.js +0 -181
  28. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/not-support.js +0 -60
  29. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/option.js +0 -126
  30. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/select.js +0 -155
  31. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/textarea.js +0 -178
  32. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/video.js +0 -165
  33. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-component.js +0 -84
  34. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-custom-component.js +0 -64
  35. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element.js +0 -970
  36. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/node.js +0 -140
  37. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style-list.js +0 -28
  38. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style.js +0 -158
  39. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/text-node.js +0 -127
  40. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/parser.js +0 -269
  41. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/query-selector.js +0 -420
  42. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/tree.js +0 -130
  43. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/cache.js +0 -95
  44. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/pool.js +0 -24
  45. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/tool.js +0 -131
  46. package/template/dist/mp/miniprogram_npm/miniprogram-render/window.js +0 -651
  47. package/template/generator/app/common.js +0 -17
  48. package/template/generator/app/global-api.js +0 -163
  49. package/template/generator/app/handlers.js +0 -13
  50. package/template/generator/datasources/config.js.tpl +0 -21
  51. package/template/generator/datasources/dataset-profiles.js.tpl +0 -5
  52. package/template/generator/datasources/datasource-profiles.js.tpl +0 -4
  53. package/template/generator/datasources/index.js.tpl +0 -14
  54. package/template/generator/handlers/NodeRenderer.jsx +0 -471
  55. package/template/generator/handlers/RenderWrapper.jsx +0 -145
  56. package/template/generator/index.jsx +0 -116
  57. package/template/generator/index.less +0 -120
  58. package/template/generator/pages/app.tpl +0 -181
  59. package/template/generator/pages/composite.tpl +0 -267
  60. package/template/generator/router/index.tpl +0 -49
  61. package/template/generator/store/computed.js +0 -11
  62. package/template/generator/store/index.js +0 -5
  63. package/template/generator/utils/ScanCodeComponent.js +0 -345
  64. package/template/generator/utils/actionHandler.js +0 -119
  65. package/template/generator/utils/common.js +0 -225
  66. package/template/generator/utils/computed.js +0 -9
  67. package/template/generator/utils/date.js +0 -324
  68. package/template/generator/utils/error.jsx +0 -14
  69. package/template/generator/utils/eventProxy.js +0 -64
  70. package/template/generator/utils/history.js +0 -35
  71. package/template/generator/utils/hooks.js +0 -10
  72. package/template/generator/utils/index.js +0 -41
  73. package/template/generator/utils/initGlobalVar.js +0 -14
  74. package/template/generator/utils/lifecycle.js +0 -158
  75. package/template/generator/utils/monitor-jssdk.min.js +0 -881
  76. package/template/generator/utils/page.js +0 -10
  77. package/template/generator/utils/scan-code-action.js +0 -27
  78. package/template/generator/utils/style.js +0 -81
  79. package/template/generator/utils/widgets.js +0 -343
@@ -1,588 +0,0 @@
1
- /**
2
- * 暂不对 ipv6 地址做支持
3
- */
4
- const EventTarget = require('../event/event-target')
5
- const tool = require('../util/tool')
6
- const cache = require('../util/cache')
7
-
8
- class Location extends EventTarget {
9
- constructor(pageId) {
10
- super()
11
-
12
- this.$_pageId = pageId
13
- this.$_pageRoute = tool.getPageRoute(pageId) // 小程序页面路由
14
-
15
- this.$_protocol = 'https:'
16
- this.$_hostname = ''
17
- this.$_port = ''
18
- this.$_pathname = '/'
19
- this.$_search = ''
20
- this.$_hash = ''
21
-
22
- this.$_lastHash = ''
23
- this.$_lastPathname = ''
24
- this.$_lastSearch = ''
25
- this.$_lastHref = ''
26
- this.$_allowCheck = true // 是否检查 url 和 hash 变化
27
- }
28
-
29
- /**
30
- * 获取 url 中旧的需要进行检测的部分
31
- */
32
- $_getOldValues() {
33
- return {
34
- protocol: this.$_protocol,
35
- hostname: this.$_hostname,
36
- port: this.$_port,
37
- pathname: this.$_pathname,
38
- search: this.$_search,
39
- hash: this.$_hash,
40
- }
41
- }
42
-
43
- /**
44
- * 设置 href,不进入 history
45
- */
46
- $_setHrefWithoutEnterHistory(value) {
47
- if (!value || typeof value !== 'string') return
48
-
49
- this.$$startCheckHash()
50
-
51
- if (!/^(([a-zA-Z0-9]+:)|(\/\/))/i.test(value)) {
52
- // 没有带协议
53
- if (value.indexOf('/') === 0) {
54
- // 以 / 开头,直接替换整个 pathname、search、hash
55
- value = `${this.origin}${value}`
56
- } else if (value.indexOf('#') === 0) {
57
- // 以 # 开头,直接替换整个 hash
58
- value = `${this.origin}${this.$_pathname}${this.$_search}${value}`
59
- } else {
60
- // 非以 / 开头,则替换 pathname 的最后一段、search、hash
61
- let pathname = this.$_pathname.split('/')
62
- pathname.pop()
63
- pathname = pathname.join('/')
64
-
65
- value = `${this.origin}${pathname}/${value}`
66
- }
67
- }
68
-
69
- const {
70
- protocol, hostname, port, hash, search, pathname
71
- } = Location.$$parse(value)
72
- const oldValues = this.$_getOldValues()
73
-
74
- this.$_protocol = protocol || this.$_protocol
75
- this.$_hostname = hostname || this.$_hostname
76
- this.$_port = port || ''
77
- this.$_pathname = pathname || '/'
78
- this.$_search = search || ''
79
- this.$_hash = hash || ''
80
-
81
- this.$$endCheckHash()
82
- this.$_checkUrl(oldValues)
83
- }
84
-
85
- /**
86
- * 进入 history
87
- */
88
- $_enterHistory() {
89
- this.$$trigger('$_addToHistory', {
90
- event: {
91
- href: this.href,
92
- }
93
- })
94
- }
95
-
96
- /**
97
- * 检查 url 变化是否需要跳转
98
- */
99
- $_checkUrl(oldValues) {
100
- if (!this.$_allowCheck) return false
101
-
102
- const window = cache.getWindow(this.$_pageId)
103
-
104
- if (this.$_protocol !== oldValues.protocol || this.$_hostname !== oldValues.hostname || this.$_port !== oldValues.port) {
105
- // 只能跳转相同 protocol、hostname 和 port 的 url
106
- const jumpUrl = this.href
107
-
108
- // 和 web 端不同,这里恢复成原状
109
- this.$_protocol = oldValues.protocol
110
- this.$_hostname = oldValues.hostname
111
- this.$_port = oldValues.port
112
- this.$_pathname = oldValues.pathname
113
- this.$_search = oldValues.search
114
- this.$_hash = oldValues.hash
115
-
116
- window.$$trigger('pageaccessdenied', {
117
- event: {
118
- url: jumpUrl,
119
- type: 'jump',
120
- },
121
- })
122
-
123
- return false
124
- }
125
-
126
- if (this.$_pathname !== oldValues.pathname || this.$_search !== oldValues.search) {
127
- const matchRoute = window.$$miniprogram.getMatchRoute(this.$_pathname)
128
-
129
- if (matchRoute) {
130
- let param = ['type=jump', `targeturl=${encodeURIComponent(this.href)}`]
131
- if (this.$_search) param.push(`search=${encodeURIComponent(this.$_search)}`)
132
- if (this.$_hash) param.push(`hash=${encodeURIComponent(this.$_hash)}`)
133
-
134
- param = '?' + param.join('&')
135
-
136
- const callMethod = window.$$miniprogram.isTabBarPage(matchRoute) ? 'switchTab' : 'redirectTo'
137
- wx[callMethod]({
138
- url: `${matchRoute}${param}`,
139
- })
140
-
141
- if (callMethod === 'switchTab') {
142
- // switchTab 不会销毁页面实例,所以也需要恢复成原状
143
- this.$_protocol = oldValues.protocol
144
- this.$_hostname = oldValues.hostname
145
- this.$_port = oldValues.port
146
- this.$_pathname = oldValues.pathname
147
- this.$_search = oldValues.search
148
- this.$_hash = oldValues.hash
149
- }
150
-
151
- return true
152
- } else {
153
- const jumpUrl = this.href
154
-
155
- // 和 web 端不同,这里恢复成原状
156
- this.$_protocol = oldValues.protocol
157
- this.$_hostname = oldValues.hostname
158
- this.$_port = oldValues.port
159
- this.$_pathname = oldValues.pathname
160
- this.$_search = oldValues.search
161
- this.$_hash = oldValues.hash
162
-
163
- window.$$trigger('pagenotfound', {
164
- event: {
165
- url: jumpUrl,
166
- type: 'jump',
167
- },
168
- })
169
-
170
- return false
171
- }
172
- }
173
-
174
- return true
175
- }
176
-
177
- /**
178
- * 打开一个新页面
179
- */
180
- $$open(url) {
181
- url = tool.completeURL(url, this.origin, true)
182
-
183
- const window = cache.getWindow(this.$_pageId)
184
- const parseRes = Location.$$parse(url)
185
-
186
- if (parseRes.protocol !== this.$_protocol || parseRes.hostname !== this.$_hostname || parseRes.port !== this.$_port) {
187
- // 只能打开相同 protocol、hostname 和 port 的 url
188
- return window.$$trigger('pageaccessdenied', {
189
- event: {
190
- url,
191
- type: 'open',
192
- },
193
- })
194
- }
195
-
196
- const matchRoute = window.$$miniprogram.getMatchRoute(parseRes.pathname || '/')
197
-
198
- if (matchRoute) {
199
- let param = ['type=open', `targeturl=${encodeURIComponent(url)}`]
200
- if (this.$_search) param.push(`search=${encodeURIComponent(parseRes.search || '')}`)
201
- if (this.$_hash) param.push(`hash=${encodeURIComponent(parseRes.hash || '')}`)
202
-
203
- param = '?' + param.join('&')
204
-
205
- const callMethod = window.$$miniprogram.isTabBarPage(matchRoute) ? 'switchTab' : 'navigateTo'
206
- wx[callMethod]({
207
- url: `${matchRoute}${param}`,
208
- })
209
- } else {
210
- window.$$trigger('pagenotfound', {
211
- event: {
212
- url,
213
- type: 'open',
214
- },
215
- })
216
- }
217
- }
218
-
219
- /**
220
- * 重置实例
221
- */
222
- $$reset(url = '') {
223
- const {
224
- protocol, hostname, port, pathname, hash, search
225
- } = Location.$$parse(url)
226
-
227
- this.$_protocol = protocol || 'https:'
228
- this.$_hostname = hostname || ''
229
- this.$_port = port || ''
230
- this.$_pathname = pathname || '/'
231
- this.$_search = search || ''
232
- this.$_hash = hash || ''
233
- }
234
-
235
- /**
236
- * 解析 href
237
- */
238
- static $$parse(href = '') {
239
- href = href.trim()
240
-
241
- // protocol
242
- let protocol = /^[a-zA-Z0-9]+:/i.exec(href)
243
- if (protocol) {
244
- protocol = protocol[0].toLowerCase()
245
- href = href.slice(protocol.length)
246
- }
247
-
248
- // 跳过 //
249
- if (href.indexOf('//') === 0) {
250
- href = href.slice(2)
251
- }
252
-
253
- let hostStart = 0
254
- let hostEnd = -1
255
- let isEnd = false
256
- let host
257
- for (let i = 0, len = href.length; i < len; i++) {
258
- const char = href[i]
259
- if ('\t\n\r "%\';<>\\^`{|}'.indexOf(char) >= 0) {
260
- // RFC 2396:不允许在 hostname 中使用的字符
261
- if (hostEnd === -1) hostEnd = i
262
- } else if ('#/?'.indexOf(char) >= 0) {
263
- // host 结束符
264
- if (hostEnd === -1) hostEnd = i
265
- isEnd = true
266
- } else if (char === '@') {
267
- hostStart = i + 1
268
- hostEnd = -1
269
- }
270
-
271
- if (isEnd) break
272
- }
273
-
274
- if (hostEnd === -1) {
275
- host = href.slice(hostStart)
276
- href = ''
277
- } else {
278
- host = href.slice(hostStart, hostEnd)
279
- href = href.slice(hostEnd)
280
- }
281
-
282
-
283
- // port
284
- let port = /:[0-9]*$/.exec(host)
285
- if (port) {
286
- port = port[0]
287
- host = host.slice(0, host.length - port.length)
288
-
289
- if (port !== ':') port = port.slice(1)
290
- } else {
291
- port = ''
292
- }
293
-
294
- // hostname
295
- for (let i = 0, len = host.length; i < len; i++) {
296
- const char = host[i]
297
- const isValid = (char >= 'a' && char <= 'z') || (char >= 'A' && char <= 'Z') || (char >= '0' && char <= '9') || '.-+_'.indexOf(char) >= 0 || char.charCodeAt(0) > 127
298
-
299
- // 不合法的 host 字符
300
- if (!isValid) {
301
- host = host.slice(0, i)
302
-
303
- href = `/${host.slice(i)}${href}`
304
- }
305
- }
306
- const hostname = host.length > 255 ? '' : host.toLowerCase()
307
-
308
- // hash
309
- let hash
310
- let searchIndex = -1
311
- let hashIndex = -1
312
- for (let i = 0, len = href.length; i < len; i++) {
313
- if (href[i] === '#') {
314
- hash = href.slice(i)
315
- hashIndex = i
316
- break
317
- } else if (href[i] === '?' && searchIndex === -1) {
318
- searchIndex = i
319
- }
320
- }
321
- hash = hash === '#' ? '' : hash
322
-
323
- // search
324
- let search
325
- if (searchIndex !== -1) {
326
- if (hashIndex === -1) {
327
- search = href.slice(searchIndex)
328
- } else {
329
- search = href.slice(searchIndex, hashIndex)
330
- }
331
- }
332
- search = search === '?' ? '' : search
333
-
334
- // pathname
335
- let pathname
336
- const firstIndex = searchIndex !== -1 && (hashIndex === -1 || searchIndex < hashIndex) ? searchIndex : hashIndex
337
- if (firstIndex > 0) {
338
- pathname = href.slice(0, firstIndex)
339
- } else if (firstIndex === -1 && href.length > 0) {
340
- pathname = href
341
- }
342
- if (hostname && !pathname) {
343
- pathname = '/'
344
- }
345
-
346
- return {
347
- protocol,
348
- hostname,
349
- port,
350
- pathname,
351
- hash,
352
- search,
353
- }
354
- }
355
-
356
- /**
357
- * 不触发检查的方式替换 href
358
- */
359
- $$setHrefWithoutCheck(value) {
360
- this.$_allowCheck = false
361
- this.replace(value)
362
- this.$_allowCheck = true
363
- }
364
-
365
- /**
366
- * 开始检查 hash 变化
367
- */
368
- $$startCheckHash() {
369
- if (!this.$_allowCheck) return
370
-
371
- this.$_lastHash = this.$_hash
372
- this.$_lastPathname = this.$_pathname
373
- this.$_lastSearch = this.$_search
374
- this.$_lastHref = this.href
375
- }
376
-
377
- /**
378
- * 检查 hash 变化
379
- */
380
- $$endCheckHash(needCheckUrlChange) {
381
- if (!this.$_allowCheck) return
382
-
383
- if ((needCheckUrlChange || (this.$_lastPathname === this.$_pathname && this.$_lastSearch === this.$_search)) && this.$_lastHash !== this.$_hash) {
384
- this.$$trigger('hashchange', {
385
- event: {
386
- oldURL: this.$_lastHref,
387
- newURL: this.href,
388
- }
389
- })
390
- }
391
-
392
- this.$_lastHash = ''
393
- this.$_lastPathname = ''
394
- this.$_lastSearch = ''
395
- this.$_lastHref = ''
396
- }
397
-
398
- /**
399
- * 对外属性和方法
400
- */
401
- get protocol() {
402
- return this.$_protocol
403
- }
404
-
405
- set protocol(value) {
406
- if (!value || typeof value !== 'string') return
407
-
408
- const parseRes = /^([a-z0-9.+-]+)(:)?$/i.exec(value)
409
- const oldValues = this.$_getOldValues()
410
-
411
- if (parseRes) {
412
- if (parseRes[2] === ':') {
413
- this.$_protocol = value
414
- } else {
415
- this.$_protocol = `${parseRes[1]}:`
416
- }
417
-
418
- if (this.$_checkUrl(oldValues)) this.$_enterHistory()
419
- }
420
- }
421
-
422
- get host() {
423
- return (this.$_hostname || '') + (this.$_port ? ':' + this.$_port : '')
424
- }
425
-
426
- set host(value) {
427
- if (!value || typeof value !== 'string') return
428
-
429
- const {hostname, port} = Location.$$parse(`//${value}`)
430
- const oldValues = this.$_getOldValues()
431
-
432
- this.$_hostname = hostname || this.$_hostname
433
- this.$_port = port || ''
434
-
435
- if (this.$_checkUrl(oldValues)) this.$_enterHistory()
436
- }
437
-
438
- get hostname() {
439
- return this.$_hostname
440
- }
441
-
442
- set hostname(value) {
443
- if (!value || typeof value !== 'string') return
444
-
445
- const {hostname} = Location.$$parse(`//${value}`)
446
- const oldValues = this.$_getOldValues()
447
-
448
- this.$_hostname = hostname || this.$_hostname
449
-
450
- if (this.$_checkUrl(oldValues)) this.$_enterHistory()
451
- }
452
-
453
- get port() {
454
- return this.$_port
455
- }
456
-
457
- set port(value) {
458
- value = +value
459
-
460
- if (typeof value !== 'number' || !isFinite(value) || value <= 0) return
461
-
462
- const port = value === 80 ? '' : value + ''
463
- const oldValues = this.$_getOldValues()
464
-
465
- this.$_port = port
466
-
467
- if (this.$_checkUrl(oldValues)) this.$_enterHistory()
468
- }
469
-
470
- get origin() {
471
- return `${this.$_protocol}//${this.host}`
472
- }
473
-
474
- set origin(value) {
475
- if (!value || typeof value !== 'string') return
476
- if (!/^(([a-zA-Z0-9]+:)|(\/\/))/i.test(value)) return // 没有带协议
477
-
478
- const {protocol, hostname, port} = Location.$$parse(value)
479
- const oldValues = this.$_getOldValues()
480
-
481
- this.$_protocol = protocol || this.$_protocol
482
- this.$_hostname = hostname || this.$_hostname
483
- this.$_port = port || ''
484
-
485
- if (this.$_checkUrl(oldValues)) this.$_enterHistory()
486
- }
487
-
488
- get pathname() {
489
- return this.$_pathname
490
- }
491
-
492
- set pathname(value) {
493
- if (typeof value !== 'string') return
494
-
495
- const oldValues = this.$_getOldValues()
496
-
497
- if (!value || value === '/') {
498
- this.$_pathname = '/'
499
- } else {
500
- if (value[0] !== '/') value = `/${value}`
501
-
502
- const {pathname} = Location.$$parse(`//miniprogram${value}`)
503
-
504
- this.$_pathname = pathname || '/'
505
- }
506
-
507
- if (this.$_checkUrl(oldValues)) this.$_enterHistory()
508
- }
509
-
510
- get search() {
511
- return this.$_search
512
- }
513
-
514
- set search(value) {
515
- if (typeof value !== 'string') return
516
-
517
- const oldValues = this.$_getOldValues()
518
-
519
- if (!value || value === '?') {
520
- this.$_search = ''
521
- } else {
522
- if (value[0] !== '?') value = `?${value}`
523
-
524
- const {search} = Location.$$parse(`//miniprogram${value}`)
525
-
526
- this.$_search = search || ''
527
- }
528
-
529
- if (this.$_checkUrl(oldValues)) this.$_enterHistory()
530
- }
531
-
532
- get hash() {
533
- return this.$_hash
534
- }
535
-
536
- set hash(value) {
537
- if (typeof value !== 'string') return
538
-
539
- this.$$startCheckHash()
540
-
541
- if (!value || value === '#') {
542
- this.$_hash = ''
543
- } else {
544
- if (value[0] !== '#') value = `#${value}`
545
-
546
- const {hash} = Location.$$parse(`//miniprogram${value}`)
547
-
548
- this.$_hash = hash || ''
549
- }
550
-
551
- this.$$endCheckHash()
552
- this.$_enterHistory()
553
- }
554
-
555
- get href() {
556
- return `${this.$_protocol}//${this.host}${this.$_pathname}${this.$_search}${this.$_hash}`
557
- }
558
-
559
- set href(value) {
560
- this.$_setHrefWithoutEnterHistory(value)
561
- this.$_enterHistory()
562
- }
563
-
564
- reload() {
565
- const window = cache.getWindow(this.$_pageId)
566
- let param = ['type=jump', `targeturl=${encodeURIComponent(this.href)}`]
567
- if (this.$_search) param.push(`search=${encodeURIComponent(this.$_search)}`)
568
- if (this.$_hash) param.push(`hash=${encodeURIComponent(this.$_hash)}`)
569
-
570
- param = '?' + param.join('&')
571
-
572
- const callMethod = window.$$miniprogram.isTabBarPage(this.$_pageRoute) ? 'switchTab' : 'redirectTo'
573
- wx[callMethod]({
574
- url: `${this.$_pageRoute}${param}`,
575
- })
576
- }
577
-
578
- replace(value) {
579
- // 和直接赋值 location.href 不同,不需要进入 history
580
- this.$_setHrefWithoutEnterHistory(value)
581
- }
582
-
583
- toString() {
584
- return this.href
585
- }
586
- }
587
-
588
- module.exports = Location
@@ -1,101 +0,0 @@
1
- const cache = require('../util/cache')
2
-
3
- let pageUrlRouteMap = null
4
-
5
- class Miniprogram {
6
- constructor(pageId) {
7
- this.$_pageId = pageId
8
- this.$_pageUrl = '' // 页面真实 url
9
- this.$_subpackagesMap = {} // 分包名映射表
10
- }
11
-
12
- get window() {
13
- return cache.getWindow(this.$_pageId) || null
14
- }
15
-
16
- get document() {
17
- return cache.getDocument(this.$_pageId) || null
18
- }
19
-
20
- get config() {
21
- return cache.getConfig()
22
- }
23
-
24
- get subpackagesMap() {
25
- return this.$_subpackagesMap
26
- }
27
-
28
- /**
29
- * 初始化
30
- */
31
- init(url) {
32
- if (typeof url === 'string') this.$_pageUrl = url // 设置真实 url
33
- const {
34
- origin, entry, router, runtime = {}
35
- } = cache.getConfig()
36
- const subpackagesMap = runtime.subpackagesMap || {}
37
-
38
- this.$_pageUrl = this.$_pageUrl || (origin + entry)
39
- this.$_subpackagesMap = subpackagesMap
40
- this.window.location.$$reset(this.$_pageUrl)
41
- this.window.history.$$reset()
42
-
43
- if (!pageUrlRouteMap) {
44
- // 需要初始化页面 url - 小程序页面路由映射表
45
- pageUrlRouteMap = {}
46
-
47
- Object.keys(router).forEach(pageName => {
48
- const regexpList = []
49
-
50
- router[pageName].forEach(pathObj => {
51
- // 构造正则表达式
52
- const regexp = new RegExp(pathObj.regexp, pathObj.options)
53
- regexpList.push(regexp)
54
- })
55
-
56
- // 将每个页面的路由改造成函数,方便后续做匹配用
57
- pageUrlRouteMap[pageName] = pathname => {
58
- for (const regexp of regexpList) {
59
- const parseRes = regexp.exec(pathname)
60
- regexp.lastIndex = 0
61
-
62
- if (parseRes) {
63
- // 匹配成功
64
- const packageName = subpackagesMap[pageName]
65
- return `/${packageName ? packageName + '/' : ''}pages/${pageName}/index`
66
- }
67
- }
68
-
69
- return null
70
- }
71
- })
72
- }
73
- }
74
-
75
- /**
76
- * 需要匹配对应路由的 route
77
- */
78
- getMatchRoute(pathname) {
79
- const keys = Object.keys(pageUrlRouteMap)
80
- for (const key of keys) {
81
- const matchRes = pageUrlRouteMap[key](pathname)
82
-
83
- if (matchRes) return matchRes // 匹配成功
84
- }
85
-
86
- return null
87
- }
88
-
89
- /**
90
- * 判断是否 tabBar 页面
91
- */
92
- isTabBarPage(pageRoute) {
93
- const {
94
- runtime = {}
95
- } = cache.getConfig()
96
- const tabBarMap = runtime.tabBarMap || {}
97
- return !!tabBarMap[pageRoute]
98
- }
99
- }
100
-
101
- module.exports = Miniprogram