1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import { config } from '@/config/axios/config'
- import { MockMethod } from 'vite-plugin-mock'
- import { toAnyString } from '@/utils'
- import Mock from 'mockjs'
- const { result_code } = config
- const timeout = 1000
- const count = 100
- const baseContent =
- '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
- const List: {
- id: string
- author: string
- title: string
- content: string
- importance: number
- display_time: string
- pageviews: number
- }[] = []
- for (let i = 0; i < count; i++) {
- List.push(
- Mock.mock({
- id: toAnyString(),
- // timestamp: +Mock.Random.date('T'),
- author: '@first',
- title: '@title(5, 10)',
- content: baseContent,
- importance: '@integer(1, 3)',
- display_time: '@datetime',
- pageviews: '@integer(300, 5000)'
- // image_uri
- })
- )
- }
- export default [
- // 登录接口
- {
- url: '/example/list',
- method: 'get',
- timeout,
- response: ({ query }) => {
- const { title, pageIndex, pageSize } = query
- const mockList = List.filter((item) => {
- if (title && item.title.indexOf(title) < 0) return false
- return true
- })
- const pageList = mockList.filter(
- (_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
- )
- return {
- code: result_code,
- data: {
- total: mockList.length,
- list: pageList
- }
- }
- }
- }
- ] as MockMethod[]
|