Files
sykl-mall/pages/article/info/info.js
2023-07-22 19:01:37 +08:00

139 lines
3.4 KiB
JavaScript

/*
* 手太欠
* 愿这世界都如故事里一样 美好而动人~
*/
Page({
/**
* 页面的初始数据
*/
data: {
id : '', //文章id
indexShow : '', //内容
mallContent : '', //简介
favoritesSee : '', //收藏状态
favoritesNumber : '', //收藏数量
subscribesSee : '', //点赞状态
subscribesNumber: '', //点赞数量
inviteText : '', //邀请码
isFixedTop : 0,
barHeight : getApp().globalData.statusBarHeight // 状态栏高度
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
id: options.id
})
if (options.type == 'memory') {
wx.setNavigationBarTitle({
title: '锶源昆仑·记忆'
})
} else if (options.type == 'wiki') {
wx.setNavigationBarTitle({
title: '锶源昆仑·健康百科'
})
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 获取详情数据
this.indexInfo();
// 获取登录状态
if(wx.getStorageSync("token")){
// 获取推广码
this.inviteInfo();
}
},
/**
* 推广码
*/
inviteInfo() {
wx.$api.user.invite().then(res => {
this.setData({
inviteText : res.data.invite
})
}).catch(err => {})
},
/**
* 详情数据
*/
indexInfo () {
wx.$api.index.articlesSee(this.data.id).then(res => {
this.setData({
indexShow : res.data,
favoritesSee : res.data.isFavorite,
subscribesSee : res.data.isSubscribed,
favoritesNumber : res.data.favorites,
subscribesNumber: res.data.subscribes,
mallContent : res.data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"')
})
}).catch(err => {})
},
// 操作按钮
toolTap(e) {
let newName = e.currentTarget.dataset.name
// 收藏
if(newName == 'favorites') {
wx.$api.index.articlesFavorite(this.data.id).then(res => {
this.setData({
favoritesSee : res.data.favorite,
favoritesNumber: res.data.count
})
}).catch(err => {})
return
}
// 点赞
wx.$api.index.articlesSubscribe(this.data.id).then(res => {
this.setData({
subscribesSee : res.data.subscribed,
subscribesNumber: res.data.count
})
}).catch(err => {})
},
/**
* 微信分享
*/
onShareAppMessage(){
return {
title : this.data.indexShow.title,
path : "/pages/index/index?invite=" + this.data.inviteText,
imageUrl: this.data.indexShow.cover
}
},
// 返回上一页
returnGo() {
wx.navigateBack({
delta: 1
})
},
// 回到首页
returnHome() {
wx.switchTab({
url: '/pages/index/index'
})
},
/**
* 监听页面滑动事件
*/
onPageScroll(e) {
this.setData({
isFixedTop: parseInt(e.scrollTop)
});
},
})