123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import {
- getMyActivity,
- thumbsUp,
- deleteActivity,
- getShareText
- } from '~/api/activity'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- isMy: false,
- pageNo: 1,
- totalSize: 0,
- list: [],
- uid: ''
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.getMyActivity()
- this.setData({
- uid: wx.getStorageSync('uid')
- })
- },
- async getMyActivity() {
- let {
- list,
- totalSize
- } = await getMyActivity({
- pageNo: this.data.pageNo,
- pageSize: 6
- })
- list = [...this.data.list, ...list]
- let isMy = false
- if (list.length > 0) {
- isMy = list[0].uid == wx.getStorageSync('uid')
- }
- this.setData({
- isMy,
- list,
- totalSize
- })
- },
- onReachBottom() {
- if (this.data.totalSize > this.data.list.length) {
- this.setData({
- pageNo: this.data.pageNo + 1
- })
- this.getMyActivity()
- }
- },
- delete({
- currentTarget
- }) {
- wx.showModal({
- title: '确认删除吗?',
- content: '作品将被永久删除,无法找回。',
- confirmText: '确认',
- cancelText: '取消',
- success: async (res) => {
- if (res.confirm) {
- await deleteActivity(currentTarget.dataset.id)
- let beforeList = this.data.list.filter(item => {
- return item.id != currentTarget.dataset.id
- })
- this.setData({
- list: beforeList
- })
- wx.showToast({
- title: '删除成功!',
- icon: "none"
- })
- }
- }
- })
- },
- async setLike({
- currentTarget
- }) {
- if (currentTarget.dataset.item.isLike) {
- return
- }
- let index = currentTarget.dataset.index
- await thumbsUp(currentTarget.dataset.item.id)
- this.setData({
- [`list[${index}].isLike`]: true,
- [`list[${index}].likeAmount`]: ++this.data.list[index].likeAmount
- })
- },
- jump() {
- wx.navigateTo({
- url: '/pages/activityList/index',
- })
- },
- createActivityImg(imageUrl, cardReadId) {
- return new Promise(async (resolve, reject) => {
- let title = await getShareText({
- cardReadId
- })
- resolve({
- title,
- path: `/pages/greeting/index?&uid=${wx.getStorageSync('uid')}`,
- imageUrl
- })
- })
- },
- onShareAppMessage({
- target,
- from,
- }) {
- if (from == 'button') {
- const promise = new Promise(resolve => {
- this.createActivityImg(target.dataset.item.cardUrl, target.dataset.item.id).then(res => {
- resolve(res)
- })
- })
- return {
- title: '',
- path: `/pages/greeting/index?&uid=${wx.getStorageSync('uid')}`,
- imageUrl: target.dataset.img,
- promise
- }
- } else {
- return {
- title: '课文朗读,从未如此有趣。',
- path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
- imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
- }
- }
- },
- })
|