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.
117 lines
2.8 KiB
117 lines
2.8 KiB
const app = getApp<IAppOption>() |
|
|
|
Page({ |
|
data: { |
|
id: '', |
|
detail: {} as any, |
|
content: '', |
|
next: null as any, |
|
}, |
|
onLoad(options: any) { |
|
if (options.id) { |
|
this.setData({ id: options.id }) |
|
app.waitLogin({ type: 'any' }).then(() => { |
|
this.getDetail(options.id) |
|
this.addViewRecord(options.id) |
|
}) |
|
} |
|
}, |
|
getDetail(id: string) { |
|
wx.ajax({ |
|
method: 'GET', |
|
url: '?r=psvt/pic-text/detail', |
|
data: { Id: id }, |
|
}).then((res: any) => { |
|
this.setData({ |
|
detail: res || {}, |
|
content: res.Content || '', |
|
next: res.Next || null, |
|
}) |
|
}) |
|
}, |
|
addViewRecord(id: string) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=psvt/pic-text/view', |
|
data: { ContentId: Number(id) }, |
|
}) |
|
}, |
|
handleCompliment() { |
|
if (!app.checkLoginType(1, true)) return |
|
const { detail, id } = this.data |
|
if (detail.IsCompliment) return |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=psvt/pic-text/compliment', |
|
data: { ContentId: Number(id) }, |
|
}).then(() => { |
|
this.setData({ |
|
'detail.IsCompliment': 1, |
|
'detail.ComplimentNum': (detail.ComplimentNum || 0) + 1, |
|
}) |
|
}) |
|
}, |
|
handleCollect() { |
|
if (!app.checkLoginType(1, true)) return |
|
const { detail, id } = this.data |
|
if (detail.IsCollect) { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=psvt/pic-text/cancel-collection', |
|
data: { ContentId: Number(id) }, |
|
}).then(() => { |
|
this.setData({ |
|
'detail.IsCollect': 0, |
|
'detail.CollectionPeopleNum': Math.max(0, (detail.CollectionPeopleNum * 1 || 0) - 1), |
|
}) |
|
}) |
|
} else { |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=psvt/pic-text/collection', |
|
data: { ContentId: Number(id) }, |
|
}).then(() => { |
|
this.setData({ |
|
'detail.IsCollect': 1, |
|
'detail.CollectionPeopleNum': (detail.CollectionPeopleNum * 1 || 0) + 1, |
|
}) |
|
}) |
|
} |
|
}, |
|
handleShare() { |
|
const { detail, id } = this.data |
|
wx.ajax({ |
|
method: 'POST', |
|
url: '?r=psvt/pic-text/share', |
|
data: { ContentId: Number(id) }, |
|
}).then(() => { |
|
this.setData({ |
|
'detail.IsShare': 1, |
|
'detail.ShareNum': (detail.ShareNum * 1 || 0) + 1, |
|
}) |
|
}) |
|
}, |
|
handleNext() { |
|
const { next } = this.data |
|
if (!next) return |
|
wx.redirectTo({ |
|
url: `/pages/articleDetail/index?id=${next.Id}`, |
|
}) |
|
}, |
|
handleRecommendTap(e: any) { |
|
const { id } = e.currentTarget.dataset |
|
wx.navigateTo({ |
|
url: `/pages/articleDetail/index?id=${id}`, |
|
}) |
|
}, |
|
onShareAppMessage() { |
|
const { detail } = this.data |
|
this.handleShare() |
|
return { |
|
title: detail.Title || '图文详情', |
|
path: `/pages/articleDetail/index?id=${this.data.id}`, |
|
} |
|
}, |
|
}) |
|
|
|
export {}
|
|
|