更新 mock 设置

Former-commit-id: 91e149862bc5c5994005c16b8921d293347c935e [formerly cc5c1b4e89e4c0bd2a86ced9e4dd4ac30cf69ad4] [formerly 91e149862bc5c5994005c16b8921d293347c935e [formerly cc5c1b4e89e4c0bd2a86ced9e4dd4ac30cf69ad4] [formerly 91e149862bc5c5994005c16b8921d293347c935e [formerly cc5c1b4e89e4c0bd2a86ced9e4dd4ac30cf69ad4] [formerly cc5c1b4e89e4c0bd2a86ced9e4dd4ac30cf69ad4 [formerly a995dd4aa6a5745242d449c1114d41592437d318 [formerly 84ceaffec1514357a65944b2b2af6ad55eed82cd]]]]]
Former-commit-id: 7fff6c3cca28a5b09ebbdb395fb250487bee6da3
Former-commit-id: ed647717531cb8a8d9ccb276c01986b5f8af7653
Former-commit-id: 7afd7c7718a1302fe0adc74bd06a1af0992fc305 [formerly fe10b57a2e3e9738867df9c88ec22d51d271891a]
Former-commit-id: 8ad7dd5c5e2ecf759e0ffd82e296658b5d735dd1
Former-commit-id: 289a192ca0d76c1e99dc1a9786a71580f705a1bd
Former-commit-id: 06de0f519d511e893333553a3a25d4388308e1b0
Former-commit-id: 0f21f9ff42abc15714f0622b0de1770509e19052
Former-commit-id: bbef35694d434bab48f2fcf49d7ae459fe7bff2b
This commit is contained in:
liyang
2018-12-13 10:29:56 +08:00
parent b1afe31a05
commit 56223d9195
10 changed files with 102 additions and 110 deletions

View File

@@ -2,7 +2,7 @@ import request from '@/plugin/axios'
export function get (id) { export function get (id) {
return request({ return request({
url: '/demo/business/issues/142', url: '/demo/business/issues/142/detail',
method: 'get', method: 'get',
params: { params: {
id id

View File

@@ -1,9 +1,9 @@
import request from '@/plugin/axios' import request from '@/plugin/axios'
export function BusinessTable1List (data) { export function BusinessTable1List (params) {
return request({ return request({
url: '/demo/business/table/1', url: '/demo/business/table/1/fetch',
method: 'post', method: 'get',
data params
}) })
} }

View File

@@ -5,8 +5,9 @@ const db = [
{ id: '4', name: '王小虎4', address: '上海市普陀区金沙江路 1516 弄' } { id: '4', name: '王小虎4', address: '上海市普陀区金沙江路 1516 弄' }
] ]
export default { export default [
path: RegExp('/api/demo/business/issues/142.*'), {
path: '/api/demo/business/issues/142/detail.*',
method: 'get', method: 'get',
handle ({ params }) { handle ({ params }) {
return { return {
@@ -16,3 +17,4 @@ export default {
} }
} }
} }
]

View File

@@ -1,15 +1,17 @@
export default { export default [
path: RegExp('/api/demo/business/table/1'), {
method: 'post', path: '/api/demo/business/table/1/fetch.*',
handle ({ body, Repeat }) { method: 'get',
const { page } = body handle ({ params, Repeat }) {
page.total = 1000 let { pageSize } = params
return { return {
code: 0, code: 0,
msg: '获取数据成功', msg: '获取数据成功',
data: { data: {
page, page: {
list: Repeat(page.size, { total: 1000
},
list: Repeat(pageSize, {
'key': '@guid', 'key': '@guid',
'value|1': [10, 100, 200, 500], 'value|1': [10, 100, 200, 500],
'type': '@boolean', 'type': '@boolean',
@@ -23,3 +25,4 @@ export default {
} }
} }
} }
]

View File

@@ -1,5 +1,6 @@
export default { export default [
path: RegExp('/api/demo/plugins/mock/ajax'), {
path: '/api/demo/plugins/mock/ajax',
method: 'get', method: 'get',
handle ({ Repeat }) { handle ({ Repeat }) {
return { return {
@@ -19,3 +20,4 @@ export default {
} }
} }
} }
]

View File

@@ -1,26 +1,12 @@
const userDB = [ const userDB = [
{ { username: 'admin', password: 'admin', uuid: 'admin-uuid', name: '管理员' },
username: 'admin', { username: 'editor', password: 'editor', uuid: 'editor-uuid', name: '编辑' },
password: 'admin', { username: 'user1', password: 'user1', uuid: 'user1-uuid', name: '用户1' }
uuid: 'admin-uuid',
name: '管理员'
},
{
username: 'editor',
password: 'editor',
uuid: 'editor-uuid',
name: '编辑'
},
{
username: 'user1',
password: 'user1',
uuid: 'user1-uuid',
name: '用户1'
}
] ]
export default { export default [
path: RegExp('/api/login'), {
path: '/api/login',
method: 'post', method: 'post',
handle ({ body }) { handle ({ body }) {
const user = userDB.find(e => e.username === body.username && e.password === body.password) const user = userDB.find(e => e.username === body.username && e.password === body.password)
@@ -30,7 +16,7 @@ export default {
msg: '登录成功', msg: '登录成功',
data: { data: {
...user, ...user,
token: 'd787syv8dys8cas80d9s0a0d8f79ads56f7s4d56f879a8as89fd980s7dg' token: '8dfhassad0asdjwoeiruty'
} }
} }
} else { } else {
@@ -42,3 +28,4 @@ export default {
} }
} }
} }
]

View File

@@ -1,24 +1,21 @@
import Mock from 'mockjs' import Mock from 'mockjs'
import qs from 'qs' import qs from 'qs'
import patch from './patch' import withCredentials from './patch/withCredentials'
/* 补丁 */ /* 补丁 */
patch(Mock) withCredentials(Mock)
/* Mock 默认配置 */ /* Mock 默认配置 */
Mock.setup({ timeout: '200-300' }) Mock.setup({ timeout: '200-300' })
/* 扩展 */ /* 扩展 [生成器] */
const Generator = (prop, template) => { const Generator = (prop, template) => {
const obj = {} const obj = {}
obj[prop] = [template] obj[prop] = [template]
return Mock.mock(obj) return Mock.mock(obj)
} }
/* 扩展 */ /* 扩展 [循环] */
const Repeat = (num, itemTemplate) => Generator(`data|${num}`, itemTemplate).data const Repeat = (num, itemTemplate) => Generator(`data|${num}`, itemTemplate).data
const CustomExtends = { const CustomExtends = {
@@ -33,7 +30,6 @@ const extend = (prop, value) => {
} }
/* 装配配置组 */ /* 装配配置组 */
const wired = ({ url, type, body }) => ({ const wired = ({ url, type, body }) => ({
method: type, method: type,
params: qs.parse(url.split('?').length > 1 ? url.split('?')[1] : ''), params: qs.parse(url.split('?').length > 1 ? url.split('?')[1] : ''),
@@ -44,7 +40,7 @@ const wired = ({ url, type, body }) => ({
const setup = (path, method, handle) => { const setup = (path, method, handle) => {
Mock.mock( Mock.mock(
path, RegExp(path),
method, method,
typeof handle === 'function' ? o => handle(wired(o)) : handle typeof handle === 'function' ? o => handle(wired(o)) : handle
) )

View File

@@ -5,4 +5,6 @@ const options = req(require.context('./api/', true, /\.js$/))
.filter(e => e.default) .filter(e => e.default)
.map(e => e.default) .map(e => e.default)
d2Mock.load(options) options.forEach(option => {
d2Mock.load(option)
})

View File

@@ -9,9 +9,9 @@
:loading="loading"/> :loading="loading"/>
<demo-page-footer <demo-page-footer
slot="footer" slot="footer"
:current="page.current" :current="page.pageCurrent"
:size="page.size" :size="page.pageSize"
:total="page.total" :total="page.pageTotal"
@change="handlePaginationChange"/> @change="handlePaginationChange"/>
</d2-container> </d2-container>
</template> </template>
@@ -32,9 +32,9 @@ export default {
table: [], table: [],
loading: false, loading: false,
page: { page: {
current: 1, pageCurrent: 1,
size: 10, pageSize: 10,
total: 0 pageTotal: 0
} }
} }
}, },
@@ -57,7 +57,7 @@ export default {
}) })
BusinessTable1List({ BusinessTable1List({
...form, ...form,
page: this.page ...this.page
}) })
.then(res => { .then(res => {
this.loading = false this.loading = false
@@ -65,7 +65,7 @@ export default {
title: '模拟表格数据请求完毕' title: '模拟表格数据请求完毕'
}) })
this.table = res.list this.table = res.list
this.page = res.page this.page.pageTotal = res.page.total
}) })
.catch(err => { .catch(err => {
this.loading = false this.loading = false