index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import {
  2. getMyActivity,
  3. thumbsUp,
  4. deleteActivity,
  5. getShareText
  6. } from '~/api/activity'
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. isMy: false,
  13. pageNo: 1,
  14. totalSize: 0,
  15. list: [],
  16. uid: ''
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad(options) {
  22. this.getMyActivity()
  23. this.setData({
  24. uid: wx.getStorageSync('uid')
  25. })
  26. },
  27. async getMyActivity() {
  28. let {
  29. list,
  30. totalSize
  31. } = await getMyActivity({
  32. pageNo: this.data.pageNo,
  33. pageSize: 6
  34. })
  35. list = [...this.data.list, ...list]
  36. let isMy = false
  37. if (list.length > 0) {
  38. isMy = list[0].uid == wx.getStorageSync('uid')
  39. }
  40. this.setData({
  41. isMy,
  42. list,
  43. totalSize
  44. })
  45. },
  46. onReachBottom() {
  47. if (this.data.totalSize > this.data.list.length) {
  48. this.setData({
  49. pageNo: this.data.pageNo + 1
  50. })
  51. this.getMyActivity()
  52. }
  53. },
  54. delete({
  55. currentTarget
  56. }) {
  57. wx.showModal({
  58. title: '确认删除吗?',
  59. content: '作品将被永久删除,无法找回。',
  60. confirmText: '确认',
  61. cancelText: '取消',
  62. success: async (res) => {
  63. if (res.confirm) {
  64. await deleteActivity(currentTarget.dataset.id)
  65. let beforeList = this.data.list.filter(item => {
  66. return item.id != currentTarget.dataset.id
  67. })
  68. this.setData({
  69. list: beforeList
  70. })
  71. wx.showToast({
  72. title: '删除成功!',
  73. icon: "none"
  74. })
  75. }
  76. }
  77. })
  78. },
  79. async setLike({
  80. currentTarget
  81. }) {
  82. if (currentTarget.dataset.item.isLike) {
  83. return
  84. }
  85. let index = currentTarget.dataset.index
  86. await thumbsUp(currentTarget.dataset.item.id)
  87. this.setData({
  88. [`list[${index}].isLike`]: true,
  89. [`list[${index}].likeAmount`]: ++this.data.list[index].likeAmount
  90. })
  91. },
  92. jump() {
  93. wx.navigateTo({
  94. url: '/pages/activityList/index',
  95. })
  96. },
  97. createActivityImg(imageUrl, cardReadId) {
  98. return new Promise(async (resolve, reject) => {
  99. let title = await getShareText({
  100. cardReadId
  101. })
  102. resolve({
  103. title,
  104. path: `/pages/greeting/index?&uid=${wx.getStorageSync('uid')}`,
  105. imageUrl
  106. })
  107. })
  108. },
  109. onShareAppMessage({
  110. target,
  111. from,
  112. }) {
  113. if (from == 'button') {
  114. const promise = new Promise(resolve => {
  115. this.createActivityImg(target.dataset.item.cardUrl, target.dataset.item.id).then(res => {
  116. resolve(res)
  117. })
  118. })
  119. return {
  120. title: '',
  121. path: `/pages/greeting/index?&uid=${wx.getStorageSync('uid')}`,
  122. imageUrl: target.dataset.img,
  123. promise
  124. }
  125. } else {
  126. return {
  127. title: '课文朗读,从未如此有趣。',
  128. path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
  129. imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
  130. }
  131. }
  132. },
  133. })