refine code

This commit is contained in:
Pan
2019-03-18 18:07:55 +08:00
parent c93d88a348
commit 8b382e1e15
13 changed files with 167 additions and 165 deletions

View File

@@ -13,7 +13,7 @@ for (let i = 0; i < count; i++) {
author: '@first',
reviewer: '@first',
title: '@title(5, 10)',
content_short: '我是测试数据',
content_short: 'mock data',
content: baseContent,
forecast: '@float(0, 100, 2, 2)',
importance: '@integer(1, 3)',

View File

@@ -1,10 +1,10 @@
import login from './login'
import user from './user'
import role from './role'
import article from './article'
import search from './remoteSearch'
export default [
...login,
...user,
...role,
...article,
...search

View File

@@ -8,9 +8,10 @@ for (let i = 0; i < count; i++) {
name: '@first'
}))
}
NameList.push({ name: 'mockPan' })
NameList.push({ name: 'mock-Pan' })
export default [
// username search
{
url: '/search/user',
type: 'get',
@@ -23,14 +24,15 @@ export default [
return { items: mockNameList }
}
},
// transaction list
{
url: '/transaction/list',
type: 'get',
response: _ => {
const count = 20
return {
total: count,
[`items|${count}`]: [{
total: 20,
'items|20': [{
order_no: '@guid()',
timestamp: +Mock.Random.date('T'),
username: '@name()',

View File

@@ -1,48 +1,57 @@
const userMap = {
const tokens = {
admin: {
token: 'admin-token'
},
editor: {
token: 'editor-token'
}
}
const users = {
'admin-token': {
roles: ['admin'],
token: 'admin',
introduction: '我是超级管理员',
introduction: 'I am a super administrator',
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
name: 'Super Admin'
},
editor: {
'editor-token': {
roles: ['editor'],
token: 'editor',
introduction: '我是编辑',
introduction: 'I am an editor',
avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
name: 'Normal Editor'
}
}
export default [
// user login
{
url: '/login/login',
url: '/user/login',
type: 'post',
response: config => {
const { username } = config.body
return userMap[username]
return tokens[username]
}
},
// get user info
{
url: '/login/logout',
url: '/user/info\.*',
type: 'get',
response: config => {
const { token } = config.query
return users[token]
}
},
// user logout
{
url: '/user/logout',
type: 'post',
response: _ => {
return {
data: 'success'
}
}
},
{
url: '/user/info\.*',
type: 'get',
response: config => {
const { token } = config.query
if (userMap[token]) {
return userMap[token]
} else {
return false
}
}
}
]