examtest/test_mini/pages/admin/exam/index.js

98 lines
1.7 KiB
JavaScript

// pages/admin/exam/index.js
const api = require("../../../utils/request.js");
Page({
/**
* 页面的初始数据
*/
data: {
page:1,
isLoadedAll:false,
count:0,
results:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getList(1)
},
getList: function(page) {
wx.showLoading({
title: '正在加载...',
})
api.requesta('/examtest/exam/', 'GET', {page:page}).then(res=>{
wx.hideLoading()
let results = this.data.results
let isLoadedAll = false
if(res.data.results){
if(page==1){results=res.data.results}else{
results = results.concat(res.data.results)
}
}
if(!res.data.next){
isLoadedAll = true
}
this.setData({
count:res.data.count,
results:results,
page:page,
isLoadedAll: isLoadedAll
})
}).catch(
wx.hideLoading()
)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.getList(1)
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if(!this.data.isLoadedAll){
this.data.page=this.data.page+1
this.getList(this.data.page)
}
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})