@ray-js/location 1.4.0-alpha.2 → 1.4.0-alpha.4
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/location.js +18 -23
- package/package.json +7 -7
package/lib/location.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import "core-js/modules/es.object.define-properties.js";
|
|
2
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
3
1
|
import "core-js/modules/es.string.replace.js";
|
|
4
|
-
import "core-js/modules/es.string.search.js";
|
|
5
2
|
import { url } from '@ray-js/library';
|
|
6
3
|
import router from '@ray-js/router';
|
|
4
|
+
|
|
7
5
|
/**
|
|
8
6
|
* 跨平台全局 location 对象,惰性获取,读取时再进行页面路径计算,性能较低
|
|
9
7
|
* 小程序原生 NavBar 跳转的页面无法预先进行设置,所以仅支持在读取可用
|
|
10
8
|
*/
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
const location = {
|
|
13
11
|
href: '',
|
|
14
12
|
hash: '',
|
|
15
13
|
host: '',
|
|
@@ -21,95 +19,92 @@ var location = {
|
|
|
21
19
|
query: {},
|
|
22
20
|
search: '',
|
|
23
21
|
basename: '/' // 只用于web端
|
|
24
|
-
|
|
25
22
|
};
|
|
23
|
+
|
|
26
24
|
Object.defineProperties(location, {
|
|
27
25
|
href: {
|
|
28
26
|
enumerable: true,
|
|
29
27
|
configurable: false,
|
|
30
|
-
get
|
|
28
|
+
get() {
|
|
31
29
|
return router.href;
|
|
32
30
|
}
|
|
33
31
|
},
|
|
34
32
|
hash: {
|
|
35
33
|
enumerable: true,
|
|
36
34
|
configurable: false,
|
|
37
|
-
get
|
|
38
|
-
|
|
35
|
+
get() {
|
|
36
|
+
const q = url.parse(router.href);
|
|
39
37
|
return q.hash;
|
|
40
38
|
}
|
|
41
39
|
},
|
|
42
40
|
host: {
|
|
43
41
|
enumerable: true,
|
|
44
42
|
configurable: false,
|
|
45
|
-
get
|
|
43
|
+
get() {
|
|
46
44
|
return url.parse(this.href).host;
|
|
47
45
|
}
|
|
48
46
|
},
|
|
49
47
|
hostname: {
|
|
50
48
|
enumerable: true,
|
|
51
49
|
configurable: false,
|
|
52
|
-
get
|
|
50
|
+
get() {
|
|
53
51
|
return url.parse(this.href).hostname;
|
|
54
52
|
}
|
|
55
53
|
},
|
|
56
54
|
pathname: {
|
|
57
55
|
enumerable: true,
|
|
58
56
|
configurable: false,
|
|
59
|
-
get
|
|
57
|
+
get() {
|
|
60
58
|
// pathname 不需要basename前缀
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const basename = this.basename;
|
|
60
|
+
const pathname = url.parse(this.href).pathname;
|
|
64
61
|
if (basename !== '/') {
|
|
65
62
|
return pathname.replace(basename, '');
|
|
66
63
|
}
|
|
67
|
-
|
|
68
64
|
return pathname;
|
|
69
65
|
}
|
|
70
66
|
},
|
|
71
67
|
port: {
|
|
72
68
|
enumerable: true,
|
|
73
69
|
configurable: false,
|
|
74
|
-
get
|
|
70
|
+
get() {
|
|
75
71
|
return url.parse(this.href).port;
|
|
76
72
|
}
|
|
77
73
|
},
|
|
78
74
|
protocol: {
|
|
79
75
|
enumerable: true,
|
|
80
76
|
configurable: false,
|
|
81
|
-
get
|
|
77
|
+
get() {
|
|
82
78
|
return url.parse(this.href).protocol;
|
|
83
79
|
}
|
|
84
80
|
},
|
|
85
81
|
search: {
|
|
86
82
|
enumerable: true,
|
|
87
83
|
configurable: false,
|
|
88
|
-
get
|
|
84
|
+
get() {
|
|
89
85
|
return url.parse(this.href).search;
|
|
90
86
|
}
|
|
91
87
|
},
|
|
92
88
|
query: {
|
|
93
89
|
enumerable: true,
|
|
94
90
|
configurable: false,
|
|
95
|
-
get
|
|
91
|
+
get() {
|
|
96
92
|
return url.parse(this.href).query;
|
|
97
93
|
}
|
|
98
94
|
},
|
|
99
95
|
params: {
|
|
100
96
|
enumerable: true,
|
|
101
97
|
configurable: false,
|
|
102
|
-
get
|
|
103
|
-
|
|
98
|
+
get() {
|
|
99
|
+
const page = router.scheduler.getMatchedPage(this.pathname);
|
|
104
100
|
return (page === null || page === void 0 ? void 0 : page.params) || {};
|
|
105
101
|
}
|
|
106
102
|
},
|
|
107
103
|
basename: {
|
|
108
104
|
enumerable: true,
|
|
109
105
|
configurable: false,
|
|
110
|
-
get
|
|
106
|
+
get() {
|
|
111
107
|
var _router$scheduler$bas;
|
|
112
|
-
|
|
113
108
|
// 小程序中没有basename
|
|
114
109
|
return ((_router$scheduler$bas = router.scheduler.basename) !== null && _router$scheduler$bas !== void 0 ? _router$scheduler$bas : '/') || '/';
|
|
115
110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/location",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.4",
|
|
4
4
|
"description": "Ray Core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ray"
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
"watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@ray-js/library": "^1.4.0-alpha.
|
|
24
|
-
"@ray-js/router": "^1.4.0-alpha.
|
|
25
|
-
"@ray-js/router-mp": "^1.4.0-alpha.
|
|
23
|
+
"@ray-js/library": "^1.4.0-alpha.4",
|
|
24
|
+
"@ray-js/router": "^1.4.0-alpha.4",
|
|
25
|
+
"@ray-js/router-mp": "^1.4.0-alpha.4"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@ray-js/cli": "^1.4.0-alpha.
|
|
29
|
-
"@ray-js/types": "^1.4.0-alpha.
|
|
28
|
+
"@ray-js/cli": "^1.4.0-alpha.4",
|
|
29
|
+
"@ray-js/types": "^1.4.0-alpha.4"
|
|
30
30
|
},
|
|
31
31
|
"maintainers": [
|
|
32
32
|
{
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
"email": "tuyafe@tuya.com"
|
|
35
35
|
}
|
|
36
36
|
],
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "ae3621a47944287771e18e926c76ea92d0516097",
|
|
38
38
|
"repository": {}
|
|
39
39
|
}
|