Skip to content

Commit 058a4ee

Browse files
committed
feat: add base mock
1 parent 8c3fd48 commit 058a4ee

File tree

8 files changed

+488
-13
lines changed

8 files changed

+488
-13
lines changed

β€Žpackage.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"lodash.get": "^4.4.2",
2121
"lodash.pick": "^4.4.0",
2222
"md5": "^2.2.1",
23+
"mockjs": "^1.0.1-beta3",
2324
"moment": "^2.24.0",
2425
"nprogress": "^0.2.0",
2526
"viser-vue": "^2.3.3",
@@ -48,10 +49,10 @@
4849
"eslint-plugin-vue": "^5.0.0",
4950
"less": "^3.8.1",
5051
"less-loader": "^4.1.0",
51-
"vue-svg-icon-loader": "^2.1.1",
52-
"vue-template-compiler": "^2.5.22",
5352
"opencollective": "^1.0.3",
54-
"opencollective-postinstall": "^2.0.2"
53+
"opencollective-postinstall": "^2.0.2",
54+
"vue-svg-icon-loader": "^2.1.1",
55+
"vue-template-compiler": "^2.5.22"
5556
},
5657
"eslintConfig": {
5758
"root": true,
@@ -128,4 +129,4 @@
128129
"type": "opencollective",
129130
"url": "https://opencollective.com/ant-design-pro-vue"
130131
}
131-
}
132+
}

β€Žsrc/main.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import './utils/filter' // global filter
1414

1515
Vue.config.productionTip = false
1616

17+
// mock
18+
if (process.env.NODE_ENV !== 'production' || process.env.VUE_APP_PREVIEW === 'true') {
19+
import('./mock')
20+
}
21+
1722
// mount axios Vue.$http and this.$http
1823
Vue.use(VueAxios)
1924

β€Žsrc/mock/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Mock from 'mockjs'
2+
3+
import './services/auth'
4+
import './services/user'
5+
6+
Mock.setup({
7+
timeout: 800 // setter delay time
8+
})

β€Žsrc/mock/services/auth.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Mock from 'mockjs'
2+
import { builder, getBody } from '../util'
3+
4+
const username = ['admin', 'user', 'super']
5+
const password = ['21232f297a57a5a743894a0e4a801fc3', '8914de686ab28dc22f30d3d8e107ff6c'] // admin, ant.design
6+
7+
const login = (options) => {
8+
const body = getBody(options)
9+
console.log('mock: body', body)
10+
if (!username.includes(body.username) || !password.includes(body.password)) {
11+
return builder({}, 'θ΄¦ζˆ·ζˆ–ε―†η ι”™θ――', 401)
12+
}
13+
14+
return builder({
15+
'id': Mock.mock('@guid'),
16+
'name': Mock.mock('@name'),
17+
'username': 'admin',
18+
'password': '',
19+
'avatar': 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
20+
'status': 1,
21+
'telephone': '',
22+
'lastLoginIp': '27.154.74.117',
23+
'lastLoginTime': 1534837621348,
24+
'creatorId': 'admin',
25+
'createTime': 1497160610259,
26+
'deleted': 0,
27+
'roleId': 'admin',
28+
'lang': 'zh-CN',
29+
'token': '4291d7da9005377ec9aec4a71ea837f'
30+
}, '', 200, { 'Custom-Header': Mock.mock('@guid') })
31+
}
32+
33+
const logout = () => {
34+
return builder({}, '[ζ΅‹θ―•ζŽ₯口] ζ³¨ι”€ζˆεŠŸ')
35+
}
36+
37+
Mock.mock(/\/auth\/login/, 'post', login)
38+
Mock.mock(/\/auth\/logout/, 'post', logout)

0 commit comments

Comments
Β (0)