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

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 (80) 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 +30 -5
  5. package/package.json +5 -3
  6. package/template/webpack/web.prod.js +1 -0
  7. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/cookie.js +0 -286
  8. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/history.js +0 -133
  9. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/local-storage.js +0 -103
  10. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/location.js +0 -588
  11. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/miniprogram.js +0 -101
  12. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/navigator.js +0 -80
  13. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/performance.js +0 -28
  14. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/screen.js +0 -31
  15. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/session-storage.js +0 -96
  16. package/template/dist/mp/miniprogram_npm/miniprogram-render/bom/xml-http-request.js +0 -290
  17. package/template/dist/mp/miniprogram_npm/miniprogram-render/document.js +0 -396
  18. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/custom-event.js +0 -12
  19. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event-target.js +0 -389
  20. package/template/dist/mp/miniprogram_npm/miniprogram-render/event/event.js +0 -186
  21. package/template/dist/mp/miniprogram_npm/miniprogram-render/index.js +0 -41
  22. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/attribute.js +0 -226
  23. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/class-list.js +0 -153
  24. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/comment.js +0 -80
  25. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/a.js +0 -165
  26. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/canvas.js +0 -138
  27. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/image.js +0 -177
  28. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/input.js +0 -181
  29. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/not-support.js +0 -60
  30. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/option.js +0 -126
  31. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/select.js +0 -155
  32. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/textarea.js +0 -178
  33. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/video.js +0 -165
  34. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-component.js +0 -84
  35. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element/wx-custom-component.js +0 -64
  36. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/element.js +0 -970
  37. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/node.js +0 -140
  38. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style-list.js +0 -28
  39. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/style.js +0 -158
  40. package/template/dist/mp/miniprogram_npm/miniprogram-render/node/text-node.js +0 -127
  41. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/parser.js +0 -269
  42. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/query-selector.js +0 -420
  43. package/template/dist/mp/miniprogram_npm/miniprogram-render/tree/tree.js +0 -130
  44. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/cache.js +0 -95
  45. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/pool.js +0 -24
  46. package/template/dist/mp/miniprogram_npm/miniprogram-render/util/tool.js +0 -131
  47. package/template/dist/mp/miniprogram_npm/miniprogram-render/window.js +0 -651
  48. package/template/generator/app/common.js +0 -17
  49. package/template/generator/app/global-api.js +0 -163
  50. package/template/generator/app/handlers.js +0 -13
  51. package/template/generator/datasources/config.js.tpl +0 -21
  52. package/template/generator/datasources/dataset-profiles.js.tpl +0 -5
  53. package/template/generator/datasources/datasource-profiles.js.tpl +0 -4
  54. package/template/generator/datasources/index.js.tpl +0 -14
  55. package/template/generator/handlers/NodeRenderer.jsx +0 -471
  56. package/template/generator/handlers/RenderWrapper.jsx +0 -145
  57. package/template/generator/index.jsx +0 -116
  58. package/template/generator/index.less +0 -120
  59. package/template/generator/pages/app.tpl +0 -181
  60. package/template/generator/pages/composite.tpl +0 -267
  61. package/template/generator/router/index.tpl +0 -49
  62. package/template/generator/store/computed.js +0 -11
  63. package/template/generator/store/index.js +0 -5
  64. package/template/generator/utils/ScanCodeComponent.js +0 -345
  65. package/template/generator/utils/actionHandler.js +0 -119
  66. package/template/generator/utils/common.js +0 -225
  67. package/template/generator/utils/computed.js +0 -9
  68. package/template/generator/utils/date.js +0 -324
  69. package/template/generator/utils/error.jsx +0 -14
  70. package/template/generator/utils/eventProxy.js +0 -64
  71. package/template/generator/utils/history.js +0 -35
  72. package/template/generator/utils/hooks.js +0 -10
  73. package/template/generator/utils/index.js +0 -41
  74. package/template/generator/utils/initGlobalVar.js +0 -14
  75. package/template/generator/utils/lifecycle.js +0 -158
  76. package/template/generator/utils/monitor-jssdk.min.js +0 -881
  77. package/template/generator/utils/page.js +0 -10
  78. package/template/generator/utils/scan-code-action.js +0 -27
  79. package/template/generator/utils/style.js +0 -81
  80. package/template/generator/utils/widgets.js +0 -343
@@ -21,12 +21,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
21
21
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
22
22
  for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
23
23
  };
24
- var __importDefault = (this && this.__importDefault) || function (mod) {
25
- return (mod && mod.__esModule) ? mod : { "default": mod };
26
- };
27
24
  Object.defineProperty(exports, "__esModule", { value: true });
28
25
  exports.sharedMaterialsDir = void 0;
29
26
  const path = __importStar(require("path"));
30
- const os_1 = __importDefault(require("os"));
27
+ const os = __importStar(require("os"));
31
28
  __exportStar(require("../../generator/config/index"), exports);
32
- exports.sharedMaterialsDir = path.join(os_1.default.homedir(), '.weapps-materials');
29
+ exports.sharedMaterialsDir = path.join(os.homedir(), '.weapps-materials');
@@ -1 +1 @@
1
- {"version":3,"file":"copy.d.ts","sourceRoot":"","sources":["../../../src/builder/core/copy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAM7D,wBAAsB,OAAO,CAC3B,WAAW,EAAE,MAAM,EACnB,iBAAiB,EAAE,kBAAkB,EACrC,OAAO,EAAE;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,iBAwBpC"}
1
+ {"version":3,"file":"copy.d.ts","sourceRoot":"","sources":["../../../src/builder/core/copy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAM7D,wBAAsB,OAAO,CAC3B,WAAW,EAAE,MAAM,EACnB,iBAAiB,EAAE,kBAAkB,EACrC,OAAO,EAAE;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,iBAwBpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"materials.d.ts","sourceRoot":"","sources":["../../../src/builder/mp/materials.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,uBAAuB,EAIxB,MAAM,mBAAmB,CAAC;AAa3B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAU/C,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAM7C,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,UAAU,EAAE,EACpB,GAAG,EAAE,aAAa,iBA+KnB;AAGD,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,UAAU,EACjB,YAAY,EAAE,oBAAoB,EAAE,EACpC,cAAc,EAAE,aAAa,EAAE,EAC/B,WAAW,CAAC,EAAE,UAAU,cAsCzB;AA6ID,wBAAgB,UAAU,CACxB,GAAG,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,YAAY,CAAC,EACpD,GAAG,EAAE,aAAa,EAClB,WAAW,CAAC,EAAE,WAAW;;;;;;EA8D1B"}
1
+ {"version":3,"file":"materials.d.ts","sourceRoot":"","sources":["../../../src/builder/mp/materials.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,uBAAuB,EAIxB,MAAM,mBAAmB,CAAC;AAa3B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAU/C,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAM7C,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,UAAU,EAAE,EACpB,GAAG,EAAE,aAAa,iBA8NnB;AAGD,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,UAAU,EACjB,YAAY,EAAE,oBAAoB,EAAE,EACpC,cAAc,EAAE,aAAa,EAAE,EAC/B,WAAW,CAAC,EAAE,UAAU,cAsCzB;AA6ID,wBAAgB,UAAU,CACxB,GAAG,EAAE,QAAQ,CAAC,uBAAuB,CAAC,CAAC,YAAY,CAAC,EACpD,GAAG,EAAE,aAAa,EAClB,WAAW,CAAC,EAAE,WAAW;;;;;;EA8D1B"}
@@ -85,8 +85,29 @@ function installMaterials(projDir, usedComps, weapps, ctx) {
85
85
  else {
86
86
  usingMaterialMap[targetDir] = true;
87
87
  }
88
+ const materialsSrcDirPath = path.join(materialsSrcDir, 'src');
89
+ let compGroupIndexJson = '';
90
+ let componentsJson = {};
91
+ const dirsToDelete = [];
92
+ try {
93
+ compGroupIndexJson = yield fs.readJSON(path.join(materialsSrcDirPath, 'index.json'));
94
+ const componentsPathMap = compGroupIndexJson.components;
95
+ componentsJson = Object.keys(componentsPathMap).reduce((acc, compName) => {
96
+ if (usedComps[name].has(compName)) {
97
+ acc[compName] = componentsPathMap[compName];
98
+ }
99
+ else {
100
+ if (typeof componentsPathMap[compName] === 'string') {
101
+ dirsToDelete.push(path.join(targetDir, path.dirname(componentsPathMap[compName])));
102
+ }
103
+ }
104
+ return acc;
105
+ }, {});
106
+ }
107
+ catch (e) {
108
+ console.error('streamline error:', e);
109
+ }
88
110
  if (libUpdated(targetDir, version)) {
89
- const materialsSrcDirPath = path.join(materialsSrcDir, 'src');
90
111
  if (fs.existsSync(materialsSrcDirPath)) {
91
112
  console.log(`Copying material ${materialId} from ${materialsSrcDir}/src to ${targetDir}`);
92
113
  const metaJosnPath = path.join(materialsSrcDir, 'meta.json');
@@ -95,8 +116,7 @@ function installMaterials(projDir, usedComps, weapps, ctx) {
95
116
  }
96
117
  yield fs.copy(materialsSrcDirPath, targetDir, {
97
118
  filter: function (src, dest) {
98
- const path = src.split('/');
99
- return !junk.is(path[path.length - 1]);
119
+ return !junk.is(path.basename(src));
100
120
  },
101
121
  });
102
122
  }
@@ -104,12 +124,17 @@ function installMaterials(projDir, usedComps, weapps, ctx) {
104
124
  console.log(`Copying material ${materialId} from ${materialsSrcDir} to ${targetDir}`);
105
125
  yield fs.copy(materialsSrcDir, targetDir, {
106
126
  filter: function (src, dest) {
107
- const path = src.split('/');
108
- return !junk.is(path[path.length - 1]);
127
+ return !junk.is(path.basename(src));
109
128
  },
110
129
  });
111
130
  }
112
131
  }
132
+ if (compGroupIndexJson) {
133
+ yield fs.writeJSON(path.join(targetDir, 'index.json'), Object.assign(Object.assign({}, compGroupIndexJson), { components: componentsJson }), { spaces: 2 });
134
+ yield Promise.all(dirsToDelete.map((dir) => __awaiter(this, void 0, void 0, function* () {
135
+ fs.remove(dir);
136
+ })));
137
+ }
113
138
  const libMeta = util_4.readComponentLibMata(targetDir);
114
139
  if (!lib.components) {
115
140
  lib.components = Object.keys((libMeta === null || libMeta === void 0 ? void 0 : libMeta.components) || {}).map((name) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/framework-plugin-low-code",
3
- "version": "0.6.32",
3
+ "version": "0.6.35",
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
+ }
@@ -247,6 +247,7 @@ module.exports = function (options) {
247
247
  options: {
248
248
  lessOptions: {
249
249
  modifyVars: themeVars,
250
+ javascriptEnabled: true,
250
251
  },
251
252
  },
252
253
  },
@@ -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
@@ -1,103 +0,0 @@
1
- const Event = require('../event/event')
2
-
3
- class LocalStorage {
4
- constructor(window) {
5
- this.$_keys = []
6
- this.$_window = window
7
- }
8
-
9
- /**
10
- * 更新 storage 信息
11
- */
12
- $_updateInfo() {
13
- try {
14
- const info = wx.getStorageInfoSync()
15
- const pages = getCurrentPages() || []
16
- pages.forEach(page => {
17
- if (page && page.window) {
18
- page.window.localStorage.$$keys = info.keys
19
- }
20
- })
21
- } catch (err) {
22
- console.warn('getStorageInfoSync fail')
23
- }
24
- }
25
-
26
- /**
27
- * 触发 window 的 storage 事件
28
- */
29
- $_triggerStorage(key, newValue, oldValue, force) {
30
- if (!force && newValue === oldValue) return
31
-
32
- const pages = getCurrentPages() || []
33
- pages.forEach(page => {
34
- if (page && page.window && page.window !== this.$_window) {
35
- page.window.$$trigger('storage', {
36
- event: new Event({
37
- name: 'storage',
38
- target: page.window,
39
- $$extra: {
40
- key,
41
- newValue,
42
- oldValue,
43
- storageArea: this,
44
- url: this.$_window.location.href,
45
- }
46
- })
47
- })
48
- }
49
- })
50
- }
51
-
52
- set $$keys(keys) {
53
- this.$_keys = keys
54
- }
55
-
56
- /**
57
- * 对外属性和方法
58
- */
59
- get length() {
60
- return this.$_keys && this.$_keys.length || 0
61
- }
62
-
63
- key(num) {
64
- if (typeof num !== 'number' || !isFinite(num) || num < 0) return null
65
-
66
- return this.$_keys[num] || null
67
- }
68
-
69
- getItem(key) {
70
- if (!key || typeof key !== 'string') return null
71
-
72
- return wx.getStorageSync(key) || null
73
- }
74
-
75
- setItem(key, data) {
76
- if (!key || typeof key !== 'string') return
77
- data = '' + data
78
-
79
- const oldValue = wx.getStorageSync(key) || null
80
-
81
- wx.setStorageSync(key, data)
82
- this.$_updateInfo()
83
- this.$_triggerStorage(key, data, oldValue)
84
- }
85
-
86
- removeItem(key) {
87
- if (!key || typeof key !== 'string') return
88
-
89
- const oldValue = wx.getStorageSync(key) || null
90
-
91
- wx.removeStorageSync(key)
92
- this.$_updateInfo()
93
- this.$_triggerStorage(key, null, oldValue)
94
- }
95
-
96
- clear() {
97
- wx.clearStorageSync()
98
- this.$_updateInfo()
99
- this.$_triggerStorage(null, null, null, true)
100
- }
101
- }
102
-
103
- module.exports = LocalStorage