Skip to content

Commit 9c48bf3

Browse files
luoqilingluoqiling
luoqiling
authored and
luoqiling
committed
优化
1 parent 4da1943 commit 9c48bf3

File tree

5 files changed

+429
-272
lines changed

5 files changed

+429
-272
lines changed

mock/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ const chokidar = require('chokidar')
22
const bodyParser = require('body-parser')
33
const chalk = require('chalk')
44
const path = require('path')
5-
const Mock = require('mockjs')
65
const fs = require('fs')
76

87
const mockDir = path.join(process.cwd(), 'mock')
98

10-
const responseFake = (url, type, respond) => {
9+
const responseFake = (url, type, response) => {
1110
return {
1211
url: new RegExp(`${process.env.VUE_APP_BASE_API}${url}$`),
1312
// url: new RegExp(`/mock${url}$`),
1413
type: type || 'get',
15-
response(req, res) {
16-
res.json(Mock.mock(respond instanceof Function ? respond(req, res) : respond))
17-
}
14+
response
1815
}
1916
}
2017

mock/table.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ module.exports = [
1515
{
1616
url: '/table/list',
1717
type: 'get',
18-
response: config => {
18+
response: (req, res) => {
1919
const items = data.items
20-
return {
20+
res.send({
2121
data: {
2222
total: items.length,
2323
items: items
2424
},
2525
code: 200,
2626
msg: "成功",
2727
success: true
28-
}
28+
})
2929
}
3030
}
3131
]

mock/user.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,45 @@ module.exports = [
1919
{
2020
url: '/session/login',
2121
type: 'post',
22-
response: config => {
23-
const { mobile } = config.body
22+
response: (req, res) => {
23+
const { mobile } = req.body
2424
const token = users[mobile]
25-
26-
// mock error
27-
if (!token) {
28-
return {
29-
code: 60204,
30-
message: 'Account and password are incorrect.'
31-
}
32-
}
33-
34-
return {
25+
res.send(token ? {
3526
code: 200,
3627
data: token,
3728
msg: '成功',
3829
success: true
39-
}
30+
} : {
31+
code: 60204,
32+
message: 'Account and password are incorrect.'
33+
})
4034
}
4135
},
4236

4337
// user logout
4438
{
4539
url: '/session/logout',
4640
type: 'post',
47-
response: _ => {
48-
return {
41+
response: (req, res) => {
42+
res.send({
4943
code: 200,
5044
data: true,
5145
msg: '成功',
5246
success: true
53-
}
47+
})
5448
}
5549
},
5650

5751
{
5852
url: '/session/sendCode',
5953
type: 'post',
60-
response: _ => {
61-
return {
54+
response: (req, res) => {
55+
res.send({
6256
code: 200,
6357
data: true,
6458
msg: '成功',
6559
success: true
66-
}
60+
})
6761
}
6862
}
6963
]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@vue/cli-plugin-eslint": "^4.1.0",
4040
"@vue/cli-plugin-router": "^4.1.0",
4141
"@vue/cli-plugin-vuex": "^4.1.0",
42-
"@vue/cli-service": "^4.1.0",
42+
"@vue/cli-service": "^4.4.4",
4343
"@vue/eslint-config-standard": "^4.0.0",
4444
"babel-eslint": "^10.0.3",
4545
"chalk": "^3.0.0",

0 commit comments

Comments
 (0)