2026-09-29 19:01:36 +08:00
|
|
|
const api = require('../../utils/api')
|
|
|
|
|
const media = require('../../utils/media')
|
|
|
|
|
const activityUtil = require('../../utils/activity')
|
|
|
|
|
|
|
|
|
|
function decorate(item) {
|
|
|
|
|
const cover = item.cover || item.poster || ''
|
2026-10-08 13:06:43 +08:00
|
|
|
return Object.assign({}, item, {
|
|
|
|
|
coverUrl: cover ? media.absUrl(cover) : ''
|
|
|
|
|
})
|
2026-09-29 19:01:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
data: {
|
|
|
|
|
list: [],
|
|
|
|
|
loaded: false,
|
|
|
|
|
deleting: false,
|
|
|
|
|
isAdmin: false
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onShow() {
|
|
|
|
|
this.loadPage()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
this.loadPage().then(() => wx.stopPullDownRefresh())
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
loadPage() {
|
|
|
|
|
const profile = api.profile().catch(() => null)
|
|
|
|
|
return Promise.all([api.pastActivities(), profile])
|
|
|
|
|
.then((results) => {
|
|
|
|
|
const isAdmin = !!(results[1] && results[1].isAdmin)
|
|
|
|
|
this.setData({
|
|
|
|
|
list: (results[0] || []).map(decorate),
|
|
|
|
|
loaded: true,
|
|
|
|
|
isAdmin: isAdmin,
|
|
|
|
|
deleting: isAdmin && this.data.deleting
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
this.setData({ loaded: true })
|
|
|
|
|
activityUtil.toast(error)
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
openDetail(event) {
|
|
|
|
|
if (this.data.deleting) return
|
|
|
|
|
wx.navigateTo({ url: '/pages/detail/detail?id=' + event.currentTarget.dataset.id })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onAdd() {
|
|
|
|
|
if (!this.data.isAdmin) return
|
|
|
|
|
wx.navigateTo({ url: '/pages/past-edit/past-edit' })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onDelete() {
|
|
|
|
|
if (!this.data.isAdmin) return
|
|
|
|
|
if (!this.data.list.length) {
|
|
|
|
|
wx.showToast({ title: '还没有可以删除的活动', icon: 'none' })
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.setData({ deleting: !this.data.deleting })
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
remove(event) {
|
|
|
|
|
if (!this.data.isAdmin) return
|
|
|
|
|
const id = event.currentTarget.dataset.id
|
|
|
|
|
wx.showModal({
|
|
|
|
|
title: '删除这场活动?',
|
|
|
|
|
content: event.currentTarget.dataset.title,
|
|
|
|
|
confirmColor: '#DC2626',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
if (!res.confirm) return
|
|
|
|
|
api
|
|
|
|
|
.removePast(id)
|
|
|
|
|
.then(() => {
|
|
|
|
|
const list = this.data.list.filter((item) => item.id !== id)
|
|
|
|
|
this.setData({ list: list, deleting: list.length > 0 && this.data.deleting })
|
|
|
|
|
})
|
|
|
|
|
.catch(activityUtil.toast)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
togglePin(event) {
|
|
|
|
|
if (!this.data.isAdmin) return
|
|
|
|
|
const dataset = event.currentTarget.dataset
|
|
|
|
|
api
|
|
|
|
|
.pinPast(dataset.id, String(dataset.pinned) !== '1')
|
|
|
|
|
.then(() => this.loadPage())
|
|
|
|
|
.catch(activityUtil.toast)
|
|
|
|
|
}
|
|
|
|
|
})
|