nsgm-cli 2.1.19 → 2.1.21
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/client/components/Button.tsx +3 -3
- package/client/components/ClientProviders.tsx +12 -12
- package/client/components/LanguageSwitcher.tsx +26 -26
- package/client/components/SSRSafeAntdProvider.tsx +7 -7
- package/client/components/SuppressHydrationWarnings.tsx +30 -30
- package/client/components/__tests__/Button.test.tsx +12 -12
- package/client/layout/index.tsx +124 -124
- package/client/redux/reducers.ts +2 -2
- package/client/redux/store.ts +24 -24
- package/client/redux/template/manage/actions.ts +40 -40
- package/client/redux/template/manage/reducers.ts +32 -32
- package/client/redux/template/manage/types.ts +19 -19
- package/client/service/template/manage.ts +29 -29
- package/client/styled/common.ts +6 -6
- package/client/styled/layout/index.ts +17 -17
- package/client/styled/template/manage.ts +19 -19
- package/client/utils/common.ts +54 -54
- package/client/utils/cookie.ts +30 -30
- package/client/utils/fetch.ts +111 -111
- package/client/utils/i18n.ts +41 -41
- package/client/utils/menu.tsx +12 -12
- package/client/utils/navigation.ts +22 -22
- package/client/utils/sso.ts +124 -124
- package/client/utils/suppressWarnings.ts +17 -17
- package/generation/prettierrc +6 -0
- package/lib/args.js +19 -19
- package/lib/cli/app.d.ts +1 -1
- package/lib/cli/app.js +2 -2
- package/lib/cli/commands/build.d.ts +1 -1
- package/lib/cli/commands/build.js +9 -9
- package/lib/cli/commands/create.d.ts +1 -1
- package/lib/cli/commands/create.js +36 -36
- package/lib/cli/commands/delete.d.ts +1 -1
- package/lib/cli/commands/delete.js +55 -55
- package/lib/cli/commands/export.d.ts +1 -1
- package/lib/cli/commands/export.js +12 -12
- package/lib/cli/commands/help.d.ts +1 -1
- package/lib/cli/commands/help.js +29 -29
- package/lib/cli/commands/init.d.ts +1 -1
- package/lib/cli/commands/init.js +31 -31
- package/lib/cli/commands/server.d.ts +1 -1
- package/lib/cli/commands/server.js +12 -12
- package/lib/cli/commands/upgrade.d.ts +1 -1
- package/lib/cli/commands/upgrade.js +13 -13
- package/lib/cli/commands/version.d.ts +1 -1
- package/lib/cli/commands/version.js +7 -7
- package/lib/cli/index.d.ts +13 -13
- package/lib/cli/parser.d.ts +1 -1
- package/lib/cli/parser.js +12 -12
- package/lib/cli/registry.d.ts +1 -1
- package/lib/cli/types.d.ts +2 -2
- package/lib/cli/utils/console.d.ts +2 -2
- package/lib/cli/utils/console.js +22 -22
- package/lib/cli/utils/index.d.ts +2 -2
- package/lib/cli/utils/prompt.d.ts +1 -1
- package/lib/cli/utils/prompt.js +98 -98
- package/lib/constants.js +28 -28
- package/lib/generate.d.ts +2 -2
- package/lib/generate.js +19 -19
- package/lib/generate_create.d.ts +1 -1
- package/lib/generate_create.js +38 -38
- package/lib/generate_delete.js +63 -63
- package/lib/generate_init.js +94 -94
- package/lib/generators/base-generator.d.ts +1 -1
- package/lib/generators/base-generator.js +23 -23
- package/lib/generators/file-generator.js +15 -15
- package/lib/generators/generator-factory.d.ts +5 -5
- package/lib/generators/i18n-generator.d.ts +1 -1
- package/lib/generators/i18n-generator.js +127 -127
- package/lib/generators/page-generator.d.ts +1 -1
- package/lib/generators/page-generator.js +25 -25
- package/lib/generators/resolver-generator.d.ts +1 -1
- package/lib/generators/resolver-generator.js +27 -27
- package/lib/generators/schema-generator.d.ts +1 -1
- package/lib/generators/schema-generator.js +4 -4
- package/lib/generators/service-generator.d.ts +1 -1
- package/lib/generators/service-generator.js +29 -29
- package/lib/generators/sql-generator.d.ts +1 -1
- package/lib/generators/sql-generator.js +10 -10
- package/lib/index.js +23 -23
- package/lib/server/csrf.d.ts +3 -3
- package/lib/server/csrf.js +20 -20
- package/lib/server/db.d.ts +1 -1
- package/lib/server/db.js +21 -21
- package/lib/server/graphql.js +26 -26
- package/lib/server/plugins/date.d.ts +1 -1
- package/lib/server/plugins/date.js +6 -6
- package/lib/server/utils/graphql-cache.js +5 -5
- package/lib/tsconfig.build.tsbuildinfo +1 -1
- package/lib/utils/project-config.d.ts +1 -1
- package/lib/utils/project-config.js +20 -20
- package/lib/utils.js +3 -3
- package/package.json +1 -1
- package/pages/_app.tsx +62 -62
- package/pages/_document.tsx +15 -15
- package/pages/_error.tsx +26 -26
- package/pages/index.tsx +48 -48
- package/pages/login.tsx +64 -64
- package/pages/template/manage.tsx +175 -175
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NextRouter } from
|
|
1
|
+
import { NextRouter } from "next/router";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 跳转到指定页面,保持当前语言设置
|
|
@@ -7,20 +7,20 @@ import { NextRouter } from 'next/router'
|
|
|
7
7
|
*/
|
|
8
8
|
export const navigateWithLocale = (router: NextRouter, path: string) => {
|
|
9
9
|
// 只在客户端执行
|
|
10
|
-
if (typeof window ===
|
|
10
|
+
if (typeof window === "undefined") return;
|
|
11
11
|
|
|
12
|
-
const currentLocale = router.locale ||
|
|
13
|
-
const baseUrl = window.location.origin
|
|
12
|
+
const currentLocale = router.locale || "zh-CN";
|
|
13
|
+
const baseUrl = window.location.origin;
|
|
14
14
|
|
|
15
|
-
let targetUrl: string
|
|
16
|
-
if (currentLocale ===
|
|
17
|
-
targetUrl = `${baseUrl}${path}
|
|
15
|
+
let targetUrl: string;
|
|
16
|
+
if (currentLocale === "zh-CN") {
|
|
17
|
+
targetUrl = `${baseUrl}${path}`;
|
|
18
18
|
} else {
|
|
19
|
-
targetUrl = `${baseUrl}/${currentLocale}${path}
|
|
19
|
+
targetUrl = `${baseUrl}/${currentLocale}${path}`;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
window.location.href = targetUrl
|
|
23
|
-
}
|
|
22
|
+
window.location.href = targetUrl;
|
|
23
|
+
};
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* 跳转到登录页面,保持当前语言设置
|
|
@@ -28,10 +28,10 @@ export const navigateWithLocale = (router: NextRouter, path: string) => {
|
|
|
28
28
|
*/
|
|
29
29
|
export const navigateToLogin = (router: NextRouter) => {
|
|
30
30
|
// 只在客户端执行
|
|
31
|
-
if (typeof window ===
|
|
31
|
+
if (typeof window === "undefined") return;
|
|
32
32
|
|
|
33
|
-
navigateWithLocale(router,
|
|
34
|
-
}
|
|
33
|
+
navigateWithLocale(router, "/login");
|
|
34
|
+
};
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* 跳转到首页,保持当前语言设置
|
|
@@ -40,19 +40,19 @@ export const navigateToLogin = (router: NextRouter) => {
|
|
|
40
40
|
*/
|
|
41
41
|
export const navigateToHome = (router: NextRouter, forceLocalePrefix = false) => {
|
|
42
42
|
// 只在客户端执行
|
|
43
|
-
if (typeof window ===
|
|
43
|
+
if (typeof window === "undefined") return;
|
|
44
44
|
|
|
45
|
-
const currentLocale = router.locale ||
|
|
46
|
-
const baseUrl = window.location.origin
|
|
45
|
+
const currentLocale = router.locale || "zh-CN";
|
|
46
|
+
const baseUrl = window.location.origin;
|
|
47
47
|
|
|
48
|
-
let targetUrl: string
|
|
49
|
-
if (forceLocalePrefix || currentLocale !==
|
|
48
|
+
let targetUrl: string;
|
|
49
|
+
if (forceLocalePrefix || currentLocale !== "zh-CN") {
|
|
50
50
|
// 强制添加语言前缀或非中文时
|
|
51
|
-
targetUrl = `${baseUrl}/${currentLocale}
|
|
51
|
+
targetUrl = `${baseUrl}/${currentLocale}`;
|
|
52
52
|
} else {
|
|
53
53
|
// 中文且不强制添加前缀
|
|
54
|
-
targetUrl = baseUrl
|
|
54
|
+
targetUrl = baseUrl;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
window.location.href = targetUrl
|
|
58
|
-
}
|
|
57
|
+
window.location.href = targetUrl;
|
|
58
|
+
};
|
package/client/utils/sso.ts
CHANGED
|
@@ -1,235 +1,235 @@
|
|
|
1
|
-
import axios from
|
|
2
|
-
import { setCookie, getCookie, delCookie } from
|
|
3
|
-
import { getUrlParamByKey, getLocalApiPrefix, getLocalEnv, handleXSS } from
|
|
4
|
-
import _ from
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { setCookie, getCookie, delCookie } from "./cookie";
|
|
3
|
+
import { getUrlParamByKey, getLocalApiPrefix, getLocalEnv, handleXSS } from "./common";
|
|
4
|
+
import _ from "lodash";
|
|
5
5
|
|
|
6
|
-
const env = getLocalEnv()
|
|
6
|
+
const env = getLocalEnv();
|
|
7
7
|
|
|
8
|
-
const LOGIN_COOKIE_ID = `${env}_cas_nsgm
|
|
9
|
-
const LOGIN_COOKIE_USER = `${env}_nsgm_user
|
|
8
|
+
const LOGIN_COOKIE_ID = `${env}_cas_nsgm`;
|
|
9
|
+
const LOGIN_COOKIE_USER = `${env}_nsgm_user`;
|
|
10
10
|
|
|
11
11
|
const getPrincipalUrl = () => {
|
|
12
|
-
const url = `${getLocalApiPrefix()}/rest/sso/sessionCheck
|
|
13
|
-
return url
|
|
14
|
-
}
|
|
12
|
+
const url = `${getLocalApiPrefix()}/rest/sso/sessionCheck`;
|
|
13
|
+
return url;
|
|
14
|
+
};
|
|
15
15
|
|
|
16
16
|
const getValidateUrl = () => {
|
|
17
|
-
const url = `${getLocalApiPrefix()}/rest/sso/ticketCheck
|
|
18
|
-
return url
|
|
19
|
-
}
|
|
17
|
+
const url = `${getLocalApiPrefix()}/rest/sso/ticketCheck`;
|
|
18
|
+
return url;
|
|
19
|
+
};
|
|
20
20
|
|
|
21
21
|
const handleLocationHref = () => {
|
|
22
|
-
let newHref =
|
|
23
|
-
if (typeof window !==
|
|
24
|
-
const locationHref = window.location.href
|
|
25
|
-
if (locationHref.indexOf(
|
|
26
|
-
const locationHrefArr = locationHref.split(
|
|
27
|
-
const locationHrefArrLen = locationHrefArr.length
|
|
22
|
+
let newHref = "";
|
|
23
|
+
if (typeof window !== "undefined") {
|
|
24
|
+
const locationHref = window.location.href;
|
|
25
|
+
if (locationHref.indexOf("?") !== -1) {
|
|
26
|
+
const locationHrefArr = locationHref.split("?");
|
|
27
|
+
const locationHrefArrLen = locationHrefArr.length;
|
|
28
28
|
|
|
29
|
-
let newParamStr =
|
|
29
|
+
let newParamStr = "";
|
|
30
30
|
|
|
31
31
|
if (locationHrefArrLen > 1) {
|
|
32
|
-
const paramStr = locationHrefArr[1]
|
|
33
|
-
if (paramStr.indexOf(
|
|
34
|
-
const paramArr = paramStr.split(
|
|
32
|
+
const paramStr = locationHrefArr[1];
|
|
33
|
+
if (paramStr.indexOf("&") !== -1) {
|
|
34
|
+
const paramArr = paramStr.split("&");
|
|
35
35
|
|
|
36
36
|
_.each(paramArr, (item) => {
|
|
37
|
-
if (item.indexOf(
|
|
38
|
-
const itemArr = item.split(
|
|
39
|
-
const itemArrLen = itemArr.length
|
|
37
|
+
if (item.indexOf("=") !== -1) {
|
|
38
|
+
const itemArr = item.split("=");
|
|
39
|
+
const itemArrLen = itemArr.length;
|
|
40
40
|
|
|
41
|
-
const key = itemArr[0]
|
|
42
|
-
let value =
|
|
43
|
-
if (itemArrLen > 1) value = itemArr[1]
|
|
41
|
+
const key = itemArr[0];
|
|
42
|
+
let value = "";
|
|
43
|
+
if (itemArrLen > 1) value = itemArr[1];
|
|
44
44
|
|
|
45
|
-
if (
|
|
46
|
-
newParamStr += `${key}=${value}
|
|
45
|
+
if ("ticket" !== key) {
|
|
46
|
+
newParamStr += `${key}=${value}&`;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
})
|
|
49
|
+
});
|
|
50
50
|
|
|
51
|
-
newParamStr = newParamStr.substring(0, newParamStr.length - 1)
|
|
51
|
+
newParamStr = newParamStr.substring(0, newParamStr.length - 1);
|
|
52
52
|
} else {
|
|
53
|
-
if (paramStr.indexOf(
|
|
54
|
-
newParamStr = paramStr
|
|
53
|
+
if (paramStr.indexOf("ticket") === -1) {
|
|
54
|
+
newParamStr = paramStr;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
const locationHrefArrFirst = locationHrefArr[0]
|
|
60
|
-
if (newParamStr !==
|
|
61
|
-
else newHref = locationHrefArrFirst
|
|
59
|
+
const locationHrefArrFirst = locationHrefArr[0];
|
|
60
|
+
if (newParamStr !== "") newHref = `${locationHrefArrFirst}?${newParamStr}`;
|
|
61
|
+
else newHref = locationHrefArrFirst;
|
|
62
62
|
} else {
|
|
63
|
-
newHref = locationHref
|
|
63
|
+
newHref = locationHref;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
return encodeURIComponent(newHref)
|
|
67
|
-
}
|
|
66
|
+
return encodeURIComponent(newHref);
|
|
67
|
+
};
|
|
68
68
|
|
|
69
69
|
const jumpToLogin = () => {
|
|
70
|
-
delCookie(LOGIN_COOKIE_ID)
|
|
71
|
-
delCookie(LOGIN_COOKIE_USER)
|
|
70
|
+
delCookie(LOGIN_COOKIE_ID);
|
|
71
|
+
delCookie(LOGIN_COOKIE_USER);
|
|
72
72
|
|
|
73
|
-
if (typeof window !==
|
|
74
|
-
window.location.href = `${window.location.origin}/login
|
|
73
|
+
if (typeof window !== "undefined") {
|
|
74
|
+
window.location.href = `${window.location.origin}/login`;
|
|
75
75
|
}
|
|
76
|
-
}
|
|
76
|
+
};
|
|
77
77
|
|
|
78
78
|
const principalLogin = (cookie: string, callback: any) => {
|
|
79
|
-
let url = getPrincipalUrl()
|
|
79
|
+
let url = getPrincipalUrl();
|
|
80
80
|
|
|
81
|
-
if (typeof window !==
|
|
82
|
-
url += `?cookieValue=${cookie}&redirectUrl=${handleLocationHref()}
|
|
81
|
+
if (typeof window !== "undefined") {
|
|
82
|
+
url += `?cookieValue=${cookie}&redirectUrl=${handleLocationHref()}`;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
axios
|
|
86
|
-
.get(url, { params: { credentials:
|
|
86
|
+
.get(url, { params: { credentials: "include" } })
|
|
87
87
|
.then((res: any) => {
|
|
88
|
-
const { data } = res
|
|
88
|
+
const { data } = res;
|
|
89
89
|
if (data) {
|
|
90
|
-
const { returnCode, userAttr } = data
|
|
90
|
+
const { returnCode, userAttr } = data;
|
|
91
91
|
if (returnCode !== 0) {
|
|
92
|
-
jumpToLogin()
|
|
92
|
+
jumpToLogin();
|
|
93
93
|
} else {
|
|
94
|
-
storeLoginUser(userAttr, callback)
|
|
94
|
+
storeLoginUser(userAttr, callback);
|
|
95
95
|
}
|
|
96
96
|
} else {
|
|
97
|
-
jumpToLogin()
|
|
97
|
+
jumpToLogin();
|
|
98
98
|
}
|
|
99
99
|
})
|
|
100
100
|
.catch((e) => {
|
|
101
|
-
console.error(
|
|
102
|
-
jumpToLogin()
|
|
103
|
-
})
|
|
104
|
-
}
|
|
101
|
+
console.error("principalLogin_exception", e);
|
|
102
|
+
jumpToLogin();
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
105
|
|
|
106
106
|
const storeLoginUser = (userAttr: any, callback: any) => {
|
|
107
107
|
if (userAttr) {
|
|
108
108
|
const user = JSON.stringify(userAttr, [
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
])
|
|
118
|
-
setCookie(LOGIN_COOKIE_USER, user, null)
|
|
119
|
-
callback?.(JSON.parse(user))
|
|
109
|
+
"city",
|
|
110
|
+
"company",
|
|
111
|
+
"department",
|
|
112
|
+
"displayName",
|
|
113
|
+
"employee",
|
|
114
|
+
"mail",
|
|
115
|
+
"name",
|
|
116
|
+
"sn",
|
|
117
|
+
]);
|
|
118
|
+
setCookie(LOGIN_COOKIE_USER, user, null);
|
|
119
|
+
callback?.(JSON.parse(user));
|
|
120
120
|
} else {
|
|
121
|
-
callback?.()
|
|
121
|
+
callback?.();
|
|
122
122
|
}
|
|
123
|
-
}
|
|
123
|
+
};
|
|
124
124
|
|
|
125
125
|
const storeLogin = (cookie: any, cookieExpire: any, userAttr: any, callback: any) => {
|
|
126
126
|
if (cookie) {
|
|
127
|
-
setCookie(LOGIN_COOKIE_ID, cookie, cookieExpire)
|
|
127
|
+
setCookie(LOGIN_COOKIE_ID, cookie, cookieExpire);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
storeLoginUser(userAttr, callback)
|
|
131
|
-
}
|
|
130
|
+
storeLoginUser(userAttr, callback);
|
|
131
|
+
};
|
|
132
132
|
|
|
133
|
-
const validateLogin = (ticket: string, name =
|
|
134
|
-
let url = getValidateUrl()
|
|
133
|
+
const validateLogin = (ticket: string, name = "", callback: any) => {
|
|
134
|
+
let url = getValidateUrl();
|
|
135
135
|
|
|
136
|
-
if (typeof window !==
|
|
137
|
-
url += `?ticket=${ticket}
|
|
136
|
+
if (typeof window !== "undefined") {
|
|
137
|
+
url += `?ticket=${ticket}`;
|
|
138
138
|
|
|
139
|
-
if (name !==
|
|
140
|
-
url += `&name=${name}
|
|
139
|
+
if (name !== "") {
|
|
140
|
+
url += `&name=${name}`;
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
axios
|
|
145
|
-
.get(url, { params: { credentials:
|
|
145
|
+
.get(url, { params: { credentials: "include" } })
|
|
146
146
|
.then((res: any) => {
|
|
147
147
|
if (res) {
|
|
148
|
-
const { data } = res
|
|
148
|
+
const { data } = res;
|
|
149
149
|
if (data) {
|
|
150
|
-
const { cookieValue, cookieExpire, returnCode, userAttr } = data
|
|
150
|
+
const { cookieValue, cookieExpire, returnCode, userAttr } = data;
|
|
151
151
|
if (returnCode === 0) {
|
|
152
|
-
storeLogin(cookieValue, cookieExpire, userAttr, callback)
|
|
152
|
+
storeLogin(cookieValue, cookieExpire, userAttr, callback);
|
|
153
153
|
} else {
|
|
154
|
-
jumpToLogin()
|
|
154
|
+
jumpToLogin();
|
|
155
155
|
}
|
|
156
156
|
} else {
|
|
157
|
-
jumpToLogin()
|
|
157
|
+
jumpToLogin();
|
|
158
158
|
}
|
|
159
159
|
} else {
|
|
160
|
-
jumpToLogin()
|
|
160
|
+
jumpToLogin();
|
|
161
161
|
}
|
|
162
162
|
})
|
|
163
163
|
.catch((e) => {
|
|
164
|
-
console.error(
|
|
165
|
-
})
|
|
166
|
-
}
|
|
164
|
+
console.error("validateLogin_exception", e);
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
167
|
|
|
168
168
|
export const login = (callback: any) => {
|
|
169
|
-
const cookieLoginValue = getCookie(LOGIN_COOKIE_ID)
|
|
169
|
+
const cookieLoginValue = getCookie(LOGIN_COOKIE_ID);
|
|
170
170
|
|
|
171
|
-
if (typeof window !==
|
|
172
|
-
const locationHref = window.location.href
|
|
171
|
+
if (typeof window !== "undefined") {
|
|
172
|
+
const locationHref = window.location.href;
|
|
173
173
|
|
|
174
174
|
// 如果已经在登录页面,不需要进行登录检查
|
|
175
|
-
if (locationHref.indexOf(
|
|
176
|
-
callback?.()
|
|
177
|
-
return
|
|
175
|
+
if (locationHref.indexOf("/login") !== -1) {
|
|
176
|
+
callback?.();
|
|
177
|
+
return;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
// 如果没有登录凭证,立即跳转到登录页面
|
|
181
|
-
if (cookieLoginValue ===
|
|
182
|
-
const urlParamTicket = getUrlParamByKey(
|
|
183
|
-
const urlParamName = getUrlParamByKey(
|
|
181
|
+
if (cookieLoginValue === "") {
|
|
182
|
+
const urlParamTicket = getUrlParamByKey("ticket");
|
|
183
|
+
const urlParamName = getUrlParamByKey("name");
|
|
184
184
|
|
|
185
|
-
if (urlParamTicket !==
|
|
186
|
-
validateLogin(urlParamTicket, urlParamName, callback)
|
|
185
|
+
if (urlParamTicket !== "") {
|
|
186
|
+
validateLogin(urlParamTicket, urlParamName, callback);
|
|
187
187
|
} else {
|
|
188
188
|
// 没有ticket参数,直接跳转到登录页
|
|
189
|
-
jumpToLogin()
|
|
189
|
+
jumpToLogin();
|
|
190
190
|
// 不执行回调,因为页面将被重定向
|
|
191
|
-
return
|
|
191
|
+
return;
|
|
192
192
|
}
|
|
193
193
|
} else {
|
|
194
194
|
// 有登录凭证,验证登录状态
|
|
195
|
-
principalLogin(cookieLoginValue, callback)
|
|
195
|
+
principalLogin(cookieLoginValue, callback);
|
|
196
196
|
}
|
|
197
197
|
} else {
|
|
198
|
-
callback?.()
|
|
198
|
+
callback?.();
|
|
199
199
|
}
|
|
200
|
-
}
|
|
200
|
+
};
|
|
201
201
|
|
|
202
202
|
export const directLogin = (userName: string, userPassword: string, callback: any) => {
|
|
203
|
-
if (userName ===
|
|
204
|
-
return { success: false, message:
|
|
203
|
+
if (userName === "") {
|
|
204
|
+
return { success: false, message: "请输入用户名" };
|
|
205
205
|
}
|
|
206
|
-
if (userPassword ===
|
|
207
|
-
return { success: false, message:
|
|
206
|
+
if (userPassword === "") {
|
|
207
|
+
return { success: false, message: "请输入密码" };
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
// 使用 encodeURIComponent 处理可能的特殊字符,然后再进行 Base64 编码
|
|
211
|
-
const safeStr = handleXSS(`${userName},${userPassword}`)
|
|
212
|
-
const encodedName = btoa(encodeURIComponent(safeStr))
|
|
213
|
-
const url = `${getLocalApiPrefix()}/rest/sso/ticketCheck?ticket=XXX&name=${encodedName}
|
|
211
|
+
const safeStr = handleXSS(`${userName},${userPassword}`);
|
|
212
|
+
const encodedName = btoa(encodeURIComponent(safeStr));
|
|
213
|
+
const url = `${getLocalApiPrefix()}/rest/sso/ticketCheck?ticket=XXX&name=${encodedName}`;
|
|
214
214
|
|
|
215
215
|
return fetch(url)
|
|
216
216
|
.then((response) => response.json())
|
|
217
217
|
.then((data) => {
|
|
218
218
|
if (data && data.returnCode === 0) {
|
|
219
219
|
// 登录成功,设置cookie
|
|
220
|
-
if (typeof window !==
|
|
221
|
-
storeLogin(data.cookieValue, data.cookieExpire, data.userAttr, callback)
|
|
222
|
-
return { success: true }
|
|
220
|
+
if (typeof window !== "undefined") {
|
|
221
|
+
storeLogin(data.cookieValue, data.cookieExpire, data.userAttr, callback);
|
|
222
|
+
return { success: true };
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
|
-
return { success: false, message:
|
|
225
|
+
return { success: false, message: "用户名或密码错误" };
|
|
226
226
|
})
|
|
227
227
|
.catch((error) => {
|
|
228
|
-
console.error(
|
|
229
|
-
return { success: false, message:
|
|
230
|
-
})
|
|
231
|
-
}
|
|
228
|
+
console.error("登录请求失败:", error);
|
|
229
|
+
return { success: false, message: "登录请求失败,请稍后重试" };
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
232
|
|
|
233
233
|
export const logout = () => {
|
|
234
|
-
jumpToLogin()
|
|
235
|
-
}
|
|
234
|
+
jumpToLogin();
|
|
235
|
+
};
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
// 这个文件需要在所有 React 组件加载之前执行
|
|
2
2
|
// 用于抑制 useLayoutEffect 在服务端渲染时的警告
|
|
3
3
|
|
|
4
|
-
if (typeof window ===
|
|
4
|
+
if (typeof window === "undefined") {
|
|
5
5
|
// 服务端环境
|
|
6
|
-
const originalError = console.error
|
|
7
|
-
const originalWarn = console.warn
|
|
6
|
+
const originalError = console.error;
|
|
7
|
+
const originalWarn = console.warn;
|
|
8
8
|
|
|
9
9
|
console.error = function (...args) {
|
|
10
|
-
const message = args[0]
|
|
10
|
+
const message = args[0];
|
|
11
11
|
if (
|
|
12
|
-
typeof message ===
|
|
13
|
-
(message.includes(
|
|
14
|
-
message.includes(
|
|
12
|
+
typeof message === "string" &&
|
|
13
|
+
(message.includes("useLayoutEffect does nothing on the server") ||
|
|
14
|
+
message.includes("Warning: useLayoutEffect does nothing on the server"))
|
|
15
15
|
) {
|
|
16
|
-
return
|
|
16
|
+
return;
|
|
17
17
|
}
|
|
18
|
-
originalError.apply(console, args)
|
|
19
|
-
}
|
|
18
|
+
originalError.apply(console, args);
|
|
19
|
+
};
|
|
20
20
|
|
|
21
21
|
console.warn = function (...args) {
|
|
22
|
-
const message = args[0]
|
|
22
|
+
const message = args[0];
|
|
23
23
|
if (
|
|
24
|
-
typeof message ===
|
|
25
|
-
(message.includes(
|
|
26
|
-
message.includes(
|
|
24
|
+
typeof message === "string" &&
|
|
25
|
+
(message.includes("useLayoutEffect does nothing on the server") ||
|
|
26
|
+
message.includes("Warning: useLayoutEffect does nothing on the server"))
|
|
27
27
|
) {
|
|
28
|
-
return
|
|
28
|
+
return;
|
|
29
29
|
}
|
|
30
|
-
originalWarn.apply(console, args)
|
|
31
|
-
}
|
|
30
|
+
originalWarn.apply(console, args);
|
|
31
|
+
};
|
|
32
32
|
}
|
package/lib/args.js
CHANGED
|
@@ -8,14 +8,14 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
8
8
|
const getProcessArgvs = (removeItems = 2) => {
|
|
9
9
|
const args = process.argv.slice(removeItems);
|
|
10
10
|
const result = {
|
|
11
|
-
command:
|
|
12
|
-
dictionary:
|
|
13
|
-
controller:
|
|
14
|
-
action:
|
|
11
|
+
command: "", // dev, start, build, export, create, delete, init, help
|
|
12
|
+
dictionary: "", // export/init dictionary=${dictionary}
|
|
13
|
+
controller: "",
|
|
14
|
+
action: "", // create/delete controller=${controller} action=${action}
|
|
15
15
|
};
|
|
16
16
|
lodash_1.default.each(args, (item, index) => {
|
|
17
|
-
if (item.indexOf(
|
|
18
|
-
const itemArr = item.split(
|
|
17
|
+
if (item.indexOf("=") !== -1) {
|
|
18
|
+
const itemArr = item.split("=");
|
|
19
19
|
const key = itemArr[0].toLowerCase();
|
|
20
20
|
result[key] = itemArr[1];
|
|
21
21
|
}
|
|
@@ -26,29 +26,29 @@ const getProcessArgvs = (removeItems = 2) => {
|
|
|
26
26
|
result.command = item;
|
|
27
27
|
break;
|
|
28
28
|
case 1:
|
|
29
|
-
if (command ===
|
|
30
|
-
command ===
|
|
31
|
-
command.indexOf(
|
|
32
|
-
command.indexOf(
|
|
29
|
+
if (command === "create" ||
|
|
30
|
+
command === "-c" ||
|
|
31
|
+
command.indexOf("delete") !== -1 ||
|
|
32
|
+
command.indexOf("-d") !== -1) {
|
|
33
33
|
result.controller = item;
|
|
34
34
|
}
|
|
35
|
-
if (command ===
|
|
35
|
+
if (command === "export" || command === "init" || command === "-i") {
|
|
36
36
|
result.dictionary = item;
|
|
37
37
|
}
|
|
38
38
|
break;
|
|
39
39
|
case 2:
|
|
40
|
-
if (command ===
|
|
41
|
-
command ===
|
|
42
|
-
command.indexOf(
|
|
43
|
-
command.indexOf(
|
|
40
|
+
if (command === "create" ||
|
|
41
|
+
command === "-c" ||
|
|
42
|
+
command.indexOf("delete") !== -1 ||
|
|
43
|
+
command.indexOf("-d") !== -1) {
|
|
44
44
|
result.action = item;
|
|
45
45
|
}
|
|
46
46
|
break;
|
|
47
47
|
case 3:
|
|
48
|
-
if (command ===
|
|
49
|
-
command ===
|
|
50
|
-
command.indexOf(
|
|
51
|
-
command.indexOf(
|
|
48
|
+
if (command === "create" ||
|
|
49
|
+
command === "-c" ||
|
|
50
|
+
command.indexOf("delete") !== -1 ||
|
|
51
|
+
command.indexOf("-d") !== -1) {
|
|
52
52
|
result.dictionary = item;
|
|
53
53
|
}
|
|
54
54
|
break;
|
package/lib/cli/app.d.ts
CHANGED
package/lib/cli/app.js
CHANGED
|
@@ -28,7 +28,7 @@ class CliApp {
|
|
|
28
28
|
const availableCommands = this.registry.getAllCommands().map((c) => c.name);
|
|
29
29
|
const suggestions = this.findSimilarCommands(command, availableCommands);
|
|
30
30
|
if (suggestions.length > 0) {
|
|
31
|
-
utils_1.Console.subtitle(
|
|
31
|
+
utils_1.Console.subtitle("你是否想要运行:");
|
|
32
32
|
suggestions.forEach((suggestion) => {
|
|
33
33
|
console.log(` nsgm ${suggestion}`);
|
|
34
34
|
});
|
|
@@ -75,7 +75,7 @@ class CliApp {
|
|
|
75
75
|
// 应用命令选项中定义的默认值
|
|
76
76
|
if (cmd.options) {
|
|
77
77
|
for (const option of cmd.options) {
|
|
78
|
-
if (option.default !== undefined && (result[option.name] === undefined || result[option.name] ===
|
|
78
|
+
if (option.default !== undefined && (result[option.name] === undefined || result[option.name] === "")) {
|
|
79
79
|
result[option.name] = option.default;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "../types";
|
|
2
2
|
export declare const buildCommand: Command;
|
|
@@ -5,24 +5,24 @@ const child_process_1 = require("child_process");
|
|
|
5
5
|
const util_1 = require("util");
|
|
6
6
|
const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
7
7
|
exports.buildCommand = {
|
|
8
|
-
name:
|
|
8
|
+
name: "build",
|
|
9
9
|
aliases: [],
|
|
10
|
-
description:
|
|
11
|
-
usage:
|
|
12
|
-
examples: [
|
|
10
|
+
description: "构建生产版本",
|
|
11
|
+
usage: "nsgm build",
|
|
12
|
+
examples: ["nsgm build"],
|
|
13
13
|
execute: async (_options) => {
|
|
14
14
|
try {
|
|
15
|
-
console.log(
|
|
16
|
-
const { stdout, stderr } = await execAsync(
|
|
15
|
+
console.log("🔨 开始构建生产版本...");
|
|
16
|
+
const { stdout, stderr } = await execAsync("next build");
|
|
17
17
|
if (stderr) {
|
|
18
|
-
console.error(
|
|
18
|
+
console.error("构建警告:", stderr);
|
|
19
19
|
}
|
|
20
|
-
console.log(
|
|
20
|
+
console.log("✅ 构建完成!");
|
|
21
21
|
console.log(stdout);
|
|
22
22
|
process.exit(0);
|
|
23
23
|
}
|
|
24
24
|
catch (error) {
|
|
25
|
-
console.error(
|
|
25
|
+
console.error("❌ 构建失败:", error);
|
|
26
26
|
process.exit(1);
|
|
27
27
|
}
|
|
28
28
|
},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Command } from
|
|
1
|
+
import { Command } from "../types";
|
|
2
2
|
export declare const createCommand: Command;
|