Blame view

mock/remote-search.js 1.04 KB
d7d9c38c2   Adam   auto commit the c...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  import Mock from 'mockjs'
  
  const NameList = []
  const count = 100
  
  for (let i = 0; i < count; i++) {
    NameList.push(Mock.mock({
      name: '@first'
    }))
  }
  NameList.push({ name: 'mock-Pan' })
  
  export default [
    // username search
    {
50760eab9   Adam   auto commit the c...
16
      url: '/yp/search/user',
d7d9c38c2   Adam   auto commit the c...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
      type: 'get',
      response: config => {
        const { name } = config.query
        const mockNameList = NameList.filter(item => {
          const lowerCaseName = item.name.toLowerCase()
          return !(name && lowerCaseName.indexOf(name.toLowerCase()) < 0)
        })
        return {
          code: 20000,
          data: { items: mockNameList }
        }
      }
    },
  
    // transaction list
    {
50760eab9   Adam   auto commit the c...
33
      url: '/yp/transaction/list',
d7d9c38c2   Adam   auto commit the c...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
      type: 'get',
      response: _ => {
        return {
          code: 20000,
          data: {
            total: 20,
            'items|20': [{
              order_no: '@guid()',
              timestamp: +Mock.Random.date('T'),
              username: '@name()',
              price: '@float(1000, 15000, 0, 2)',
              'status|1': ['success', 'pending']
            }]
          }
        }
      }
    }
  ]