create-bubbles 0.1.20 → 0.1.22
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/dist/{index.js → index.mjs} +9 -7
- package/package.json +5 -4
- package/template-nextjs-vinext-eslint/vite.config.ts +1 -1
- package/template-vp-monorepo-react-nestjs/.spaces/server//347/231/273/345/275/225/JWT/344/270/216RefreshToken/350/275/256/346/215/242/351/211/264/346/235/203/346/236/266/346/236/204/345/256/236/347/216/260/346/214/207/345/215/227.md +6614 -0
- package/template-vp-monorepo-react-nestjs/.vite-hooks/commit-msg +1 -0
- package/template-vp-monorepo-react-nestjs/.vite-hooks/pre-commit +2 -1
- package/template-vp-monorepo-react-nestjs/.vscode/settings.json +25 -0
- package/template-vp-monorepo-react-nestjs/AGENTS.md +16 -0
- package/template-vp-monorepo-react-nestjs/README.md +2 -2
- package/template-vp-monorepo-react-nestjs/apps/server/.env.development +61 -0
- package/template-vp-monorepo-react-nestjs/apps/server/.env.production +20 -0
- package/template-vp-monorepo-react-nestjs/apps/server/README.md +3 -0
- package/template-vp-monorepo-react-nestjs/apps/server/drizzle.config.ts +15 -0
- package/template-vp-monorepo-react-nestjs/apps/server/nest-cli.json +8 -0
- package/template-vp-monorepo-react-nestjs/apps/server/package.json +57 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/app.controller.ts +12 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/app.module.ts +58 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/app.service.ts +8 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/common/constants/decorator.ts +2 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/common/constants/response.ts +15 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/common/decorators/bypass.ts +12 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/common/interceptors/transform.ts +34 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/common/model/response.ts +23 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/config/app.config.ts +6 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/config/auth.config.ts +64 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/config/database.config.ts +10 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/config/index.ts +5 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/config/llm.config.ts +7 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/config/redis.config.ts +18 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/database/db.module.ts +32 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/database/schema.ts +14 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/main.ts +34 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/modules/test/db/db.controller.ts +28 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/modules/test/db/db.module.ts +9 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/modules/test/db/db.service.ts +22 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/modules/test/db/dto/create-user.dto.ts +27 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/modules/test/redis/dto/redis-quary.dto.ts +18 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/modules/test/redis/redis.controller.ts +31 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/modules/test/redis/redis.module.ts +9 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/modules/test/redis/redis.service.ts +37 -0
- package/template-vp-monorepo-react-nestjs/apps/server/src/utils/server-address.ts +33 -0
- package/template-vp-monorepo-react-nestjs/apps/server/tsconfig.build.json +4 -0
- package/template-vp-monorepo-react-nestjs/apps/server/tsconfig.json +28 -0
- package/template-vp-monorepo-react-nestjs/apps/web/.env +1 -0
- package/template-vp-monorepo-react-nestjs/apps/web/.env.dev +1 -0
- package/template-vp-monorepo-react-nestjs/apps/web/.env.prod +1 -0
- package/template-vp-monorepo-react-nestjs/apps/web/package.json +21 -25
- package/template-vp-monorepo-react-nestjs/apps/web/src/App.tsx +5 -4
- package/template-vp-monorepo-react-nestjs/apps/web/src/locales/en_US.json +4 -0
- package/template-vp-monorepo-react-nestjs/apps/web/src/locales/zh_CN.json +4 -0
- package/template-vp-monorepo-react-nestjs/apps/web/src/main.tsx +4 -4
- package/template-vp-monorepo-react-nestjs/apps/web/src/pages/home/index.tsx +38 -8
- package/template-vp-monorepo-react-nestjs/apps/web/src/router/index.tsx +15 -15
- package/template-vp-monorepo-react-nestjs/apps/web/src/utils/env/index.ts +6 -0
- package/template-vp-monorepo-react-nestjs/apps/web/src/utils/request/core/index.ts +420 -0
- package/template-vp-monorepo-react-nestjs/apps/web/src/utils/request/core/utils.ts +39 -0
- package/template-vp-monorepo-react-nestjs/apps/web/src/utils/request/index.ts +61 -0
- package/template-vp-monorepo-react-nestjs/apps/web/tsconfig.json +10 -14
- package/template-vp-monorepo-react-nestjs/apps/web/vite.config.ts +15 -2
- package/template-vp-monorepo-react-nestjs/apps/web-vue/.env.production +2 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/.vscode/extensions.json +3 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/AGENTS.md +16 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/README.md +98 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/commitlint.config.js +1 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/eslint.config.js +13 -0
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/lefthook.yml +1 -1
- package/template-vp-monorepo-react-nestjs/apps/web-vue/package.json +67 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/pnpm-workspace.yaml +16 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/App.vue +12 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/api/index.ts +12 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/assets/image/.gitkeep +0 -0
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/components/Icon/svg-icon.vue +3 -3
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/hooks/chart/lib.ts +6 -6
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/hooks/chart/useEcharts.ts +65 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/i18n/instance.ts +8 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/layout/default/header/index.vue +30 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/layout/default/index.vue +138 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/locales/en_US.json +4 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/locales/zh_CN.json +4 -0
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/main.ts +0 -3
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/router/guard/index.ts +7 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/router/guard/permissionGuard.ts +13 -0
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/router/index.ts +7 -7
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/router/interface.ts +9 -0
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/router/modules/index.ts +1 -4
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/store/index.ts +11 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/store/modules/user.ts +17 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/styles/font.scss +0 -0
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/styles/index.scss +3 -3
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/types/components.d.ts +8 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/types/vite-env.d.ts +15 -0
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/utils/env.ts +1 -1
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/utils/request/index.ts +5 -3
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/views/example/echart/config.ts +687 -687
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/views/example/echart/index.vue +20 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/views/example/tree-chart.vue +16 -0
- package/template-vp-monorepo-react-nestjs/apps/web-vue/src/views/home/index.vue +27 -0
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/tsconfig.json +2 -9
- package/template-vp-monorepo-react-nestjs/apps/web-vue/uno.config.ts +17 -0
- package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/vite.config.ts +4 -6
- package/template-vp-monorepo-react-nestjs/commitlint.config.js +0 -0
- package/template-vp-monorepo-react-nestjs/docker-compose.yml +41 -0
- package/template-vp-monorepo-react-nestjs/mise.toml +3 -0
- package/template-vp-monorepo-react-nestjs/package.json +16 -11
- package/template-vp-monorepo-react-nestjs/packages/i18n/core/package.json +20 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/core/src/format.ts +9 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/core/src/i18n.ts +73 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/core/src/index.ts +24 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/core/src/storage.ts +47 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/core/src/store.ts +48 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/core/src/types.ts +36 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/core/tsconfig.json +15 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/core/vite.config.ts +13 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/react/package.json +28 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/react/src/index.tsx +26 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/react/src/use-store.ts +14 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/react/tsconfig.json +16 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/react/vite.config.ts +16 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/vue/package.json +27 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/vue/src/index.ts +52 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/vue/src/use-store.ts +19 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/vue/tsconfig.json +15 -0
- package/template-vp-monorepo-react-nestjs/packages/i18n/vue/vite.config.ts +16 -0
- package/template-vp-monorepo-react-nestjs/pnpm-workspace.yaml +97 -9
- package/template-vp-monorepo-react-nestjs/vite.config.ts +15 -4
- package/template-vue-vp-eslint/.env +6 -0
- package/template-vue-vp-eslint/.env.development +2 -0
- package/template-vue-vp-eslint/.env.production +2 -0
- package/template-vue-vp-eslint/.vscode/extensions.json +3 -0
- package/template-vue-vp-eslint/AGENTS.md +16 -0
- package/template-vue-vp-eslint/README.md +98 -0
- package/template-vue-vp-eslint/commitlint.config.js +1 -0
- package/template-vue-vp-eslint/eslint.config.js +13 -0
- package/template-vue-vp-eslint/index.html +13 -0
- package/template-vue-vp-eslint/lefthook.yml +11 -0
- package/template-vue-vp-eslint/package.json +63 -0
- package/template-vue-vp-eslint/pnpm-workspace.yaml +3 -0
- package/template-vue-vp-eslint/public/vite.svg +1 -0
- package/template-vue-vp-eslint/src/App.vue +7 -0
- package/template-vue-vp-eslint/src/api/index.ts +12 -0
- package/template-vue-vp-eslint/src/assets/icon/home.svg +3 -0
- package/template-vue-vp-eslint/src/assets/icon/logo.svg +1 -0
- package/template-vue-vp-eslint/src/assets/image/.gitkeep +0 -0
- package/template-vue-vp-eslint/src/components/Icon/svg-icon.vue +29 -0
- package/template-vue-vp-eslint/src/hooks/chart/lib.ts +57 -0
- package/template-vue-vp-eslint/src/hooks/chart/useEcharts.ts +65 -0
- package/template-vue-vp-eslint/src/layout/default/header/index.vue +30 -0
- package/template-vue-vp-eslint/src/layout/default/index.vue +138 -0
- package/template-vue-vp-eslint/src/main.ts +16 -0
- package/template-vue-vp-eslint/src/router/guard/index.ts +7 -0
- package/{template-vue-vite-eslint → template-vue-vp-eslint}/src/router/guard/permissionGuard.ts +3 -3
- package/template-vue-vp-eslint/src/router/index.ts +18 -0
- package/template-vue-vp-eslint/src/router/interface.ts +9 -0
- package/template-vue-vp-eslint/src/router/modules/index.ts +33 -0
- package/template-vue-vp-eslint/src/store/index.ts +11 -0
- package/template-vue-vp-eslint/src/store/modules/user.ts +17 -0
- package/template-vue-vp-eslint/src/styles/font.scss +0 -0
- package/template-vue-vp-eslint/src/styles/index.scss +29 -0
- package/template-vue-vp-eslint/src/styles/variables.scss +3 -0
- package/template-vue-vp-eslint/src/types/vite-env.d.ts +15 -0
- package/template-vue-vp-eslint/src/utils/env.ts +11 -0
- package/template-vue-vp-eslint/src/utils/request/core/index.ts +425 -0
- package/template-vue-vp-eslint/src/utils/request/core/utils.ts +39 -0
- package/template-vue-vp-eslint/src/utils/request/index.ts +44 -0
- package/template-vue-vp-eslint/src/views/example/echart/config.ts +1794 -0
- package/template-vue-vp-eslint/src/views/example/echart/index.vue +20 -0
- package/template-vue-vp-eslint/src/views/example/tree-chart.vue +16 -0
- package/template-vue-vp-eslint/src/views/home/index.vue +16 -0
- package/template-vue-vp-eslint/src/views/login/index.vue +9 -0
- package/template-vue-vp-eslint/tsconfig.json +29 -0
- package/template-vue-vp-eslint/uno.config.ts +17 -0
- package/template-vue-vp-eslint/vite.config.ts +58 -0
- package/template-vp-monorepo-react-nestjs/.oxfmtrc.jsonc +0 -8
- package/template-vp-monorepo-react-nestjs/.oxlintrc.jsonc +0 -3
- package/template-vp-monorepo-react-nestjs/.specs//351/234/200/346/261/202.md +0 -5
- package/template-vp-monorepo-react-nestjs/apps/service/.oxlintrc.jsonc +0 -3
- package/template-vp-monorepo-react-nestjs/apps/web/.oxlintrc.jsonc +0 -4
- package/template-vp-monorepo-react-nestjs/packages/utils/README.md +0 -23
- package/template-vp-monorepo-react-nestjs/packages/utils/package.json +0 -39
- package/template-vp-monorepo-react-nestjs/packages/utils/src/index.ts +0 -3
- package/template-vp-monorepo-react-nestjs/packages/utils/tests/index.test.ts +0 -6
- package/template-vp-monorepo-react-nestjs/packages/utils/tsconfig.json +0 -20
- package/template-vp-monorepo-react-nestjs/packages/utils/tsdown.config.ts +0 -9
- package/template-vp-monorepo-react-nestjs/packages/utils/vite.config.ts +0 -7
- package/template-vue-vite-eslint/.env.production +0 -1
- package/template-vue-vite-eslint/README.md +0 -3
- package/template-vue-vite-eslint/commitlint.config.js +0 -1
- package/template-vue-vite-eslint/eslint.config.js +0 -69
- package/template-vue-vite-eslint/package.json +0 -56
- package/template-vue-vite-eslint/src/App.vue +0 -19
- package/template-vue-vite-eslint/src/api/index.ts +0 -12
- package/template-vue-vite-eslint/src/hooks/chart/useEcharts.ts +0 -65
- package/template-vue-vite-eslint/src/layout/default/header/index.vue +0 -12
- package/template-vue-vite-eslint/src/layout/default/index.vue +0 -55
- package/template-vue-vite-eslint/src/router/guard/index.ts +0 -7
- package/template-vue-vite-eslint/src/router/interface.ts +0 -9
- package/template-vue-vite-eslint/src/router/modules/example.ts +0 -21
- package/template-vue-vite-eslint/src/store/index.ts +0 -11
- package/template-vue-vite-eslint/src/store/modules/user.ts +0 -20
- package/template-vue-vite-eslint/src/types/vite-env.d.ts +0 -15
- package/template-vue-vite-eslint/src/views/example/echart/index.vue +0 -22
- package/template-vue-vite-eslint/src/views/example/h-full.vue +0 -24
- package/template-vue-vite-eslint/src/views/example/tree-chart.vue +0 -94
- package/template-vue-vite-eslint/src/views/home/index.vue +0 -25
- package/template-vue-vite-eslint/uno.config.ts +0 -21
- /package/{template-vue-vite-eslint/src/assets/image/.gitkeep → template-vp-monorepo-react-nestjs/.agents/auth.config.ts} +0 -0
- /package/{template-vue-vite-eslint/src/styles/font.scss → template-vp-monorepo-react-nestjs/apps/server/src/config/security.config.ts} +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/.env +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/.env.development +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/index.html +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/public/vite.svg +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/assets/icon/computer-data.svg +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/assets/icon/cpu.svg +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/assets/icon/data-search.svg +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/assets/icon/home.svg +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/assets/icon/knowledge-graph.svg +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/assets/icon/logo.svg +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/assets/icon/robot.svg +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/styles/variables.scss +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/types/auto-import.d.ts +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/utils/request/core/index.ts +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/utils/request/core/utils.ts +0 -0
- /package/{template-vue-vite-eslint → template-vp-monorepo-react-nestjs/apps/web-vue}/src/views/login/index.vue +0 -0
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AlovaGlobalCacheAdapter,
|
|
3
|
+
AlovaOptions,
|
|
4
|
+
AlovaRequestAdapter,
|
|
5
|
+
GlobalCacheConfig,
|
|
6
|
+
StatesExport,
|
|
7
|
+
StatesHook,
|
|
8
|
+
} from 'alova'
|
|
9
|
+
import { createAlova } from 'alova'
|
|
10
|
+
import type { FetchRequestInit } from 'alova/fetch'
|
|
11
|
+
import adapterFetch from 'alova/fetch'
|
|
12
|
+
import { deepMergeObject, isPlainObject, isReadableStream, tryParseJsonString } from './utils.ts'
|
|
13
|
+
|
|
14
|
+
type MaybePromise<T> = T | Promise<T>
|
|
15
|
+
type HeaderValue =
|
|
16
|
+
| string
|
|
17
|
+
| number
|
|
18
|
+
| boolean
|
|
19
|
+
| null
|
|
20
|
+
| undefined
|
|
21
|
+
| (() => MaybePromise<string | number | boolean | null | undefined>)
|
|
22
|
+
type StatusMatcher<RE> = number | number[] | ((status: number, response: RE) => boolean)
|
|
23
|
+
type CodeMatcher = Array<number | string>
|
|
24
|
+
|
|
25
|
+
export interface StatusMap<RE = unknown> {
|
|
26
|
+
success?: StatusMatcher<RE>
|
|
27
|
+
unAuthorized?: StatusMatcher<RE>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CodeMap {
|
|
31
|
+
success?: CodeMatcher
|
|
32
|
+
unAuthorized?: CodeMatcher
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RequestMeta {
|
|
36
|
+
isWrapped?: boolean
|
|
37
|
+
isTransformResponse?: boolean
|
|
38
|
+
isShowSuccessMessage?: boolean
|
|
39
|
+
isShowErrorMessage?: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface BaseRequestOption<
|
|
43
|
+
RC extends object = FetchRequestInit,
|
|
44
|
+
RE = Response,
|
|
45
|
+
RH = Headers,
|
|
46
|
+
SE extends StatesExport<any> = StatesExport<any>,
|
|
47
|
+
> extends RequestMeta {
|
|
48
|
+
baseUrl?: string
|
|
49
|
+
timeout?: number
|
|
50
|
+
commonHeaders?: () => Record<string, HeaderValue>
|
|
51
|
+
statusMap?: StatusMap<RE>
|
|
52
|
+
codeMap?: CodeMap
|
|
53
|
+
responseCodeKey?: string
|
|
54
|
+
responseDataKey?: string
|
|
55
|
+
responseMessageKey?: string
|
|
56
|
+
cacheFor?: GlobalCacheConfig<any> | null
|
|
57
|
+
cacheLogger?: boolean
|
|
58
|
+
statesHook?: StatesHook<SE>
|
|
59
|
+
successDefaultMessage?: string
|
|
60
|
+
errorDefaultMessage?: string
|
|
61
|
+
successMessageFunc?: (message: string) => void
|
|
62
|
+
errorMessageFunc?: (message: string) => void
|
|
63
|
+
unAuthorizedResponseFunc?: () => void
|
|
64
|
+
requestAdapter?: AlovaRequestAdapter<RC, RE, RH>
|
|
65
|
+
l1Cache?: AlovaGlobalCacheAdapter
|
|
66
|
+
l2Cache?: AlovaGlobalCacheAdapter
|
|
67
|
+
storageAdapter?: AlovaGlobalCacheAdapter
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export type baseRequestOption<
|
|
71
|
+
RC extends object = FetchRequestInit,
|
|
72
|
+
RE = Response,
|
|
73
|
+
RH = Headers,
|
|
74
|
+
SE extends StatesExport<any> = StatesExport<any>,
|
|
75
|
+
> = BaseRequestOption<RC, RE, RH, SE>
|
|
76
|
+
|
|
77
|
+
export type RequestOption<
|
|
78
|
+
RC extends object = FetchRequestInit,
|
|
79
|
+
RE = Response,
|
|
80
|
+
RH = Headers,
|
|
81
|
+
SE extends StatesExport<any> = StatesExport<any>,
|
|
82
|
+
> = BaseRequestOption<RC, RE, RH, SE>
|
|
83
|
+
|
|
84
|
+
type RequestAlovaGenerics<RC extends object, RE, RH, SE extends StatesExport<any>> = {
|
|
85
|
+
Responded: unknown
|
|
86
|
+
Transformed: unknown
|
|
87
|
+
RequestConfig: RC
|
|
88
|
+
Response: RE
|
|
89
|
+
ResponseHeader: RH
|
|
90
|
+
L1Cache: AlovaGlobalCacheAdapter
|
|
91
|
+
L2Cache: AlovaGlobalCacheAdapter
|
|
92
|
+
StatesExport: SE
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type ResolvedRequestOption<RC extends object, RE, RH, SE extends StatesExport<any>> = Required<
|
|
96
|
+
Pick<
|
|
97
|
+
BaseRequestOption<RC, RE, RH, SE>,
|
|
98
|
+
| 'baseUrl'
|
|
99
|
+
| 'statusMap'
|
|
100
|
+
| 'codeMap'
|
|
101
|
+
| 'responseCodeKey'
|
|
102
|
+
| 'responseDataKey'
|
|
103
|
+
| 'responseMessageKey'
|
|
104
|
+
| 'isWrapped'
|
|
105
|
+
| 'isTransformResponse'
|
|
106
|
+
| 'isShowSuccessMessage'
|
|
107
|
+
| 'successDefaultMessage'
|
|
108
|
+
| 'isShowErrorMessage'
|
|
109
|
+
| 'errorDefaultMessage'
|
|
110
|
+
| 'cacheLogger'
|
|
111
|
+
>
|
|
112
|
+
> &
|
|
113
|
+
BaseRequestOption<RC, RE, RH, SE>
|
|
114
|
+
|
|
115
|
+
const DEFAULT_SUCCESS_MESSAGE = '操作成功'
|
|
116
|
+
const DEFAULT_ERROR_MESSAGE = '服务异常'
|
|
117
|
+
|
|
118
|
+
const defaultRequestOption: BaseRequestOption<any, any, any, any> = {
|
|
119
|
+
baseUrl: '/',
|
|
120
|
+
timeout: undefined,
|
|
121
|
+
statusMap: {
|
|
122
|
+
success: 200,
|
|
123
|
+
unAuthorized: 401,
|
|
124
|
+
},
|
|
125
|
+
codeMap: {
|
|
126
|
+
success: [200],
|
|
127
|
+
unAuthorized: [401],
|
|
128
|
+
},
|
|
129
|
+
responseCodeKey: 'code',
|
|
130
|
+
responseDataKey: 'data',
|
|
131
|
+
responseMessageKey: 'message',
|
|
132
|
+
isWrapped: true,
|
|
133
|
+
isTransformResponse: true,
|
|
134
|
+
isShowSuccessMessage: false,
|
|
135
|
+
successDefaultMessage: DEFAULT_SUCCESS_MESSAGE,
|
|
136
|
+
isShowErrorMessage: true,
|
|
137
|
+
errorDefaultMessage: DEFAULT_ERROR_MESSAGE,
|
|
138
|
+
cacheFor: null,
|
|
139
|
+
cacheLogger: true,
|
|
140
|
+
requestAdapter: adapterFetch() as AlovaRequestAdapter<any, any, any>,
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getMethodMeta(method: unknown): RequestMeta {
|
|
144
|
+
const methodRecord = method as { meta?: RequestMeta; config?: { meta?: RequestMeta } } | undefined
|
|
145
|
+
return methodRecord?.config?.meta ?? methodRecord?.meta ?? {}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function getMetaFlag(meta: RequestMeta, key: keyof RequestMeta, fallback: boolean): boolean {
|
|
149
|
+
const value = meta[key]
|
|
150
|
+
return typeof value === 'boolean' ? value : fallback
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function isMatchedStatus<RE>(
|
|
154
|
+
status: number,
|
|
155
|
+
matcher: StatusMatcher<RE> | undefined,
|
|
156
|
+
response: RE,
|
|
157
|
+
): boolean {
|
|
158
|
+
if (matcher === undefined) return status >= 200 && status < 300
|
|
159
|
+
|
|
160
|
+
if (typeof matcher === 'function') return matcher(status, response)
|
|
161
|
+
|
|
162
|
+
return Array.isArray(matcher) ? matcher.includes(status) : matcher === status
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function isMatchedCode(code: unknown, matcher: CodeMatcher | undefined): boolean {
|
|
166
|
+
if (!matcher?.length) return true
|
|
167
|
+
|
|
168
|
+
return matcher.some((item) => String(item) === String(code))
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function getResponseStatus(response: unknown): number {
|
|
172
|
+
const responseRecord = response as { status?: unknown; statusCode?: unknown }
|
|
173
|
+
const status = responseRecord.statusCode ?? responseRecord.status
|
|
174
|
+
return typeof status === 'number' ? status : Number(status)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function getResponseMessage(data: unknown, messageKey: string, defaultMessage: string): string {
|
|
178
|
+
if (!isPlainObject(data)) return defaultMessage
|
|
179
|
+
|
|
180
|
+
const message = data[messageKey] ?? data.message ?? data.msg
|
|
181
|
+
if (typeof message === 'string') return message || defaultMessage
|
|
182
|
+
if (typeof message === 'number') return String(message)
|
|
183
|
+
|
|
184
|
+
return defaultMessage
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function getResponseField(data: unknown, key: string): unknown {
|
|
188
|
+
return isPlainObject(data) ? data[key] : undefined
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function parseFetchResponse(response: {
|
|
192
|
+
status?: number
|
|
193
|
+
body?: unknown
|
|
194
|
+
headers?: Headers | Record<string, unknown>
|
|
195
|
+
clone?: () => Response
|
|
196
|
+
json?: () => Promise<unknown>
|
|
197
|
+
text?: () => Promise<string>
|
|
198
|
+
}): Promise<unknown> {
|
|
199
|
+
if (response.status === 204) return undefined
|
|
200
|
+
|
|
201
|
+
const reader = typeof response.clone === 'function' ? response.clone() : response
|
|
202
|
+
const contentType = getHeaderValue(response.headers, 'content-type')
|
|
203
|
+
|
|
204
|
+
if (contentType.includes('application/json') && typeof reader.json === 'function')
|
|
205
|
+
return reader.json()
|
|
206
|
+
|
|
207
|
+
if (contentType.startsWith('text/') && typeof reader.text === 'function')
|
|
208
|
+
return tryParseJsonString(await reader.text())
|
|
209
|
+
|
|
210
|
+
if (typeof reader.json === 'function') {
|
|
211
|
+
try {
|
|
212
|
+
return await reader.json()
|
|
213
|
+
} catch {
|
|
214
|
+
// Fall through to text parsing.
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (typeof reader.text === 'function') return tryParseJsonString(await reader.text())
|
|
219
|
+
|
|
220
|
+
return undefined
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function getHeaderValue(
|
|
224
|
+
headers: Headers | Record<string, unknown> | undefined,
|
|
225
|
+
key: string,
|
|
226
|
+
): string {
|
|
227
|
+
if (!headers) return ''
|
|
228
|
+
|
|
229
|
+
if (typeof Headers !== 'undefined' && headers instanceof Headers) return headers.get(key) ?? ''
|
|
230
|
+
|
|
231
|
+
const headerRecord = headers as Record<string, unknown>
|
|
232
|
+
const value =
|
|
233
|
+
headerRecord[key] ?? headerRecord[key.toLowerCase()] ?? headerRecord[key.toUpperCase()]
|
|
234
|
+
return typeof value === 'string' ? value : ''
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async function getResponseData(response: unknown): Promise<unknown> {
|
|
238
|
+
const responseRecord = response as {
|
|
239
|
+
body?: unknown
|
|
240
|
+
data?: unknown
|
|
241
|
+
json?: () => Promise<unknown>
|
|
242
|
+
text?: () => Promise<string>
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if ('data' in responseRecord && !isReadableStream(responseRecord.body))
|
|
246
|
+
return tryParseJsonString(responseRecord.data)
|
|
247
|
+
|
|
248
|
+
if (
|
|
249
|
+
isReadableStream(responseRecord.body) ||
|
|
250
|
+
typeof responseRecord.json === 'function' ||
|
|
251
|
+
typeof responseRecord.text === 'function'
|
|
252
|
+
) {
|
|
253
|
+
return parseFetchResponse(responseRecord)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return response
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function resolveHeaderValue(value: HeaderValue): Promise<string | undefined> {
|
|
260
|
+
const resolved = typeof value === 'function' ? await value() : value
|
|
261
|
+
if (resolved === null || resolved === undefined) return undefined
|
|
262
|
+
return String(resolved)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function setHeader(target: unknown, key: string, value: string): void {
|
|
266
|
+
if (typeof Headers !== 'undefined' && target instanceof Headers) {
|
|
267
|
+
target.set(key, value)
|
|
268
|
+
return
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (Array.isArray(target)) {
|
|
272
|
+
target.push([key, value])
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
;(target as Record<string, string>)[key] = value
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function resolveConfig<RC extends object, RE, RH, SE extends StatesExport<any>>(
|
|
280
|
+
option: BaseRequestOption<RC, RE, RH, SE>,
|
|
281
|
+
): ResolvedRequestOption<RC, RE, RH, SE> {
|
|
282
|
+
return deepMergeObject(defaultRequestOption, option) as ResolvedRequestOption<RC, RE, RH, SE>
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function createInstance<
|
|
286
|
+
RC extends object = FetchRequestInit,
|
|
287
|
+
RE = Response,
|
|
288
|
+
RH = Headers,
|
|
289
|
+
SE extends StatesExport<any> = StatesExport<any>,
|
|
290
|
+
>(option: RequestOption<RC, RE, RH, SE> = {}) {
|
|
291
|
+
const config = resolveConfig(option)
|
|
292
|
+
|
|
293
|
+
const alovaOptions: AlovaOptions<RequestAlovaGenerics<RC, RE, RH, SE>> = {
|
|
294
|
+
baseURL: config.baseUrl,
|
|
295
|
+
timeout: config.timeout,
|
|
296
|
+
cacheFor: config.cacheFor as GlobalCacheConfig<any>,
|
|
297
|
+
cacheLogger: config.cacheLogger,
|
|
298
|
+
statesHook: config.statesHook,
|
|
299
|
+
requestAdapter: config.requestAdapter!,
|
|
300
|
+
l1Cache: config.l1Cache,
|
|
301
|
+
l2Cache: config.l2Cache ?? config.storageAdapter,
|
|
302
|
+
beforeRequest: async (method) => {
|
|
303
|
+
const methodConfig = method.config as { headers?: unknown }
|
|
304
|
+
const headers = methodConfig.headers ?? {}
|
|
305
|
+
methodConfig.headers = headers
|
|
306
|
+
|
|
307
|
+
for (const [key, value] of Object.entries(config.commonHeaders?.() ?? {})) {
|
|
308
|
+
const resolvedValue = await resolveHeaderValue(value)
|
|
309
|
+
if (resolvedValue !== undefined) setHeader(headers, key, resolvedValue)
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
responded: {
|
|
313
|
+
onSuccess: async (response, method) => {
|
|
314
|
+
const meta = getMethodMeta(method)
|
|
315
|
+
const shouldTransform = getMetaFlag(meta, 'isTransformResponse', config.isTransformResponse)
|
|
316
|
+
const showSuccess = getMetaFlag(meta, 'isShowSuccessMessage', config.isShowSuccessMessage)
|
|
317
|
+
const showError = getMetaFlag(meta, 'isShowErrorMessage', config.isShowErrorMessage)
|
|
318
|
+
const isWrapped = getMetaFlag(meta, 'isWrapped', config.isWrapped)
|
|
319
|
+
|
|
320
|
+
if (!shouldTransform) return response
|
|
321
|
+
|
|
322
|
+
const status = getResponseStatus(response)
|
|
323
|
+
const data = await getResponseData(response)
|
|
324
|
+
|
|
325
|
+
if (!isMatchedStatus(status, config.statusMap.success, response)) {
|
|
326
|
+
if (isMatchedStatus(status, config.statusMap.unAuthorized, response))
|
|
327
|
+
config.unAuthorizedResponseFunc?.()
|
|
328
|
+
|
|
329
|
+
if (showError) {
|
|
330
|
+
config.errorMessageFunc?.(
|
|
331
|
+
getResponseMessage(data, config.responseMessageKey, config.errorDefaultMessage),
|
|
332
|
+
)
|
|
333
|
+
}
|
|
334
|
+
return Promise.reject(response)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (!isWrapped) {
|
|
338
|
+
if (showSuccess) config.successMessageFunc?.(config.successDefaultMessage)
|
|
339
|
+
return data
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const code = getResponseField(data, config.responseCodeKey)
|
|
343
|
+
const responseData = getResponseField(data, config.responseDataKey)
|
|
344
|
+
const responseMessage = getResponseMessage(
|
|
345
|
+
data,
|
|
346
|
+
config.responseMessageKey,
|
|
347
|
+
config.successDefaultMessage,
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
if (!isMatchedCode(code, config.codeMap.success)) {
|
|
351
|
+
if (isMatchedCode(code, config.codeMap.unAuthorized)) config.unAuthorizedResponseFunc?.()
|
|
352
|
+
|
|
353
|
+
if (showError) {
|
|
354
|
+
config.errorMessageFunc?.(
|
|
355
|
+
getResponseMessage(data, config.responseMessageKey, config.errorDefaultMessage),
|
|
356
|
+
)
|
|
357
|
+
}
|
|
358
|
+
return Promise.reject(response)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
if (showSuccess) config.successMessageFunc?.(responseMessage)
|
|
362
|
+
|
|
363
|
+
return responseData
|
|
364
|
+
},
|
|
365
|
+
onError: (error, method) => {
|
|
366
|
+
const meta = getMethodMeta(method)
|
|
367
|
+
const showError = getMetaFlag(meta, 'isShowErrorMessage', config.isShowErrorMessage)
|
|
368
|
+
|
|
369
|
+
if (showError) {
|
|
370
|
+
config.errorMessageFunc?.(
|
|
371
|
+
error instanceof Error ? error.message : config.errorDefaultMessage,
|
|
372
|
+
)
|
|
373
|
+
}
|
|
374
|
+
return Promise.reject(error)
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return createAlova(alovaOptions)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export type RequestInstance<
|
|
383
|
+
RC extends object = FetchRequestInit,
|
|
384
|
+
RE = Response,
|
|
385
|
+
RH = Headers,
|
|
386
|
+
SE extends StatesExport<any> = StatesExport<any>,
|
|
387
|
+
> = ReturnType<typeof createInstance<RC, RE, RH, SE>>
|
|
388
|
+
|
|
389
|
+
export type DualCallInstance<
|
|
390
|
+
RC extends object = FetchRequestInit,
|
|
391
|
+
RE = Response,
|
|
392
|
+
RH = Headers,
|
|
393
|
+
SE extends StatesExport<any> = StatesExport<any>,
|
|
394
|
+
> = RequestInstance<RC, RE, RH, SE> &
|
|
395
|
+
((option?: RequestOption<RC, RE, RH, SE>) => RequestInstance<RC, RE, RH, SE>)
|
|
396
|
+
|
|
397
|
+
export function createDualCallInstance<
|
|
398
|
+
RC extends object = FetchRequestInit,
|
|
399
|
+
RE = Response,
|
|
400
|
+
RH = Headers,
|
|
401
|
+
SE extends StatesExport<any> = StatesExport<any>,
|
|
402
|
+
>(baseConfig: BaseRequestOption<RC, RE, RH, SE>): DualCallInstance<RC, RE, RH, SE> {
|
|
403
|
+
const defaultInstance = createInstance(baseConfig)
|
|
404
|
+
const dualInstance = ((option?: RequestOption<RC, RE, RH, SE>) => {
|
|
405
|
+
if (!option) return defaultInstance
|
|
406
|
+
return createInstance(deepMergeObject(baseConfig, option))
|
|
407
|
+
}) as DualCallInstance<RC, RE, RH, SE>
|
|
408
|
+
|
|
409
|
+
Object.assign(dualInstance, defaultInstance)
|
|
410
|
+
dualInstance.Get = defaultInstance.Get.bind(defaultInstance)
|
|
411
|
+
dualInstance.Post = defaultInstance.Post.bind(defaultInstance)
|
|
412
|
+
dualInstance.Put = defaultInstance.Put.bind(defaultInstance)
|
|
413
|
+
dualInstance.Delete = defaultInstance.Delete.bind(defaultInstance)
|
|
414
|
+
dualInstance.Patch = defaultInstance.Patch.bind(defaultInstance)
|
|
415
|
+
dualInstance.Head = defaultInstance.Head.bind(defaultInstance)
|
|
416
|
+
dualInstance.Options = defaultInstance.Options.bind(defaultInstance)
|
|
417
|
+
dualInstance.Request = defaultInstance.Request.bind(defaultInstance)
|
|
418
|
+
|
|
419
|
+
return dualInstance
|
|
420
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function deepMergeObject<T = any>(source: T, target: Partial<T>): T {
|
|
2
|
+
const merge = (src: any, tgt: any): any => {
|
|
3
|
+
if (!isPlainObject(src) || !isPlainObject(tgt)) return tgt === undefined ? src : tgt
|
|
4
|
+
|
|
5
|
+
const result = { ...src }
|
|
6
|
+
for (const key of Object.keys(tgt)) {
|
|
7
|
+
const targetValue = tgt[key]
|
|
8
|
+
result[key] = isPlainObject(targetValue) ? merge(result[key], targetValue) : targetValue
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return result
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return merge(source, target)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isPlainObject(data: unknown): data is Record<string, any> {
|
|
18
|
+
return Object.prototype.toString.call(data) === '[object Object]'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isReadableStream(data: unknown): boolean {
|
|
22
|
+
if (typeof ReadableStream === 'undefined') return false
|
|
23
|
+
return data instanceof ReadableStream
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function tryParseJsonString(data: unknown): unknown {
|
|
27
|
+
if (typeof data !== 'string') return data
|
|
28
|
+
|
|
29
|
+
const value = data.trim()
|
|
30
|
+
if (!value) return data
|
|
31
|
+
|
|
32
|
+
if (!value.startsWith('{') && !value.startsWith('[')) return data
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(value)
|
|
36
|
+
} catch {
|
|
37
|
+
return data
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { axiosRequestAdapter, type AlovaAxiosRequestConfig } from '@alova/adapter-axios'
|
|
2
|
+
import reactHook, { type ReactHookExportType } from 'alova/react'
|
|
3
|
+
import { message } from 'antd'
|
|
4
|
+
import type { AxiosResponse, AxiosResponseHeaders } from 'axios'
|
|
5
|
+
import { navigator } from '@/router'
|
|
6
|
+
import { envVariables } from '@/utils/env'
|
|
7
|
+
import { createDualCallInstance, type BaseRequestOption } from './core/index.ts'
|
|
8
|
+
|
|
9
|
+
type WebRequestOption = BaseRequestOption<
|
|
10
|
+
AlovaAxiosRequestConfig,
|
|
11
|
+
AxiosResponse,
|
|
12
|
+
AxiosResponseHeaders,
|
|
13
|
+
ReactHookExportType<unknown>
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
function normalizeBaseUrl(apiAffix?: string) {
|
|
17
|
+
if (!apiAffix) return '/'
|
|
18
|
+
if (/^https?:\/\//.test(apiAffix) || apiAffix.startsWith('/')) {
|
|
19
|
+
return apiAffix
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return `/${apiAffix}`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getBaseConfig(): WebRequestOption {
|
|
26
|
+
return {
|
|
27
|
+
baseUrl: normalizeBaseUrl(envVariables.API_AFFIX),
|
|
28
|
+
statusMap: {
|
|
29
|
+
success: [200, 201, 204],
|
|
30
|
+
unAuthorized: 401,
|
|
31
|
+
},
|
|
32
|
+
codeMap: {
|
|
33
|
+
success: [200],
|
|
34
|
+
unAuthorized: [401],
|
|
35
|
+
},
|
|
36
|
+
responseDataKey: 'data',
|
|
37
|
+
responseMessageKey: 'msg',
|
|
38
|
+
commonHeaders: () => ({}),
|
|
39
|
+
successMessageFunc: (msg) => {
|
|
40
|
+
message.success(msg)
|
|
41
|
+
},
|
|
42
|
+
errorMessageFunc: (msg) => {
|
|
43
|
+
message.error(msg)
|
|
44
|
+
},
|
|
45
|
+
unAuthorizedResponseFunc: () => {
|
|
46
|
+
void navigator('/login')
|
|
47
|
+
message.error('登录过期或未登录')
|
|
48
|
+
},
|
|
49
|
+
statesHook: reactHook,
|
|
50
|
+
requestAdapter: axiosRequestAdapter(),
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const alovaRequest = createDualCallInstance<
|
|
55
|
+
AlovaAxiosRequestConfig,
|
|
56
|
+
AxiosResponse,
|
|
57
|
+
AxiosResponseHeaders,
|
|
58
|
+
ReactHookExportType<unknown>
|
|
59
|
+
>(getBaseConfig())
|
|
60
|
+
|
|
61
|
+
export default alovaRequest
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
2
3
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"lib": ["ES2023", "DOM"
|
|
7
|
-
"types": ["vite/client"],
|
|
4
|
+
"target": "es2023",
|
|
5
|
+
"module": "esnext",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"lib": ["ES2023", "DOM"],
|
|
8
|
+
"types": ["vite-plus/client"],
|
|
9
|
+
"paths": {
|
|
10
|
+
"@/*": ["./src/*"]
|
|
11
|
+
},
|
|
8
12
|
"skipLibCheck": true,
|
|
9
13
|
|
|
10
14
|
/* Bundler mode */
|
|
@@ -13,20 +17,12 @@
|
|
|
13
17
|
"verbatimModuleSyntax": true,
|
|
14
18
|
"moduleDetection": "force",
|
|
15
19
|
"noEmit": true,
|
|
16
|
-
"jsx": "react-jsx",
|
|
17
20
|
|
|
18
21
|
/* Linting */
|
|
19
|
-
"strict": true,
|
|
20
22
|
"noUnusedLocals": true,
|
|
21
23
|
"noUnusedParameters": true,
|
|
22
24
|
"erasableSyntaxOnly": true,
|
|
23
|
-
"noFallthroughCasesInSwitch": true
|
|
24
|
-
"noUncheckedSideEffectImports": true,
|
|
25
|
-
|
|
26
|
-
"baseUrl": ".",
|
|
27
|
-
"paths": {
|
|
28
|
-
"@/*": ["src/*"]
|
|
29
|
-
}
|
|
25
|
+
"noFallthroughCasesInSwitch": true
|
|
30
26
|
},
|
|
31
27
|
"include": ["src"]
|
|
32
28
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
-
|
|
3
2
|
import tailwindcss from '@tailwindcss/vite'
|
|
4
3
|
import react from '@vitejs/plugin-react'
|
|
5
4
|
import AutoImport from 'unplugin-auto-import/vite'
|
|
@@ -8,7 +7,14 @@ import { defineConfig, loadEnv } from 'vite-plus'
|
|
|
8
7
|
export default defineConfig(({ mode }) => {
|
|
9
8
|
const root = process.cwd()
|
|
10
9
|
const env = loadEnv(mode, root)
|
|
11
|
-
const { VITE_PORT } = env
|
|
10
|
+
const { VITE_PORT, VITE_API_AFFIX, VITE_API_URL } = env
|
|
11
|
+
|
|
12
|
+
console.log(`
|
|
13
|
+
mode: ${mode}
|
|
14
|
+
VITE_PORT: ${VITE_PORT}
|
|
15
|
+
VITE_API_AFFIX: ${VITE_API_AFFIX}
|
|
16
|
+
VITE_API_URL: ${VITE_API_URL}
|
|
17
|
+
`)
|
|
12
18
|
|
|
13
19
|
return {
|
|
14
20
|
resolve: {
|
|
@@ -19,6 +25,13 @@ export default defineConfig(({ mode }) => {
|
|
|
19
25
|
server: {
|
|
20
26
|
port: Number(VITE_PORT),
|
|
21
27
|
host: '0.0.0.0',
|
|
28
|
+
proxy: {
|
|
29
|
+
[VITE_API_AFFIX]: {
|
|
30
|
+
target: VITE_API_URL,
|
|
31
|
+
changeOrigin: true,
|
|
32
|
+
rewrite: (path) => path.replace(new RegExp('^' + VITE_API_AFFIX), ''),
|
|
33
|
+
},
|
|
34
|
+
},
|
|
22
35
|
},
|
|
23
36
|
plugins: [
|
|
24
37
|
react(),
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!--VITE PLUS START-->
|
|
2
|
+
|
|
3
|
+
# Using Vite+, the Unified Toolchain for the Web
|
|
4
|
+
|
|
5
|
+
This project is using Vite+, a unified toolchain built on top of Vite, Rolldown, Vitest, tsdown, Oxlint, Oxfmt, and Vite Task. Vite+ wraps runtime management, package management, and frontend tooling in a single global CLI called `vp`. Vite+ is distinct from Vite, and it invokes Vite through `vp dev` and `vp build`. Run `vp help` to print a list of commands and `vp <command> --help` for information about a specific command.
|
|
6
|
+
|
|
7
|
+
Docs are local at `node_modules/vite-plus/docs` or online at https://viteplus.dev/guide/.
|
|
8
|
+
|
|
9
|
+
## Review Checklist
|
|
10
|
+
|
|
11
|
+
- [ ] Run `vp install` after pulling remote changes and before getting started.
|
|
12
|
+
- [ ] Run `vp check` and `vp test` to format, lint, type check and test changes.
|
|
13
|
+
- [ ] Check if there are `vite.config.ts` tasks or `package.json` scripts necessary for validation, run via `vp run <script>`.
|
|
14
|
+
- [ ] If setup, runtime, or package-manager behavior looks wrong, run `vp env doctor` and include its output when asking for help.
|
|
15
|
+
|
|
16
|
+
<!--VITE PLUS END-->
|