import { MockRequest , MockStatusError } from '@delon/mock' ; const list = [ ] ; const total = 50 ; for ( let i = 0 ; i < total ; i += 1 ) { list . push ( { id : i + 1 , disabled : i % 6 === 0 , href : 'https://ant.design' , avatar : [ 'https://gw.alipayobjects.com/zos/rmsportal/eeHMaZBwmTvLdIwMfBpg.png' , 'https://gw.alipayobjects.com/zos/rmsportal/udxAbMEhpwthVVcjLXik.png' , ] [ i % 2 ] , no : `TradeCode ${ i }` , title : `一个任务名称 ${ i }` , owner : '曲丽丽' , description : '这是一段描述' , callNo : Math . floor ( Math . random ( ) * 1000 ) , status : Math . floor ( Math . random ( ) * 10 ) % 4 , updatedAt : new Date ( `2017-07-${ Math . floor ( i / 2 ) + 1 }` ) , createdAt : new Date ( `2017-07-${ Math . floor ( i / 2 ) + 1 }` ) , progress : Math . ceil ( Math . random ( ) * 100 ) , } ) ; } function genData ( params ) { let ret = [ ... list ] ; const pi = + params . pi , ps = + params . ps , start = ( pi - 1 ) * ps ; if ( params . no ) { ret = ret . filter ( data => data . no . indexOf ( params . no ) > - 1 ) ; } return { total : ret . length , list : ret . slice ( start , ps * pi ) } ; } function saveData ( id , value ) { const item = list . find ( w => w . id === id ) ; if ( ! item ) { return { msg : '无效用户信息' } ; } Object . assign ( item , value ) ; return { msg : 'ok' } ; } export const USERS = { '/user' : ( req ) => genData ( req . queryString ) , '/user/:id' : ( req ) => list . find ( w => w . id === + req . params . id ) , 'POST /user/:id' : ( req ) => saveData ( + req . params . id , req . body ) , 'GET /users' : { users : [ 1 , 2 ] , total : 2 } , 'POST /users/1' : { uid : 1 } , '/qs' : ( req ) => req . queryString . pi , '/users/:id' : ( req ) => req . params , '/404' : ( ) => { throw new MockStatusError ( 404 ) ; } , } ;