Files
2026-08-02 09:57:11 +08:00

59 lines
1.5 KiB
TypeScript

// index.ts
import { BASE_URL, appId } from '../../env'
Component({
data: {
showPopup: false,
showToast: false,
},
pageLifetimes: {
show() {
// 开启右上角菜单的"转发给朋友"和"分享到朋友圈"
wx.showShareMenu({
menus: ['shareAppMessage', 'shareTimeline'],
})
},
},
methods: {
// 转发给好友
onShareAppMessage() {
return {
title: '2024新款男士轻薄羽绒服 限时5折¥299',
path: '/pages/index/index',
imageUrl: '/pages/index/assets/test.png',
}
},
// 分享到朋友圈
onShareTimeline() {
return {
title: '2024新款男士轻薄羽绒服 限时5折¥299',
imageUrl: '/pages/index/assets/test.png',
}
},
preventTouchMove() {},
onOverlayTap() {
wx.request({
url: `${BASE_URL}/api/ad/ww-join-fans/result/${appId}`,
method: 'GET',
success: (res: any) => {
const data = res.data
if (data.data.url || data.data) {
// @ts-ignore
wx.openOfficialAccountArticle({
url: data.data.url || data.data,
fail: () => {
wx.showToast({ title: '打开失败', icon: 'none' })
},
})
} else {
wx.showToast({ title: '未获取到链接', icon: 'none' })
}
},
fail: () => {
wx.showToast({ title: '请求失败', icon: 'none' })
},
})
},
},
})