学员端小程序
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.

39 lines
955 B

9 months ago
  1. export let downloadImg = function (imageUrl) {
  2. uni.downloadFile({
  3. url: imageUrl,
  4. success(res) {
  5. if (res.statusCode === 200) {
  6. // 下载成功后,获取临时文件路径
  7. const tempFilePath = res.tempFilePath;
  8. // 保存图片到本地相册
  9. uni.saveImageToPhotosAlbum({
  10. filePath: tempFilePath,
  11. success() {
  12. uni.showToast({
  13. title: '图片保存成功',
  14. icon: 'success',
  15. duration: 2000
  16. });
  17. },
  18. fail(err) {
  19. console.error('保存图片失败', err);
  20. uni.showToast({
  21. title: '图片保存失败',
  22. icon: 'none',
  23. duration: 2000
  24. });
  25. }
  26. });
  27. }
  28. },
  29. fail(err) {
  30. console.error('下载图片失败', err);
  31. uni.showToast({
  32. title: '图片下载失败',
  33. icon: 'none',
  34. duration: 2000
  35. });
  36. }
  37. });
  38. }