// pages/topics/attract/oceanDetail/index.js import { ArticeModel } from '../../../../models/artice.js' import dayjs from '../../../../utils/dayjs/index.js' import { store } from '../../../../utils/store.js' var WxParse = require('../../../../components/wxParse/wxParse.js'); let artice = new ArticeModel() const app = getApp() Page({ /** * 页面的初始数据 */ data: { nodes: '', isStar: true, // 是否 showBtn: false, image: '', aId: '', title: '', date: '', origin: '', unStar: '/images/common/star.png', star: '/images/common/star_light.png', readNum: 0, collectNum: 0, associationType: '' }, onClickCollect() { // 收藏功能 if (store.hasBindUserInfo()) { this.addOrRemoveCollectionApi() } else { wx.redirectTo({ url: '/pages/weChatAuth/index', }) } }, onShareAppMessage(res) { return { title: this.data.title, path: `/pages/article/index?id=${this.data.aId}` } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { //console.log(options) const { id } = options this.setData({ aId: id }) this.fetchArticeApi() }, fetchArticeApi() { artice.getDetail(this.data.aId, (res) => { console.log('海洋人才赋能中心详情-->', res) const data = res.result const date = dayjs(data.createTime).format('MM月DD日') if (data.flag == 0 || data.flag == 1) { var disable = false; } else { var disable = true; } this.setData({ nodes: data.content, title: data.title, date: date, image: data.titlePic, origin: data.source, isStar: data.isCollection ? true : false, disable: disable, readNum: data.readNum, collectNum: data.collectNum, flag: data.flag, associationType: data.associationType }, () => { // wx.hideLoading() }) console.log(this.data.associationType) WxParse.wxParse('article', 'html', this.data.nodes, this, 5); }) }, addOrRemoveCollectionApi() { artice.addOrRemoveCollect(this.data.aId, res => { //console.log(res) if (res.code == 200) { this.setData({ isStar: !this.data.isStar }) wx.showToast({ title: this.data.isStar ? '收藏成功' : '取消收藏成功', icon: 'none' }) } }) }, //关联链接跳转 goLinkPage(e) { console.log('链接--',e) if (e.currentTarget.dataset.association == '1') { app.globalData.currentTab = "3" wx.switchTab({ url: '../../../topics/index' }) } else { app.globalData.currentTab = "5" wx.switchTab({ url: '../../../topics/index' }) } } })