diff --git a/mock/users.js b/mock/users.js index e168aa1..eb7bf79 100644 --- a/mock/users.js +++ b/mock/users.js @@ -1,10 +1,10 @@ -'use strict'; +'use strict' -const qs = require('qs'); -const mockjs = require('mockjs'); +const qs = require('qs') +const mockjs = require('mockjs') // 数据持久 -let tableListData = {}; +let tableListData = {} if (!global.tableListData) { const data = mockjs.mock({ 'data|100': [{ @@ -17,43 +17,43 @@ if (!global.tableListData) { total: 100, current: 1 } - }); - tableListData = data; - global.tableListData = tableListData; + }) + tableListData = data + global.tableListData = tableListData } else { - tableListData = global.tableListData; + tableListData = global.tableListData } module.exports = { 'GET /api/users' (req, res) { - const page = qs.parse(req.query); - const pageSize = page.pageSize || 10; - const currentPage = page.page || 1; + const page = qs.parse(req.query) + const pageSize = page.pageSize || 10 + const currentPage = page.page || 1 - let data; - let newPage; + let data + let newPage - let newData = tableListData.data.concat(); + let newData = tableListData.data.concat() if (page.field) { const d = newData.filter(function (item) { - return item[page.field].indexOf(page.keyword) > -1; - }); + return item[page.field].indexOf(page.keyword) > -1 + }) - data = d.slice((currentPage - 1) * pageSize, currentPage * pageSize); + data = d.slice((currentPage - 1) * pageSize, currentPage * pageSize) newPage = { current: currentPage * 1, total: d.length - }; + } } else { - data = tableListData.data.slice((currentPage - 1) * pageSize, currentPage * pageSize); - tableListData.page.current = currentPage * 1; + data = tableListData.data.slice((currentPage - 1) * pageSize, currentPage * pageSize) + tableListData.page.current = currentPage * 1 newPage = { current: tableListData.page.current, total: tableListData.page.total - }; + } } @@ -62,69 +62,69 @@ module.exports = { success: true, data, page: newPage - }); - }, 500); + }) + }, 500) }, 'POST /api/users' (req, res) { setTimeout(function () { - const newData = qs.parse(req.body); + const newData = qs.parse(req.body) - newData.id = tableListData.data.length + 1; - tableListData.data.unshift(newData); + newData.id = tableListData.data.length + 1 + tableListData.data.unshift(newData) - tableListData.page.total = tableListData.data.length; - tableListData.page.current = 1; + tableListData.page.total = tableListData.data.length + tableListData.page.current = 1 - global.tableListData = tableListData; + global.tableListData = tableListData res.json({ success: true, data: tableListData.data, page: tableListData.page - }); - }, 500); + }) + }, 500) }, 'DELETE /api/users' (req, res) { setTimeout(function () { - const deleteItem = qs.parse(req.body); + const deleteItem = qs.parse(req.body) tableListData.data = tableListData.data.filter(function (item) { if (item.id == deleteItem.id) { - return false; + return false } - return true; - }); + return true + }) - tableListData.page.total = tableListData.data.length; + tableListData.page.total = tableListData.data.length - global.tableListData = tableListData; + global.tableListData = tableListData res.json({ success: true, data: tableListData.data, page: tableListData.page - }); - }, 500); + }) + }, 500) }, 'PUT /api/users' (req, res) { setTimeout(function () { - const editItem = qs.parse(req.body); + const editItem = qs.parse(req.body) tableListData.data = tableListData.data.map(function (item) { if (item.id == editItem.id) { - return editItem; + return editItem } - return item; - }); + return item + }) - global.tableListData = tableListData; + global.tableListData = tableListData res.json({ success: true, data: tableListData.data, page: tableListData.page - }); - }, 500); + }) + }, 500) } -}; +} diff --git a/src/components/Example.js b/src/components/Example.js deleted file mode 100644 index a9bc7a0..0000000 --- a/src/components/Example.js +++ /dev/null @@ -1,14 +0,0 @@ -import React from 'react'; - -const Example = (props) => { - return ( -