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.
107 lines
2.1 KiB
107 lines
2.1 KiB
5 years ago
|
import {checkAuth} from "../../utils";
|
||
|
import {getFormatDatetime} from "../../../js/utils"
|
||
|
const app = getApp();
|
||
|
const db = wx.cloud.database();
|
||
|
const pageHistoryCollection = db.collection("pageHistory");
|
||
|
|
||
|
|
||
|
Page({
|
||
|
|
||
|
data: {
|
||
|
data:[]
|
||
|
},
|
||
|
subscribe(){
|
||
|
wx.requestSubscribeMessage({
|
||
|
tmplIds: ["atZ4ZFfGIPxTiFGTCtkwvnfqjBA-fM7o1p5OiJQA_0Y"],
|
||
|
fail:console.error
|
||
|
})
|
||
|
},
|
||
|
onLoad: function (options) {
|
||
|
this.options = {page:1, limit:20};
|
||
|
if(checkAuth()){
|
||
|
this.refresh({refresh:1});
|
||
|
pageHistoryCollection.count()
|
||
|
.then(res=>{
|
||
|
console.log(res);
|
||
|
this.setData({total: res.total});
|
||
|
})
|
||
|
}else{
|
||
|
wx.showModal({
|
||
|
title:"提示",
|
||
|
content:"您没有权限访问",
|
||
|
success: res=>{
|
||
|
wx.navigateBack({
|
||
|
delta: 1
|
||
|
});
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
|
||
|
async refresh({refresh=0}={}){
|
||
|
if(!checkAuth())
|
||
|
return;
|
||
|
if(refresh){
|
||
|
this.options.page = 1;
|
||
|
}else{
|
||
|
this.options.page ++
|
||
|
}
|
||
|
let {page,limit} = this.options;
|
||
|
let skip = (page-1)*limit;
|
||
|
console.log(skip, limit);
|
||
|
let res = await pageHistoryCollection.orderBy("time", "desc").skip(skip).limit(limit).get();
|
||
|
let data = res.data.map(i=>{
|
||
|
i.time_show = getFormatDatetime(i.time);
|
||
|
i.options_show = JSON.stringify(i.options);
|
||
|
i.page_show = i.page.match(/\/([^\/]*$)/)[1];
|
||
|
return i;
|
||
|
});
|
||
|
console.log(data);
|
||
|
if(!refresh){
|
||
|
data = this.data.data.concat(data)
|
||
|
}
|
||
|
this.setData({data});
|
||
|
},
|
||
|
deleteMine(){
|
||
|
app.cloudapi("clearPageHistory")({
|
||
|
openid: app.globalData.openid
|
||
|
}).then(res=>{
|
||
|
console.log(res);
|
||
|
wx.showToast({
|
||
|
title: res.errMsg,
|
||
|
})
|
||
|
this.refresh({refresh:1});
|
||
|
}).catch(e=>{
|
||
|
wx.showToast({
|
||
|
title: e.errMsg,icon:"none"
|
||
|
})
|
||
|
})
|
||
|
},
|
||
|
onReady: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
onShow: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
onHide: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
onUnload: function () {
|
||
|
|
||
|
},
|
||
|
|
||
|
onPullDownRefresh: function () {
|
||
|
this.refresh({refresh:1});
|
||
|
},
|
||
|
|
||
|
onReachBottom: function () {
|
||
|
this.refresh({refresh:0});
|
||
|
},
|
||
|
|
||
|
onShareAppMessage: function () {
|
||
|
|
||
|
}
|
||
|
})
|