A 管理界面浏览记录历史查看

master
educoder_weapp 5 years ago
parent deb3c86769
commit a9c184df1d

@ -1,6 +1,7 @@
{
"permissions": {
"openapi": [
"subscribeMessage.send"
]
}
}

@ -87,17 +87,30 @@ const sceneDescMap = {
1150: "扫一扫商品条码结果页打开小程序",
1153: '“识物”结果页打开小程序'
}
function getFormatTime(date){
date = date || new Date();
let hour = date.getHours();
let minu = date.getMinutes();
let sec = date.getSeconds();
if (hour < 10) hour = "0" + hour;
if (minu < 10) minu = "0" + minu;
if (sec < 10) sec = "0" + sec;
return hour + ":" + minu + ":" + sec;
}
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
});
const db = cloud.database();
const pageHistoryCollection = db.collection("pageHistory");
exports.main = async (event, context) => {
let {name, data} = event;
console.log(event);
const wxContext = cloud.getWXContext();
let db = cloud.database();
switch (name) {
case 'getOpenData': {
return cloud.getOpenData(data);
@ -112,16 +125,49 @@ exports.main = async (event, context) => {
}
case "reportPageHistory":{
console.log("reportPageHistory");
return db.collection("pageHistory").add({
var now = new Date();
let res = await pageHistoryCollection.add({
data:{
...data,
isCrawl: data.scene==1129,
sceneDesc: sceneDescMap[data.scene],
time: new Date(),
time: now,
timestamp: Date.now(),
openid: wxContext.OPENID
}
});
try{
console.log(sceneDescMap[data.scene].slice(0,31),now.toLocaleTimeString());
let result = await cloud.openapi.subscribeMessage.send({
touser: 'oqugK431bepFwW6TGrHpQTerPkI0',
page: 'admin/pages/page_history/page_history',
lang: 'zh_CN',
templateId: 'atZ4ZFfGIPxTiFGTCtkwvnfqjBA-fM7o1p5OiJQA_0Y',
miniprogramState: 'trial',
data: {
character_string1:{
value:"pageHistory" //服务器
},
character_string2:{
value: data.page.match(/\/([^\/]*$)/)[1] //数据类型
},
thing4:{
value:sceneDescMap[data.scene].slice(0,20) //添加内容
},
date3:{
value:getFormatTime(now)
}
}
})
console.log(result);
}catch(e){
console.error(e);
}
return res;
}
case "clearPageHistory":{
return pageHistoryCollection.where(data).remove();
}
default: {
return

@ -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"
}

@ -7,7 +7,7 @@
"backgroundColor": "#f5f5f5"
},
"usingComponents": {
"iconfont":"/components/iconfont/iconfont",
"iconfont": "/components/iconfont/iconfont",
"require-login": "/components/require-login/require-login"
},
"pages": [
@ -17,6 +17,12 @@
"pages/tidings/tidings"
],
"subpackages": [
{
"root": "admin",
"pages": [
"pages/page_history/page_history"
]
},
{
"root": "markdown",
"pages": [
@ -129,8 +135,8 @@
]
},
"account/pages/account/account": {
"network":"all",
"packages":[
"network": "all",
"packages": [
"markdown"
]
}

@ -81,6 +81,6 @@
</swiper-item>
</swiper>
<view class="operations">
<button type="main" plain bindtap="collect" class="collect">{{subject.is_collect?'已收藏':'收藏'}}</button>
<button type="secondary" bindtap="collect" class="collect">{{subject.is_collect?'已收藏':'收藏'}}</button>
<button type="main" bindtap="enterSend">发送至</button>
</view>

@ -98,10 +98,6 @@
display: flex;
background: white;
}
.operations>.collect{
background: white!important;
flex: 1;
}
.operations>button{
flex: 1;
border-radius: 0;

@ -44,8 +44,8 @@
</swiper-item>
</swiper>
<view wx:if="{{shixun.task_operation[0]}}" class="operations">
<button class="collect" bindtap="collect" type="main" plain>{{shixun.is_collect?'已收藏':'收藏'}}</button>
<button class="collect" bindtap="collect" type="secondary" >{{shixun.is_collect?'已收藏':'收藏'}}</button>
<button bindtap="enterChallenge" disabled="{{loading}}" type="main">{{shixun.task_operation[0]}}</button>
<button class="send" type="main" bindtap="sendToCourse" plain>发送至</button>
<button class="send" type="secondary" bindtap="sendToCourse">发送至</button>
</view>
<send-to-course show="{{showSendDialog}}" shixun_ids="{{shixun_ids}}"/>

@ -80,9 +80,6 @@
white-space: nowrap;
border-radius: 0;
}
button.collect, button.send{
background: white!important;
}
/* tmp solution*/
.weui-half-screen-dialog__hd__side .weui-icon-btn.weui-icon-btn_more{
display: none;

@ -190,7 +190,6 @@ Page({
}, 1000);
},
onSwiperChange(e){
;
let {detail:{current,source}} = e;
if(source=="touch"){
this.setData({current});
@ -215,7 +214,6 @@ Page({
},
async pullContent(){
;
let {path} = this.data.challenge;
path = this.processPath(path);
let {identifier} = this.data;
@ -233,17 +231,14 @@ Page({
}
}else
this.setData({content});
;
},
onEditorReady({pullContent=0}={}) {
const that = this
wx.createSelectorQuery().select('#code-editor').context(function (res) {
that.editor = res.context
if(pullContent&&that.editor)
that.pullContent();
//that.editor.insertText({text:that.content});
;
}).exec();
},

@ -39,9 +39,9 @@
bindinput="onTextAreaInput">
</textarea>
<view class="operations">
<button class="button-challenge" plain="1" type="main" bindtap="enterChallenge">任务</button>
<button class="button-challenge" type="secondary" bindtap="enterChallenge">任务</button>
<button id="task-build" class="button-build" loading="{{building}}" disabled="{{building}}" type="main" form-type="submit">测评</button>
<button class="button-outcome" plain="1" type="main" bindtap="enterOutcome">测试集</button>
<button class="button-outcome" type="secondary" bindtap="enterOutcome">测试集</button>
</view>
</form>
</view>

@ -4,6 +4,7 @@
.sticky-top{
top: 0;
position: sticky;
z-index: 1000;
}
.header{
background: white;

@ -22,15 +22,19 @@ Page({
let { envVersion, env } = global.config;
if (envVersion && envVersion != "release") {
wx.showActionSheet({
itemList: [env != "release" ? "切换为发布环境" : "切换为开发环境"],
itemList: [env != "release" ? "切换为发布环境" : "切换为开发环境", "查看页面访问记录"],
success: res => {
global.config.switchEnv(env != "release" ? "release" : "trial");
wx.showToast({
title: '切换成功'
});
this.logout({ showToast: 0 });
let { version, eduImgDir } = global.config;
this.setData({ version, eduImgDir });
if(res.tapIndex==0){
global.config.switchEnv(env != "release" ? "release" : "trial");
wx.showToast({
title: '切换成功'
});
this.logout({ showToast: 0 });
let { version, eduImgDir } = global.config;
this.setData({ version, eduImgDir });
}else if(res.tapIndex==1){
app.navigateTo({url:"{page_history}"})
}
}
})
return;

@ -50,6 +50,7 @@ Page({
onShareAppMessage(){
let {list, current} = this.data;
return app.shareApp({
imageUrl: global.config.attachDir + "944406",
path: "/"+this.route+"?type="+list[current].type
})
}

@ -99,8 +99,10 @@ Component({
},
exit_course(){
wx.showModal({
title: '提示',
title: '警告',
content: '退出后您将不再是本课题的成员,\n作品将全部被删除\n确定要退出该课堂吗',
confirmColor:"#fa5151",
confirmText:"退出",
success:res=>{
if(res.confirm){
app.api("courses.exit_course")({course_id:this.data.data.id})
@ -173,6 +175,7 @@ Component({
title: '警告',
content: '课堂删除后所有数据将被删除并且【无法恢复】,\n是否确定删除',
confirmColor:"#fa5151",
confirmText:"删除",
success: res=>{
if(!res.confirm)
return;

@ -43,7 +43,7 @@
background: orange;
top: -6px;
left: -16px;
border-bottom: #f0f0f0 3px solid;
border-bottom: #f0f0f0 2px solid;
}
.body{
display: flex;

@ -5,13 +5,13 @@
<template is="we-cropper" data="{{...cropperOpt}}" />
</view>
<view class="operations flex-row">
<button class="upload" type="main" plain="1" bindtap="chooseImage">
<button class="upload" type="secondary" bindtap="chooseImage">
重选图片
</button>
<button type="main" disabled="{{submitting}}" class="getCropperImage" bindtap="onConfirm">
确认
</button>
<button type="main" plain open-type="getUserInfo" bindgetuserinfo="onGetUserInfo">
<button type="secondary" open-type="getUserInfo" bindgetuserinfo="onGetUserInfo">
微信头像
</button>
</view>

@ -227,6 +227,12 @@
"pathName": "course/pages/course_invite/course_invite",
"query": "course_id=7582",
"scene": null
},
{
"id": -1,
"name": "admin/pages/page_history/page_history",
"pathName": "admin/pages/page_history/page_history",
"scene": null
}
]
}

Loading…
Cancel
Save