parent
deb3c86769
commit
a9c184df1d
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"permissions": {
|
"permissions": {
|
||||||
"openapi": [
|
"openapi": [
|
||||||
|
"subscribeMessage.send"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,107 @@
|
|||||||
|
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 () {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"usingComponents": {},
|
||||||
|
"enablePullDownRefresh": true,
|
||||||
|
"onReachBottomDistance": 260,
|
||||||
|
"navigationBarTitleText": "访问记录"
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<view class="list">
|
||||||
|
<view class="history {{item.isCrawl?'crawl':''}}" wx:for="{{data}}" wx:key="_id">
|
||||||
|
<view class="header">
|
||||||
|
{{item.time_show}} {{item.isCrawl?'爬虫访问':""}}
|
||||||
|
</view>
|
||||||
|
<view class="body">
|
||||||
|
{{item.page_show}}
|
||||||
|
{{item.options_show}}
|
||||||
|
</view>
|
||||||
|
<view class="single-line">
|
||||||
|
{{item.scene}} {{item.sceneDesc}}
|
||||||
|
</view>
|
||||||
|
<view class="detail">
|
||||||
|
{{item.openid}}
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="sticky footer">
|
||||||
|
<button type="main" bindtap="subscribe">订阅({{total}})</button>
|
||||||
|
<button type="secondary" bindtap="deleteMine">删除我的</button>
|
||||||
|
</view>
|
@ -0,0 +1,31 @@
|
|||||||
|
page{
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
.list{
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
.history{
|
||||||
|
background: white;
|
||||||
|
padding: 12px;
|
||||||
|
margin: 10px;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
.history.crawl{
|
||||||
|
border: 2px green solid;
|
||||||
|
}
|
||||||
|
.header,
|
||||||
|
.detail{
|
||||||
|
color: dimgray;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
.footer{
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
.footer>button{
|
||||||
|
flex: 1;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
.sticky{
|
||||||
|
bottom: 0;
|
||||||
|
position: sticky;
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
export function checkAuth(){
|
||||||
|
return getApp().globalData.openid == "oqugK431bepFwW6TGrHpQTerPkI0"
|
||||||
|
}
|
Loading…
Reference in new issue