@cloudbase/framework-plugin-low-code 0.6.31 → 0.6.34

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 (83) 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/lib/generator/template.d.ts +1 -101
  6. package/lib/generator/template.d.ts.map +1 -1
  7. package/lib/generator/template.js +1 -101
  8. package/package.json +5 -3
  9. package/template/webpack/web.prod.js +66 -85
  10. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/cookie.js +0 -286
  11. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/history.js +0 -133
  12. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/local-storage.js +0 -103
  13. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/location.js +0 -588
  14. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/miniprogram.js +0 -101
  15. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/navigator.js +0 -80
  16. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/performance.js +0 -28
  17. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/screen.js +0 -31
  18. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/session-storage.js +0 -96
  19. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/xml-http-request.js +0 -290
  20. package/template/dist/mp/miniprogram_npm/miniprogram-render/document.js +0 -396
  21. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/custom-event.js +0 -12
  22. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event-target.js +0 -389
  23. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event.js +0 -186
  24. package/template/dist/mp/miniprogram_npm/miniprogram-render/index.js +0 -41
  25. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/attribute.js +0 -226
  26. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/class-list.js +0 -153
  27. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/comment.js +0 -80
  28. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/a.js +0 -165
  29. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/canvas.js +0 -138
  30. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/image.js +0 -177
  31. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/input.js +0 -181
  32. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/not-support.js +0 -60
  33. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/option.js +0 -126
  34. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/select.js +0 -155
  35. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/textarea.js +0 -178
  36. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/video.js +0 -165
  37. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-component.js +0 -84
  38. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-custom-component.js +0 -64
  39. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element.js +0 -970
  40. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/node.js +0 -140
  41. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style-list.js +0 -28
  42. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style.js +0 -158
  43. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/text-node.js +0 -127
  44. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/parser.js +0 -269
  45. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/query-selector.js +0 -420
  46. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/tree.js +0 -130
  47. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/cache.js +0 -95
  48. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/pool.js +0 -24
  49. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/tool.js +0 -131
  50. package/template/dist/mp/miniprogram_npm/miniprogram-render/window.js +0 -651
  51. package/template/generator/app/common.js +0 -17
  52. package/template/generator/app/global-api.js +0 -163
  53. package/template/generator/app/handlers.js +0 -13
  54. package/template/generator/datasources/config.js.tpl +0 -21
  55. package/template/generator/datasources/dataset-profiles.js.tpl +0 -5
  56. package/template/generator/datasources/datasource-profiles.js.tpl +0 -4
  57. package/template/generator/datasources/index.js.tpl +0 -14
  58. package/template/generator/handlers/NodeRenderer.jsx +0 -471
  59. package/template/generator/handlers/RenderWrapper.jsx +0 -145
  60. package/template/generator/index.jsx +0 -116
  61. package/template/generator/index.less +0 -120
  62. package/template/generator/pages/app.tpl +0 -181
  63. package/template/generator/pages/composite.tpl +0 -267
  64. package/template/generator/router/index.tpl +0 -49
  65. package/template/generator/store/computed.js +0 -11
  66. package/template/generator/store/index.js +0 -5
  67. package/template/generator/utils/ScanCodeComponent.js +0 -345
  68. package/template/generator/utils/actionHandler.js +0 -119
  69. package/template/generator/utils/common.js +0 -225
  70. package/template/generator/utils/computed.js +0 -9
  71. package/template/generator/utils/date.js +0 -324
  72. package/template/generator/utils/error.jsx +0 -14
  73. package/template/generator/utils/eventProxy.js +0 -64
  74. package/template/generator/utils/history.js +0 -35
  75. package/template/generator/utils/hooks.js +0 -10
  76. package/template/generator/utils/index.js +0 -41
  77. package/template/generator/utils/initGlobalVar.js +0 -14
  78. package/template/generator/utils/lifecycle.js +0 -158
  79. package/template/generator/utils/monitor-jssdk.min.js +0 -881
  80. package/template/generator/utils/page.js +0 -10
  81. package/template/generator/utils/scan-code-action.js +0 -27
  82. package/template/generator/utils/style.js +0 -81
  83. package/template/generator/utils/widgets.js +0 -343
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/framework-plugin-low-code",
3
- "version": "0.6.31",
3
+ "version": "0.6.34",
4
4
  "description": "云开发 Tencent CloudBase Framework Low Code Plugin,将低码配置生成完整项目并一键部署云开发资源。",
5
5
  "author": "yhsunshining@gmail.com",
6
6
  "homepage": "https://github.com/TencentCloudBase/cloudbase-framework#readme",
@@ -28,7 +28,8 @@
28
28
  "dev": "tsc -w",
29
29
  "prebuild": "rm -rf ./lib && rm -rf ./tsconfig.tsbuildinfo && npm run template",
30
30
  "build": "tsc",
31
- "test": "jest"
31
+ "test": "jest",
32
+ "link": "node scripts/link-packages.js"
32
33
  },
33
34
  "bugs": {
34
35
  "url": "https://github.com/TencentCloudBase/cloudbase-framework/issues"
@@ -70,6 +71,7 @@
70
71
  "xml-js": "^1.6.11"
71
72
  },
72
73
  "devDependencies": {
74
+ "@lerna/create-symlink": "^4.0.0",
73
75
  "@types/archiver": "^3.1.0",
74
76
  "@types/command-exists": "^1.2.0",
75
77
  "@types/cross-spawn": "^6.0.2",
@@ -85,4 +87,4 @@
85
87
  "jest": "^26.0.1",
86
88
  "typescript": "^3.8.3"
87
89
  }
88
- }
90
+ }
@@ -92,22 +92,16 @@ module.exports = function (options) {
92
92
  threadMode: true,
93
93
  loaders: {
94
94
  js: [babelLoader],
95
- ts: [
96
- babelLoader,
97
- typescriptLoader,
98
- ],
99
- }
100
- }
95
+ ts: [babelLoader, typescriptLoader],
96
+ },
97
+ },
101
98
  },
102
99
  ],
103
- threadPool: happyThreadPool
100
+ threadPool: happyThreadPool,
104
101
  }),
105
102
  new HappyPack({
106
103
  id: TS_LOADER_ID,
107
- loaders: [
108
- babelLoader,
109
- typescriptLoader,
110
- ],
104
+ loaders: [babelLoader, typescriptLoader],
111
105
  threadPool: happyThreadPool,
112
106
  }),
113
107
  new HappyPack({
@@ -125,13 +119,15 @@ module.exports = function (options) {
125
119
  filename: '[name].[contenthash].css',
126
120
  chunkFilename: '[id].[contenthash].css',
127
121
  }),
128
- new webpack.DefinePlugin(Object.assign(
129
- {
130
- 'process.env.isMiniprogram': false, // 注入环境变量,用于业务代码判断
131
- 'process.env.SSR': false,
132
- },
133
- definePlugin,
134
- )),
122
+ new webpack.DefinePlugin(
123
+ Object.assign(
124
+ {
125
+ 'process.env.isMiniprogram': false, // 注入环境变量,用于业务代码判断
126
+ 'process.env.SSR': false,
127
+ },
128
+ definePlugin
129
+ )
130
+ ),
135
131
  new CopyWebpackPlugin({
136
132
  patterns: [
137
133
  {
@@ -157,6 +153,36 @@ module.exports = function (options) {
157
153
  }),
158
154
  ]);
159
155
  }
156
+
157
+ const cssLoaders = [
158
+ MiniCssExtractPlugin.loader,
159
+ {
160
+ loader: 'css-loader',
161
+ options: {
162
+ modules: false,
163
+ importLoaders: 2,
164
+ },
165
+ },
166
+ {
167
+ loader: 'postcss-loader',
168
+ options: {
169
+ postcssOptions: {
170
+ plugins: [
171
+ [
172
+ 'postcss-pxtorem',
173
+ {
174
+ rootValue: 14,
175
+ propList: ['*'],
176
+ // todo
177
+ selectorBlackList: ['.weui-picker__indicator'],
178
+ },
179
+ ],
180
+ ],
181
+ },
182
+ },
183
+ },
184
+ ];
185
+
160
186
  return {
161
187
  context,
162
188
  entry,
@@ -184,7 +210,7 @@ module.exports = function (options) {
184
210
  rules: [
185
211
  {
186
212
  test: /\.vue$/,
187
- loader: 'happypack/loader?id=vue'
213
+ loader: 'happypack/loader?id=vue',
188
214
  },
189
215
  {
190
216
  test: /\.tsx?$/,
@@ -199,32 +225,7 @@ module.exports = function (options) {
199
225
  {
200
226
  test: /\.(scss|sass)$/,
201
227
  use: [
202
- MiniCssExtractPlugin.loader,
203
- {
204
- loader: 'css-loader',
205
- options: {
206
- modules: false,
207
- importLoaders: 2,
208
- },
209
- },
210
- {
211
- loader: 'postcss-loader',
212
- options: {
213
- postcssOptions: {
214
- plugins: [
215
- [
216
- 'postcss-pxtorem',
217
- {
218
- rootValue: 14,
219
- propList: ['*'],
220
- // todo
221
- selectorBlackList: ['.weui-picker__indicator'],
222
- },
223
- ],
224
- ],
225
- },
226
- },
227
- },
228
+ ...cssLoaders,
228
229
  {
229
230
  loader: 'sass-loader',
230
231
  options: {
@@ -234,39 +235,19 @@ module.exports = function (options) {
234
235
  ],
235
236
  },
236
237
  {
237
- test: /\.(css|less)$/,
238
+ test: /\.css$/,
239
+ use: [...cssLoaders],
240
+ },
241
+ {
242
+ test: /\.less$/,
238
243
  use: [
239
- MiniCssExtractPlugin.loader,
240
- {
241
- loader: 'css-loader',
242
- options: {
243
- modules: false,
244
- importLoaders: 2,
245
- },
246
- },
247
- {
248
- loader: 'postcss-loader',
249
- options: {
250
- postcssOptions: {
251
- plugins: [
252
- [
253
- 'postcss-pxtorem',
254
- {
255
- rootValue: 14,
256
- propList: ['*'],
257
- // todo
258
- selectorBlackList: ['.weui-picker__indicator'],
259
- },
260
- ],
261
- ],
262
- },
263
- },
264
- },
244
+ ...cssLoaders,
265
245
  {
266
246
  loader: 'less-loader',
267
247
  options: {
268
248
  lessOptions: {
269
249
  modifyVars: themeVars,
250
+ javascriptEnabled: true,
270
251
  },
271
252
  },
272
253
  },
@@ -310,20 +291,20 @@ module.exports = function (options) {
310
291
  },
311
292
  ...(isDevelopment
312
293
  ? {
313
- minimize: false,
314
- removeAvailableModules: false,
315
- removeEmptyChunks: true,
316
- }
294
+ minimize: false,
295
+ removeAvailableModules: false,
296
+ removeEmptyChunks: true,
297
+ }
317
298
  : {
318
- minimizer: [
319
- new TerserPlugin({
320
- test: /\.js(\?.*)?$/i,
321
- cache: false,
322
- parallel: true,
323
- sourceMap: false,
324
- }),
325
- ],
326
- }),
299
+ minimizer: [
300
+ new TerserPlugin({
301
+ test: /\.js(\?.*)?$/i,
302
+ cache: false,
303
+ parallel: true,
304
+ sourceMap: false,
305
+ }),
306
+ ],
307
+ }),
327
308
  },
328
309
  };
329
310
  };
@@ -1,286 +0,0 @@
1
- const Location = require('./location')
2
- const cache = require('../util/cache')
3
-
4
- class Cookie {
5
- constructor(pageName) {
6
- const config = cache.getConfig()
7
- const runtime = config.runtime || {}
8
- this.cookieStore = runtime.cookieStore
9
- this.$_pageName = pageName
10
-
11
- if (this.cookieStore !== 'storage' && this.cookieStore !== 'memory') {
12
- // 需要全局共享
13
- this.$_map = cache.getCookie()
14
- } else {
15
- this.$_map = {} // 三维数组,domain - path - key
16
- }
17
- }
18
-
19
- static parse(cookieStr) {
20
- if (!cookieStr && typeof cookieStr !== 'string') return null
21
-
22
- cookieStr = cookieStr.trim().split(';')
23
-
24
- // key-value
25
- const parseKeyValue = /^([^=;\x00-\x1F]+)=([^;\n\r\0\x00-\x1F]*).*/.exec(cookieStr.shift())
26
- if (!parseKeyValue) return null
27
-
28
- const key = (parseKeyValue[1] || '').trim()
29
- const value = (parseKeyValue[2] || '').trim()
30
-
31
- // 其他字段
32
- let path = null
33
- let domain = null
34
- let expires = null
35
- let maxAge = null
36
- let secure = false
37
- let httpOnly = false
38
-
39
- for (let item of cookieStr) {
40
- item = item.trim()
41
- if (!item) continue
42
-
43
- let [key, value] = item.split('=')
44
- key = (key || '').trim().toLowerCase()
45
- value = (value || '').trim()
46
-
47
- if (!key) continue
48
-
49
- switch (key) {
50
- case 'path':
51
- if (value[0] === '/') path = value
52
- break
53
- case 'domain':
54
- value = value.replace(/^\./, '').toLowerCase()
55
- if (value) domain = value
56
- break
57
- case 'expires':
58
- if (value) {
59
- const timeStamp = Date.parse(value)
60
- if (timeStamp) expires = timeStamp
61
- }
62
- break
63
- case 'max-age':
64
- if (/^-?[0-9]+$/.test(value)) maxAge = +value * 1000
65
- break
66
- case 'secure':
67
- secure = true
68
- break
69
- case 'httponly':
70
- httpOnly = true
71
- break
72
- default:
73
- // ignore
74
- break
75
- }
76
- }
77
-
78
- return {
79
- key, value, path, domain, expires, maxAge, secure, httpOnly
80
- }
81
- }
82
-
83
- /**
84
- * 判断 domain
85
- */
86
- $_checkDomain(host, cookieDomain) {
87
- if (host === cookieDomain) return true
88
-
89
- const index = host.indexOf(`.${cookieDomain}`)
90
-
91
- return index > 0 && cookieDomain.length + index + 1 === host.length
92
- }
93
-
94
- /**
95
- * 判断 path
96
- */
97
- $_checkPath(path, cookiePath) {
98
- if (path === cookiePath) return true
99
-
100
- cookiePath = cookiePath === '/' ? '' : cookiePath
101
- return path.indexOf(`${cookiePath}/`) === 0
102
- }
103
-
104
- /**
105
- * 判断过期
106
- */
107
- $_checkExpires(cookie) {
108
- const now = Date.now()
109
-
110
- // maxAge 优先
111
- if (cookie.maxAge !== null) return cookie.createTime + cookie.maxAge > now
112
-
113
- // 判断 expires
114
- if (cookie.expires !== null) return cookie.expires > now
115
-
116
- return true
117
- }
118
-
119
- /**
120
- * 设置 cookie
121
- */
122
- setCookie(cookie, url) {
123
- cookie = Cookie.parse(cookie)
124
-
125
- if (!cookie) return
126
-
127
- const {hostname, port, pathname} = Location.$$parse(url)
128
- const host = ((hostname || '') + (port ? ':' + port : '')) || ''
129
- const path = (pathname || '')[0] === '/' ? pathname : '/'
130
-
131
- if (cookie.domain) {
132
- // 判断 domain
133
- if (!this.$_checkDomain(host, cookie.domain)) return
134
- } else {
135
- // 使用 host 作为默认的 domain
136
- cookie.domain = host
137
- }
138
-
139
- // 需要设置 path 字段的情况,取 url 中除去最后一节的 path
140
- if (!cookie.path || cookie.path[0] !== '/') {
141
- const lastIndex = path.lastIndexOf('/')
142
-
143
- cookie.path = lastIndex === 0 ? path : path.substr(0, lastIndex)
144
- }
145
-
146
- // 存入 cookie
147
- const map = this.$_map
148
- const cookieDomain = cookie.domain
149
- const cookiePath = cookie.path
150
- const cookieKey = cookie.key
151
-
152
- if (!map[cookieDomain]) map[cookieDomain] = {}
153
- if (!map[cookieDomain][cookiePath]) map[cookieDomain][cookiePath] = {}
154
-
155
- const oldCookie = map[cookieDomain][cookiePath][cookieKey]
156
- cookie.createTime = oldCookie && oldCookie.createTime || Date.now()
157
-
158
- if (this.$_checkExpires(cookie)) {
159
- // 未过期
160
- map[cookieDomain][cookiePath][cookieKey] = cookie
161
- } else if (oldCookie) {
162
- // 存在旧 cookie,且被设置为已过期
163
- delete map[cookieDomain][cookiePath][cookieKey]
164
- }
165
-
166
- // 持久化 cookie
167
- if (this.cookieStore !== 'memory' && this.cookieStore !== 'globalmemory') {
168
- const key = this.cookieStore === 'storage' ? `PAGE_COOKIE_${this.$_pageName}` : 'PAGE_COOKIE'
169
- wx.setStorage({
170
- key,
171
- data: this.serialize(),
172
- })
173
- }
174
- }
175
-
176
- /**
177
- * 拉取 cookie
178
- */
179
- getCookie(url, includeHttpOnly) {
180
- const {
181
- protocol, hostname, port, pathname
182
- } = Location.$$parse(url)
183
- const host = ((hostname || '') + (port ? ':' + port : '')) || ''
184
- const path = (pathname || '')[0] === '/' ? pathname : '/'
185
- const res = []
186
-
187
- const map = this.$_map
188
- const domainList = Object.keys(map)
189
-
190
- for (const domainItem of domainList) {
191
- // 判断 domain
192
- if (this.$_checkDomain(host, domainItem)) {
193
- const domainMap = map[domainItem] || {}
194
- const pathList = Object.keys(domainMap)
195
-
196
- for (const pathItem of pathList) {
197
- // 判断 path
198
- if (this.$_checkPath(path, pathItem)) {
199
- const pathMap = map[domainItem][pathItem] || {}
200
-
201
- Object.keys(pathMap).forEach(key => {
202
- const cookie = pathMap[key]
203
-
204
- if (!cookie) return
205
-
206
- // 判断协议
207
- if (cookie.secure && protocol !== 'https:' && protocol !== 'wss:') return
208
- if (!includeHttpOnly && cookie.httpOnly && protocol && protocol !== 'http:') return
209
-
210
- // 判断过期
211
- if (this.$_checkExpires(cookie)) {
212
- res.push(cookie)
213
- } else {
214
- // 过期,删掉
215
- delete map[domainItem][pathItem][key]
216
- }
217
- })
218
- }
219
- }
220
- }
221
- }
222
-
223
- return res
224
- .sort((a, b) => {
225
- const gap = a.createTime - b.createTime
226
-
227
- if (!gap) {
228
- return a.key < b.key ? -1 : 1
229
- } else {
230
- return gap
231
- }
232
- })
233
- .map(cookie => `${cookie.key}=${cookie.value}`)
234
- .join('; ')
235
- }
236
-
237
- /**
238
- * 序列化
239
- */
240
- serialize() {
241
- try {
242
- return JSON.stringify(this.$_map)
243
- } catch (err) {
244
- console.log('cannot serialize the cookie')
245
- return ''
246
- }
247
- }
248
-
249
- /**
250
- * 反序列化
251
- */
252
- deserialize(str) {
253
- let map = {}
254
- try {
255
- map = JSON.parse(str)
256
- } catch (err) {
257
- console.log('cannot deserialize the cookie')
258
- map = {}
259
- }
260
-
261
- // 合并 cookie
262
- const domainList = Object.keys(map)
263
-
264
- for (const domainItem of domainList) {
265
- const domainMap = map[domainItem] || {}
266
- const pathList = Object.keys(domainMap)
267
-
268
- for (const pathItem of pathList) {
269
- const pathMap = map[domainItem][pathItem] || {}
270
-
271
- Object.keys(pathMap).forEach(key => {
272
- const cookie = pathMap[key]
273
-
274
- if (!cookie) return
275
-
276
- // 已存在则不覆盖
277
- if (!this.$_map[domainItem]) this.$_map[domainItem] = {}
278
- if (!this.$_map[domainItem][pathItem]) this.$_map[domainItem][pathItem] = {}
279
- if (!this.$_map[domainItem][pathItem][key]) this.$_map[domainItem][pathItem][key] = cookie
280
- })
281
- }
282
- }
283
- }
284
- }
285
-
286
- module.exports = Cookie
@@ -1,133 +0,0 @@
1
- /**
2
- * 暂不维护跳转后页面的历史,不做页面刷新的操作
3
- */
4
- const Location = require('./location')
5
- const EventTarget = require('../event/event-target')
6
-
7
- class History extends EventTarget {
8
- constructor(location) {
9
- super()
10
-
11
- this.$_location = location
12
- this.$_stack = [{
13
- state: null,
14
- title: '',
15
- url: location.href,
16
- }]
17
- this.$_currentIndex = 0
18
-
19
- this.$_location.addEventListener('$_addToHistory', evt => {
20
- this.$_currentIndex++
21
- this.$_stack = this.$_stack.slice(0, this.$_currentIndex)
22
- this.$_stack.push({
23
- state: null,
24
- title: '',
25
- url: evt.href
26
- })
27
- })
28
- }
29
-
30
- /**
31
- * 检查是否同源
32
- */
33
- $_checkOrigin(url) {
34
- const {protocol, hostname, port} = Location.$$parse(url)
35
-
36
- return (!protocol || this.$_location.protocol === protocol) && (!hostname || this.$_location.hostname === hostname) && ((!hostname && !port) || this.$_location.port === port)
37
- }
38
-
39
- /**
40
- * 重置实例
41
- */
42
- $$reset() {
43
- this.$_stack = [{
44
- state: null,
45
- title: '',
46
- url: this.$_location.href,
47
- }]
48
- this.$_currentIndex = 0
49
- }
50
-
51
- /**
52
- * 对外属性和方法
53
- */
54
- get state() {
55
- const current = this.$_stack[this.$_currentIndex]
56
- return current && current.state || null
57
- }
58
-
59
- get length() {
60
- return this.$_stack.length
61
- }
62
-
63
- back() {
64
- this.go(-1)
65
- }
66
-
67
- forward() {
68
- this.go(1)
69
- }
70
-
71
- go(delta) {
72
- if (typeof delta === 'number') {
73
- const next = this.$_currentIndex + delta
74
-
75
- if (next >= 0 && next < this.$_stack.length && this.$_currentIndex !== next) {
76
- this.$_currentIndex = next
77
- // 替换 href,但不做跳转(理论上此处应该做跳转,但是在小程序环境里不适合)
78
- this.$_location.$$startCheckHash()
79
- this.$_location.$$setHrefWithoutCheck(this.$_stack[this.$_currentIndex].url)
80
- this.$_location.$$endCheckHash(true) // 因为不跳转,所以要强制触发 hashchange 检测
81
-
82
- this.$$trigger('popstate', {
83
- event: {
84
- state: this.state
85
- }
86
- })
87
- }
88
- } else {
89
- // 刷新当前页面
90
- this.$_location.reload()
91
- }
92
- }
93
-
94
- pushState(state = null, title, url) {
95
- if (!url || typeof url !== 'string') return
96
-
97
- if (this.$_checkOrigin(url)) {
98
- // 同源才允许操作
99
- if (title && typeof title === 'string') {
100
- // 设置标题
101
- wx.setNavigationBarTitle({title})
102
- }
103
-
104
-
105
- this.$_currentIndex++
106
- this.$_stack = this.$_stack.slice(0, this.$_currentIndex)
107
-
108
- // 替换 href,但不做跳转
109
- this.$_location.$$setHrefWithoutCheck(url)
110
-
111
- this.$_stack.push({state, title, url: this.$_location.href})
112
- }
113
- }
114
-
115
- replaceState(state = null, title, url) {
116
- if (!url || typeof url !== 'string') return
117
-
118
- if (this.$_checkOrigin(url)) {
119
- // 同源才允许操作
120
- if (title && typeof title === 'string') {
121
- // 设置标题
122
- wx.setNavigationBarTitle({title})
123
- }
124
-
125
- // 替换 href,但不做跳转
126
- this.$_location.$$setHrefWithoutCheck(url)
127
-
128
- this.$_stack.splice(this.$_currentIndex, 1, {state, title, url: this.$_location.href})
129
- }
130
- }
131
- }
132
-
133
- module.exports = History