@qlover/create-app 0.4.1 → 0.4.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/CHANGELOG.md +37 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/templates/react-app/.env +1 -2
- package/templates/react-app/README.md +70 -8
- package/templates/react-app/config/app.router.json +13 -13
- package/templates/react-app/config/common.ts +8 -0
- package/templates/react-app/config/i18n.ts +3 -1
- package/templates/react-app/config/{Identifier.I18n.ts → identifier/I18n.ts} +321 -3
- package/templates/react-app/index.html +1 -1
- package/templates/react-app/public/locales/en/common.json +54 -8
- package/templates/react-app/public/locales/zh/common.json +54 -8
- package/templates/react-app/public/router-root/logo.svg +1 -0
- package/templates/react-app/src/App.tsx +6 -3
- package/templates/react-app/src/base/cases/PublicAssetsPath.ts +17 -0
- package/templates/react-app/src/base/port/LoginInterface.ts +8 -0
- package/templates/react-app/src/base/port/StoreInterface.ts +58 -0
- package/templates/react-app/src/base/services/I18nService.ts +15 -9
- package/templates/react-app/src/{uikit/controllers/RouterController.ts → base/services/RouteService.ts} +12 -12
- package/templates/react-app/src/{uikit/controllers/UserController.ts → base/services/UserService.ts} +21 -11
- package/templates/react-app/src/core/bootstrap.ts +1 -1
- package/templates/react-app/src/core/registers/RegisterCommon.ts +11 -1
- package/templates/react-app/src/core/registers/RegisterControllers.ts +3 -12
- package/templates/react-app/src/pages/auth/Layout.tsx +5 -5
- package/templates/react-app/src/pages/auth/Login.tsx +50 -29
- package/templates/react-app/src/pages/auth/Register.tsx +238 -1
- package/templates/react-app/src/pages/base/About.tsx +1 -1
- package/templates/react-app/src/pages/base/ErrorIdentifier.tsx +2 -2
- package/templates/react-app/src/pages/base/Executor.tsx +4 -4
- package/templates/react-app/src/pages/base/Home.tsx +1 -1
- package/templates/react-app/src/pages/base/JSONStorage.tsx +3 -3
- package/templates/react-app/src/pages/base/Request.tsx +4 -4
- package/templates/react-app/src/pages/base/components/BaseHeader.tsx +8 -2
- package/templates/react-app/src/uikit/components/LanguageSwitcher.tsx +7 -7
- package/templates/react-app/src/uikit/components/ThemeSwitcher.tsx +3 -3
- package/templates/react-app/src/uikit/contexts/BaseRouteContext.ts +1 -1
- package/templates/react-app/src/uikit/controllers/ExecutorController.ts +6 -3
- package/templates/react-app/src/uikit/controllers/JSONStorageController.ts +6 -3
- package/templates/react-app/src/uikit/controllers/RequestController.ts +3 -4
- package/templates/react-app/src/uikit/hooks/useDocumentTitle.ts +15 -0
- package/templates/react-app/src/uikit/hooks/useStore.ts +12 -0
- package/templates/react-app/src/uikit/providers/BaseRouteProvider.tsx +7 -1
- package/templates/react-app/src/uikit/providers/ProcessProvider.tsx +7 -7
- package/templates/react-app/vite.config.ts +20 -11
- /package/templates/react-app/config/{Identifier.Error.ts → identifier/Error.ts} +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
|
+
import { inject, injectable } from 'inversify';
|
|
1
2
|
import { FeApi } from '@/base/apis/feApi/FeApi';
|
|
2
3
|
import { logger } from '@/core/globals';
|
|
3
4
|
import { UserApi } from '@/base/apis/userApi/UserApi';
|
|
4
5
|
import { aiHello } from '@/base/apis/AiApi';
|
|
5
|
-
import {
|
|
6
|
-
import { injectable } from 'inversify';
|
|
7
|
-
import { SliceStore } from '@qlover/slice-store-react';
|
|
6
|
+
import { StoreInterface } from '@/base/port/StoreInterface';
|
|
8
7
|
|
|
9
8
|
function createDefaultState() {
|
|
10
9
|
return {
|
|
@@ -39,7 +38,7 @@ function createDefaultState() {
|
|
|
39
38
|
export type RequestControllerState = ReturnType<typeof createDefaultState>;
|
|
40
39
|
|
|
41
40
|
@injectable()
|
|
42
|
-
export class RequestController extends
|
|
41
|
+
export class RequestController extends StoreInterface<RequestControllerState> {
|
|
43
42
|
constructor(
|
|
44
43
|
@inject(FeApi) private readonly feApi: FeApi,
|
|
45
44
|
@inject(UserApi) private readonly userApi: UserApi
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export function useDocumentTitle(title: string) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (!title) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const prevTitle = document.title;
|
|
10
|
+
document.title = title;
|
|
11
|
+
return () => {
|
|
12
|
+
document.title = prevTitle;
|
|
13
|
+
};
|
|
14
|
+
}, [title]);
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StoreInterface,
|
|
3
|
+
StoreStateInterface
|
|
4
|
+
} from '@/base/port/StoreInterface';
|
|
5
|
+
import { useSliceStore } from '@qlover/slice-store-react';
|
|
6
|
+
|
|
7
|
+
export function useStore<
|
|
8
|
+
C extends StoreInterface<StoreStateInterface>,
|
|
9
|
+
State = C['state']
|
|
10
|
+
>(store: C, selector?: (state: C['state']) => State): State {
|
|
11
|
+
return useSliceStore(store, selector);
|
|
12
|
+
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
2
|
import { RouteMeta } from '@/base/types/Page';
|
|
3
|
-
import { BaseRoutePageContext } from '
|
|
3
|
+
import { BaseRoutePageContext } from '@/uikit/contexts/BaseRouteContext';
|
|
4
|
+
import { useDocumentTitle } from '@/uikit/hooks/useDocumentTitle';
|
|
5
|
+
import { IOC } from '@/core/IOC';
|
|
6
|
+
import { useTranslation } from 'react-i18next';
|
|
4
7
|
|
|
5
8
|
export default function BaseRouteProvider(props: PropsWithChildren<RouteMeta>) {
|
|
9
|
+
const { t } = useTranslation();
|
|
10
|
+
useDocumentTitle(props.title ? t(props.title) : IOC('AppConfig').appName);
|
|
11
|
+
|
|
6
12
|
return (
|
|
7
13
|
<BaseRoutePageContext.Provider value={props}>
|
|
8
14
|
{props.children}
|
|
@@ -5,9 +5,9 @@ import { useStrictEffect } from '@/uikit/hooks/useStrictEffect';
|
|
|
5
5
|
import { ProcesserService } from '@/base/services/ProcesserService';
|
|
6
6
|
import { Navigate, useNavigate } from 'react-router-dom';
|
|
7
7
|
import { Loading } from '@/uikit/components/Loading';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { RouteService } from '../../base/services/RouteService';
|
|
9
|
+
import { UserService } from '../../base/services/UserService';
|
|
10
|
+
import { useStore } from '@/uikit/hooks/useStore';
|
|
11
11
|
|
|
12
12
|
const PageProcesserContext = createContext<ProcesserService>(
|
|
13
13
|
IOC(ProcesserService)
|
|
@@ -15,9 +15,9 @@ const PageProcesserContext = createContext<ProcesserService>(
|
|
|
15
15
|
|
|
16
16
|
export function ProcessProvider({ children }: { children: React.ReactNode }) {
|
|
17
17
|
useLanguageGuard();
|
|
18
|
-
const
|
|
18
|
+
const userService = IOC(UserService);
|
|
19
19
|
const pageProcesser = IOC(ProcesserService);
|
|
20
|
-
const success =
|
|
20
|
+
const success = useStore(userService, (state) => state.success);
|
|
21
21
|
|
|
22
22
|
const navigate = useNavigate();
|
|
23
23
|
|
|
@@ -26,14 +26,14 @@ export function ProcessProvider({ children }: { children: React.ReactNode }) {
|
|
|
26
26
|
}, []);
|
|
27
27
|
|
|
28
28
|
useEffect(() => {
|
|
29
|
-
IOC(
|
|
29
|
+
IOC(RouteService).setDependencies({ navigate });
|
|
30
30
|
}, [navigate]);
|
|
31
31
|
|
|
32
32
|
if (!success) {
|
|
33
33
|
return <Loading fullscreen />;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
if (!
|
|
36
|
+
if (!userService.isAuthenticated()) {
|
|
37
37
|
return <Navigate to="/login" />;
|
|
38
38
|
}
|
|
39
39
|
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { defineConfig } from 'vitest/config';
|
|
2
2
|
import react from '@vitejs/plugin-react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
envPrefix,
|
|
5
|
+
overrideAntdThemeMode,
|
|
6
|
+
routerPrefix
|
|
7
|
+
} from './config/common';
|
|
4
8
|
import { name, version } from './package.json';
|
|
5
9
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
6
10
|
import envConfig from '@qlover/corekit-bridge/vite-env-config/index';
|
|
@@ -9,6 +13,8 @@ import i18nConfig from './config/i18n';
|
|
|
9
13
|
import tailwindcss from '@tailwindcss/vite';
|
|
10
14
|
import viteDeprecatedAntd from '@brain-toolkit/antd-theme-override/vite';
|
|
11
15
|
import vitePluginImp from 'vite-plugin-imp';
|
|
16
|
+
import { readdirSync } from 'fs';
|
|
17
|
+
import { join } from 'path';
|
|
12
18
|
|
|
13
19
|
// https://vite.dev/config/
|
|
14
20
|
export default defineConfig({
|
|
@@ -87,16 +93,18 @@ export default defineConfig({
|
|
|
87
93
|
tsconfigPaths(),
|
|
88
94
|
ts2Locales({
|
|
89
95
|
locales: i18nConfig.supportedLngs as unknown as string[],
|
|
90
|
-
options:
|
|
91
|
-
{
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
options: readdirSync(join(__dirname, './config/Identifier'))
|
|
97
|
+
.map((file) => ({
|
|
98
|
+
file,
|
|
99
|
+
name: file.replace('.ts', ''),
|
|
100
|
+
path: join('./config/Identifier', file)
|
|
101
|
+
}))
|
|
102
|
+
.map(({ path }) => ({
|
|
103
|
+
source: path,
|
|
104
|
+
// You can use namespace
|
|
105
|
+
// target: `./public/locales/{{lng}}/{{${name}}}.json`
|
|
106
|
+
target: `./public/locales/{{lng}}/common.json`
|
|
107
|
+
}))
|
|
100
108
|
}),
|
|
101
109
|
viteDeprecatedAntd({
|
|
102
110
|
mode: overrideAntdThemeMode,
|
|
@@ -104,6 +112,7 @@ export default defineConfig({
|
|
|
104
112
|
targetPath: './src/base/types/deprecated-antd.d.ts'
|
|
105
113
|
})
|
|
106
114
|
],
|
|
115
|
+
base: routerPrefix,
|
|
107
116
|
envPrefix: envPrefix,
|
|
108
117
|
publicDir: 'public',
|
|
109
118
|
server: {
|
|
File without changes
|