pest.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. uni.r
  13. return new Promise((resolve, reject) => {
  14. uni.uploadFile({
  15. url: config.baseUrl +
  16. 'api/api_gateway?method=pest.pests.' + url, //仅为示例,非真实的接口地址
  17. formData: {
  18. 'img_file': img_file,
  19. token: cache.get(LOGIN_TOKEN)
  20. },
  21. success: (uploadFileRes) => {
  22. resolve(uploadFileRes.data);
  23. }
  24. });
  25. })
  26. }
  27. // 病虫害库
  28. export const loadPestList = (data) => async (data) => {
  29. const res = await request.post(`api/api_gateway?method=pest.pests.pests_info`, data);
  30. return res?.data;
  31. }
  32. // 虫害识别
  33. export const handleInsectDiscern = (img_file) => baseDiscern('insect_discern', img_file);
  34. // 病害识别
  35. export const handlePlantDiscern = (img_file) => baseDiscern('plant_discern', img_file);