Skip to content

Commit

Permalink
add eslint style for mock-folder
Browse files Browse the repository at this point in the history
  • Loading branch information
zuiidea committed Mar 17, 2017
1 parent ac6fdc5 commit 741ba9e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 58 deletions.
16 changes: 8 additions & 8 deletions mock/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import mockStorge from '../src/utils/mockStorge'
let dataKey = mockStorge('AdminUsers', [
{
username: 'guest',
password: 'guest'
password: 'guest',
},
{
username: '吴彦祖',
password: '123456'
}
password: '123456',
},
])

module.exports = {
'POST /api/login' (req, res) {
const userItem = req.body
const response = {
success: false,
message: ''
message: '',
}
const d = global[dataKey].filter(function (item) {
const d = global[dataKey].filter((item) => {
return item.username === userItem.username
})
if (d.length) {
Expand All @@ -43,7 +43,7 @@ module.exports = {
const response = {
success: Cookie.get('user_session') && Cookie.get('user_session') > new Date().getTime(),
username: Cookie.get('user_name') || '',
message: ''
message: '',
}
res.json(response)
},
Expand All @@ -53,7 +53,7 @@ module.exports = {
Cookie.remove('user_name', { path: '/' })
res.json({
success: true,
message: '退出成功'
message: '退出成功',
})
}
},
}
72 changes: 36 additions & 36 deletions mock/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {color} from '../src/utils/theme'
import { color } from '../src/utils/theme'
const Mock = require('mockjs')
import mockStorge from '../src/utils/mockStorge'

Expand All @@ -8,122 +8,122 @@ let dataKey = mockStorge('Dashboard', Mock.mock({
'name|+1': 2008,
'Clothes|200-500': 1,
'Food|180-400': 1,
'Electronics|300-550': 1
}
'Electronics|300-550': 1,
},
],
'cpu': {
cpu: {
'usage|50-600': 1,
space: 825,
'cpu|40-90': 1,
'data|20': [
{
'cpu|20-80': 1
}
]
'cpu|20-80': 1,
},
],
},
'browser': [
browser: [
{
name: 'Google Chrome',
percent: 43.3,
status: 1
status: 1,
},
{
name: 'Mozilla Firefox',
percent: 33.4,
status: 2
status: 2,
},
{
name: 'Apple Safari',
percent: 34.6,
status: 3
status: 3,
},
{
name: 'Internet Explorer',
percent: 12.3,
status: 4
status: 4,
},
{
name: 'Opera Mini',
percent: 3.3,
status: 1
status: 1,
},
{
name: 'Chromium',
percent: 2.53,
status: 1
}
status: 1,
},
],
user: {
name: 'zuiidea',
email: '[email protected]',
sales: 3241,
sold: 3556,
avatar: 'http://tva4.sinaimg.cn/crop.0.0.996.996.180/6ee6a3a3jw8f0ks5pk7btj20ro0rodi0.jpg'
avatar: 'http://tva4.sinaimg.cn/crop.0.0.996.996.180/6ee6a3a3jw8f0ks5pk7btj20ro0rodi0.jpg',
},
'completed|12': [
{
'name|+1': 2008,
'Task complete|200-1000': 1,
'Cards Complete|200-1000': 1
}
'Cards Complete|200-1000': 1,
},
],
'comments|5': [
{
name: '@last',
'status|1-3': 1,
content: '@sentence',
avatar: function () {
avatar () {
return Mock.Random.image('48x48', Mock.Random.color(), '#757575', 'png', this.name.substr(0, 1))
},
date: function () {
return '2016-' + Mock.Random.date('MM-dd') + ' ' + Mock.Random.time('HH:mm:ss')
}
}
date () {
return `2016-${Mock.Random.date('MM-dd')} ${Mock.Random.time('HH:mm:ss')}`
},
},
],
'recentSales|36': [
{
'id|+1': 1,
name: '@last',
'status|1-4': 1,
date: function () {
return Mock.Random.integer(2015, 2016) + '-' + Mock.Random.date('MM-dd') + ' ' + Mock.Random.time('HH:mm:ss')
date () {
return `${Mock.Random.integer(2015, 2016)}-${Mock.Random.date('MM-dd')} ${Mock.Random.time('HH:mm:ss')}`
},
'price|10-200.1-2': 1
}
'price|10-200.1-2': 1,
},
],
quote: {
name: 'Joho Doe',
title: 'Graphic Designer',
content: `I'm selfish, impatient and a little insecure. I make mistakes, I am out of control and at times hard to handle. But if you can't handle me at my worst, then you sure as hell don't deserve me at my best.`,
avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236'
content: 'I\'m selfish, impatient and a little insecure. I make mistakes, I am out of control and at times hard to handle. But if you can\'t handle me at my worst, then you sure as hell don\'t deserve me at my best.',
avatar: 'http://img.hb.aicdn.com/bc442cf0cc6f7940dcc567e465048d1a8d634493198c4-sPx5BR_fw236',
},
numbers: [
{
icon: 'pay-circle-o',
color: color.green,
title: 'Online Review',
number: 2781
number: 2781,
}, {
icon: 'team',
color: color.blue,
title: 'New Customers',
number: 3241
number: 3241,
}, {
icon: 'message',
color: color.purple,
title: 'Active Projects',
number: 253
number: 253,
}, {
icon: 'shopping-cart',
color: color.red,
title: 'Referrals',
number: 4324
}
]
number: 4324,
},
],
}))

module.exports = {
'GET /api/dashboard' (req, res) {
res.json(global[dataKey])
}
},
}
28 changes: 14 additions & 14 deletions mock/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ let dataKey = mockStorge('UsersList', Mock.mock({
isMale: '@boolean',
email: '@email',
createTime: '@datetime',
avatar: function () {
avatar () {
return Mock.Random.image('100x100', Mock.Random.color(), '#757575', 'png', this.nickName.substr(0, 1))
}
}
},
},
],
page: {
total: 100,
current: 1
}
current: 1,
},
}))

let usersListData = global[dataKey]
Expand All @@ -40,22 +40,22 @@ module.exports = {
let newData = usersListData.data.concat()

if (page.field) {
const d = newData.filter(function (item) {
const d = newData.filter((item) => {
return item[page.field].indexOf(decodeURI(page.keyword)) > -1
})

data = d.slice((currentPage - 1) * pageSize, currentPage * pageSize)

newPage = {
current: currentPage * 1,
total: d.length
total: d.length,
}
} else {
data = usersListData.data.slice((currentPage - 1) * pageSize, currentPage * pageSize)
usersListData.page.current = currentPage * 1
newPage = usersListData.page
}
res.json({success: true, data, page: {...newPage, pageSize: Number(pageSize)}})
res.json({ success: true, data, page: { ...newPage, pageSize: Number(pageSize) } })
},

'POST /api/users' (req, res) {
Expand All @@ -71,13 +71,13 @@ module.exports = {

global[dataKey] = usersListData

res.json({success: true, data: usersListData.data, page: usersListData.page})
res.json({ success: true, data: usersListData.data, page: usersListData.page })
},

'DELETE /api/users' (req, res) {
const deleteItem = req.body

usersListData.data = usersListData.data.filter(function (item) {
usersListData.data = usersListData.data.filter((item) => {
if (item.id === deleteItem.id) {
return false
}
Expand All @@ -88,7 +88,7 @@ module.exports = {

global[dataKey] = usersListData

res.json({success: true, data: usersListData.data, page: usersListData.page})
res.json({ success: true, data: usersListData.data, page: usersListData.page })
},

'PUT /api/users' (req, res) {
Expand All @@ -97,15 +97,15 @@ module.exports = {
editItem.createTime = Mock.mock('@now')
editItem.avatar = Mock.Random.image('100x100', Mock.Random.color(), '#757575', 'png', editItem.nickName.substr(0, 1))

usersListData.data = usersListData.data.map(function (item) {
usersListData.data = usersListData.data.map((item) => {
if (item.id === editItem.id) {
return editItem
}
return item
})

global[dataKey] = usersListData
res.json({success: true, data: usersListData.data, page: usersListData.page})
}
res.json({ success: true, data: usersListData.data, page: usersListData.page })
},

}

0 comments on commit 741ba9e

Please sign in to comment.