classTeam.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import Api from "../../model/api";
  2. import {getDataSet, showLoading, toast} from "../../utils/utils";
  3. import {wxToPromise} from "../../utils/wx";
  4. Page({
  5. data: {
  6. images: [],
  7. teamName: ''
  8. },
  9. async onLoad(options) {
  10. const {teamId} = options;
  11. let res = await Api.getTeam(teamId);
  12. let images = JSON.parse(res.data.teamCodeUrls);
  13. this.setData({
  14. teamName: res.data.teamName,
  15. images
  16. })
  17. },
  18. async saveImg(e) {
  19. let url = getDataSet(e, "url");
  20. showLoading('保存中...')
  21. const res = await wxToPromise("downloadFile", {url});
  22. if (res.statusCode === 200) {
  23. try {
  24. await wx.saveImageToPhotosAlbum({
  25. filePath: res.tempFilePath,
  26. });
  27. wx.nextTick(() => {
  28. wx.showToast({
  29. title: '保存成功!',
  30. icon: 'success',
  31. duration: 2000
  32. });
  33. });
  34. } catch (e) {
  35. console.log(e)
  36. if (e.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
  37. wx.showModal({
  38. title: "提示",
  39. content: "请点击右上角进入设置勾选相册后方可保存到相册",
  40. showCancel: false
  41. })
  42. }
  43. }
  44. } else {
  45. toast(`保存失败,请稍后重试${res.statusCode}:${res.errMsg}`)
  46. }
  47. wx.hideLoading();
  48. }
  49. })