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.

185 lines
5.8 KiB

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