create-bubbles 0.0.8 → 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.
Files changed (34) hide show
  1. package/package.json +1 -1
  2. package/template-react-rsbuild/biome.json +102 -101
  3. package/template-react-rsbuild/commitlint.config.js +1 -1
  4. package/template-react-rsbuild/package.json +16 -16
  5. package/template-react-rsbuild/postcss.config.mjs +5 -5
  6. package/template-react-rsbuild/rsbuild.config.ts +28 -28
  7. package/template-react-rsbuild/src/App.tsx +9 -9
  8. package/template-react-rsbuild/src/components/Loading/PageLoading.tsx +11 -11
  9. package/template-react-rsbuild/src/env.d.ts +1 -1
  10. package/template-react-rsbuild/src/index.tsx +20 -20
  11. package/template-react-rsbuild/src/pages/home/index.tsx +26 -26
  12. package/template-react-rsbuild/src/router/index.tsx +27 -27
  13. package/template-react-rsbuild/src/store/index.ts +0 -0
  14. package/template-react-rsbuild/src/store/modules/user.ts +11 -0
  15. package/template-react-rsbuild/src/types/auto-import.d.ts +47 -47
  16. package/template-react-rsbuild/src/utils/request/axios.ts +82 -93
  17. package/template-react-rsbuild/src/utils/request/index.ts +43 -26
  18. package/template-react-rsbuild/tsconfig.json +29 -29
  19. package/template-react-rsbuild/uno.config.ts +8 -8
  20. package/template-vue-rsbuild/biome.json +2 -1
  21. package/template-vue-rsbuild/package.json +7 -6
  22. package/template-vue-rsbuild/rsbuild.config.ts +4 -4
  23. package/template-vue-rsbuild/src/env.d.ts +17 -9
  24. package/template-vue-rsbuild/src/index.ts +9 -1
  25. package/template-vue-rsbuild/src/router/guard/index.tsx +6 -0
  26. package/template-vue-rsbuild/src/router/guard/permissionGuard.ts +8 -0
  27. package/template-vue-rsbuild/src/router/index.tsx +14 -0
  28. package/template-vue-rsbuild/src/router/modules/index.tsx +10 -0
  29. package/template-vue-rsbuild/src/store/index.ts +7 -0
  30. package/template-vue-rsbuild/src/store/modules/user.ts +17 -0
  31. package/template-vue-rsbuild/src/utils/request/axios.ts +83 -0
  32. package/template-vue-rsbuild/src/utils/request/index.ts +77 -0
  33. package/template-vue-rsbuild/src/views/home/index.vue +13 -0
  34. package/template-react-rsbuild/pnpm-lock.yaml +0 -3615
@@ -1,93 +1,82 @@
1
- import { message } from 'ant-design-vue';
2
- import axios, { type AxiosResponse } from 'axios';
3
- import _ from 'lodash-es';
4
-
5
- import { router } from '@/router';
6
- import { useUserStoreWithOut } from '@/store/modules/user';
7
-
8
- export interface CustomConfig {
9
- /** 直接返回响应体 */
10
- isTransformResponse?: boolean;
11
- // 成功需要提示
12
- isShowSuccessMsg?: boolean;
13
- }
14
-
15
- export enum CodeEnum {
16
- SUCCESS = 200,
17
- UNAUTHORIZED = 401,
18
- }
19
-
20
- const unAuthFunc = _.debounce(() => {
21
- message.error('暂未登录或登录已过期,请重新登录');
22
- router.push('/login');
23
- }, 500);
24
-
25
- export default (customConfig?: CustomConfig) => {
26
- // const { getToken } = useUserStore()
27
- const userStore = useUserStoreWithOut();
28
-
29
- const instance = axios.create({
30
- baseURL: import.meta.env.PUBLIC_API_AFFIX,
31
- });
32
-
33
- instance.interceptors.request.use(
34
- (config) => {
35
- // config.headers = {
36
- // 'X-Access-Token': userStore.token,
37
- // 'Allow-Control-Allow-Origin': '*',
38
- // ...config?.headers,
39
- // } as any
40
- config.headers.set('X-Access-Token', userStore.token);
41
- config.headers.set('Allow-Control-Allow-Origin', '*');
42
- return config;
43
- },
44
- (error) => {
45
- message.error('请求错误');
46
- return Promise.reject(error);
47
- },
48
- );
49
-
50
- interface ResponseData<T = any> {
51
- code: number;
52
- message: string;
53
- requestId: string;
54
- responseTime: number;
55
- result: T;
56
- }
57
-
58
- instance.interceptors.response.use(
59
- (response: AxiosResponse<ResponseData>) => {
60
- const { status, data } = response;
61
- if (status === 200) {
62
- if (customConfig?.isTransformResponse === false) return data;
63
- const { code, message: msg } = data;
64
- if (code === CodeEnum.SUCCESS) {
65
- if (customConfig?.isShowSuccessMsg) {
66
- message.success(msg);
67
- }
68
- return data.result;
69
- }
70
- message.error(msg);
71
- return Promise.reject(data);
72
- }
73
- if (status === CodeEnum.UNAUTHORIZED) {
74
- // _.debounce(() => {
75
- message.error(data.message);
76
- router.push('/login');
77
- // }, 500)
78
- } else return Promise.reject(data.message);
79
- },
80
- (error) => {
81
- const response = error.response;
82
- const { status, data } = response;
83
- if (status === CodeEnum.UNAUTHORIZED) {
84
- unAuthFunc();
85
- } else {
86
- message.error(data?.message || '系统异常');
87
- return Promise.reject(error);
88
- }
89
- },
90
- );
91
-
92
- return instance;
93
- };
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
+ }
@@ -1,40 +1,41 @@
1
- import type { AxiosRequestConfig } from 'axios';
1
+ import type { AxiosRequestConfig } from 'axios'
2
2
 
3
- import request, { type CustomConfig } from './axios';
3
+ import request, { type CustomConfig } from './axios'
4
4
 
5
5
  interface createAxiosType {
6
- get: (
6
+ get: <T = any>(
7
7
  config: {
8
- url: string;
9
- params?: AxiosRequestConfig['params'];
10
- config?: AxiosRequestConfig<any>;
8
+ url: string
9
+ params?: AxiosRequestConfig['params']
10
+ config?: AxiosRequestConfig<any>
11
11
  },
12
12
  option?: CustomConfig,
13
- ) => Promise<any>;
14
- post: (
13
+ ) => Promise<T>
14
+ post: <T = any>(
15
15
  config: {
16
- url: string;
17
- data?: AxiosRequestConfig['data'];
18
- config?: AxiosRequestConfig<any>;
16
+ url: string
17
+ data?: AxiosRequestConfig['data']
18
+ params?: AxiosRequestConfig['params']
19
+ config?: AxiosRequestConfig<any>
19
20
  },
20
21
  option?: CustomConfig,
21
- ) => Promise<any>;
22
- put: (
22
+ ) => Promise<T>
23
+ put: <T = any>(
23
24
  config: {
24
- url: string;
25
- data?: AxiosRequestConfig['data'];
26
- config?: AxiosRequestConfig<any>;
25
+ url: string
26
+ data?: AxiosRequestConfig['data']
27
+ config?: AxiosRequestConfig<any>
27
28
  },
28
29
  option?: CustomConfig,
29
- ) => Promise<any>;
30
- delete: (
30
+ ) => Promise<T>
31
+ delete: <T = any>(
31
32
  config: {
32
- url: string;
33
- data?: AxiosRequestConfig['data'];
34
- config?: AxiosRequestConfig<any>;
33
+ url: string
34
+ data?: AxiosRequestConfig['data']
35
+ config?: AxiosRequestConfig<any>
35
36
  },
36
37
  option?: CustomConfig,
37
- ) => Promise<any>;
38
+ ) => Promise<T>
38
39
  }
39
40
 
40
41
  const createAxios: createAxiosType = {
@@ -44,9 +45,25 @@ const createAxios: createAxiosType = {
44
45
  ...config?.config,
45
46
  }),
46
47
  post: (
47
- config: { url: string; data?: any; config?: AxiosRequestConfig<any> },
48
+ config: {
49
+ url: string
50
+ params?: Record<string, string>
51
+ data?: any
52
+ config?: AxiosRequestConfig<any>
53
+ },
48
54
  option?: CustomConfig,
49
- ) => request(option).post(config.url, config?.data, config?.config),
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
+ },
50
67
  put: (
51
68
  config: { url: string; data?: any; config?: AxiosRequestConfig<any> },
52
69
  option?: CustomConfig,
@@ -55,6 +72,6 @@ const createAxios: createAxiosType = {
55
72
  config: { url: string; config?: AxiosRequestConfig<any> },
56
73
  customConfig?: CustomConfig,
57
74
  ) => request(customConfig).delete(config.url, config?.config),
58
- };
75
+ }
59
76
 
60
- export default createAxios;
77
+ export default createAxios
@@ -1,29 +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
- }
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
+ }
@@ -1,8 +1,8 @@
1
- import { defineConfig, presetUno } from 'unocss';
2
-
3
- export default defineConfig({
4
- content: {
5
- filesystem: ['**/*.{html,js,ts,jsx,tsx,vue,svelte,astro}'],
6
- },
7
- presets: [presetUno()],
8
- });
1
+ import { defineConfig, presetUno } from 'unocss';
2
+
3
+ export default defineConfig({
4
+ content: {
5
+ filesystem: ['**/*.{html,js,ts,jsx,tsx,vue,svelte,astro}'],
6
+ },
7
+ presets: [presetUno()],
8
+ });
@@ -22,7 +22,8 @@
22
22
  },
23
23
  "javascript": {
24
24
  "formatter": {
25
- "quoteStyle": "single"
25
+ "quoteStyle": "single",
26
+ "semicolons": "asNeeded"
26
27
  }
27
28
  },
28
29
  "organizeImports": {
@@ -11,6 +11,7 @@
11
11
  "preview": "rsbuild preview"
12
12
  },
13
13
  "dependencies": {
14
+ "ant-design-vue": "^4.2.6",
14
15
  "pinia": "^3.0.1",
15
16
  "vue": "^3.5.13",
16
17
  "vue-router": "^4.5.0"
@@ -18,13 +19,13 @@
18
19
  "devDependencies": {
19
20
  "@biomejs/biome": "^1.9.4",
20
21
  "@ianvs/prettier-plugin-sort-imports": "^4.4.1",
21
- "@rsbuild/core": "^1.2.4",
22
- "@rsbuild/plugin-vue": "^1.0.5",
22
+ "@rsbuild/core": "^1.3.1",
23
+ "@rsbuild/plugin-vue": "^1.0.7",
23
24
  "@unocss/postcss": "^65.5.0",
24
- "lefthook": "^1.10.1",
25
- "prettier": "^3.4.2",
26
- "typescript": "^5.7.3",
25
+ "lefthook": "^1.11.6",
26
+ "prettier": "^3.5.3",
27
+ "typescript": "^5.8.2",
27
28
  "unocss": "^65.5.0",
28
- "unplugin-auto-import": "^19.1.0"
29
+ "unplugin-auto-import": "^19.1.2"
29
30
  }
30
31
  }
@@ -1,6 +1,6 @@
1
- import { defineConfig } from '@rsbuild/core';
2
- import { pluginVue } from '@rsbuild/plugin-vue';
3
- import AutoImport from 'unplugin-auto-import/rspack';
1
+ import { defineConfig } from '@rsbuild/core'
2
+ import { pluginVue } from '@rsbuild/plugin-vue'
3
+ import AutoImport from 'unplugin-auto-import/rspack'
4
4
 
5
5
  export default defineConfig({
6
6
  html: {
@@ -25,4 +25,4 @@ export default defineConfig({
25
25
  ],
26
26
  },
27
27
  },
28
- });
28
+ })
@@ -1,9 +1,17 @@
1
- /// <reference types="@rsbuild/core/types" />
2
-
3
- declare module '*.vue' {
4
- import type { DefineComponent } from 'vue';
5
-
6
- // biome-ignore lint/complexity/noBannedTypes: reason
7
- const component: DefineComponent<{}, {}, any>;
8
- export default component;
9
- }
1
+ /// <reference types="@rsbuild/core/types" />
2
+
3
+ declare module '*.vue' {
4
+ import type { DefineComponent } from 'vue';
5
+
6
+ // biome-ignore lint/complexity/noBannedTypes: reason
7
+ const component: DefineComponent<{}, {}, any>;
8
+ export default component;
9
+ }
10
+
11
+ interface ImportMetaEnv {
12
+ readonly PUBLIC_PATH: string;
13
+ }
14
+
15
+ interface ImportMeta {
16
+ readonly env: ImportMetaEnv;
17
+ }
@@ -4,4 +4,12 @@ import App from './App.vue';
4
4
 
5
5
  import '@/styles/index.css';
6
6
 
7
- createApp(App).mount('#root');
7
+ import { setupRouter } from './router';
8
+ import { setupStore } from './store';
9
+
10
+ const app = createApp(App);
11
+
12
+ setupRouter(app);
13
+ setupStore(app);
14
+
15
+ app.mount('#root');
@@ -0,0 +1,6 @@
1
+ import type { Router } from 'vue-router';
2
+ import { createPermissionGuard } from './permissionGuard';
3
+
4
+ export const setupGuard = (router: Router) => {
5
+ createPermissionGuard(router);
6
+ };
@@ -0,0 +1,8 @@
1
+ import type { Router } from 'vue-router';
2
+
3
+ export const createPermissionGuard = (router: Router) => {
4
+ router.beforeEach((to, from, next) => {
5
+ next();
6
+ });
7
+ router.afterEach((to, from) => {});
8
+ };
@@ -0,0 +1,14 @@
1
+ import { createRouter, createWebHistory } from 'vue-router';
2
+ import { routes } from './modules';
3
+ import type { App } from 'vue';
4
+
5
+ export const router = createRouter({
6
+ history: createWebHistory(import.meta.env.PUBLIC_PATH),
7
+ routes: routes,
8
+ strict: true,
9
+ scrollBehavior: () => ({ left: 0, top: 0 }),
10
+ });
11
+
12
+ export const setupRouter = (app: App) => {
13
+ app.use(router);
14
+ };
@@ -0,0 +1,10 @@
1
+ import type { RouteRecordRaw } from 'vue-router';
2
+
3
+ export const routes: RouteRecordRaw[] = [
4
+ {
5
+ path: '/home',
6
+ name: 'Home',
7
+ meta: {},
8
+ component: () => import('@/views/home/index.vue'),
9
+ },
10
+ ];
@@ -0,0 +1,7 @@
1
+ import type { App } from "vue"
2
+ import { createPinia } from "pinia"
3
+
4
+ export const store = createPinia()
5
+ export const setupStore = (app: App) => {
6
+ app.use(store)
7
+ }
@@ -0,0 +1,17 @@
1
+ import { defineStore } from "pinia";
2
+ import { store } from "..";
3
+
4
+ export const useUserStore = defineStore(
5
+ 'user',{
6
+ state: () => {
7
+ return {
8
+ name: 'admin',
9
+ token: 'admin',
10
+ avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif'
11
+ }
12
+ },
13
+ })
14
+
15
+ export function useUserStoreWithOut() {
16
+ return useUserStore(store);
17
+ }
@@ -0,0 +1,83 @@
1
+ import { message } from 'ant-design-vue'
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 userStore = useUserStore()
25
+ const token = userStore.token
26
+
27
+ const instance = axios.create({
28
+ baseURL: import.meta.env.PUBLIC_API_AFFIX,
29
+ })
30
+
31
+ instance.interceptors.request.use(
32
+ (config) => {
33
+ config.headers.set('X-Access-Token', token)
34
+ config.headers.set('Allow-Control-Allow-Origin', '*')
35
+ return config
36
+ },
37
+ (error) => {
38
+ message.error('请求错误')
39
+ return Promise.reject(error)
40
+ },
41
+ )
42
+
43
+ interface ResponseData<T = any> {
44
+ code: number
45
+ message: string
46
+ requestId: string
47
+ responseTime: number
48
+ result: T
49
+ }
50
+
51
+ instance.interceptors.response.use(
52
+ (response: AxiosResponse<ResponseData>) => {
53
+ const { status, data } = response
54
+ if (status === 200) {
55
+ if (customConfig?.isTransformResponse === false) return data
56
+ const { code, message: msg } = data
57
+ if (code === CodeEnum.SUCCESS) {
58
+ if (customConfig?.isShowSuccessMsg) {
59
+ message.success(msg)
60
+ }
61
+ return data.result
62
+ }
63
+ message.error(msg)
64
+ return Promise.reject(data)
65
+ }
66
+ if (status === CodeEnum.UNAUTHORIZED) {
67
+ unAuthFunc()
68
+ } else return Promise.reject(data.message)
69
+ },
70
+ (error) => {
71
+ const response = error.response
72
+ const { status, data } = response
73
+ if (status === CodeEnum.UNAUTHORIZED) {
74
+ unAuthFunc()
75
+ } else {
76
+ message.error(data?.message || '系统异常')
77
+ return Promise.reject(error)
78
+ }
79
+ },
80
+ )
81
+
82
+ return instance
83
+ }