sharePop.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // components/sharePop/sharePop.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. url: {
  8. type: String,
  9. value: '', // 属性值 (可选)
  10. },
  11. bottom:{
  12. type: Number,
  13. value: 0, // 属性值 (可选)
  14. }
  15. },
  16. /**
  17. * 组件的初始数据
  18. */
  19. data: {
  20. // 弹窗显示控制
  21. showPop: false,
  22. },
  23. /**
  24. * 组件的方法列表
  25. */
  26. methods: {
  27. closeShare: function() {
  28. this.setData({
  29. showPop: false,
  30. });
  31. },
  32. togglePopup: function() {
  33. let that = this;
  34. this.setData({
  35. showPop: !this.data.showPop,
  36. });
  37. },
  38. // 保存分享图
  39. _saveShare: function() {
  40. wx.showLoading({
  41. title: '加载中',
  42. });
  43. setTimeout(function() {
  44. wx.hideLoading()
  45. }, 2000);
  46. let that = this;
  47. wx.downloadFile({
  48. url: that.data.url,
  49. success: function(res) {
  50. console.log(res)
  51. wx.saveImageToPhotosAlbum({
  52. filePath: res.tempFilePath,
  53. success: function(res) {
  54. wx.showModal({
  55. title: '存图成功',
  56. content: '图片成功保存到相册了,可以分享到朋友圈了',
  57. showCancel: false,
  58. confirmText: '好的',
  59. confirmColor: '#a78845',
  60. success: function(res) {
  61. if (res.confirm) {
  62. console.log('用户点击确定');
  63. }
  64. }
  65. });
  66. wx.hideLoading();
  67. },
  68. fail: function(res) {
  69. console.log('fail')
  70. }
  71. })
  72. },
  73. fail: function() {
  74. console.log('fail')
  75. }
  76. })
  77. },
  78. }
  79. })