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.

200 lines
6.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import {
doStr
} from "../../../utils/doStr.js"
const app = getApp();
let iPageIndex = 1 // 当前第几页,0代表第一页
let iPageSize = 10 //每页显示多少数据
Page({
data: {
imageUrl: getApp().globalData.imageUrl,
id: "",
source: "",
user_author: "",
sourcetime: "",
title: "",
content: "",
affections: "",
crisis: "",
ssim: "",
uri: "",
dataList: [], //放置返回数据的数组
loadMore: false, //"上拉加载"的变量默认false隐藏
loadAll: false, //“没有数据”的变量默认false隐藏
totalNum: 0,
c1: "",
c2: "",
showMore: false,
showDialog: false
},
onLoad() {
wx.setNavigationBarTitle({
title: '详情'
})
let pages = getCurrentPages();
let currentPage = pages[pages.length - 1]
let options = currentPage.options
this.setData({
id: options.id
})
},
onShow() {
iPageIndex = 1;
this.setData({
dataList: []
})
this.getData().then(() => {
this.getLikeData()
})
},
//页面上拉触底事件的处理函数
onReachBottom: function () {
console.log("上拉触底事件")
let that = this
if (!that.data.loadMore) {
that.setData({
loadMore: true, //加载中
loadAll: false //是否加载完所有数据
});
//加载更多,这里做下延时加载
that.getLikeData();
}
},
searchScrollLower() {
this.getLikeData();
},
getData() {
return new Promise((resolve, reject) => {
app.globalData.request({
action: 'getDataById',
sId: this.data.id,
sType: 'ZhuTiFenXiBl',
token: app.globalData.getStorage('token')
}).then(res => {
let arr = res || [];
if (arr.length > 0) {
let data = arr[0];
let c1 = data._source.content.replace(/\<img/gi, '<img class="imgs"');
let c2 = doStr(data._source.content.replace(/\<img/gi, '<img class="imgs"'), 700);
let title = doStr(data._source.title, 200);
this.setData({
source: data._source.source,
user_author: data._source.user_author,
sourcetime: data._source.sourcetime,
title: title,
content: c2,
affections: data._source.affections,
crisis: data._source.crisis,
ssim: data._source.ssim,
uri: data._source.url,
c1: c1,
c2: c2
})
}
resolve(true)
}).catch(() => {
reject(false)
})
})
},
getLikeData() {
let sTimeType = wx.getStorageSync('sTimeType') || 34;
let sStartTime = "";
let sEndTime = "";
if (sTimeType == 4) {
sStartTime = wx.getStorageSync('sStartTime') || '';
sEndTime = wx.getStorageSync('sEndTime') || '';
}
let obj = {
action: "getSimilarityData",
sId: this.data.id,
sSsim: this.data.ssim,
sType: "ZhuTiFenXiBl",
iPageIndex: iPageIndex,
iPageSize: iPageSize,
token: app.globalData.getStorage('token'),
affections: this.data.affections
// sTimeType: sTimeType,
// sStartTime: sStartTime,
// sEndTime: sEndTime
}
//第一次加载数据
if (iPageIndex == 1) {
this.setData({
loadMore: true, //把"上拉加载"的变量设为true显示
loadAll: false //把“没有数据”设为false隐藏
})
}
app.globalData.request(obj, (database) => {
this.setData({
totalNum: database.totalNum
})
}).then(res => {
if (res && res.length > 0) {
iPageIndex++;
//把新请求到的数据添加到dataList里
let list = this.data.dataList.concat(res);
this.setData({
dataList: list, //获取数据数组
loadMore: false //把"上拉加载"的变量设为false显示
});
if (res.length < iPageSize) {
this.setData({
loadMore: false, //隐藏加载中。。
loadAll: true //所有数据都加载完了
});
}
} else {
this.setData({
loadAll: true, //把“没有数据”设为true显示
loadMore: false //把"上拉加载"的变量设为false隐藏
});
}
})
},
showMoreData() {
let sm = !this.data.showMore;
if (sm) {
this.setData({
content: this.data.c1
})
} else {
this.setData({
content: this.data.c2
})
}
this.setData({
showMore: sm
})
},
handlerCopy() {
if (this.data.affections == 1) {
this.setData({
affections: '正面',
})
} else if (this.data.affections == 2) {
this.setData({
affections: '负面',
})
} else {
this.setData({
affections: '中性',
})
}
wx.setClipboardData({
data: `发布时间:${this.data.sourcetime}\n来源: ${this.data.source}\n标题: ${doStr(this.data.title, 70)}\n链接:${this.data.uri}\n调性:${this.data.affections}\n作者:${this.data.user_author}` || '',
success: () => {
this.setData({
showDialog: true
})
}
})
},
handlerSource(e) {
const row = e.currentTarget.dataset.row;
wx.navigateTo({
url: '/subPackages/pages/detail/index?id=' + row._id,
})
}
})