| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- const { Random } = require('mockjs')
- const { getDB, saveDB } = require('../utils')
- const db = getDB('program')
- function save () {
- saveDB('program', db)
- }
- module.exports = [
- {
- url: '/item/listByPage',
- type: 'post',
- response: config => {
- const { name = '', currentPage = 1, pageCount = 10 } = config.body
- if (currentPage < 1) {
- return {
- success: false,
- errMessage: '参数错误'
- }
- }
- const list = name ? db.filter(item => ~item.name.indexOf(name)) : db
- const start = (currentPage - 1) * pageCount
- return {
- success: true,
- data: list.slice(start, start + pageCount),
- totalCount: list.length
- }
- }
- },
- {
- url: '/item/getById/:id',
- type: 'get',
- response: config => {
- const { id } = config.params
- const program = db.find(item => item.id === id)
- if (!program) {
- return {
- success: false,
- errMessage: '节目不存在'
- }
- }
- return {
- success: true,
- data: program
- }
- }
- },
- {
- url: '/item/add',
- type: 'post',
- response: config => {
- const { name, resolutionRatio } = config.body
- const layout = {
- id: Random.id(),
- name,
- resolutionRatio,
- createTime: Random.now('yyyy-MM-dd HH:mm:ss')
- }
- db.unshift(layout)
- save()
- return {
- success: true,
- data: layout.id
- }
- }
- },
- {
- url: '/item/delete',
- type: 'get',
- response: config => {
- const { id } = config.query
- const index = db.findIndex(item => item.id === id)
- if (~index) {
- db.splice(index, 1)
- save()
- }
- return {
- success: true
- }
- }
- },
- {
- url: '/item/update',
- type: 'post',
- response: config => {
- const { id, itemJsonStr } = config.body
- const index = db.findIndex(item => item.id === id)
- if (~index) {
- db[index].itemJsonStr = itemJsonStr
- db.unshift(db.splice(index, 1)[0])
- save()
- }
- return {
- success: true
- }
- }
- }
- ]
|