index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // components/My_TwoDimensionalCode/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. title: {
  8. type: String
  9. },
  10. codeName: {
  11. type: String
  12. },
  13. imageUrl: {
  14. type: String,
  15. value: 'https://bwj.obs.cn-east-2.myhuaweicloud.com:443/202112101639101631143B33e18617.png'
  16. }
  17. },
  18. /**
  19. * 组件的初始数据
  20. */
  21. data: {
  22. },
  23. /**
  24. * 组件的方法列表
  25. */
  26. methods: {
  27. /* 预览大图 */
  28. preViewImage() {
  29. const url = [this.data.imageUrl];
  30. wx.previewImage({
  31. urls: url,
  32. })
  33. },
  34. /* 下载二维码 */
  35. download() {
  36. wx.downloadFile({
  37. url: this.data.imageUrl,
  38. success: function (res) {
  39. const tempFilePath = res.tempFilePath;
  40. // 保存文件
  41. wx.saveFile({
  42. tempFilePath,
  43. success: function (res) {
  44. const savedFilePath = res.savedFilePath;
  45. // 打开文件
  46. wx.openDocument({
  47. filePath: savedFilePath,
  48. success: function (res) {
  49. console.log(res)
  50. },
  51. });
  52. },
  53. fail: function (err) {
  54. console.log('保存失败:', err)
  55. wx.showToast({
  56. title: '保存失败',
  57. icon: "none"
  58. })
  59. }
  60. });
  61. },
  62. fail: function (err) {
  63. console.log('下载失败:', err);
  64. wx.showToast({
  65. title: '下载失败',
  66. icon: "none"
  67. })
  68. },
  69. });
  70. }
  71. }
  72. })