user mocj

This commit is contained in:
zuiidea
2017-04-28 16:34:08 +08:00
parent 30f14769f0
commit 5641cc61c4
2 changed files with 28 additions and 15 deletions
+26 -13
View File
@@ -129,24 +129,37 @@ module.exports = {
[`GET ${apiPrefix}/users`] (req, res) {
const { query } = req
const pageSize = query.pageSize || 10
const currentPage = query.page || 1
let { pageSize, page, ...other } = query
pageSize = pageSize || 10
page = page || 1
let data
let total
let newData = database
for (let key in other) {
if ({}.hasOwnProperty.call(other, key)) {
newData = newData.filter((item) => {
if ({}.hasOwnProperty.call(item, key)) {
if (key === 'address') {
return other[key].every(iitem => item[key].indexOf(iitem) > -1)
} else if (key === 'createTime') {
const start = new Date(other[key][0]).getTime()
const end = new Date(other[key][1]).getTime()
const now = new Date(item[key]).getTime()
if (query.field) {
const newData = database.filter((item) => item[query.field].indexOf(decodeURI(query.keyword)) > -1)
data = newData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
total = newData.length
} else {
data = database.slice((currentPage - 1) * pageSize, currentPage * pageSize)
total = database.length
if (start && end) {
return now >= start && now <= end
}
return true
}
return String(item[key]).trim().indexOf(decodeURI(other[key]).trim()) > -1
}
return true
})
}
}
res.status(200).json({
data,
total,
data: newData.slice((page - 1) * pageSize, page * pageSize),
total: newData.length,
})
},
+2 -2
View File
@@ -8,7 +8,7 @@ import UserModal from './UserModal'
const User = ({ location, dispatch, user, loading }) => {
const { list, pagination, currentItem, modalVisible, modalType, isMotion } = user
const { current, pageSize } = pagination
const { pageSize } = pagination
const userModalProps = {
item: modalType === 'create' ? {} : currentItem,
@@ -71,7 +71,7 @@ const User = ({ location, dispatch, user, loading }) => {
pathname: location.pathname,
query: {
...value,
page: current,
page: 1,
pageSize,
},
}))