@qlover/create-app 0.4.5 → 0.5.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/CHANGELOG.md +95 -35
- package/dist/index.cjs +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +10 -2418
- package/{templates → dist/templates}/node-lib/package.json +2 -2
- package/{templates → dist/templates}/react-app/README.md +6 -6
- package/{templates/react-app/config/Identifier/Error.ts → dist/templates/react-app/config/Identifier/common.error.ts} +8 -8
- package/dist/templates/react-app/config/Identifier/common.ts +62 -0
- package/dist/templates/react-app/config/Identifier/index.ts +10 -0
- package/dist/templates/react-app/config/Identifier/page.about.ts +181 -0
- package/dist/templates/react-app/config/Identifier/page.executor.ts +267 -0
- package/dist/templates/react-app/config/Identifier/page.home.ts +63 -0
- package/dist/templates/react-app/config/Identifier/page.identifiter.ts +39 -0
- package/dist/templates/react-app/config/Identifier/page.jsonStorage.ts +70 -0
- package/dist/templates/react-app/config/Identifier/page.login.ts +152 -0
- package/dist/templates/react-app/config/Identifier/page.register.ts +147 -0
- package/dist/templates/react-app/config/Identifier/page.request.ts +179 -0
- package/dist/templates/react-app/config/app.router.ts +163 -0
- package/{templates → dist/templates}/react-app/config/feapi.mock.json +6 -0
- package/dist/templates/react-app/config/theme.ts +11 -0
- package/{templates → dist/templates}/react-app/package.json +2 -2
- package/{templates → dist/templates}/react-app/public/locales/en/common.json +97 -116
- package/{templates → dist/templates}/react-app/public/locales/zh/common.json +98 -117
- package/{templates → dist/templates}/react-app/src/App.tsx +6 -5
- package/dist/templates/react-app/src/base/apis/userApi/UserApi.ts +142 -0
- package/{templates → dist/templates}/react-app/src/base/apis/userApi/UserApiType.ts +11 -0
- package/{templates → dist/templates}/react-app/src/base/cases/AppConfig.ts +11 -0
- package/dist/templates/react-app/src/base/cases/I18nKeyErrorPlugin.ts +36 -0
- package/{templates → dist/templates}/react-app/src/base/cases/RouterLoader.ts +2 -1
- package/{templates → dist/templates}/react-app/src/base/services/I18nService.ts +4 -4
- package/{templates/react-app/src/base/services/ProcesserService.ts → dist/templates/react-app/src/base/services/ProcesserExecutor.ts} +15 -5
- package/{templates → dist/templates}/react-app/src/base/services/RouteService.ts +11 -13
- package/dist/templates/react-app/src/base/services/UserService.ts +132 -0
- package/{templates → dist/templates}/react-app/src/base/types/Page.ts +12 -2
- package/{templates → dist/templates}/react-app/src/core/IOC.ts +11 -6
- package/{templates → dist/templates}/react-app/src/core/bootstrap.ts +2 -2
- package/{templates → dist/templates}/react-app/src/core/bootstraps/index.ts +3 -1
- package/{templates → dist/templates}/react-app/src/core/globals.ts +23 -7
- package/{templates → dist/templates}/react-app/src/core/registers/RegisterApi.ts +1 -1
- package/{templates → dist/templates}/react-app/src/core/registers/RegisterCommon.ts +14 -15
- package/{templates → dist/templates}/react-app/src/core/registers/RegisterControllers.ts +9 -4
- package/{templates → dist/templates}/react-app/src/core/registers/RegisterGlobals.ts +12 -4
- package/{templates → dist/templates}/react-app/src/pages/404.tsx +4 -1
- package/{templates → dist/templates}/react-app/src/pages/500.tsx +2 -1
- package/{templates → dist/templates}/react-app/src/pages/auth/Layout.tsx +2 -2
- package/{templates/react-app/src/pages/auth/Login.tsx → dist/templates/react-app/src/pages/auth/LoginPage.tsx} +2 -4
- package/{templates/react-app/src/pages/auth/Register.tsx → dist/templates/react-app/src/pages/auth/RegisterPage.tsx} +3 -6
- package/{templates/react-app/src/pages/base/About.tsx → dist/templates/react-app/src/pages/base/AboutPage.tsx} +4 -4
- package/{templates/react-app/src/pages/base/ErrorIdentifier.tsx → dist/templates/react-app/src/pages/base/ErrorIdentifierPage.tsx} +3 -3
- package/{templates/react-app/src/pages/base/Executor.tsx → dist/templates/react-app/src/pages/base/ExecutorPage.tsx} +3 -3
- package/{templates/react-app/src/pages/base/Home.tsx → dist/templates/react-app/src/pages/base/HomePage.tsx} +15 -45
- package/{templates/react-app/src/pages/base/JSONStorage.tsx → dist/templates/react-app/src/pages/base/JSONStoragePage.tsx} +3 -3
- package/{templates → dist/templates}/react-app/src/pages/base/Layout.tsx +4 -4
- package/{templates/react-app/src/pages/base/Request.tsx → dist/templates/react-app/src/pages/base/RequestPage.tsx} +2 -2
- package/{templates/react-app/src/pages/base → dist/templates/react-app/src/uikit}/components/LogoutButton.tsx +1 -1
- package/{templates → dist/templates}/react-app/src/uikit/components/ThemeSwitcher.tsx +5 -6
- package/{templates → dist/templates}/react-app/src/uikit/contexts/BaseRouteContext.ts +1 -1
- package/{templates → dist/templates}/react-app/src/uikit/controllers/ExecutorController.ts +2 -2
- package/{templates → dist/templates}/react-app/src/uikit/controllers/JSONStorageController.ts +5 -5
- package/{templates → dist/templates}/react-app/src/uikit/controllers/RequestController.ts +1 -1
- package/{templates/react-app/src/uikit/hooks/useLanguageGuard.ts → dist/templates/react-app/src/uikit/hooks/useI18nGuard.ts} +1 -1
- package/{templates → dist/templates}/react-app/src/uikit/hooks/useStore.ts +2 -2
- package/dist/templates/react-app/src/uikit/hooks/userRouterService.ts +12 -0
- package/{templates → dist/templates}/react-app/src/uikit/providers/BaseRouteProvider.tsx +1 -0
- package/dist/templates/react-app/src/uikit/providers/ProcessExecutorProvider.tsx +24 -0
- package/dist/templates/react-app/src/uikit/providers/UserAuthProvider.tsx +16 -0
- package/{templates → dist/templates}/react-app/vite.config.ts +2 -1
- package/package.json +4 -6
- package/templates/react-app/config/Identifier/Auth.ts +0 -13
- package/templates/react-app/config/Identifier/I18n.ts +0 -1366
- package/templates/react-app/config/app.router.json +0 -159
- package/templates/react-app/config/theme.json +0 -9
- package/templates/react-app/src/base/apis/userApi/UserApi.ts +0 -64
- package/templates/react-app/src/base/port/LoginInterface.ts +0 -12
- package/templates/react-app/src/base/port/StoreInterface.ts +0 -58
- package/templates/react-app/src/base/services/UserService.ts +0 -130
- package/templates/react-app/src/uikit/providers/ProcessProvider.tsx +0 -45
- /package/{configs → dist/configs}/_common/.editorconfig +0 -0
- /package/{configs → dist/configs}/_common/.env.template +0 -0
- /package/{configs → dist/configs}/_common/.gitattributes +0 -0
- /package/{configs → dist/configs}/_common/.github/workflows/general-check.yml +0 -0
- /package/{configs → dist/configs}/_common/.github/workflows/release.yml +0 -0
- /package/{configs → dist/configs}/_common/.gitignore.template +0 -0
- /package/{configs → dist/configs}/_common/.husky/commit-msg +0 -0
- /package/{configs → dist/configs}/_common/.husky/pre-commit +0 -0
- /package/{configs → dist/configs}/_common/.prettierignore +0 -0
- /package/{configs → dist/configs}/_common/.prettierrc.js +0 -0
- /package/{configs → dist/configs}/_common/.vscode/extensions.json +0 -0
- /package/{configs → dist/configs}/_common/.vscode/react.code-snippets +0 -0
- /package/{configs → dist/configs}/_common/.vscode/settings.json +0 -0
- /package/{configs → dist/configs}/_common/commitlint.config.js +0 -0
- /package/{configs → dist/configs}/_common/package.json.template +0 -0
- /package/{configs → dist/configs}/node-lib/eslint.config.js +0 -0
- /package/{configs → dist/configs}/react-app/eslint.config.js +0 -0
- /package/{templates → dist/templates}/node-lib/__tests__/readJson.test.ts +0 -0
- /package/{templates → dist/templates}/node-lib/bin/test.js +0 -0
- /package/{templates → dist/templates}/node-lib/rollup.config.js +0 -0
- /package/{templates → dist/templates}/node-lib/src/index.ts +0 -0
- /package/{templates → dist/templates}/node-lib/src/readJson.ts +0 -0
- /package/{templates → dist/templates}/node-lib/tsconfig.json +0 -0
- /package/{templates → dist/templates}/pack-app/README.md +0 -0
- /package/{templates → dist/templates}/pack-app/eslint.config.js +0 -0
- /package/{templates → dist/templates}/pack-app/fe-config.json +0 -0
- /package/{templates → dist/templates}/pack-app/package.json +0 -0
- /package/{templates → dist/templates}/pack-app/pnpm-workspace.yaml +0 -0
- /package/{templates → dist/templates}/pack-app/tsconfig.json +0 -0
- /package/{templates → dist/templates}/pack-app/tsconfig.test.json +0 -0
- /package/{templates → dist/templates}/pack-app/vite.config.ts +0 -0
- /package/{templates → dist/templates}/react-app/.env.template +0 -0
- /package/{templates → dist/templates}/react-app/config/common.ts +0 -0
- /package/{templates → dist/templates}/react-app/config/i18n.ts +0 -0
- /package/{templates → dist/templates}/react-app/index.html +0 -0
- /package/{templates → dist/templates}/react-app/postcss.config.js +0 -0
- /package/{templates → dist/templates}/react-app/public/logo.svg +0 -0
- /package/{templates → dist/templates}/react-app/public/router-root/logo.svg +0 -0
- /package/{templates → dist/templates}/react-app/src/assets/react.svg +0 -0
- /package/{templates → dist/templates}/react-app/src/base/apis/AiApi.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/apis/feApi/FeApi.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/apis/feApi/FeApiAdapter.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/apis/feApi/FeApiBootstarp.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/apis/feApi/FeApiType.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/apis/userApi/UserApiAdapter.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/apis/userApi/UserApiBootstarp.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/cases/AppError.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/cases/DialogHandler.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/cases/PublicAssetsPath.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/cases/RequestLogger.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/cases/RequestStatusCatcher.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/port/ApiTransactionInterface.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/port/InteractionHubInterface.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/port/RequestCatcherInterface.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/port/UIDependenciesInterface.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/types/deprecated-antd.d.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/base/types/global.d.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/core/bootstraps/BootstrapApp.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/core/bootstraps/PrintBootstrap.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/core/registers/index.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/main.tsx +0 -0
- /package/{templates → dist/templates}/react-app/src/pages/base/RedirectPathname.tsx +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/antd-themes/_default.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/antd-themes/dark.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/antd-themes/index.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/antd-themes/no-context.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/antd-themes/pink.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/index.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/page.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/tailwind.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/themes/_default.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/themes/dark.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/themes/index.css +0 -0
- /package/{templates → dist/templates}/react-app/src/styles/css/themes/pink.css +0 -0
- /package/{templates/react-app/src/pages/base → dist/templates/react-app/src/uikit}/components/BaseHeader.tsx +0 -0
- /package/{templates → dist/templates}/react-app/src/uikit/components/LanguageSwitcher.tsx +0 -0
- /package/{templates → dist/templates}/react-app/src/uikit/components/Loading.tsx +0 -0
- /package/{templates → dist/templates}/react-app/src/uikit/components/LocaleLink.tsx +0 -0
- /package/{templates → dist/templates}/react-app/src/uikit/components/RouterRenderComponent.tsx +0 -0
- /package/{templates → dist/templates}/react-app/src/uikit/hooks/useDocumentTitle.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/uikit/hooks/useStrictEffect.ts +0 -0
- /package/{templates → dist/templates}/react-app/src/vite-env.d.ts +0 -0
- /package/{templates → dist/templates}/react-app/tailwind.config.js +0 -0
- /package/{templates → dist/templates}/react-app/tsconfig.app.json +0 -0
- /package/{templates → dist/templates}/react-app/tsconfig.json +0 -0
- /package/{templates → dist/templates}/react-app/tsconfig.node.json +0 -0
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"base": {
|
|
3
|
-
"routes": [
|
|
4
|
-
{
|
|
5
|
-
"path": "/",
|
|
6
|
-
"element": "base/RedirectPathname",
|
|
7
|
-
"meta": {
|
|
8
|
-
"category": "main"
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"path": "/:lng",
|
|
13
|
-
"element": "base/Layout",
|
|
14
|
-
"meta": {
|
|
15
|
-
"category": "main"
|
|
16
|
-
},
|
|
17
|
-
"children": [
|
|
18
|
-
{
|
|
19
|
-
"index": true,
|
|
20
|
-
"element": "base/Home",
|
|
21
|
-
"meta": {
|
|
22
|
-
"title": "page.home.title",
|
|
23
|
-
"icon": "home",
|
|
24
|
-
"localNamespace": "common"
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
"path": "about",
|
|
29
|
-
"element": "base/About",
|
|
30
|
-
"meta": {
|
|
31
|
-
"title": "page.about.title",
|
|
32
|
-
"icon": "info",
|
|
33
|
-
"localNamespace": "common"
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"path": "jsonStorage",
|
|
38
|
-
"element": "base/JSONStorage",
|
|
39
|
-
"meta": {
|
|
40
|
-
"title": "page.jsonstorage.title",
|
|
41
|
-
"icon": "info",
|
|
42
|
-
"localNamespace": "common"
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
"path": "request",
|
|
47
|
-
"element": "base/Request",
|
|
48
|
-
"meta": {
|
|
49
|
-
"title": "page.request.title",
|
|
50
|
-
"icon": "info",
|
|
51
|
-
"localNamespace": "common"
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"path": "executor",
|
|
56
|
-
"element": "base/Executor",
|
|
57
|
-
"meta": {
|
|
58
|
-
"title": "page.executor.title",
|
|
59
|
-
"icon": "info",
|
|
60
|
-
"localNamespace": "common"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
"path": "errorIdentifier",
|
|
65
|
-
"element": "base/ErrorIdentifier",
|
|
66
|
-
"meta": {
|
|
67
|
-
"title": "page.error_identifier.title",
|
|
68
|
-
"icon": "info",
|
|
69
|
-
"localNamespace": "common"
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
"path": "404",
|
|
74
|
-
"element": "404",
|
|
75
|
-
"meta": {
|
|
76
|
-
"category": "common",
|
|
77
|
-
"title": "page.404.title",
|
|
78
|
-
"layout": "blank",
|
|
79
|
-
"localNamespace": "common"
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
"path": "500",
|
|
84
|
-
"element": "500",
|
|
85
|
-
"meta": {
|
|
86
|
-
"category": "common",
|
|
87
|
-
"title": "page.500.title",
|
|
88
|
-
"layout": "blank",
|
|
89
|
-
"localNamespace": "common"
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
]
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
{
|
|
96
|
-
"path": "/:lng",
|
|
97
|
-
"element": "auth/Layout",
|
|
98
|
-
"meta": {
|
|
99
|
-
"category": "auth"
|
|
100
|
-
},
|
|
101
|
-
"children": [
|
|
102
|
-
{
|
|
103
|
-
"index": true,
|
|
104
|
-
"element": "auth/Login"
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
"path": "login",
|
|
108
|
-
"element": "auth/Login",
|
|
109
|
-
"meta": {
|
|
110
|
-
"title": "page.login.title",
|
|
111
|
-
"icon": "info",
|
|
112
|
-
"localNamespace": "common"
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
{
|
|
116
|
-
"path": "register",
|
|
117
|
-
"element": "auth/Register",
|
|
118
|
-
"meta": {
|
|
119
|
-
"title": "page.register.title",
|
|
120
|
-
"icon": "info",
|
|
121
|
-
"localNamespace": "common"
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
},
|
|
126
|
-
|
|
127
|
-
{
|
|
128
|
-
"path": "404",
|
|
129
|
-
"element": "404",
|
|
130
|
-
"meta": {
|
|
131
|
-
"category": "common",
|
|
132
|
-
"title": "page.404.title",
|
|
133
|
-
"layout": "blank",
|
|
134
|
-
"localNamespace": "common"
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
"path": "500",
|
|
139
|
-
"element": "500",
|
|
140
|
-
"meta": {
|
|
141
|
-
"category": "common",
|
|
142
|
-
"title": "page.500.title",
|
|
143
|
-
"layout": "blank",
|
|
144
|
-
"localNamespace": "common"
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
"path": "*",
|
|
149
|
-
"element": "404",
|
|
150
|
-
"meta": {
|
|
151
|
-
"category": "common",
|
|
152
|
-
"title": "page.404.title",
|
|
153
|
-
"layout": "blank",
|
|
154
|
-
"localNamespace": "common"
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
]
|
|
158
|
-
}
|
|
159
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FetchAbortPlugin,
|
|
3
|
-
RequestAdapterFetch,
|
|
4
|
-
RequestTransaction
|
|
5
|
-
} from '@qlover/fe-corekit';
|
|
6
|
-
import {
|
|
7
|
-
GetIpInfoTransaction,
|
|
8
|
-
UserApiGetUserInfoTransaction,
|
|
9
|
-
UserApiLoginTransaction,
|
|
10
|
-
UserApiTestApiCatchResultTransaction
|
|
11
|
-
} from './UserApiType';
|
|
12
|
-
import { inject, injectable } from 'inversify';
|
|
13
|
-
import { UserApiAdapter } from './UserApiAdapter';
|
|
14
|
-
import { UserApiConfig } from './UserApiBootstarp';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* UserApi
|
|
18
|
-
*
|
|
19
|
-
* @description
|
|
20
|
-
* UserApi is a client for the user API.
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
@injectable()
|
|
24
|
-
export class UserApi extends RequestTransaction<UserApiConfig> {
|
|
25
|
-
constructor(
|
|
26
|
-
@inject(FetchAbortPlugin) private abortPlugin: FetchAbortPlugin,
|
|
27
|
-
@inject(UserApiAdapter) adapter: RequestAdapterFetch
|
|
28
|
-
) {
|
|
29
|
-
super(adapter);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
stop(request: UserApiConfig): Promise<void> | void {
|
|
33
|
-
this.abortPlugin.abort(request);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async getRandomUser(): Promise<GetIpInfoTransaction['response']> {
|
|
37
|
-
return this.request<GetIpInfoTransaction>({
|
|
38
|
-
url: 'https://randomuser.me/api/',
|
|
39
|
-
method: 'GET',
|
|
40
|
-
disabledMock: true
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async testApiCatchResult(): Promise<
|
|
45
|
-
UserApiTestApiCatchResultTransaction['response']
|
|
46
|
-
> {
|
|
47
|
-
return this.request<UserApiTestApiCatchResultTransaction>({
|
|
48
|
-
url: 'https://randomuser.me/api/?_name=ApiCatchResult',
|
|
49
|
-
method: 'GET',
|
|
50
|
-
disabledMock: true,
|
|
51
|
-
openApiCatch: true
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async getUserInfo(): Promise<UserApiGetUserInfoTransaction['response']> {
|
|
56
|
-
return this.get<UserApiGetUserInfoTransaction>('/api/userinfo');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async login(
|
|
60
|
-
params: UserApiLoginTransaction['data']
|
|
61
|
-
): Promise<UserApiLoginTransaction['response']> {
|
|
62
|
-
return this.post<UserApiLoginTransaction>('/api/login', params);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export interface RegisterFormData {
|
|
2
|
-
username: string;
|
|
3
|
-
email: string;
|
|
4
|
-
password: string;
|
|
5
|
-
confirmPassword: string;
|
|
6
|
-
agreeToTerms: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface LoginInterface {
|
|
9
|
-
login(params: unknown): Promise<unknown>;
|
|
10
|
-
logout(): void;
|
|
11
|
-
register(params: RegisterFormData): Promise<unknown>;
|
|
12
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { SliceStore } from '@qlover/slice-store-react';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Store State Interface
|
|
5
|
-
*
|
|
6
|
-
* This interface is used to define the state of a store.
|
|
7
|
-
* It is used to define the state of a store.
|
|
8
|
-
*
|
|
9
|
-
* must implement the copyWith method
|
|
10
|
-
*/
|
|
11
|
-
export interface StoreStateInterface {
|
|
12
|
-
// You can define your own properties here
|
|
13
|
-
// ...
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Store Interface
|
|
18
|
-
*
|
|
19
|
-
* This class is used to define the store interface.
|
|
20
|
-
* It is used to define the store interface.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* class ChatStoreState implements StoreStateInterface {
|
|
25
|
-
* isChatRunning: boolean = false;
|
|
26
|
-
*
|
|
27
|
-
* copyWith(state: { isChatRunning?: boolean }): this {
|
|
28
|
-
* return Object.assign(new ChatStoreState(), this, state);
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
*
|
|
32
|
-
* export class ChatStore extends StoreInterface<ChatStoreState> {
|
|
33
|
-
* constructor() {
|
|
34
|
-
* super(() => new ChatStoreState());
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
export abstract class StoreInterface<
|
|
40
|
-
T extends StoreStateInterface
|
|
41
|
-
> extends SliceStore<T> {
|
|
42
|
-
/**
|
|
43
|
-
* Constructor
|
|
44
|
-
*
|
|
45
|
-
* @param stateFactory - The factory function to create the initial state
|
|
46
|
-
*/
|
|
47
|
-
constructor(protected stateFactory: () => T) {
|
|
48
|
-
super(stateFactory);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Reset the state of the store
|
|
53
|
-
*/
|
|
54
|
-
resetState(): void {
|
|
55
|
-
// Create a new instance of initial state
|
|
56
|
-
this.emit(this.stateFactory());
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { ExecutorPlugin } from '@qlover/fe-corekit';
|
|
2
|
-
import type {
|
|
3
|
-
UserApiGetUserInfoTransaction,
|
|
4
|
-
UserApiLoginTransaction
|
|
5
|
-
} from '@/base/apis/userApi/UserApiType';
|
|
6
|
-
import { RouteService } from './RouteService';
|
|
7
|
-
import { ThreadUtil, type StorageTokenInterface } from '@qlover/corekit-bridge';
|
|
8
|
-
import { inject, injectable } from 'inversify';
|
|
9
|
-
import { IOCIdentifier } from '@/core/IOC';
|
|
10
|
-
import { LoginInterface, RegisterFormData } from '@/base/port/LoginInterface';
|
|
11
|
-
import { UserApi } from '@/base/apis/userApi/UserApi';
|
|
12
|
-
import { AppError } from '@/base/cases/AppError';
|
|
13
|
-
import { StoreInterface, StoreStateInterface } from '../port/StoreInterface';
|
|
14
|
-
import * as errKeys from '@config/Identifier/Error';
|
|
15
|
-
|
|
16
|
-
class UserServiceState implements StoreStateInterface {
|
|
17
|
-
success: boolean = false;
|
|
18
|
-
userInfo: UserApiGetUserInfoTransaction['response']['data'] = {
|
|
19
|
-
name: '',
|
|
20
|
-
email: '',
|
|
21
|
-
picture: ''
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@injectable()
|
|
26
|
-
export class UserService
|
|
27
|
-
extends StoreInterface<UserServiceState>
|
|
28
|
-
implements ExecutorPlugin, LoginInterface
|
|
29
|
-
{
|
|
30
|
-
readonly pluginName = 'UserService';
|
|
31
|
-
|
|
32
|
-
constructor(
|
|
33
|
-
@inject(UserApi) private userApi: UserApi,
|
|
34
|
-
@inject(RouteService) private routerController: RouteService,
|
|
35
|
-
@inject(IOCIdentifier.FeApiToken)
|
|
36
|
-
private userToken: StorageTokenInterface<string>
|
|
37
|
-
) {
|
|
38
|
-
super(() => new UserServiceState());
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
setState(state: Partial<UserServiceState>): void {
|
|
42
|
-
this.emit({ ...this.state, ...state });
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @override
|
|
47
|
-
*/
|
|
48
|
-
async onBefore(): Promise<void> {
|
|
49
|
-
await ThreadUtil.sleep(1000);
|
|
50
|
-
|
|
51
|
-
const userToken = this.userToken.getToken();
|
|
52
|
-
|
|
53
|
-
if (!userToken) {
|
|
54
|
-
throw new AppError(errKeys.LOCAL_NO_USER_TOKEN);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const userInfo = await this.userApi.getUserInfo();
|
|
58
|
-
|
|
59
|
-
this.setState({
|
|
60
|
-
success: true,
|
|
61
|
-
userInfo: userInfo.data
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @override
|
|
67
|
-
*/
|
|
68
|
-
async onError(): Promise<void> {
|
|
69
|
-
this.logout();
|
|
70
|
-
|
|
71
|
-
this.routerController.gotoLogin();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @override
|
|
76
|
-
*/
|
|
77
|
-
async login(
|
|
78
|
-
params: UserApiLoginTransaction['data']
|
|
79
|
-
): Promise<UserApiGetUserInfoTransaction['response']> {
|
|
80
|
-
const response = await this.userApi.login(params);
|
|
81
|
-
|
|
82
|
-
if (response.apiCatchResult) {
|
|
83
|
-
throw response.apiCatchResult;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (!response.data.token) {
|
|
87
|
-
throw new AppError(errKeys.RES_NO_TOKEN);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
this.userToken.setToken(response.data.token);
|
|
91
|
-
|
|
92
|
-
const userInfo = await this.userApi.getUserInfo();
|
|
93
|
-
|
|
94
|
-
this.setState({
|
|
95
|
-
success: true,
|
|
96
|
-
userInfo: userInfo.data
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
return userInfo;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @override
|
|
104
|
-
*/
|
|
105
|
-
logout(): void {
|
|
106
|
-
this.reset();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @override
|
|
111
|
-
*/
|
|
112
|
-
reset(): void {
|
|
113
|
-
this.userToken.removeToken();
|
|
114
|
-
super.reset();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
isAuthenticated(): boolean {
|
|
118
|
-
return this.state.success;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @override
|
|
123
|
-
*/
|
|
124
|
-
async register(params: RegisterFormData): Promise<unknown> {
|
|
125
|
-
return this.login({
|
|
126
|
-
username: params.username,
|
|
127
|
-
password: params.password
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { createContext, useEffect } from 'react';
|
|
2
|
-
import { IOC } from '@/core/IOC';
|
|
3
|
-
import { useLanguageGuard } from '@/uikit/hooks/useLanguageGuard';
|
|
4
|
-
import { useStrictEffect } from '@/uikit/hooks/useStrictEffect';
|
|
5
|
-
import { ProcesserService } from '@/base/services/ProcesserService';
|
|
6
|
-
import { Navigate, useNavigate } from 'react-router-dom';
|
|
7
|
-
import { Loading } from '@/uikit/components/Loading';
|
|
8
|
-
import { RouteService } from '../../base/services/RouteService';
|
|
9
|
-
import { UserService } from '../../base/services/UserService';
|
|
10
|
-
import { useStore } from '@/uikit/hooks/useStore';
|
|
11
|
-
|
|
12
|
-
const PageProcesserContext = createContext<ProcesserService>(
|
|
13
|
-
IOC(ProcesserService)
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
export function ProcessProvider({ children }: { children: React.ReactNode }) {
|
|
17
|
-
useLanguageGuard();
|
|
18
|
-
const userService = IOC(UserService);
|
|
19
|
-
const pageProcesser = IOC(ProcesserService);
|
|
20
|
-
const success = useStore(userService, (state) => state.success);
|
|
21
|
-
|
|
22
|
-
const navigate = useNavigate();
|
|
23
|
-
|
|
24
|
-
useStrictEffect(() => {
|
|
25
|
-
pageProcesser.init();
|
|
26
|
-
}, []);
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
IOC(RouteService).setDependencies({ navigate });
|
|
30
|
-
}, [navigate]);
|
|
31
|
-
|
|
32
|
-
if (!success) {
|
|
33
|
-
return <Loading fullscreen />;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (!userService.isAuthenticated()) {
|
|
37
|
-
return <Navigate to="/login" />;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<PageProcesserContext.Provider value={pageProcesser}>
|
|
42
|
-
{children}
|
|
43
|
-
</PageProcesserContext.Provider>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|