swico 1.6.0-beta.5 → 1.6.0-beta.6
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 -1
- package/src/project-path/.swico-react/$env/index.d.ts +1 -1
- package/src/project-path/.swico-react/$env/index.js +1 -1
- package/src/template/global.d.ts +0 -3
- package/src/template/global.js +0 -3
- package/src/template/layout/Layout.d.ts +0 -2
- package/src/template/layout/Layout.js +0 -6
- package/src/template/layout/index.d.ts +0 -3
- package/src/template/layout/index.js +0 -8
- package/src/template/react/$env/config.d.ts +0 -3
- package/src/template/react/$env/config.js +0 -5
- package/src/template/react/$env/history.d.ts +0 -18
- package/src/template/react/$env/history.js +0 -168
- package/src/template/react/$env/index.d.ts +0 -13
- package/src/template/react/$env/index.js +0 -109
- package/src/template/react/$env/routes.d.ts +0 -3
- package/src/template/react/$env/routes.js +0 -3
- package/src/template/react/loading.d.ts +0 -2
- package/src/template/react/loading.js +0 -3
- package/src/template/react/react-hooks.d.ts +0 -3
- package/src/template/react/react-hooks.js +0 -73
- package/src/template/vue/$env/config.d.ts +0 -3
- package/src/template/vue/$env/config.js +0 -5
- package/src/template/vue/$env/history.d.ts +0 -3
- package/src/template/vue/$env/history.js +0 -76
- package/src/template/vue/$env/index.d.ts +0 -1
- package/src/template/vue/$env/index.js +0 -17
- package/src/template/vue/$env/routes.d.ts +0 -6
- package/src/template/vue/$env/routes.js +0 -3
- package/src/template/vue/Container.d.ts +0 -2
- package/src/template/vue/Container.js +0 -4
- package/src/template/vue/Container.vue +0 -15
- package/src/template/vue/vue-hooks.d.ts +0 -4
- package/src/template/vue/vue-hooks.js +0 -85
package/package.json
CHANGED
|
@@ -47,7 +47,7 @@ var react_1 = __importStar(require("react"));
|
|
|
47
47
|
var react_router_dom_1 = require("react-router-dom");
|
|
48
48
|
var loading_1 = __importDefault(require("../loading"));
|
|
49
49
|
var history_1 = require("./history");
|
|
50
|
-
require("../../global");
|
|
50
|
+
require("../../src/global");
|
|
51
51
|
var layout_1 = __importDefault(require("../../src/layout"));
|
|
52
52
|
var routes_1 = __importDefault(require("./routes"));
|
|
53
53
|
var config_1 = require("./config");
|
package/src/template/global.d.ts
DELETED
package/src/template/global.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
var react_router_dom_1 = require("react-router-dom");
|
|
7
|
-
var react_1 = __importDefault(require("react"));
|
|
8
|
-
exports.default = (function () { return react_1.default.createElement(react_router_dom_1.Outlet, null); });
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { SwicoHistoryType, SwicoLocationType } from '../../../typings/global-type';
|
|
2
|
-
export declare const compareURLPatterns: (urlPatternWithValues: string, urlPatternWithParams: string) => boolean;
|
|
3
|
-
export declare const interpolatePath: (pathTemplate: string, params: Record<string, any>) => string;
|
|
4
|
-
export declare const formatAncPath: (ancPath: string) => string;
|
|
5
|
-
export declare const pathNameList: {
|
|
6
|
-
path: string;
|
|
7
|
-
name: string;
|
|
8
|
-
custom?: any;
|
|
9
|
-
}[];
|
|
10
|
-
export declare const getHistory: (router: any) => {
|
|
11
|
-
go: (delta: any) => void;
|
|
12
|
-
forward: () => void;
|
|
13
|
-
back: () => void;
|
|
14
|
-
push: (to: any) => void;
|
|
15
|
-
replace: (to: any) => void;
|
|
16
|
-
readonly location: SwicoLocationType;
|
|
17
|
-
};
|
|
18
|
-
export declare let history: SwicoHistoryType;
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.history = exports.getHistory = exports.pathNameList = exports.formatAncPath = exports.interpolatePath = exports.compareURLPatterns = void 0;
|
|
7
|
-
var qs_1 = __importDefault(require("qs"));
|
|
8
|
-
var routes_1 = __importDefault(require("./routes"));
|
|
9
|
-
var config_1 = require("./config");
|
|
10
|
-
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
11
|
-
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
12
|
-
var compareURLPatterns = function (urlPatternWithValues, urlPatternWithParams) {
|
|
13
|
-
var patternWithValuesParts = urlPatternWithValues.split('/');
|
|
14
|
-
var patternWithParamsParts = urlPatternWithParams.split('/');
|
|
15
|
-
if (patternWithValuesParts.length !== patternWithParamsParts.length) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
for (var i = 0; i < patternWithValuesParts.length; i++) {
|
|
19
|
-
var valuePart = patternWithValuesParts[i];
|
|
20
|
-
var paramPart = patternWithParamsParts[i];
|
|
21
|
-
if (paramPart.startsWith(':') && paramPart !== '') {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
if (valuePart !== paramPart) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
29
|
-
};
|
|
30
|
-
exports.compareURLPatterns = compareURLPatterns;
|
|
31
|
-
var interpolatePath = function (pathTemplate, params) {
|
|
32
|
-
var pathParts = pathTemplate.split('/');
|
|
33
|
-
var interpolatedParts = pathParts.map(function (part) {
|
|
34
|
-
var paramMatch = part.match(/^\:(.+)$/);
|
|
35
|
-
if (paramMatch) {
|
|
36
|
-
var paramName = paramMatch[1];
|
|
37
|
-
if (params[paramName]) {
|
|
38
|
-
return params[paramName];
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
throw "Missing required params '".concat(paramName, "'");
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return part;
|
|
45
|
-
});
|
|
46
|
-
return interpolatedParts.join('/');
|
|
47
|
-
};
|
|
48
|
-
exports.interpolatePath = interpolatePath;
|
|
49
|
-
var interpolatePathParams = function (pathTemplate, path) {
|
|
50
|
-
var _a;
|
|
51
|
-
if (pathTemplate === void 0) { pathTemplate = ''; }
|
|
52
|
-
var regexPattern = pathTemplate.replace(/:(\w+)/g, '([^/]+)');
|
|
53
|
-
var regex = new RegExp("^".concat(regexPattern, "$"));
|
|
54
|
-
var match = path.match(regex);
|
|
55
|
-
if (match) {
|
|
56
|
-
var params_1 = match.slice(1);
|
|
57
|
-
var paramNames = ((_a = pathTemplate.match(/:(\w+)/g)) === null || _a === void 0 ? void 0 : _a.map(function (name) { return name.slice(1); })) || [];
|
|
58
|
-
var result_1 = {};
|
|
59
|
-
paramNames.forEach(function (name, index) {
|
|
60
|
-
result_1[name] = params_1[index];
|
|
61
|
-
});
|
|
62
|
-
return result_1;
|
|
63
|
-
}
|
|
64
|
-
return {};
|
|
65
|
-
};
|
|
66
|
-
var formatAncPath = function (ancPath) {
|
|
67
|
-
var newAncPath = ancPath.startsWith('/') ? ancPath : '/' + ancPath;
|
|
68
|
-
newAncPath = newAncPath.endsWith('/') ? newAncPath.slice(0, -1) : newAncPath;
|
|
69
|
-
return newAncPath;
|
|
70
|
-
};
|
|
71
|
-
exports.formatAncPath = formatAncPath;
|
|
72
|
-
var getPathNameList = function (routes) {
|
|
73
|
-
var list = [];
|
|
74
|
-
var checkRouteItem = function (item, ancPath) {
|
|
75
|
-
var path = item.path, name = item.name, children = item.children, custom = item.custom;
|
|
76
|
-
var newAncPath = "".concat((0, exports.formatAncPath)(ancPath)).concat(path.startsWith('/') ? path : '/' + path);
|
|
77
|
-
list.push({ path: newAncPath, name: name, custom: custom });
|
|
78
|
-
if (children) {
|
|
79
|
-
children.some(function (item) { return checkRouteItem(item, newAncPath); });
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
routes.forEach(function (item) { return checkRouteItem(item, ''); });
|
|
83
|
-
return list;
|
|
84
|
-
};
|
|
85
|
-
exports.pathNameList = getPathNameList(routes_1.default);
|
|
86
|
-
var getLocation = function (historyLocation) {
|
|
87
|
-
var pathname = historyLocation.pathname, hash = historyLocation.hash, search = historyLocation.search, state = historyLocation.state;
|
|
88
|
-
var routerBaseLength = formatRouterBase.length;
|
|
89
|
-
var path = pathname.slice(routerBaseLength);
|
|
90
|
-
var matchPathNameItem = exports.pathNameList.find(function (item) { return item.path === path || (0, exports.compareURLPatterns)(path, item.path); });
|
|
91
|
-
var params = interpolatePathParams(matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.path, path);
|
|
92
|
-
return {
|
|
93
|
-
state: state !== null && state !== void 0 ? state : {},
|
|
94
|
-
hash: hash,
|
|
95
|
-
search: search,
|
|
96
|
-
pathname: pathname,
|
|
97
|
-
query: search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {},
|
|
98
|
-
name: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.name,
|
|
99
|
-
params: params,
|
|
100
|
-
path: path,
|
|
101
|
-
custom: matchPathNameItem === null || matchPathNameItem === void 0 ? void 0 : matchPathNameItem.custom
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
var getFormatHistoryOption = function (to, pathList, type) {
|
|
105
|
-
var _a;
|
|
106
|
-
var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
|
|
107
|
-
var obj = {
|
|
108
|
-
hash: hash,
|
|
109
|
-
search: query ? qs_1.default.stringify(query) : undefined
|
|
110
|
-
};
|
|
111
|
-
if (path) {
|
|
112
|
-
obj.pathname = path;
|
|
113
|
-
}
|
|
114
|
-
if (name) {
|
|
115
|
-
var fullPath = (_a = pathList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path;
|
|
116
|
-
var targetPath = fullPath ? (0, exports.interpolatePath)(fullPath, params) : null;
|
|
117
|
-
if (targetPath) {
|
|
118
|
-
obj.pathname = targetPath;
|
|
119
|
-
}
|
|
120
|
-
else {
|
|
121
|
-
throw "An error occurred while executing 'history.".concat(type, "' operation: The path for the name \"").concat(name, "\" could not be found");
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return obj;
|
|
125
|
-
};
|
|
126
|
-
var getHistory = function (router) {
|
|
127
|
-
return {
|
|
128
|
-
go: function (delta) {
|
|
129
|
-
router.navigate(delta);
|
|
130
|
-
},
|
|
131
|
-
forward: function () {
|
|
132
|
-
router.navigate(1);
|
|
133
|
-
},
|
|
134
|
-
back: function () {
|
|
135
|
-
router.navigate(-1);
|
|
136
|
-
},
|
|
137
|
-
push: function (to) {
|
|
138
|
-
switch (typeof to) {
|
|
139
|
-
case 'string':
|
|
140
|
-
router.navigate(to);
|
|
141
|
-
break;
|
|
142
|
-
case 'object':
|
|
143
|
-
var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'push');
|
|
144
|
-
router.navigate(formatOption, { state: to.state });
|
|
145
|
-
break;
|
|
146
|
-
default:
|
|
147
|
-
throw "An error occurred while executing history.push operation: unexpected type of 'to':".concat(typeof to);
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
replace: function (to) {
|
|
151
|
-
switch (typeof to) {
|
|
152
|
-
case 'string':
|
|
153
|
-
router.navigate(to, { replace: true });
|
|
154
|
-
break;
|
|
155
|
-
case 'object':
|
|
156
|
-
var formatOption = getFormatHistoryOption(to, exports.pathNameList, 'replace');
|
|
157
|
-
router.navigate(formatOption, { state: to.state, replace: true });
|
|
158
|
-
break;
|
|
159
|
-
default:
|
|
160
|
-
throw "An error occurred while executing history.replace operation: unexpected type of 'to':".concat(typeof to);
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
get location() {
|
|
164
|
-
return getLocation(router.state.location);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
};
|
|
168
|
-
exports.getHistory = getHistory;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import '../../global';
|
|
3
|
-
export type RoutesItemType = {
|
|
4
|
-
component?: () => Promise<{
|
|
5
|
-
default: FC;
|
|
6
|
-
}>;
|
|
7
|
-
children?: RoutesItemType[];
|
|
8
|
-
path: string;
|
|
9
|
-
redirect?: string;
|
|
10
|
-
name?: string;
|
|
11
|
-
custom?: any;
|
|
12
|
-
};
|
|
13
|
-
export declare const getChildrenRouteList: (childrenRoutes: RoutesItemType[], ancPathKey: string) => any;
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
20
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
21
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
}) : (function(o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
}));
|
|
28
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
30
|
-
}) : function(o, v) {
|
|
31
|
-
o["default"] = v;
|
|
32
|
-
});
|
|
33
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
41
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
42
|
-
};
|
|
43
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
44
|
-
exports.getChildrenRouteList = void 0;
|
|
45
|
-
var client_1 = require("react-dom/client");
|
|
46
|
-
var react_1 = __importStar(require("react"));
|
|
47
|
-
var react_router_dom_1 = require("react-router-dom");
|
|
48
|
-
var loading_1 = __importDefault(require("../loading"));
|
|
49
|
-
var history_1 = require("./history");
|
|
50
|
-
require("../../global");
|
|
51
|
-
var layout_1 = __importDefault(require("../../layout"));
|
|
52
|
-
var routes_1 = __importDefault(require("./routes"));
|
|
53
|
-
var config_1 = require("./config");
|
|
54
|
-
var Container = (function (_super) {
|
|
55
|
-
__extends(Container, _super);
|
|
56
|
-
function Container() {
|
|
57
|
-
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
58
|
-
_this.state = {
|
|
59
|
-
error: null
|
|
60
|
-
};
|
|
61
|
-
return _this;
|
|
62
|
-
}
|
|
63
|
-
Container.getDerivedStateFromError = function (error) {
|
|
64
|
-
return { error: error.toString() };
|
|
65
|
-
};
|
|
66
|
-
Container.prototype.componentDidCatch = function (error, errorInfo) {
|
|
67
|
-
};
|
|
68
|
-
Container.prototype.render = function () {
|
|
69
|
-
return this.state.error ? null : this.props.children;
|
|
70
|
-
};
|
|
71
|
-
return Container;
|
|
72
|
-
}(react_1.default.Component));
|
|
73
|
-
var getChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
74
|
-
return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
|
|
75
|
-
var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
|
|
76
|
-
var newAncPathKey = "".concat(ancPathKey, "-").concat(path);
|
|
77
|
-
return {
|
|
78
|
-
element: redirect ? (react_1.default.createElement(react_router_dom_1.Navigate, { to: redirect, replace: true })) : component ? (react_1.default.createElement(react_1.Suspense, { fallback: react_1.default.createElement(loading_1.default, null) }, (0, react_1.createElement)((0, react_1.lazy)(component)))) : (react_1.default.createElement(react_router_dom_1.Outlet, null)),
|
|
79
|
-
key: newAncPathKey,
|
|
80
|
-
path: path.startsWith('/') ? path.slice(1) : path,
|
|
81
|
-
children: (0, exports.getChildrenRouteList)(children, newAncPathKey)
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
exports.getChildrenRouteList = getChildrenRouteList;
|
|
86
|
-
var App = function () {
|
|
87
|
-
var routeList = [
|
|
88
|
-
{
|
|
89
|
-
element: (react_1.default.createElement(Container, null,
|
|
90
|
-
react_1.default.createElement(layout_1.default, null))),
|
|
91
|
-
path: '/',
|
|
92
|
-
children: (0, exports.getChildrenRouteList)(routes_1.default, '')
|
|
93
|
-
}
|
|
94
|
-
];
|
|
95
|
-
var router = (config_1.routerType === 'hash' ? react_router_dom_1.createHashRouter : react_router_dom_1.createBrowserRouter)(routeList, {
|
|
96
|
-
basename: config_1.routerBase
|
|
97
|
-
});
|
|
98
|
-
if (config_1.routerBase && config_1.routerBase !== '/') {
|
|
99
|
-
if (config_1.routerType === 'browser' && window.location.pathname === '/') {
|
|
100
|
-
window.location.replace("".concat(config_1.routerBase));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
(0, react_1.useLayoutEffect)(function () {
|
|
104
|
-
history_1.history = (0, history_1.getHistory)(router);
|
|
105
|
-
});
|
|
106
|
-
return react_1.default.createElement(react_router_dom_1.RouterProvider, { router: router });
|
|
107
|
-
};
|
|
108
|
-
var root = (0, client_1.createRoot)(document.getElementById('root'));
|
|
109
|
-
root.render(react_1.default.createElement(App, null));
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.useNav = exports.useLocation = void 0;
|
|
18
|
-
var react_router_dom_1 = require("react-router-dom");
|
|
19
|
-
var history_1 = require("./$env/history");
|
|
20
|
-
var qs_1 = __importDefault(require("qs"));
|
|
21
|
-
var useLocation = function () {
|
|
22
|
-
var _a;
|
|
23
|
-
var location = (0, react_router_dom_1.useLocation)();
|
|
24
|
-
var params = (0, react_router_dom_1.useParams)();
|
|
25
|
-
var search = location.search, hash = location.hash, pathname = location.pathname, state = location.state;
|
|
26
|
-
var matchItem = history_1.pathNameList.find(function (item) {
|
|
27
|
-
return (Object.keys(params).length > 0 && (0, history_1.compareURLPatterns)(pathname, item.path)) ||
|
|
28
|
-
item.path === pathname;
|
|
29
|
-
});
|
|
30
|
-
var query = search ? qs_1.default.parse(search.startsWith('?') ? search.slice(1) : search) : {};
|
|
31
|
-
return {
|
|
32
|
-
name: matchItem === null || matchItem === void 0 ? void 0 : matchItem.name,
|
|
33
|
-
custom: matchItem === null || matchItem === void 0 ? void 0 : matchItem.custom,
|
|
34
|
-
state: state !== null && state !== void 0 ? state : {},
|
|
35
|
-
path: pathname,
|
|
36
|
-
pathname: (_a = window === null || window === void 0 ? void 0 : window.location) === null || _a === void 0 ? void 0 : _a.pathname,
|
|
37
|
-
search: '',
|
|
38
|
-
query: query,
|
|
39
|
-
hash: hash,
|
|
40
|
-
params: params
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
exports.useLocation = useLocation;
|
|
44
|
-
var getFormatNavPath = function (to) {
|
|
45
|
-
var _a;
|
|
46
|
-
var params = to.params, path = to.path, hash = to.hash, name = to.name, query = to.query;
|
|
47
|
-
var search = query ? "?".concat(qs_1.default.stringify(query)) : '';
|
|
48
|
-
var formatHash = hash ? (hash.startsWith('#') ? hash : "#".concat(hash)) : '';
|
|
49
|
-
var formatPath = name ? (_a = history_1.pathNameList.find(function (item) { return item.name === name; })) === null || _a === void 0 ? void 0 : _a.path : path;
|
|
50
|
-
var newPath = formatPath ? (0, history_1.interpolatePath)(formatPath, params || {}) : null;
|
|
51
|
-
newPath = newPath + search + formatHash;
|
|
52
|
-
return newPath;
|
|
53
|
-
};
|
|
54
|
-
var useNav = function () {
|
|
55
|
-
var navigate = (0, react_router_dom_1.useNavigate)();
|
|
56
|
-
var newNavigate = function (to, options) {
|
|
57
|
-
switch (typeof to) {
|
|
58
|
-
case 'string':
|
|
59
|
-
navigate(to, options);
|
|
60
|
-
break;
|
|
61
|
-
case 'number':
|
|
62
|
-
navigate(to);
|
|
63
|
-
break;
|
|
64
|
-
case 'object':
|
|
65
|
-
navigate(getFormatNavPath(to), __assign(__assign({}, (options || {})), { state: to.state }));
|
|
66
|
-
break;
|
|
67
|
-
default:
|
|
68
|
-
throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
return newNavigate;
|
|
72
|
-
};
|
|
73
|
-
exports.useNav = useNav;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getRouter = exports.history = void 0;
|
|
18
|
-
var vue_router_1 = require("vue-router");
|
|
19
|
-
var config_1 = require("./config");
|
|
20
|
-
var routes_1 = __importDefault(require("./routes"));
|
|
21
|
-
var qs_1 = __importDefault(require("qs"));
|
|
22
|
-
var transformRouteItemCustomToMeta = function (routeItem) {
|
|
23
|
-
var newRouteItem = __assign({}, routeItem);
|
|
24
|
-
var custom = routeItem.custom, children = routeItem.children;
|
|
25
|
-
newRouteItem.meta = custom;
|
|
26
|
-
return __assign(__assign({}, newRouteItem), { children: children === null || children === void 0 ? void 0 : children.map(function (item) { return transformRouteItemCustomToMeta(item); }) });
|
|
27
|
-
};
|
|
28
|
-
var formatRoutes = routes_1.default.map(function (routeItem) { return transformRouteItemCustomToMeta(routeItem); });
|
|
29
|
-
var getRouter = function () {
|
|
30
|
-
var router = (0, vue_router_1.createRouter)({
|
|
31
|
-
history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
|
|
32
|
-
routes: formatRoutes
|
|
33
|
-
});
|
|
34
|
-
exports.history = {
|
|
35
|
-
push: function (options) {
|
|
36
|
-
if (typeof options === 'string') {
|
|
37
|
-
router.push(options);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
var query = options.query, name_1 = options.name, hash = options.hash, params = options.params, path = options.path, state = options.state;
|
|
41
|
-
router.push({ name: name_1, path: path, query: query, hash: hash, params: params, state: { swicoState: state } });
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
replace: function (options) {
|
|
45
|
-
if (typeof options === 'string') {
|
|
46
|
-
router.replace(options);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
var query = options.query, name_2 = options.name, hash = options.hash, params = options.params, path = options.path, state = options.state;
|
|
50
|
-
router.replace({ name: name_2, path: path, query: query, hash: hash, params: params, state: { swicoState: state } });
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
go: router.go,
|
|
54
|
-
back: router.back,
|
|
55
|
-
forward: router.forward,
|
|
56
|
-
get location() {
|
|
57
|
-
var _a, _b;
|
|
58
|
-
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
59
|
-
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
60
|
-
var _c = router.currentRoute.value, path = _c.path, params = _c.params, query = _c.query, name = _c.name, hash = _c.hash, fullPath = _c.fullPath, meta = _c.meta;
|
|
61
|
-
return {
|
|
62
|
-
path: path,
|
|
63
|
-
custom: meta,
|
|
64
|
-
pathname: formatRouterBase + path,
|
|
65
|
-
params: params,
|
|
66
|
-
query: query,
|
|
67
|
-
name: name,
|
|
68
|
-
hash: hash,
|
|
69
|
-
state: (_b = (_a = window.history.state) === null || _a === void 0 ? void 0 : _a.swicoState) !== null && _b !== void 0 ? _b : {},
|
|
70
|
-
search: query ? qs_1.default.stringify(query) : ''
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
return router;
|
|
75
|
-
};
|
|
76
|
-
exports.getRouter = getRouter;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
var _a;
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
var vue_1 = require("vue");
|
|
8
|
-
var Container_1 = __importDefault(require("../Container"));
|
|
9
|
-
var Layout_1 = __importDefault(require("../../layout/Layout"));
|
|
10
|
-
var global_1 = __importDefault(require("../../global"));
|
|
11
|
-
var history_1 = require("./history");
|
|
12
|
-
var router = (0, history_1.getRouter)();
|
|
13
|
-
var app = (0, vue_1.createApp)(Container_1.default);
|
|
14
|
-
app.component('Layout', Layout_1.default);
|
|
15
|
-
app.use(router);
|
|
16
|
-
(_a = global_1.default === null || global_1.default === void 0 ? void 0 : global_1.default.onInit) === null || _a === void 0 ? void 0 : _a.call(global_1.default, app, router);
|
|
17
|
-
app.mount('#root');
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { onErrorCaptured, ref } from 'vue';
|
|
3
|
-
const error = ref<string | null>(null);
|
|
4
|
-
onErrorCaptured((err, instance, info) => {
|
|
5
|
-
console.error(err);
|
|
6
|
-
error.value = err.toString();
|
|
7
|
-
return false;
|
|
8
|
-
});
|
|
9
|
-
</script>
|
|
10
|
-
|
|
11
|
-
<template>
|
|
12
|
-
<Layout v-if="!error"><RouterView /></Layout>
|
|
13
|
-
</template>
|
|
14
|
-
|
|
15
|
-
<style scoped></style>
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.useNav = exports.useLocation = exports.getFormatRouterBase = void 0;
|
|
18
|
-
var vue_router_1 = require("vue-router");
|
|
19
|
-
var qs_1 = __importDefault(require("qs"));
|
|
20
|
-
var vue_1 = require("vue");
|
|
21
|
-
var config_1 = require("./$env/config");
|
|
22
|
-
var getFormatRouterBase = function (routerBase) {
|
|
23
|
-
var lastIndexBase = routerBase[routerBase.length - 1];
|
|
24
|
-
return lastIndexBase === '/' ? routerBase.slice(0, routerBase.length - 1) : routerBase;
|
|
25
|
-
};
|
|
26
|
-
exports.getFormatRouterBase = getFormatRouterBase;
|
|
27
|
-
var useLocation = function () {
|
|
28
|
-
var route = (0, vue_router_1.useRoute)();
|
|
29
|
-
var location = (0, vue_1.reactive)({
|
|
30
|
-
name: '',
|
|
31
|
-
path: '',
|
|
32
|
-
search: '',
|
|
33
|
-
state: {},
|
|
34
|
-
hash: '',
|
|
35
|
-
pathname: '',
|
|
36
|
-
params: {},
|
|
37
|
-
query: {}
|
|
38
|
-
});
|
|
39
|
-
(0, vue_1.watchEffect)(function () {
|
|
40
|
-
var _a;
|
|
41
|
-
var hash = route.hash, path = route.path, params = route.params, fullPath = route.fullPath, query = route.query, name = route.name, meta = route.meta;
|
|
42
|
-
var search = query ? qs_1.default.stringify(query) : '';
|
|
43
|
-
location.name = name;
|
|
44
|
-
location.path = path;
|
|
45
|
-
location.pathname = (0, exports.getFormatRouterBase)(config_1.routerBase) + path;
|
|
46
|
-
location.search = search;
|
|
47
|
-
location.query = query;
|
|
48
|
-
location.hash = hash;
|
|
49
|
-
location.params = params;
|
|
50
|
-
location.state = ((_a = window.history.state) === null || _a === void 0 ? void 0 : _a.swicoState) || {};
|
|
51
|
-
location.custom = meta;
|
|
52
|
-
});
|
|
53
|
-
return location;
|
|
54
|
-
};
|
|
55
|
-
exports.useLocation = useLocation;
|
|
56
|
-
var useNav = function () {
|
|
57
|
-
var router = (0, vue_router_1.useRouter)();
|
|
58
|
-
var newNavigate = function (to, options) {
|
|
59
|
-
switch (typeof to) {
|
|
60
|
-
case 'string':
|
|
61
|
-
if (options === null || options === void 0 ? void 0 : options.replace) {
|
|
62
|
-
router.replace(to);
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
router.push(to);
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
case 'number':
|
|
69
|
-
router.go(to);
|
|
70
|
-
break;
|
|
71
|
-
case 'object':
|
|
72
|
-
if (options === null || options === void 0 ? void 0 : options.replace) {
|
|
73
|
-
router.replace(to);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
router.push(__assign(__assign({}, to), { state: { swicoState: to.state } }));
|
|
77
|
-
}
|
|
78
|
-
break;
|
|
79
|
-
default:
|
|
80
|
-
throw "An error occurred while executing useNav() operation: unexpected type of 'to':".concat(typeof to);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
return newNavigate;
|
|
84
|
-
};
|
|
85
|
-
exports.useNav = useNav;
|