@ray-js/framework-shared 0.6.21 → 0.6.22-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/normalizeTabBar.d.ts +2 -0
- package/lib/normalizeTabBar.js +71 -0
- package/package.json +6 -4
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
2
|
+
import "core-js/modules/es.array.filter.js";
|
3
|
+
import "core-js/modules/es.object.to-string.js";
|
4
|
+
import "core-js/modules/es.array.map.js";
|
5
|
+
import "core-js/modules/es.array.find.js";
|
6
|
+
import "core-js/modules/es.array.concat.js";
|
7
|
+
import "core-js/modules/es.json.stringify.js";
|
8
|
+
import { match, parse } from 'path-to-regexp';
|
9
|
+
export function normalizeTabBar(tabBar, routes) {
|
10
|
+
var list = tabBar.list;
|
11
|
+
|
12
|
+
if (Array.isArray(list)) {
|
13
|
+
// tabBar.list[number].pagePath 必须在 routes[number].page 中,即tab.pagePath === routes[number].page
|
14
|
+
// tabBar.list[number].route 可不配置
|
15
|
+
// tabBar.list[number].route 若未配置,则设置 tabBar.list[number].route = routes[number].page(非模式匹配)或tabBar.list[number].pagePath
|
16
|
+
// tabBar.list[number].route 不能用模式,如不能用/xxx/:id等,必须是明确的 如/xxx/123
|
17
|
+
// tabBar.list[number].route 必须要能命中对应routes[number].route 路由规则,规则详见 path-to-regexp 模块
|
18
|
+
tabBar.list = list.map(function (tab, index) {
|
19
|
+
var _m$route;
|
20
|
+
|
21
|
+
tab = _objectSpread({}, tab);
|
22
|
+
var m = routes.find(function (i) {
|
23
|
+
return tab.pagePath === i.path;
|
24
|
+
});
|
25
|
+
|
26
|
+
if (!m) {
|
27
|
+
throw new Error("tabBar.list[".concat(index, "].pagePath: ").concat(tab.pagePath, " \u9700\u8981\u5728\u8DEF\u7531\u914D\u7F6E\u4E2D: ").concat(JSON.stringify(routes, null, 2)));
|
28
|
+
}
|
29
|
+
|
30
|
+
if (!tab.route) {
|
31
|
+
// 判断 routes[number].route 是否为模式匹配规则
|
32
|
+
tab.route = m.route && parse(m.route).length === 1 ? m.route : m.path;
|
33
|
+
} // 判断是否能被路由命中
|
34
|
+
|
35
|
+
|
36
|
+
var matched = match((_m$route = m.route) !== null && _m$route !== void 0 ? _m$route : m.path)(tab.route);
|
37
|
+
|
38
|
+
if (!matched) {
|
39
|
+
console.warn("tabBar.list[".concat(index, "]\n.route: ").concat(tab.route, "\n.pagePath: ").concat(tab.pagePath, "\n\u5E94\u88AB\u8DEF\u7531\u547D\u4E2D: \n").concat(JSON.stringify(m, null, 2)));
|
40
|
+
return;
|
41
|
+
} // 判断是否还被其他路由命中
|
42
|
+
|
43
|
+
|
44
|
+
var otherMatched = routes.filter(function (r) {
|
45
|
+
return tab.pagePath !== r.path;
|
46
|
+
}).filter(function (r) {
|
47
|
+
var _r$route;
|
48
|
+
|
49
|
+
return match((_r$route = r.route) !== null && _r$route !== void 0 ? _r$route : r.path)(tab.route);
|
50
|
+
});
|
51
|
+
var unusable = otherMatched.filter(function (r) {
|
52
|
+
return r.path !== tab.pagePath;
|
53
|
+
});
|
54
|
+
|
55
|
+
if (unusable.length) {
|
56
|
+
console.warn("tabBar.list[".concat(index, "]\n.route: ").concat(tab.route, "\n%c.pagePath: ").concat(tab.pagePath, "\n%c\u88AB\u5176\u5B83\u8DEF\u7531\u547D\u4E2D\uFF1A\n").concat(JSON.stringify(unusable, null, 2)), 'background:#290000;color:green', 'background:#290000;color:green', 'color:red');
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
|
60
|
+
return tab;
|
61
|
+
}).filter(function (tab) {
|
62
|
+
return !!tab;
|
63
|
+
});
|
64
|
+
|
65
|
+
if (!tabBar.list.length) {
|
66
|
+
return {};
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
return tabBar;
|
71
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ray-js/framework-shared",
|
3
|
-
"version": "0.6.
|
3
|
+
"version": "0.6.22-beta-1",
|
4
4
|
"description": "Ray shared for framework",
|
5
5
|
"keywords": [
|
6
6
|
"ray"
|
@@ -21,10 +21,12 @@
|
|
21
21
|
},
|
22
22
|
"dependencies": {
|
23
23
|
"@ray-core/wechat": "^0.0.x",
|
24
|
-
"@ray-js/env": "^0.6.
|
24
|
+
"@ray-js/env": "^0.6.22-beta-1",
|
25
|
+
"@ray-js/types": "^0.6.22-beta-1",
|
26
|
+
"path-to-regexp": "^6.2.1"
|
25
27
|
},
|
26
28
|
"devDependencies": {
|
27
|
-
"@ray-js/cli": "^0.6.
|
29
|
+
"@ray-js/cli": "^0.6.22-beta-1"
|
28
30
|
},
|
29
31
|
"maintainers": [
|
30
32
|
{
|
@@ -32,6 +34,6 @@
|
|
32
34
|
"email": "tuyafe@tuya.com"
|
33
35
|
}
|
34
36
|
],
|
35
|
-
"gitHead": "
|
37
|
+
"gitHead": "2e905a1820d0adfc0a6ca8cf3ecf1f3a584a0d44",
|
36
38
|
"repository": {}
|
37
39
|
}
|