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