You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1 KiB

2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. export let goPage = (url, params = {}, type = 'navigateTo') => {
  2. uni.$u.route({
  3. url,
  4. params,
  5. type
  6. })
  7. }
  8. import setObj from '@/config/site.config.js';
  9. let { H5_API, WX_API,httpPrefix } = setObj
  10. var _url = H5_API+ WX_API + httpPrefix
  11. export function uploadImgApi(filePath, imgName, imgLink='image') {
  12. console.log(filePath)
  13. let token = 'Bearer '+ uni.getStorageSync('token')
  14. let timer = new Date() * 1
  15. return new Promise((reslove, reject)=>{
  16. // 上传图片到服务器
  17. uni.uploadFile({
  18. url: _url + 'infra/file/upload',//接口
  19. filePath: filePath,//要上传的图片的本地路径
  20. name: 'file',
  21. // complain
  22. formData: {
  23. path: imgLink+'/'+ uni.$u.date(timer, 'yyyy-mm-dd')+'/'+timer + '-'+ imgName,
  24. type: 1,
  25. fileSuffix: "png"
  26. },
  27. header: {
  28. Authorization: token,
  29. // 'tenant-id': '1704459882232553474'
  30. },
  31. success(res) {
  32. console.log('上传成功??')
  33. console.log(res)
  34. let res2 = JSON.parse(res.data)
  35. reslove(res2.data)
  36. },
  37. fail(error) {
  38. return Promise.reject(error)
  39. },
  40. complete: (err)=> {
  41. uni.hideLoading();
  42. }
  43. })
  44. })
  45. }