邃芒智像相册
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

160 regels
3.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. if (options.id == "example") {
  25. console.log(1);
  26. const arr = [
  27. { image: "https://formall.oss-accelerate.aliyuncs.com/smartcapi/2023-09-27/5263476f945343bbab20e007bfd32c4b.jpg?x-oss-process=image/resize,w_10000/quality,q_60" },
  28. { image: "https://formall.oss-accelerate.aliyuncs.com/smartcapi/2023-09-27/5263476f945343bbab20e007bfd32c4b.jpg?x-oss-process=image/resize,w_10000/quality,q_60" },
  29. { image: "https://formall.oss-accelerate.aliyuncs.com/smartcapi/2023-09-27/5263476f945343bbab20e007bfd32c4b.jpg?x-oss-process=image/resize,w_10000/quality,q_60" },
  30. { image: "https://formall.oss-accelerate.aliyuncs.com/smartcapi/2023-09-27/5263476f945343bbab20e007bfd32c4b.jpg?x-oss-process=image/resize,w_10000/quality,q_60" }
  31. ]
  32. this.setData({
  33. swiperList: arr,
  34. title: "示例"
  35. })
  36. return
  37. }
  38. app.tokenCallBack = token => {
  39. if (!token) {
  40. wx.redirectTo({
  41. url: '/pages/login/login',
  42. })
  43. } else {
  44. this.getImageDetail(options.id)
  45. }
  46. }
  47. },
  48. /**
  49. * 生命周期函数--监听页面显示
  50. */
  51. onShow() {
  52. const isLogin = wx.getStorageSync('token')
  53. if (isLogin) {
  54. this.getImageDetail(this.data.id)
  55. }
  56. },
  57. getImageDetail(id) {
  58. const that = this
  59. console.log(id, 'id');
  60. request.get({
  61. url: `/api/digitalAvatarPhoto/findById?id=${id}`
  62. }).then(res => {
  63. console.log(res, 'getImageDetail');
  64. that.setData({
  65. swiperList: res.data.photoList,
  66. title: res.data.title,
  67. })
  68. }).catch(err => {
  69. console.log(err, 'err');
  70. })
  71. },
  72. switchImg(e) {
  73. const currentIndex = e.currentTarget.dataset.index
  74. this.setData({
  75. currentIndex
  76. })
  77. },
  78. previewImage() {
  79. const array = []
  80. this.data.swiperList.forEach(item => {
  81. array.push(item.image)
  82. })
  83. wx.previewImage({
  84. urls: array,
  85. showmenu: true,
  86. })
  87. },
  88. swiperChanged(e) {
  89. const currentIndex = e.detail.current
  90. this.setData({
  91. currentIndex
  92. })
  93. },
  94. downloadImage() {
  95. const isLogin = wx.getStorageSync('token')
  96. if (!isLogin) {
  97. wx.redirectTo({
  98. url: '/pages/login/login',
  99. })
  100. return
  101. }
  102. const index = this.data.currentIndex
  103. const list = this.data.swiperList
  104. const filePath = "zhixiangImg.png"
  105. const url = list[index].image
  106. wx.downloadFile({
  107. url,
  108. success: res => {
  109. console.log(res, 'res');
  110. if (res.statusCode === 200) {
  111. wx.saveImageToPhotosAlbum({
  112. filePath: res.tempFilePath,
  113. success: () => {
  114. wx.showToast({
  115. title: '保存成功!',
  116. icon: "success"
  117. })
  118. }
  119. })
  120. }
  121. }
  122. })
  123. },
  124. /**
  125. * 页面相关事件处理函数--监听用户下拉动作
  126. */
  127. onPullDownRefresh() {
  128. },
  129. /**
  130. * 页面上拉触底事件的处理函数
  131. */
  132. onReachBottom() {
  133. },
  134. /**
  135. * 用户点击右上角分享
  136. */
  137. onShareAppMessage() {
  138. }
  139. })