select-demo.ts
913 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { MockMethod } from 'vite-plugin-mock';
import { resultSuccess, baseUrl } from '../_util';
const demoList = (keyword, count = 20) => {
const result = {
list: [] as any[],
};
for (let index = 0; index < count; index++) {
//根据搜索关键词做一下匹配
const name = `选项${index}`;
if (keyword && name.indexOf(keyword) != -1) {
result.list.push({
name: `选项${index}`,
id: `${index}`,
});
} else if (!keyword) {
result.list.push({
name: `选项${index}`,
id: `${index}`,
});
}
}
return result;
};
export default [
{
url: `${baseUrl}/select/getDemoOptions`,
timeout: 1000,
method: 'get',
response: ({ query }) => {
const { keyword, count } = query;
console.log('查询条件:', keyword);
return resultSuccess(demoList(keyword, count));
},
},
] as MockMethod[];