schoollist.js 1.33 KB
import { getUrlParams } from './utils';

export function schoolList(count,filter) {
  const list = [];
  for (let i = 0; i < count; i += 1) {
    var temp = new String(i);
    if((!filter)|| temp.indexOf(filter)>=0){
      list.push({
        key: i,
        id: `fake-list-${i}`,
        name:`学校名字-${i}`,
        corp:`wx_xxxx111100111_${i}`,
        schoolCode:`sch_000111234${i}`,
        showArea:`address_xxxx-${i}`,
        code:`sch_000111234${i}`,
        avatar:'XXX',
        updatedAt: new Date(new Date().getTime() - (1000 * 60 * 60 * 2 * i)),
        createdAt: new Date(new Date().getTime() - (1000 * 60 * 60 * 2 * i)),
      });
    }
  }
  return list;
}


export function getSchoolLists(req, res, u) {
    let url = u;
    if (!url || Object.prototype.toString.call(url) !== '[object String]') {
      url = req.url; // eslint-disable-line
    }
  
    const params = getUrlParams(url);
  
    console.log('server side recevice params:')
    console.log(url);
    console.log(params);

    const pageSize = (params.pageSize * 1) || 10;
  
    const result = schoolList(100,params.name);
  
    if (res && res.json) {
      res.json({'list':result,'pagination': {
        'total': result.length,
        'pageSize':pageSize,
        'current': parseInt(params.currentPage, 10) || 1,
      },});
    } else {
      return result;
    }
  }