Skip to content

Commit 94215fc

Browse files
committed
feat(): formatGlobModules解析与封装
1 parent 5c56fd1 commit 94215fc

File tree

14 files changed

+956
-37
lines changed

14 files changed

+956
-37
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313
- vite-plugin-style-import (按需导入样式)
1414
- vite-plugin-compression (开启GZIP压缩)
1515
- vite-plugin-cdn-import (cdn引入)
16-
- @vitejs/plugin-legacy (传统浏览器支持)--->对vue3来说无意义,Proxy决定了vue3不支持ie11,但对react或其他可通过此实现支持
16+
- @vitejs/plugin-legacy (传统浏览器支持)--->对vue3来说无意义,Proxy决定了vue3不支持ie11,但对react或其他可通过此实现支持
17+
- mockjs、vite-plugin-mock

build/plugin/mock.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* @Author: wangguixing [email protected]
3+
* @Date: 2023-04-01 00:40:02
4+
* @LastEditors: wangguixing [email protected]
5+
* @LastEditTime: 2023-04-01 00:40:15
6+
* @FilePath: \arcro-vue\build\plugin\mock.ts
7+
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8+
*/
9+
import { viteMockServe } from 'vite-plugin-mock';
10+
11+
export default function ConfigViteMock() {
12+
const config = viteMockServe({
13+
mockPath: './src/mock/source',
14+
localEnabled: true,
15+
});
16+
return config;
17+
}

build/vite.config.dev.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: wangguixing [email protected]
33
* @Date: 2023-03-06 16:54:08
44
* @LastEditors: wangguixing [email protected]
5-
* @LastEditTime: 2023-04-01 00:00:44
5+
* @LastEditTime: 2023-04-01 00:41:49
66
* @FilePath: \myPages\build\vite.config.dev.ts
77
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88
*/
@@ -11,6 +11,7 @@ import { mergeConfig, loadEnv } from 'vite';
1111
import eslint from 'vite-plugin-eslint';
1212
import { createHtmlPlugin } from 'vite-plugin-html';
1313
import commonConfig from './vite.config.common';
14+
import ConfigViteMock from './plugin/mock';
1415

1516
const getViteEnv = (mode: string, target: string) => {
1617
return loadEnv(mode, process.cwd())[target];
@@ -34,9 +35,9 @@ export default mergeConfig(
3435
proxy: {
3536
// 使用 proxy 实例
3637
'/api': {
37-
target: process.env.VITE_APP_API_BASE_URL,
38+
target: process.env.VITE_API_BASE_URL,
3839
changeOrigin: true,
39-
rewrite: (path: string) => path.replace(/^\/api/, ''),
40+
// rewrite: (path: string) => path.replace(/^\/api/, ''),
4041
},
4142
},
4243
},
@@ -56,6 +57,7 @@ export default mergeConfig(
5657
},
5758
},
5859
}),
60+
ConfigViteMock(),
5961
],
6062
},
6163
commonConfig

env.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
* @Author: guixing-wang [email protected]
33
* @Date: 2023-03-05 16:08:45
44
* @LastEditors: wangguixing [email protected]
5-
* @LastEditTime: 2023-03-31 10:56:00
5+
* @LastEditTime: 2023-04-01 00:30:29
66
* @FilePath: \myPages\env.d.ts
77
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
88
*/
99
/// <reference types="vite/client" />
10-
declare module 'crypto-js';
11-
declare module 'vite-plugin-imagemin';
1210
declare module '*.vue' {
1311
import type { DefineComponent } from 'vue';
1412
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types

image.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
declare module '*.svg';
2+
declare module '*.png';
3+
declare module '*.jpg';
4+
declare module '*.jpeg';
5+
declare module '*.gif';
6+
declare module '*.bmp';
7+
declare module '*.tiff';

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"jsdom": "^21.1.0",
6262
"less": "^4.1.3",
6363
"lint-staged": "^13.1.2",
64+
"mockjs": "^1.1.0",
6465
"npm-run-all": "^4.1.5",
6566
"nprogress": "^0.2.0",
6667
"prettier": "^2.8.4",
@@ -77,6 +78,7 @@
7778
"vite-plugin-eslint": "^1.8.1",
7879
"vite-plugin-html": "^3.2.0",
7980
"vite-plugin-imagemin": "^0.6.1",
81+
"vite-plugin-mock": "^2.9.6",
8082
"vite-plugin-style-import": "^2.0.0",
8183
"vite-svg-loader": "^4.0.0",
8284
"vitest": "^0.29.1",

src/mock/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* @Author: wangguixing [email protected]
3+
* @Date: 2023-04-01 00:42:41
4+
* @LastEditors: wangguixing [email protected]
5+
* @LastEditTime: 2023-04-01 01:23:54
6+
* @FilePath: \arcro-vue\src\mock\mock.ts
7+
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8+
*/
9+
10+
import type { MockMethod } from 'vite-plugin-mock';
11+
import { formatGlobModules } from '@/utils/importMetaGlob';
12+
13+
const services = import.meta.glob('./service/*.ts');
14+
const mockServices = formatGlobModules(services, [] as MockMethod[]);
15+
16+
export default mockServices;

src/mock/service/login.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* @Author: wangguixing [email protected]
3+
* @Date: 2023-04-01 00:45:08
4+
* @LastEditors: wangguixing [email protected]
5+
* @LastEditTime: 2023-04-01 01:13:03
6+
* @FilePath: \arcro-vue\src\mock\login\index.ts
7+
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8+
*/
9+
import type { mockService } from './types.d';
10+
11+
export default {
12+
url: '/api/getUserInfo', // 注意,这里只能是string格式
13+
method: 'get',
14+
response: () => ({
15+
code: 1,
16+
data: {
17+
account: 'admin',
18+
birthday: '0',
19+
certificatesNumber: null,
20+
certificatesType: null,
21+
description: null,
22+
education: null,
23+
24+
entryDate: '0',
25+
firstLoginIp: '127.0.0.1',
26+
firstLoginTime: '1635295040000',
27+
gender: 1,
28+
headIcon: null,
29+
id: '1',
30+
lastChangePasswordDate: '0',
31+
lastLoginIp: '218.29.222.2',
32+
lastLoginTime: '1680251906531',
33+
loginAppFlag: 1,
34+
managerUid: null,
35+
mobilePhone: '13311112222',
36+
nation: null,
37+
nativePlace: null,
38+
nickName: null,
39+
postalAddress: null,
40+
prevLoginIp: '218.29.222.2',
41+
prevLoginTime: '1680250497020',
42+
propertyJson: null,
43+
quickQuery: null,
44+
realName: '超级管理员',
45+
signature: null,
46+
sortNum: '35.00',
47+
sourceType: 1,
48+
sysFlag: 0,
49+
sysTheme: null,
50+
telephone: null,
51+
tokenInfo: {
52+
tokenName: 'token',
53+
tokenValue: 'f788bd14187c4735a5331e44a2aa558a',
54+
},
55+
urgentContacts: null,
56+
urgentTelephone: null,
57+
workStatus: 2,
58+
},
59+
msg: '操作成功',
60+
success: true,
61+
}),
62+
} as mockService;

src/mock/service/types.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* @Author: wangguixing [email protected]
3+
* @Date: 2023-04-01 01:00:22
4+
* @LastEditors: wangguixing [email protected]
5+
* @LastEditTime: 2023-04-01 01:04:11
6+
* @FilePath: \arcro-vue\src\mock\service\types.ts
7+
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8+
*/
9+
export interface mockService {
10+
url: string;
11+
method: string;
12+
response: () => {
13+
code: number;
14+
data: unknown;
15+
msg: string;
16+
success: boolean;
17+
};
18+
}

0 commit comments

Comments
 (0)