mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-21 15:04:26 +00:00
32 lines
767 B
JavaScript
32 lines
767 B
JavaScript
const { config, posts } = require('./common')
|
|
|
|
const { apiPrefix } = config
|
|
let database = posts
|
|
|
|
module.exports = {
|
|
|
|
[`GET ${apiPrefix}/posts`] (req, res) {
|
|
const { query } = req
|
|
let { pageSize, page, ...other } = query
|
|
pageSize = pageSize || 10
|
|
page = page || 1
|
|
|
|
let newData = database
|
|
for (let key in other) {
|
|
if ({}.hasOwnProperty.call(other, key)) {
|
|
newData = newData.filter((item) => {
|
|
if ({}.hasOwnProperty.call(item, key)) {
|
|
return String(item[key]).trim().indexOf(decodeURI(other[key]).trim()) > -1
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
}
|
|
|
|
res.status(200).json({
|
|
data: newData.slice((page - 1) * pageSize, page * pageSize),
|
|
total: newData.length,
|
|
})
|
|
},
|
|
}
|