@truenewx/tnxvue3 3.0.0-alpha.16 → 3.0.0-alpha.17
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/package.json +1 -2
- package/src/tnxvue-router.js +21 -17
- package/src/tdesign/tnxtd.css +0 -4
- package/src/tdesign/tnxtd.js +0 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truenewx/tnxvue3",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.17",
|
|
4
4
|
"description": "互联网技术解决方案:Vue3扩展支持",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,7 +20,6 @@
|
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"element-plus": "~2.8.0",
|
|
23
|
-
"tdesign-vue-next": "~1.9.0",
|
|
24
23
|
"vue": "~3.4.0",
|
|
25
24
|
"vue-router": "~4.4.0"
|
|
26
25
|
},
|
package/src/tnxvue-router.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 基于Vue的路由器构建函数
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import {FunctionUtil, NetUtil} from '@truenewx/tnxcore/src/tnxcore-util';
|
|
5
5
|
|
|
6
6
|
function addRoute(routes, superiorPath, item, fnImportPage) {
|
|
7
7
|
if (item && item.path) {
|
|
@@ -14,12 +14,15 @@ function addRoute(routes, superiorPath, item, fnImportPage) {
|
|
|
14
14
|
cache: {}, // 路由级缓存
|
|
15
15
|
isHistory() { // 通过setTimeout()方式调用才能确保获得正确结果
|
|
16
16
|
return this.historyFrom !== undefined;
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
component() {
|
|
20
|
-
return fnImportPage(page);
|
|
17
|
+
},
|
|
21
18
|
},
|
|
19
|
+
component: item.component,
|
|
22
20
|
};
|
|
21
|
+
if (!route.component) {
|
|
22
|
+
route.component = () => {
|
|
23
|
+
return fnImportPage(page);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
23
26
|
// 如果直接定义route的redirect/alias字段,则item的redirect/alias为undefined时,route仍然有redirect/alias字段,只是其值为undefined,这将导致VueRouter报错
|
|
24
27
|
if (item.redirect) {
|
|
25
28
|
route.redirect = item.redirect;
|
|
@@ -48,7 +51,8 @@ function instantiatePath(path, params) {
|
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
53
|
if (path.contains('/:')) { // 参数替换完之后,还有路径参数,则为无效路径,返回首页
|
|
51
|
-
console.warn(
|
|
54
|
+
console.warn(
|
|
55
|
+
'路径中的参数无法获得参数值,请确保具有参数的路径所属菜单项的下级菜单路径包含相同的参数:' + path);
|
|
52
56
|
return '/';
|
|
53
57
|
}
|
|
54
58
|
}
|
|
@@ -59,11 +63,11 @@ function getCurrentRoute(router) {
|
|
|
59
63
|
return router.currentRoute._value;
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
export default function(VueRouter, menu, fnImportPage) {
|
|
66
|
+
export default function (VueRouter, menu, fnImportPage) {
|
|
63
67
|
let items;
|
|
64
68
|
if (Array.isArray(menu)) {
|
|
65
69
|
items = [];
|
|
66
|
-
menu.forEach(function(m) {
|
|
70
|
+
menu.forEach(function (m) {
|
|
67
71
|
items = items.concat(m.items);
|
|
68
72
|
});
|
|
69
73
|
} else {
|
|
@@ -84,7 +88,7 @@ export default function(VueRouter, menu, fnImportPage) {
|
|
|
84
88
|
// if (window.history && window.history.pushState) {
|
|
85
89
|
// window.history.pushState(null, null, document.URL);
|
|
86
90
|
// }
|
|
87
|
-
window.addEventListener('popstate', function() {
|
|
91
|
+
window.addEventListener('popstate', function () {
|
|
88
92
|
let $route = getCurrentRoute(router);
|
|
89
93
|
if ($route) {
|
|
90
94
|
$route.meta.historyFrom = router.history.state.forward;
|
|
@@ -93,7 +97,7 @@ export default function(VueRouter, menu, fnImportPage) {
|
|
|
93
97
|
|
|
94
98
|
// 注册离开页面前事件处理支持
|
|
95
99
|
router.$beforeLeaveHandlers = {};
|
|
96
|
-
router.beforeLeave = function(handler) {
|
|
100
|
+
router.beforeLeave = function (handler) {
|
|
97
101
|
if (typeof handler === 'function') {
|
|
98
102
|
let $route = getCurrentRoute(router);
|
|
99
103
|
let path = $route.path;
|
|
@@ -101,7 +105,7 @@ export default function(VueRouter, menu, fnImportPage) {
|
|
|
101
105
|
}
|
|
102
106
|
};
|
|
103
107
|
|
|
104
|
-
router.beforeEach(function(to, from, next) {
|
|
108
|
+
router.beforeEach(function (to, from, next) {
|
|
105
109
|
if (typeof window.tnx.router.beforeLeave === 'function') {
|
|
106
110
|
window.tnx.router.beforeLeave(router, from);
|
|
107
111
|
}
|
|
@@ -118,7 +122,7 @@ export default function(VueRouter, menu, fnImportPage) {
|
|
|
118
122
|
}
|
|
119
123
|
});
|
|
120
124
|
|
|
121
|
-
router.afterEach(function(to, from) {
|
|
125
|
+
router.afterEach(function (to, from) {
|
|
122
126
|
router.prev = from;
|
|
123
127
|
// 前后hash相同,但全路径不同(意味着参数不同),则需要刷新页面,否则页面不会刷新
|
|
124
128
|
if (to.href === from.href && to.fullPath !== from.fullPath) {
|
|
@@ -126,7 +130,7 @@ export default function(VueRouter, menu, fnImportPage) {
|
|
|
126
130
|
}
|
|
127
131
|
});
|
|
128
132
|
|
|
129
|
-
router.back = FunctionUtil.around(router.back, function(back, path) {
|
|
133
|
+
router.back = FunctionUtil.around(router.back, function (back, path) {
|
|
130
134
|
if (!router.prev || !router.prev.href) { // 没有href,说明当前页面为刷新后进入的第一个页面,无法简单返回
|
|
131
135
|
let $route = getCurrentRoute(router);
|
|
132
136
|
if (!path) { // 未指定默认返回路径,则返回上一级页面
|
|
@@ -141,21 +145,21 @@ export default function(VueRouter, menu, fnImportPage) {
|
|
|
141
145
|
back.call(router);
|
|
142
146
|
});
|
|
143
147
|
|
|
144
|
-
router.pushState = function(path) {
|
|
148
|
+
router.pushState = function (path) {
|
|
145
149
|
let success = NetUtil.pushState('#' + path);
|
|
146
150
|
if (!success) {
|
|
147
151
|
this.push(path);
|
|
148
152
|
}
|
|
149
153
|
return success;
|
|
150
|
-
}
|
|
154
|
+
};
|
|
151
155
|
|
|
152
|
-
router.replaceState = function(path) {
|
|
156
|
+
router.replaceState = function (path) {
|
|
153
157
|
let success = NetUtil.replaceState('#' + path);
|
|
154
158
|
if (!success) {
|
|
155
159
|
this.replace(path);
|
|
156
160
|
}
|
|
157
161
|
return success;
|
|
158
|
-
}
|
|
162
|
+
};
|
|
159
163
|
|
|
160
164
|
return router;
|
|
161
165
|
}
|
package/src/tdesign/tnxtd.css
DELETED
package/src/tdesign/tnxtd.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 对Tencent TDesign Vue3组件库的扩展支持
|
|
3
|
-
*/
|
|
4
|
-
import TDesign from 'tdesign-vue-next';
|
|
5
|
-
import tnxvue from '../tnxvue.js';
|
|
6
|
-
|
|
7
|
-
import 'tdesign-vue-next/es/style/index.css';
|
|
8
|
-
import './tnxtd.css';
|
|
9
|
-
|
|
10
|
-
export const build = tnxvue.build;
|
|
11
|
-
|
|
12
|
-
export default build('tnxtd', () => {
|
|
13
|
-
const tnxtd = Object.assign({}, tnxvue, {});
|
|
14
|
-
tnxtd.install = tnxtd.util.function.around(tnxtd.install, function (install, vm) {
|
|
15
|
-
install.call(tnxtd, vm);
|
|
16
|
-
if (!tnxtd.libs.TDesign) {
|
|
17
|
-
vm.use(TDesign);
|
|
18
|
-
tnxtd.libs = Object.assign({}, tnxtd.libs, {TDesign});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
return tnxtd;
|
|
22
|
-
});
|