邃芒智像相册
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

138 satır
2.5 KiB

  1. const app = getApp()
  2. import request from '../../utils/request'
  3. import Dialog from '@vant/weapp/dialog/dialog';
  4. const { appId } = require("../../utils/request");
  5. // pages/checkImg/checkImg.ts
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. currentIndex: 0,
  12. id: "",
  13. swiperList: [],
  14. title: ""
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad(options) {
  20. console.log(options);
  21. this.setData({
  22. id: options.id
  23. })
  24. app.tokenCallBack = token => {
  25. if (!token) {
  26. wx.redirectTo({
  27. url: '/pages/login/login',
  28. })
  29. } else {
  30. this.getImageDetail(options.id)
  31. }
  32. }
  33. },
  34. /**
  35. * 生命周期函数--监听页面显示
  36. */
  37. onShow() {
  38. const isLogin = wx.getStorageSync('token')
  39. if (isLogin) {
  40. this.getImageDetail(this.data.id)
  41. }
  42. },
  43. getImageDetail(id) {
  44. const that = this
  45. console.log(id, 'id');
  46. request.get({
  47. url: `/api/digitalAvatarPhoto/findById?id=${id}`
  48. }).then(res => {
  49. console.log(res, 'getImageDetail');
  50. that.setData({
  51. swiperList: res.data.photoList,
  52. title: res.data.title,
  53. })
  54. }).catch(err => {
  55. console.log(err, 'err');
  56. })
  57. },
  58. switchImg(e) {
  59. const currentIndex = e.currentTarget.dataset.index
  60. this.setData({
  61. currentIndex
  62. })
  63. },
  64. previewImage() {
  65. const array = []
  66. this.data.swiperList.forEach(item => {
  67. array.push(item.image)
  68. })
  69. wx.previewImage({
  70. urls: array,
  71. showmenu: true,
  72. })
  73. },
  74. swiperChanged(e) {
  75. const currentIndex = e.detail.current
  76. this.setData({
  77. currentIndex
  78. })
  79. },
  80. downloadImage() {
  81. const index = this.data.currentIndex
  82. const list = this.data.swiperList
  83. const filePath = "zhixiangImg.png"
  84. const url = list[index].image
  85. wx.downloadFile({
  86. url,
  87. success: res => {
  88. console.log(res, 'res');
  89. if (res.statusCode === 200) {
  90. wx.saveImageToPhotosAlbum({
  91. filePath: res.tempFilePath,
  92. success: () => {
  93. wx.showToast({
  94. title: '保存成功!',
  95. icon: "success"
  96. })
  97. }
  98. })
  99. }
  100. }
  101. })
  102. },
  103. /**
  104. * 页面相关事件处理函数--监听用户下拉动作
  105. */
  106. onPullDownRefresh() {
  107. },
  108. /**
  109. * 页面上拉触底事件的处理函数
  110. */
  111. onReachBottom() {
  112. },
  113. /**
  114. * 用户点击右上角分享
  115. */
  116. onShareAppMessage() {
  117. }
  118. })