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.

143 lines
3.0 KiB

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 query = pageHistoryCollection;
if(this.data.conditions){
query = query.where(this.data.conditions);
}
if(refresh){
query.count().then(res=>{
console.log(res);
this.setData({total: res.total});
})
}
let res = await query.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"
})
})
},
onConditionChange(e){
let {detail} = e;
console.log(e);
console.log(detail);
let conditions = {...this.data.conditions, ...detail};
this.setData({conditions});
this.refresh({refresh:1})
.then(res=>{
wx.showToast({
title:"筛选成功"
})
})
},
deleteCondition(e){
console.log(e);
let {currentTarget:{dataset:{key}}} = e;
let conditions = this.data.conditions;
delete conditions[key];
this.setData({conditions});
this.refresh({refresh:1}).then(res=>{
wx.showToast({
title: '去除成功'
})
})
},
onReady: function () {
},
onShow: function () {
},
onHide: function () {
},
onUnload: function () {
},
onPullDownRefresh: function () {
this.conditions = null;
this.refresh({refresh:1});
},
onReachBottom: function () {
this.refresh({refresh:0});
},
onShareAppMessage: function () {
}
})