create-bubbles 0.0.7 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/template-react-rsbuild/.env +3 -0
- package/template-react-rsbuild/.env.development +0 -0
- package/template-react-rsbuild/.env.production +0 -0
- package/template-react-rsbuild/.prettierignore +34 -0
- package/template-react-rsbuild/.prettierrc +17 -0
- package/template-react-rsbuild/biome.json +102 -0
- package/template-react-rsbuild/commitlint.config.js +1 -0
- package/template-react-rsbuild/index.en-US.md +0 -0
- package/template-react-rsbuild/index.html +7 -0
- package/template-react-rsbuild/index.zh-CN.md +0 -0
- package/template-react-rsbuild/lefthook.yml +14 -0
- package/template-react-rsbuild/package.json +39 -0
- package/template-react-rsbuild/postcss.config.mjs +5 -0
- package/template-react-rsbuild/public/.gitkeep +0 -0
- package/template-react-rsbuild/rsbuild.config.ts +28 -0
- package/template-react-rsbuild/src/App.tsx +9 -0
- package/template-react-rsbuild/src/components/Loading/PageLoading.tsx +11 -0
- package/template-react-rsbuild/src/env.d.ts +1 -0
- package/template-react-rsbuild/src/index.tsx +20 -0
- package/template-react-rsbuild/src/pages/home/index.tsx +26 -0
- package/template-react-rsbuild/src/router/index.tsx +27 -0
- package/template-react-rsbuild/src/store/index.ts +0 -0
- package/template-react-rsbuild/src/store/modules/user.ts +11 -0
- package/template-react-rsbuild/src/styles/index.css +16 -0
- package/template-react-rsbuild/src/types/auto-import.d.ts +47 -0
- package/template-react-rsbuild/src/utils/request/axios.ts +82 -0
- package/template-react-rsbuild/src/utils/request/index.ts +77 -0
- package/template-react-rsbuild/tsconfig.json +29 -0
- package/template-react-rsbuild/uno.config.ts +8 -0
- package/template-vue-rsbuild/.env +3 -0
- package/template-vue-rsbuild/.env.development +0 -0
- package/template-vue-rsbuild/.env.production +0 -0
- package/template-vue-rsbuild/.prettierignore +4 -0
- package/template-vue-rsbuild/.prettierrc +17 -0
- package/template-vue-rsbuild/biome.json +113 -0
- package/template-vue-rsbuild/index.html +7 -0
- package/template-vue-rsbuild/package.json +31 -0
- package/template-vue-rsbuild/postcss.config.mjs +5 -0
- package/template-vue-rsbuild/public/.gitkeep +0 -0
- package/template-vue-rsbuild/rsbuild.config.ts +28 -0
- package/template-vue-rsbuild/src/App.vue +29 -0
- package/template-vue-rsbuild/src/env.d.ts +17 -0
- package/template-vue-rsbuild/src/index.css +6 -0
- package/template-vue-rsbuild/src/index.ts +15 -0
- package/template-vue-rsbuild/src/router/guard/index.tsx +6 -0
- package/template-vue-rsbuild/src/router/guard/permissionGuard.ts +8 -0
- package/template-vue-rsbuild/src/router/index.tsx +14 -0
- package/template-vue-rsbuild/src/router/modules/index.tsx +10 -0
- package/template-vue-rsbuild/src/store/index.ts +7 -0
- package/template-vue-rsbuild/src/store/modules/user.ts +17 -0
- package/template-vue-rsbuild/src/styles/index.css +16 -0
- package/template-vue-rsbuild/src/types/auto-import.d.ts +91 -0
- package/template-vue-rsbuild/src/utils/request/axios.ts +83 -0
- package/template-vue-rsbuild/src/utils/request/index.ts +77 -0
- package/template-vue-rsbuild/src/views/home/index.vue +13 -0
- package/template-vue-rsbuild/tsconfig.json +29 -0
- package/template-vue-rsbuild/uno.config.ts +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-bubbles",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "bubbles plant",
|
|
6
6
|
"bin": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"index.js",
|
|
11
|
-
"template
|
|
11
|
+
"template-*/**",
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
**/*.png
|
|
2
|
+
**/*.svg
|
|
3
|
+
CODEOWNERS
|
|
4
|
+
.dockerignore
|
|
5
|
+
Dockerfile.ui-test
|
|
6
|
+
.dumi/tmp
|
|
7
|
+
.dumi/tmp-production
|
|
8
|
+
!dumi
|
|
9
|
+
# AUTHORS.txt
|
|
10
|
+
lib/
|
|
11
|
+
es/
|
|
12
|
+
dist/
|
|
13
|
+
# _site/
|
|
14
|
+
# server
|
|
15
|
+
# coverage/
|
|
16
|
+
# CNAME
|
|
17
|
+
LICENSE
|
|
18
|
+
yarn.lock
|
|
19
|
+
# netlify.toml
|
|
20
|
+
yarn-error.log
|
|
21
|
+
*.sh
|
|
22
|
+
*.snap
|
|
23
|
+
components/*/*.js
|
|
24
|
+
components/*/*.jsx
|
|
25
|
+
.gitignore
|
|
26
|
+
.npmignore
|
|
27
|
+
.prettierignore
|
|
28
|
+
.DS_Store
|
|
29
|
+
.editorconfig
|
|
30
|
+
.eslintignore
|
|
31
|
+
.history
|
|
32
|
+
**/*.yml
|
|
33
|
+
*.html
|
|
34
|
+
CHANGELOG.*.md
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"singleQuote": true,
|
|
3
|
+
"jsxSingleQuote": false,
|
|
4
|
+
"trailingComma": "all",
|
|
5
|
+
"printWidth": 100,
|
|
6
|
+
"proseWrap": "never",
|
|
7
|
+
"importOrder": ["^(react|react-dom)$", "^([a-z]|@[a-z])", "", ".*"],
|
|
8
|
+
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
|
|
9
|
+
"overrides": [
|
|
10
|
+
{
|
|
11
|
+
"files": ".prettierrc",
|
|
12
|
+
"options": {
|
|
13
|
+
"parser": "json"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": {
|
|
3
|
+
"ignoreUnknown": true,
|
|
4
|
+
"ignore": ["dist/*", "node_modules", "package.json", "auto-import.d.ts", "*.js"]
|
|
5
|
+
},
|
|
6
|
+
"formatter": {
|
|
7
|
+
"enabled": true,
|
|
8
|
+
"indentStyle": "space",
|
|
9
|
+
"lineWidth": 100,
|
|
10
|
+
"indentWidth": 2
|
|
11
|
+
},
|
|
12
|
+
"javascript": {
|
|
13
|
+
"formatter": {
|
|
14
|
+
"quoteStyle": "single",
|
|
15
|
+
"semicolons": "asNeeded"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"organizeImports": {
|
|
19
|
+
"enabled": false
|
|
20
|
+
},
|
|
21
|
+
"linter": {
|
|
22
|
+
"rules": {
|
|
23
|
+
"style": {
|
|
24
|
+
"useImportType": "off",
|
|
25
|
+
"useNumberNamespace": "off",
|
|
26
|
+
"useNodejsImportProtocol": "off",
|
|
27
|
+
"noNonNullAssertion": "off",
|
|
28
|
+
"noUnusedTemplateLiteral": "off"
|
|
29
|
+
},
|
|
30
|
+
"complexity": {
|
|
31
|
+
"noUselessTypeConstraint": "off",
|
|
32
|
+
"noForEach": "off"
|
|
33
|
+
},
|
|
34
|
+
"correctness": {
|
|
35
|
+
"useExhaustiveDependencies": "off"
|
|
36
|
+
},
|
|
37
|
+
"suspicious": {
|
|
38
|
+
"noGlobalIsNan": "off",
|
|
39
|
+
"noGlobalIsFinite": "off",
|
|
40
|
+
"noExplicitAny": "off",
|
|
41
|
+
"noArrayIndexKey": "off",
|
|
42
|
+
"noConfusingVoidType": "off",
|
|
43
|
+
"noThenProperty": "off"
|
|
44
|
+
},
|
|
45
|
+
"performance": {
|
|
46
|
+
"noDelete": "off",
|
|
47
|
+
"noAccumulatingSpread": "off"
|
|
48
|
+
},
|
|
49
|
+
"a11y": {
|
|
50
|
+
"noAriaHiddenOnFocusable": "off",
|
|
51
|
+
"noLabelWithoutControl": "off",
|
|
52
|
+
"useFocusableInteractive": "off",
|
|
53
|
+
"useKeyWithClickEvents": "off",
|
|
54
|
+
"useSemanticElements": "off"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"css": {
|
|
59
|
+
"formatter": {
|
|
60
|
+
"quoteStyle": "single"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"overrides": [
|
|
64
|
+
{
|
|
65
|
+
"include": ["**/*.test.ts", "**/*.test.tsx", "tests/**/*", "scripts/**/*"],
|
|
66
|
+
"linter": {
|
|
67
|
+
"rules": {
|
|
68
|
+
"style": {
|
|
69
|
+
"noParameterAssign": "off"
|
|
70
|
+
},
|
|
71
|
+
"suspicious": {
|
|
72
|
+
"noThenProperty": "off",
|
|
73
|
+
"noImplicitAnyLet": "off"
|
|
74
|
+
},
|
|
75
|
+
"complexity": {
|
|
76
|
+
"noUselessFragments": "off"
|
|
77
|
+
},
|
|
78
|
+
"a11y": {
|
|
79
|
+
"useValidAnchor": "off",
|
|
80
|
+
"useAnchorContent": "off",
|
|
81
|
+
"useKeyWithClickEvents": "off"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"include": ["components/*/demo/*"],
|
|
88
|
+
"linter": {
|
|
89
|
+
"rules": {
|
|
90
|
+
"correctness": {
|
|
91
|
+
"noVoidTypeReturn": "off"
|
|
92
|
+
},
|
|
93
|
+
"a11y": {
|
|
94
|
+
"useValidAnchor": "off",
|
|
95
|
+
"useAnchorContent": "off",
|
|
96
|
+
"useKeyWithClickEvents": "off"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = { extends: ['@commitlint/config-conventional'] };
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
pre-commit:
|
|
2
|
+
commands:
|
|
3
|
+
check:
|
|
4
|
+
glob: "*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc,vue}"
|
|
5
|
+
run: npx @biomejs/biome check --write --no-errors-on-unmatched --files-ignore-unknown=true --colors=off {staged_files}
|
|
6
|
+
stage_fixed: true
|
|
7
|
+
|
|
8
|
+
commit-msg:
|
|
9
|
+
commands:
|
|
10
|
+
"lint commit message":
|
|
11
|
+
run: npx commitlint --edit {1}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "template-react",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "rsbuild dev --open",
|
|
7
|
+
"dev:prod": "rsbuild dev --env-mode production",
|
|
8
|
+
"build": "rsbuild build",
|
|
9
|
+
"check": "biome check --write",
|
|
10
|
+
"format": "prettier --write .",
|
|
11
|
+
"preview": "rsbuild preview",
|
|
12
|
+
"reinstall": "rimraf pnpm-lock.yaml && rimraf node_modules && pnpm install"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"ahooks": "^3.8.4",
|
|
16
|
+
"antd": "^5.24.5",
|
|
17
|
+
"axios": "^1.8.4",
|
|
18
|
+
"dayjs": "^1.11.13",
|
|
19
|
+
"react": "^19.1.0",
|
|
20
|
+
"react-dom": "^19.1.0",
|
|
21
|
+
"react-router": "^7.4.1",
|
|
22
|
+
"zustand": "^5.0.3"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@biomejs/biome": "^1.9.4",
|
|
26
|
+
"@commitlint/config-conventional": "^19.8.0",
|
|
27
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
|
|
28
|
+
"@rsbuild/core": "^1.3.1",
|
|
29
|
+
"@rsbuild/plugin-react": "^1.1.1",
|
|
30
|
+
"@types/react": "^19.0.12",
|
|
31
|
+
"@types/react-dom": "^19.0.4",
|
|
32
|
+
"@unocss/postcss": "^0.65.4",
|
|
33
|
+
"lefthook": "^1.11.6",
|
|
34
|
+
"prettier": "^3.5.3",
|
|
35
|
+
"typescript": "^5.8.2",
|
|
36
|
+
"unocss": "^0.65.4",
|
|
37
|
+
"unplugin-auto-import": "^19.1.2"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineConfig } from '@rsbuild/core';
|
|
2
|
+
import { pluginReact } from '@rsbuild/plugin-react';
|
|
3
|
+
import AutoImport from 'unplugin-auto-import/rspack';
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
html: {
|
|
7
|
+
template: './index.html',
|
|
8
|
+
},
|
|
9
|
+
resolve: {
|
|
10
|
+
alias: {
|
|
11
|
+
'@': './src',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
server: {
|
|
15
|
+
port: process.env.PUBLIC_PORT,
|
|
16
|
+
},
|
|
17
|
+
plugins: [pluginReact()],
|
|
18
|
+
tools: {
|
|
19
|
+
rspack: {
|
|
20
|
+
plugins: [
|
|
21
|
+
AutoImport({
|
|
22
|
+
imports: ['react', 'react-router', 'react-router-dom'],
|
|
23
|
+
dts: './src/types/auto-import.d.ts',
|
|
24
|
+
}),
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="@rsbuild/core/types" />
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { Suspense } from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom/client';
|
|
3
|
+
|
|
4
|
+
import App from './App';
|
|
5
|
+
|
|
6
|
+
import '@/styles/index.css';
|
|
7
|
+
|
|
8
|
+
import Loading from './components/Loading/PageLoading';
|
|
9
|
+
|
|
10
|
+
const rootEl = document.getElementById('root');
|
|
11
|
+
if (rootEl) {
|
|
12
|
+
const root = ReactDOM.createRoot(rootEl);
|
|
13
|
+
root.render(
|
|
14
|
+
<React.StrictMode>
|
|
15
|
+
<Suspense fallback={<Loading />}>
|
|
16
|
+
<App />
|
|
17
|
+
</Suspense>
|
|
18
|
+
</React.StrictMode>,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { use } from 'react';
|
|
2
|
+
|
|
3
|
+
const fetchData = () => {
|
|
4
|
+
return new Promise((resolve) => {
|
|
5
|
+
setTimeout(() => {
|
|
6
|
+
resolve({
|
|
7
|
+
data: [
|
|
8
|
+
{
|
|
9
|
+
id: 1,
|
|
10
|
+
title: 'Album 1',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: 2,
|
|
14
|
+
title: 'Album 2',
|
|
15
|
+
},
|
|
16
|
+
],
|
|
17
|
+
});
|
|
18
|
+
}, 1000);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const Home = () => {
|
|
23
|
+
return <h1>111</h1>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default Home;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Suspense } from 'react';
|
|
2
|
+
import { createBrowserRouter, type RouteObject } from 'react-router';
|
|
3
|
+
|
|
4
|
+
import Loading from '@/components/Loading/PageLoading';
|
|
5
|
+
|
|
6
|
+
export const lazyLoad = (path: string) => {
|
|
7
|
+
const Module = lazy(() => import(`@/pages/${path}.tsx`));
|
|
8
|
+
return (
|
|
9
|
+
<Suspense fallback={<Loading />}>
|
|
10
|
+
<Module />
|
|
11
|
+
</Suspense>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const routes: RouteObject[] = [
|
|
16
|
+
{
|
|
17
|
+
path: '/',
|
|
18
|
+
id: 'home',
|
|
19
|
+
element: lazyLoad('home/index'),
|
|
20
|
+
},
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
export const router = createBrowserRouter(routes, {
|
|
24
|
+
basename: import.meta.env.PUBLIC_PATH,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export default router;
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { create } from 'zustand'
|
|
2
|
+
|
|
3
|
+
interface searchFormState {
|
|
4
|
+
token?: string
|
|
5
|
+
setToken: (token?: string) => void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const useUserStore = create<searchFormState>((set) => ({
|
|
9
|
+
token: undefined,
|
|
10
|
+
setToken: (token) => set(() => ({ token })),
|
|
11
|
+
}))
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/* prettier-ignore */
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
// noinspection JSUnusedGlobalSymbols
|
|
5
|
+
// Generated by unplugin-auto-import
|
|
6
|
+
// biome-ignore lint: disable
|
|
7
|
+
export {};
|
|
8
|
+
declare global {
|
|
9
|
+
const Link: typeof import('react-router-dom')['Link'];
|
|
10
|
+
const NavLink: typeof import('react-router-dom')['NavLink'];
|
|
11
|
+
const Navigate: typeof import('react-router-dom')['Navigate'];
|
|
12
|
+
const Outlet: typeof import('react-router-dom')['Outlet'];
|
|
13
|
+
const Route: typeof import('react-router-dom')['Route'];
|
|
14
|
+
const Routes: typeof import('react-router-dom')['Routes'];
|
|
15
|
+
const createRef: typeof import('react')['createRef'];
|
|
16
|
+
const forwardRef: typeof import('react')['forwardRef'];
|
|
17
|
+
const lazy: typeof import('react')['lazy'];
|
|
18
|
+
const memo: typeof import('react')['memo'];
|
|
19
|
+
const startTransition: typeof import('react')['startTransition'];
|
|
20
|
+
const useCallback: typeof import('react')['useCallback'];
|
|
21
|
+
const useContext: typeof import('react')['useContext'];
|
|
22
|
+
const useDebugValue: typeof import('react')['useDebugValue'];
|
|
23
|
+
const useDeferredValue: typeof import('react')['useDeferredValue'];
|
|
24
|
+
const useEffect: typeof import('react')['useEffect'];
|
|
25
|
+
const useHref: typeof import('react-router-dom')['useHref'];
|
|
26
|
+
const useId: typeof import('react')['useId'];
|
|
27
|
+
const useImperativeHandle: typeof import('react')['useImperativeHandle'];
|
|
28
|
+
const useInRouterContext: typeof import('react-router-dom')['useInRouterContext'];
|
|
29
|
+
const useInsertionEffect: typeof import('react')['useInsertionEffect'];
|
|
30
|
+
const useLayoutEffect: typeof import('react')['useLayoutEffect'];
|
|
31
|
+
const useLinkClickHandler: typeof import('react-router-dom')['useLinkClickHandler'];
|
|
32
|
+
const useLocation: typeof import('react-router-dom')['useLocation'];
|
|
33
|
+
const useMemo: typeof import('react')['useMemo'];
|
|
34
|
+
const useNavigate: typeof import('react-router-dom')['useNavigate'];
|
|
35
|
+
const useNavigationType: typeof import('react-router-dom')['useNavigationType'];
|
|
36
|
+
const useOutlet: typeof import('react-router-dom')['useOutlet'];
|
|
37
|
+
const useOutletContext: typeof import('react-router-dom')['useOutletContext'];
|
|
38
|
+
const useParams: typeof import('react-router-dom')['useParams'];
|
|
39
|
+
const useReducer: typeof import('react')['useReducer'];
|
|
40
|
+
const useRef: typeof import('react')['useRef'];
|
|
41
|
+
const useResolvedPath: typeof import('react-router-dom')['useResolvedPath'];
|
|
42
|
+
const useRoutes: typeof import('react-router-dom')['useRoutes'];
|
|
43
|
+
const useSearchParams: typeof import('react-router-dom')['useSearchParams'];
|
|
44
|
+
const useState: typeof import('react')['useState'];
|
|
45
|
+
const useSyncExternalStore: typeof import('react')['useSyncExternalStore'];
|
|
46
|
+
const useTransition: typeof import('react')['useTransition'];
|
|
47
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { message } from 'antd'
|
|
2
|
+
import axios, { type AxiosResponse } from 'axios'
|
|
3
|
+
|
|
4
|
+
import { router } from '@/router'
|
|
5
|
+
import { useUserStore } from '@/store/modules/user'
|
|
6
|
+
|
|
7
|
+
export interface CustomConfig {
|
|
8
|
+
/** 直接返回响应体 */
|
|
9
|
+
isTransformResponse?: boolean
|
|
10
|
+
// 成功需要提示
|
|
11
|
+
isShowSuccessMsg?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export enum CodeEnum {
|
|
15
|
+
SUCCESS = 200,
|
|
16
|
+
UNAUTHORIZED = 401,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const unAuthFunc = () => {
|
|
20
|
+
message.error('暂未登录或登录已过期,请重新登录')
|
|
21
|
+
router.navigate('/login')
|
|
22
|
+
}
|
|
23
|
+
export default (customConfig?: CustomConfig) => {
|
|
24
|
+
const token = useUserStore((state) => state.token)
|
|
25
|
+
|
|
26
|
+
const instance = axios.create({
|
|
27
|
+
baseURL: import.meta.env.PUBLIC_API_AFFIX,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
instance.interceptors.request.use(
|
|
31
|
+
(config) => {
|
|
32
|
+
config.headers.set('X-Access-Token', token)
|
|
33
|
+
config.headers.set('Allow-Control-Allow-Origin', '*')
|
|
34
|
+
return config
|
|
35
|
+
},
|
|
36
|
+
(error) => {
|
|
37
|
+
message.error('请求错误')
|
|
38
|
+
return Promise.reject(error)
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
interface ResponseData<T = any> {
|
|
43
|
+
code: number
|
|
44
|
+
message: string
|
|
45
|
+
requestId: string
|
|
46
|
+
responseTime: number
|
|
47
|
+
result: T
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
instance.interceptors.response.use(
|
|
51
|
+
(response: AxiosResponse<ResponseData>) => {
|
|
52
|
+
const { status, data } = response
|
|
53
|
+
if (status === 200) {
|
|
54
|
+
if (customConfig?.isTransformResponse === false) return data
|
|
55
|
+
const { code, message: msg } = data
|
|
56
|
+
if (code === CodeEnum.SUCCESS) {
|
|
57
|
+
if (customConfig?.isShowSuccessMsg) {
|
|
58
|
+
message.success(msg)
|
|
59
|
+
}
|
|
60
|
+
return data.result
|
|
61
|
+
}
|
|
62
|
+
message.error(msg)
|
|
63
|
+
return Promise.reject(data)
|
|
64
|
+
}
|
|
65
|
+
if (status === CodeEnum.UNAUTHORIZED) {
|
|
66
|
+
unAuthFunc()
|
|
67
|
+
} else return Promise.reject(data.message)
|
|
68
|
+
},
|
|
69
|
+
(error) => {
|
|
70
|
+
const response = error.response
|
|
71
|
+
const { status, data } = response
|
|
72
|
+
if (status === CodeEnum.UNAUTHORIZED) {
|
|
73
|
+
unAuthFunc()
|
|
74
|
+
} else {
|
|
75
|
+
message.error(data?.message || '系统异常')
|
|
76
|
+
return Promise.reject(error)
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
return instance
|
|
82
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios'
|
|
2
|
+
|
|
3
|
+
import request, { type CustomConfig } from './axios'
|
|
4
|
+
|
|
5
|
+
interface createAxiosType {
|
|
6
|
+
get: <T = any>(
|
|
7
|
+
config: {
|
|
8
|
+
url: string
|
|
9
|
+
params?: AxiosRequestConfig['params']
|
|
10
|
+
config?: AxiosRequestConfig<any>
|
|
11
|
+
},
|
|
12
|
+
option?: CustomConfig,
|
|
13
|
+
) => Promise<T>
|
|
14
|
+
post: <T = any>(
|
|
15
|
+
config: {
|
|
16
|
+
url: string
|
|
17
|
+
data?: AxiosRequestConfig['data']
|
|
18
|
+
params?: AxiosRequestConfig['params']
|
|
19
|
+
config?: AxiosRequestConfig<any>
|
|
20
|
+
},
|
|
21
|
+
option?: CustomConfig,
|
|
22
|
+
) => Promise<T>
|
|
23
|
+
put: <T = any>(
|
|
24
|
+
config: {
|
|
25
|
+
url: string
|
|
26
|
+
data?: AxiosRequestConfig['data']
|
|
27
|
+
config?: AxiosRequestConfig<any>
|
|
28
|
+
},
|
|
29
|
+
option?: CustomConfig,
|
|
30
|
+
) => Promise<T>
|
|
31
|
+
delete: <T = any>(
|
|
32
|
+
config: {
|
|
33
|
+
url: string
|
|
34
|
+
data?: AxiosRequestConfig['data']
|
|
35
|
+
config?: AxiosRequestConfig<any>
|
|
36
|
+
},
|
|
37
|
+
option?: CustomConfig,
|
|
38
|
+
) => Promise<T>
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const createAxios: createAxiosType = {
|
|
42
|
+
get: (config, option) =>
|
|
43
|
+
request(option).get(config.url, {
|
|
44
|
+
params: config.params,
|
|
45
|
+
...config?.config,
|
|
46
|
+
}),
|
|
47
|
+
post: (
|
|
48
|
+
config: {
|
|
49
|
+
url: string
|
|
50
|
+
params?: Record<string, string>
|
|
51
|
+
data?: any
|
|
52
|
+
config?: AxiosRequestConfig<any>
|
|
53
|
+
},
|
|
54
|
+
option?: CustomConfig,
|
|
55
|
+
) => {
|
|
56
|
+
let url = config.url
|
|
57
|
+
if (config.params instanceof Object) {
|
|
58
|
+
url += '?'
|
|
59
|
+
const entries = Object.entries(config.params)
|
|
60
|
+
for (let i = 0; i < entries.length; i++) {
|
|
61
|
+
const [key, value] = entries[i]
|
|
62
|
+
url += `${key}=${value}${i < entries.length - 1 ? '&' : ''}`
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return request(option).post(url, config?.data, config?.config)
|
|
66
|
+
},
|
|
67
|
+
put: (
|
|
68
|
+
config: { url: string; data?: any; config?: AxiosRequestConfig<any> },
|
|
69
|
+
option?: CustomConfig,
|
|
70
|
+
) => request(option).put(config.url, config?.data, config?.config),
|
|
71
|
+
delete: (
|
|
72
|
+
config: { url: string; config?: AxiosRequestConfig<any> },
|
|
73
|
+
customConfig?: CustomConfig,
|
|
74
|
+
) => request(customConfig).delete(config.url, config?.config),
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export default createAxios
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["DOM", "ES2020"],
|
|
4
|
+
"jsx": "react-jsx",
|
|
5
|
+
"target": "ES2020",
|
|
6
|
+
"noEmit": true,
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
"useDefineForClassFields": true,
|
|
9
|
+
|
|
10
|
+
/* modules */
|
|
11
|
+
"module": "ESNext",
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"resolveJsonModule": true,
|
|
14
|
+
"moduleResolution": "Bundler",
|
|
15
|
+
"allowImportingTsExtensions": true,
|
|
16
|
+
|
|
17
|
+
/* type checking */
|
|
18
|
+
"strict": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
|
|
22
|
+
"baseUrl": "./",
|
|
23
|
+
"paths": {
|
|
24
|
+
"@/*": ["src/*"]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"include": ["src"],
|
|
28
|
+
"exclude": ["node_modules", "dist"]
|
|
29
|
+
}
|