pest.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import request from '@/utils/request/index.js'
  2. import config from '@/config/config.js'
  3. import cache from '@/utils/cache'
  4. import {
  5. LOGIN_TOKEN
  6. } from '@/config/cache'
  7. /**
  8. * 病害监测模块
  9. */
  10. // 识别基类 (uni.request 对formData数据不支持,暂时先写成独立的基类,后期遇到好的方案可改进)
  11. export const baseDiscern = (url, img_file) => {
  12. return new Promise((resolve, reject) => {
  13. uni.uploadFile({
  14. url: config.baseUrl +
  15. 'api/api_gateway?method=pest.pests.' + url, //仅为示例,非真实的接口地址
  16. formData: {
  17. 'img_file': img_file,
  18. token: cache.get(LOGIN_TOKEN)
  19. },
  20. success: (res) => {
  21. let resule=JSON.parse(res.data ?? '{}')
  22. if(resule.message){
  23. uni.showToast({
  24. title:resule.message,
  25. duration: 1500,
  26. mask: true,
  27. icon: 'none'
  28. });
  29. return resolve(null);
  30. }
  31. resolve(resule.data);
  32. },
  33. fail:(e) =>{
  34. resolve(null);
  35. }
  36. });
  37. })
  38. }
  39. // 病虫害库
  40. export const loadPestList = async (data) => {
  41. const res = await request.post(`api/api_gateway?method=pest.pests.pests_info`, data);
  42. return res?.data;
  43. }
  44. // 虫害识别
  45. export const handleInsectDiscern = (img_file) => baseDiscern('insect_discern', img_file);
  46. // 病害识别
  47. export const handlePlantDiscern = (img_file) => baseDiscern('plant_discern', img_file);