| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- const { Random } = require('mockjs')
- const { getDB, saveDB } = require('../utils')
- const db = getDB('schedule')
- function save () {
- saveDB('schedule', db)
- }
- module.exports = [
- {
- url: '/scheduling/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: '/scheduling/detail',
- type: 'get',
- response: config => {
- const { id } = config.query
- const schedule = db.find(item => item.id === id)
- if (!schedule) {
- return {
- success: false,
- errMessage: '排期不存在'
- }
- }
- return {
- success: true,
- data: schedule
- }
- }
- },
- {
- url: '/scheduling/add',
- type: 'post',
- response: config => {
- const { name, resolutionRatio } = config.body
- const layout = {
- id: Random.id(),
- name,
- resolutionRatio,
- status: 0,
- schedulingStatus: 0,
- createTime: Random.now('yyyy-MM-dd HH:mm:ss'),
- programs: []
- }
- db.unshift(layout)
- save()
- return {
- success: true,
- data: layout.id
- }
- }
- },
- {
- url: '/scheduling/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: '/scheduling/update',
- type: 'post',
- response: config => {
- const { id, programs } = config.body
- const index = db.findIndex(item => item.id === id)
- if (~index) {
- db[index].timestamp = Random.now('yyyy-MM-dd HH:mm:ss')
- db[index].programs = programs
- db.unshift(db.splice(index, 1)[0])
- save()
- }
- return {
- success: true,
- }
- }
- }
- ]
|