Skip to content

Commit

Permalink
feat(mock): Add mock
Browse files Browse the repository at this point in the history
  • Loading branch information
kailong321200875 committed Jan 8, 2022
1 parent 357fc44 commit 3fc7d4d
Show file tree
Hide file tree
Showing 20 changed files with 354 additions and 67 deletions.
15 changes: 15 additions & 0 deletions mock/_createProductionServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer'

const modules = import.meta.globEager('./**/*.ts')

const mockModules: any[] = []
Object.keys(modules).forEach((key) => {
if (key.includes('_')) {
return
}
mockModules.push(...modules[key].default)
})

export function setupProdMockServer() {
createProdMockServer(mockModules)
}
51 changes: 51 additions & 0 deletions mock/user/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { config } from '@/config/axios'
import { MockMethod } from 'vite-plugin-mock'

const { result_code } = config

const List: {
username: string
password: string
role: string
roleId: string
}[] = [
{
username: 'admin',
password: 'admin',
role: 'admin',
roleId: '1'
},
{
username: 'test',
password: 'test',
role: 'test',
roleId: '2'
}
]

export default [
// 登录接口
{
url: '/user/login',
method: 'post',
response: ({ body }) => {
const data = body
let hasUser = false
for (const user of List) {
if (user.username === data.username && user.password === data.password) {
hasUser = true
return {
code: result_code,
data: user
}
}
}
if (!hasUser) {
return {
code: '500',
message: '账号或密码错误'
}
}
}
}
] as MockMethod[]
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
"@vueuse/core": "^7.5.1",
"@zxcvbn-ts/core": "^1.2.0",
"animate.css": "^4.1.1",
"axios": "^0.24.0",
"element-plus": "1.3.0-beta.1",
"lodash-es": "^4.17.21",
"mockjs": "^1.1.0",
"pinia": "^2.0.9",
"qs": "^6.10.2",
"vue": "3.2.26",
"vue-i18n": "9.1.9",
"vue-router": "^4.0.12",
Expand Down
128 changes: 83 additions & 45 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3fc7d4d

Please sign in to comment.