swico 0.6.2-beta5 → 0.6.2
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/template/react/$env/history.d.ts +2 -4
- package/src/template/react/$env/history.js +5 -6
- package/src/template/react/$env/index.d.ts +0 -1
- package/src/template/react/$env/index.js +1 -6
- package/src/template/vue/$env/history.d.ts +2 -0
- package/src/template/vue/$env/history.js +55 -0
- package/src/template/vue/$env/index.d.ts +1 -1
- package/src/template/vue/$env/index.js +2 -49
- package/src/utils/config.js +1 -1
- package/src/utils/tools.js +1 -1
package/package.json
CHANGED
|
@@ -5,7 +5,5 @@ export declare const pathNameList: {
|
|
|
5
5
|
path: string;
|
|
6
6
|
name: string;
|
|
7
7
|
}[];
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
originalHistory: import("history").HashHistory;
|
|
11
|
-
};
|
|
8
|
+
export declare let history: SwicoHistoryType;
|
|
9
|
+
export declare const getOriHistory: (routerType: ConfigRouterType['type']) => import("history").HashHistory;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getOriHistory = exports.history = exports.pathNameList = exports.formatAncPath = exports.HistoryRouter = void 0;
|
|
7
7
|
var qs_1 = __importDefault(require("qs"));
|
|
8
8
|
var history_1 = require("history");
|
|
9
9
|
var routes_1 = __importDefault(require("./routes"));
|
|
@@ -122,11 +122,10 @@ var getFormatHistoryOption = function (to, formatRouterBase, pathList, type) {
|
|
|
122
122
|
}
|
|
123
123
|
return obj;
|
|
124
124
|
};
|
|
125
|
-
var
|
|
125
|
+
var getOriHistory = function (routerType) {
|
|
126
126
|
var _a;
|
|
127
|
-
var history;
|
|
128
127
|
var originalHistory = (_a = (routerType === 'hash' ? history_1.createHashHistory : history_1.createBrowserHistory)) === null || _a === void 0 ? void 0 : _a();
|
|
129
|
-
history = {
|
|
128
|
+
exports.history = {
|
|
130
129
|
go: originalHistory.go,
|
|
131
130
|
forward: originalHistory.forward,
|
|
132
131
|
back: originalHistory.back,
|
|
@@ -160,6 +159,6 @@ var getHistory = function (routerBase, routerType) {
|
|
|
160
159
|
return getLocation(originalHistory);
|
|
161
160
|
}
|
|
162
161
|
};
|
|
163
|
-
return
|
|
162
|
+
return originalHistory;
|
|
164
163
|
};
|
|
165
|
-
exports.
|
|
164
|
+
exports.getOriHistory = getOriHistory;
|
|
@@ -26,7 +26,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.history = void 0;
|
|
30
29
|
var client_1 = require("react-dom/client");
|
|
31
30
|
var react_1 = __importStar(require("react"));
|
|
32
31
|
var react_router_dom_1 = require("react-router-dom");
|
|
@@ -36,8 +35,6 @@ var history_1 = require("./history");
|
|
|
36
35
|
var config_1 = require("./config");
|
|
37
36
|
require("../../global");
|
|
38
37
|
var layout_1 = __importDefault(require("../../layout"));
|
|
39
|
-
var _a = (0, history_1.getHistory)(config_1.routerBase, config_1.routerType), swicoHistory = _a.history, originalHistory = _a.originalHistory;
|
|
40
|
-
exports.history = swicoHistory;
|
|
41
38
|
var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
42
39
|
return childrenRoutes === null || childrenRoutes === void 0 ? void 0 : childrenRoutes.map(function (item) {
|
|
43
40
|
var component = item.component, path = item.path, children = item.children, redirect = item.redirect;
|
|
@@ -46,14 +43,12 @@ var renderChildrenRouteList = function (childrenRoutes, ancPathKey) {
|
|
|
46
43
|
});
|
|
47
44
|
};
|
|
48
45
|
var App = function () {
|
|
46
|
+
var originalHistory = (0, history_1.getOriHistory)(config_1.routerType);
|
|
49
47
|
if (config_1.routerBase && config_1.routerBase !== '/') {
|
|
50
48
|
if (config_1.routerType === 'browser' && window.location.pathname === '/') {
|
|
51
49
|
window.location.replace("".concat(config_1.routerBase));
|
|
52
50
|
}
|
|
53
51
|
}
|
|
54
|
-
window.Swico = {
|
|
55
|
-
history: exports.history
|
|
56
|
-
};
|
|
57
52
|
return (react_1.default.createElement(history_1.HistoryRouter, { basename: config_1.routerBase, history: originalHistory },
|
|
58
53
|
react_1.default.createElement(react_router_dom_1.Routes, null,
|
|
59
54
|
react_1.default.createElement(react_router_dom_1.Route, { element: react_1.default.createElement(layout_1.default, null), path: '' }, renderChildrenRouteList(routes_1.default, '')))));
|
|
@@ -0,0 +1,55 @@
|
|
|
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.getRouter = exports.history = void 0;
|
|
7
|
+
var vue_router_1 = require("vue-router");
|
|
8
|
+
var config_1 = require("./config");
|
|
9
|
+
var routes_1 = __importDefault(require("./routes"));
|
|
10
|
+
var qs_1 = __importDefault(require("qs"));
|
|
11
|
+
var getRouter = function () {
|
|
12
|
+
var router = (0, vue_router_1.createRouter)({
|
|
13
|
+
history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
|
|
14
|
+
routes: routes_1.default
|
|
15
|
+
});
|
|
16
|
+
exports.history = {
|
|
17
|
+
push: function (options) {
|
|
18
|
+
if (typeof options === 'string') {
|
|
19
|
+
router.push(options);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
var query = options.query, name_1 = options.name, hash = options.hash, params = options.params, path = options.path;
|
|
23
|
+
router.push({ name: name_1, path: path, query: query, hash: hash, params: params });
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
replace: function (options) {
|
|
27
|
+
if (typeof options === 'string') {
|
|
28
|
+
router.replace(options);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
var query = options.query, name_2 = options.name, hash = options.hash, params = options.params, path = options.path;
|
|
32
|
+
router.replace({ name: name_2, path: path, query: query, hash: hash, params: params });
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
go: router.go,
|
|
36
|
+
back: router.back,
|
|
37
|
+
forward: router.forward,
|
|
38
|
+
get location() {
|
|
39
|
+
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
40
|
+
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
41
|
+
var _a = router.currentRoute.value, path = _a.path, params = _a.params, query = _a.query, name = _a.name, hash = _a.hash, fullPath = _a.fullPath;
|
|
42
|
+
return {
|
|
43
|
+
path: path,
|
|
44
|
+
pathname: formatRouterBase + path,
|
|
45
|
+
params: params,
|
|
46
|
+
query: query,
|
|
47
|
+
name: name,
|
|
48
|
+
hash: hash,
|
|
49
|
+
search: query ? qs_1.default.stringify(query) : ''
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return router;
|
|
54
|
+
};
|
|
55
|
+
exports.getRouter = getRouter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export {};
|
|
@@ -4,61 +4,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
var _a;
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.history = void 0;
|
|
8
7
|
var vue_1 = require("vue");
|
|
9
|
-
var routes_1 = __importDefault(require("./routes"));
|
|
10
|
-
var vue_router_1 = require("vue-router");
|
|
11
8
|
var Container_1 = __importDefault(require("../Container"));
|
|
12
|
-
var config_1 = require("./config");
|
|
13
9
|
var Layout_1 = __importDefault(require("../../layout/Layout"));
|
|
14
10
|
var global_1 = __importDefault(require("../../global"));
|
|
15
|
-
var
|
|
16
|
-
var router = (0,
|
|
17
|
-
history: (config_1.routerType === 'hash' ? vue_router_1.createWebHashHistory : vue_router_1.createWebHistory)(config_1.routerBase),
|
|
18
|
-
routes: routes_1.default
|
|
19
|
-
});
|
|
11
|
+
var history_1 = require("./history");
|
|
12
|
+
var router = (0, history_1.getRouter)();
|
|
20
13
|
var app = (0, vue_1.createApp)(Container_1.default);
|
|
21
|
-
var Swico = { history: null };
|
|
22
|
-
exports.history = {
|
|
23
|
-
push: function (options) {
|
|
24
|
-
if (typeof options === 'string') {
|
|
25
|
-
router.push(options);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
var query = options.query, name_1 = options.name, hash = options.hash, params = options.params, path = options.path;
|
|
29
|
-
router.push({ name: name_1, path: path, query: query, hash: hash, params: params });
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
replace: function (options) {
|
|
33
|
-
if (typeof options === 'string') {
|
|
34
|
-
router.replace(options);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
var query = options.query, name_2 = options.name, hash = options.hash, params = options.params, path = options.path;
|
|
38
|
-
router.replace({ name: name_2, path: path, query: query, hash: hash, params: params });
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
go: router.go,
|
|
42
|
-
back: router.back,
|
|
43
|
-
forward: router.forward,
|
|
44
|
-
get location() {
|
|
45
|
-
var lastIndexBase = config_1.routerBase[config_1.routerBase.length - 1];
|
|
46
|
-
var formatRouterBase = lastIndexBase === '/' ? config_1.routerBase.slice(0, config_1.routerBase.length - 1) : config_1.routerBase;
|
|
47
|
-
var _a = router.currentRoute.value, path = _a.path, params = _a.params, query = _a.query, name = _a.name, hash = _a.hash, fullPath = _a.fullPath;
|
|
48
|
-
return {
|
|
49
|
-
path: path,
|
|
50
|
-
pathname: formatRouterBase + path,
|
|
51
|
-
params: params,
|
|
52
|
-
query: query,
|
|
53
|
-
name: name,
|
|
54
|
-
hash: hash,
|
|
55
|
-
search: query ? qs_1.default.stringify(query) : ''
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
Swico.history = exports.history;
|
|
60
14
|
app.component('Layout', Layout_1.default);
|
|
61
15
|
app.use(router);
|
|
62
|
-
window.Swico = Swico;
|
|
63
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);
|
|
64
17
|
app.mount('#root');
|
package/src/utils/config.js
CHANGED
|
@@ -240,7 +240,7 @@ var initCliIndexFile = function (templateType, env) { return __awaiter(void 0, v
|
|
|
240
240
|
.replaceAll('\\', '/');
|
|
241
241
|
replaceFileText = replaceFileText.replaceAll('require("./template/react/react-hooks");', "require(\"".concat(formatHooksPath, "\");"));
|
|
242
242
|
formatHistoryPath = path_1.default
|
|
243
|
-
.resolve(projectPath, "./src/.swico/.".concat(env, "/
|
|
243
|
+
.resolve(projectPath, "./src/.swico/.".concat(env, "/history"))
|
|
244
244
|
.replaceAll('\\', '/');
|
|
245
245
|
replaceFileText = replaceFileText.replaceAll('require("./mock-history");', "require(\"".concat(formatHistoryPath, "\");"));
|
|
246
246
|
return [4, fs_extra_1.default.writeFile(targetPath, replaceFileText)];
|
package/src/utils/tools.js
CHANGED
|
@@ -210,7 +210,7 @@ var initIndexFile = function (env) { return __awaiter(void 0, void 0, void 0, fu
|
|
|
210
210
|
_a.label = 3;
|
|
211
211
|
case 3:
|
|
212
212
|
formatHistoryPath = path_1.default
|
|
213
|
-
.resolve(process.cwd(), "./src/.swico/.".concat(env, "/
|
|
213
|
+
.resolve(process.cwd(), "./src/.swico/.".concat(env, "/history"))
|
|
214
214
|
.replaceAll('\\', '/');
|
|
215
215
|
if (!fileText.includes("require(\"".concat(formatHistoryPath, "\");"))) return [3, 5];
|
|
216
216
|
fileText = fileText.replaceAll("require(\"".concat(formatHistoryPath, "\");"), 'require("./mock-history");');
|