select-demo.ts 901 B

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