mp.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // pages/mp/mp.ts
  2. import ActionSheet, { ActionSheetTheme, ActionSheetShowOption } from 'tdesign-miniprogram/action-sheet/index';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. pageImage: 'https://4dkk.4dage.com/miniapp-source/daikan/about_us.png',
  9. pageQRcode: 'https://4dkk.4dage.com/miniapp-source/daikan/about_qrcode.png',
  10. handler: null,
  11. },
  12. handleActionShow() {
  13. const basicListOption: ActionSheetShowOption = {
  14. theme: ActionSheetTheme.List,
  15. selector: '#t-action-sheet',
  16. items: [
  17. {
  18. label: '下载图片',
  19. },
  20. ],
  21. };
  22. const handler = ActionSheet.show(basicListOption);
  23. this.setData({
  24. handler: handler
  25. })
  26. },
  27. handleSelected(event: WechatMiniprogram.TouchEvent) {
  28. const { index } = event.detail
  29. console.log('event', index)
  30. if (index === 0) {
  31. wx.downloadFile({
  32. url: this.data.pageQRcode,
  33. success (res) {
  34. wx.saveImageToPhotosAlbum({
  35. filePath: res.tempFilePath,
  36. success(res) {
  37. wx.showModal({
  38. title: '图片保存成功',
  39. content: '图片成功保存到相册了,通过扫一扫就可以哒!',
  40. showCancel: false,
  41. confirmText: '好哒',
  42. confirmColor: '#72B9C3',
  43. success: (res) => {
  44. if (res.confirm) {
  45. }
  46. }
  47. })
  48. }
  49. })
  50. }
  51. })
  52. }
  53. },
  54. handleCancel() {
  55. const { handler } = this.data
  56. if (handler) {
  57. (handler as any).close()
  58. }
  59. },
  60. /**
  61. * 生命周期函数--监听页面加载
  62. */
  63. onLoad() {
  64. },
  65. /**
  66. * 生命周期函数--监听页面初次渲染完成
  67. */
  68. onReady() {
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow() {
  74. },
  75. /**
  76. * 生命周期函数--监听页面隐藏
  77. */
  78. onHide() {
  79. },
  80. /**
  81. * 生命周期函数--监听页面卸载
  82. */
  83. onUnload() {
  84. },
  85. /**
  86. * 页面相关事件处理函数--监听用户下拉动作
  87. */
  88. onPullDownRefresh() {
  89. },
  90. /**
  91. * 页面上拉触底事件的处理函数
  92. */
  93. onReachBottom() {
  94. },
  95. /**
  96. * 用户点击右上角分享
  97. */
  98. onShareAppMessage() {
  99. }
  100. })