Skip to content

Commit 0a933bb

Browse files
committed
Feat: Support mock server
1 parent b888044 commit 0a933bb

File tree

22 files changed

+1931
-1283
lines changed

22 files changed

+1931
-1283
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VITE_APP_PUBLIC_PATH=/
2+
VITE_APP_PREVIEW=true
3+
VITE_APP_API_BASE_URL=/api

.env.development

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
VITE_APP_PREVIEW=true
2+
VITE_APP_API_BASE_URL=/api
3+
VITE_MOCK=true
4+
VITE_HTTP_MOCK=true

.env.production

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
NODE_ENV=production
2+
VITE_APP_PREVIEW=false
3+
VITE_APP_API_URL=/api

.umirc.mock.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
...require('./mock/index'),
3+
// 这里可以引入任意的mock文件,位置也随意。
4+
}

build/mockServer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createMockMiddleware } from 'umi-mock-middleware'
2+
import express from 'express'
3+
const createMockServer = () => {
4+
const mockTarget = `http://127.0.0.1:${process.env.MOCK_SERVER_PORT}`
5+
const app = express()
6+
app.use(createMockMiddleware())
7+
app.listen(process.env.MOCK_SERVER_PORT, () => {
8+
console.log(`Mock Server listening at ${mockTarget}`)
9+
})
10+
return mockTarget
11+
}
12+
13+
export default createMockServer

mock/dashboard/workplace.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
const getNotice = { name: 'Hello world' }
4+
5+
module.exports = {
6+
'GET /api/project/notice': getNotice
7+
}

mock/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const dashboardWorkplace = require('./dashboard/workplace.js')
2+
3+
module.exports = {
4+
...dashboardWorkplace
5+
}

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
{
22
"name": "vue3-vant-mobile",
3-
"private": true,
43
"version": "0.2.0",
54
"scripts": {
6-
"dev": "vite",
5+
"dev": "cross-env MOCK_SERVER_PORT=8086 vite",
76
"build": "vue-tsc --noEmit && vite build",
87
"preview": "vite preview"
98
},
109
"dependencies": {
1110
"@vant/touch-emulator": "^1.3.2",
11+
"axios": "^0.27.2",
1212
"nprogress": "^0.2.0",
1313
"pinia": "^2.0.14",
14+
"store": "^2.0.12",
1415
"vant": "^3.4.9",
1516
"vconsole": "^3.14.6",
1617
"vue": "^3.2.25",
1718
"vue-router": "^4.0.15"
1819
},
1920
"devDependencies": {
21+
"@types/express": "^4.17.13",
22+
"@types/node": "^17.0.36",
2023
"@types/nprogress": "^0.2.0",
24+
"@types/store": "^2.0.2",
2125
"@vitejs/plugin-vue": "^2.3.3",
26+
"chokidar": "^3.5.3",
27+
"cross-env": "^7.0.3",
28+
"express": "4.17.3",
29+
"glob": "^8.0.3",
2230
"less": "^4.1.2",
23-
"postcss-preset-env": "^7.6.0",
31+
"mockjs": "^1.1.0",
2432
"postcss-px-to-viewport": "^1.1.1",
2533
"typescript": "^4.5.4",
34+
"umi-mock-middleware": "^1.0.0",
2635
"vite": "^2.9.9",
2736
"vite-plugin-style-import": "1.4.1",
2837
"vue-tsc": "^0.34.7"

postcss.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// postcss.config.js
22
module.exports = {
33
plugins: {
4-
'postcss-preset-env': {},
54
'postcss-px-to-viewport': {
65
viewportWidth: 375
76
}

src/api/dashboard/workplace.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import request from '@/utils/request'
2+
3+
export async function queryProjectNotice(): Promise<any> {
4+
return request('/project/notice')
5+
}

0 commit comments

Comments
 (0)