小程序考试详情

This commit is contained in:
caoqianming 2021-06-01 22:15:05 +08:00
parent 308e948da8
commit c3732da9e4
11 changed files with 120 additions and 23 deletions

View File

@ -70,9 +70,9 @@ App({
globalData: {
userInfo: {},
userinfo: {}, // 服务器传回的消费者信息
host: 'https://apitest.ahctc.cn',
//host: 'https://apitest.ahctc.cn',
mediahost: 'https://apitest.ahctc.cn',
//host: 'http://127.0.0.1:8000',
host: 'http://127.0.0.1:8000',
//mediahost: 'http://127.0.0.1:8000',
token : '',
}

View File

@ -1,11 +1,13 @@
// pages/admin/exam/detail.js
const api = require("../../../utils/request.js");
Page({
/**
* 页面的初始数据
*/
data: {
exam:{},
tests:[]
},
/**
@ -13,7 +15,17 @@ Page({
*/
onLoad: function (options) {
if(options.id){
console.log(options.id)
let id = options.id
api.requesta(`/examtest/exam/${id}/`, 'GET').then(res=>{
this.setData({
exam:res.data
})
})
api.requesta('/examtest/examtest/', 'GET', {exam:id, pageoff:true}).then(res=>{
this.setData({
tests:res.data
})
})
}
},

View File

@ -1,2 +1,51 @@
<!--pages/admin/exam/detail.wxml-->
<text>pages/admin/exam/detail.wxml</text>
<view class="page">
<view class="page__bd">
<view style="height:4px"></view>
<view class="weui-panel weui-panel_access" style="margin:8px">
<view class="weui-panel__hd">{{exam.name}}</view>
<view class="weui-panel__bd">
<view class="weui-media-box weui-media-box_text">
<!-- <h4 class="weui-media-box__title">标题一</h4> -->
<view class="weui-media-box__desc">
考试地点:{{exam.place}}
</view>
<view class="weui-media-box__desc">
开关时间:{{exam.opentime}}-{{exam.closetime}}
</view>
<view class="weui-media-box__desc">
监考人:{{exam.proctor_name}}-{{exam.proctor_phone}}
</view>
</view>
</view>
</view>
<view class="weui-panel weui-panel_access">
<view class="weui-panel__hd">共{{tests.count}}人员参加考试</view>
<view class="weui-panel__bd">
<navigator class="weui-media-box weui-media-box_text" wx:for="{{results}}" wx:key="unique" url="detail?id={{item.id}}">
<h4 class="weui-media-box__title">
<text style="color:blue;font-weight:bold;">{{item.workscope_name}}</text>
{{item.name}}
</h4>
<view class="weui-media-box__desc">
考试地点:{{item.place}}
</view>
<view class="weui-media-box__desc">
开关时间:{{item.opentime}}-{{item.closetime}}
</view>
<view class="weui-media-box__desc">
监考人:{{item.proctor_name}}-{{item.proctor_phone}}
</view>
</navigator>
</view>
<view class="weui-loadmore weui-loadmore_line" wx:if="{{isLoadedAll}}">
<text class="weui-loadmore__tips">到底了</text>
</view>
<!-- <view class="weui-panel__ft">
<a class="weui-cell weui-cell_active weui-cell_access weui-cell_link">
<view class="weui-cell__bd">查看更多</view>
<text class="weui-cell__ft"></text>
</a>
</view> -->
</view>
</view>
</view>

View File

@ -6,22 +6,44 @@ Page({
* 页面的初始数据
*/
data: {
page:1,
isLoadedAll:false,
count:0,
results:[]
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.showLoading({
title: '正在查询...',
})
api.requesta('/examtest/exam/', 'GET').then(res=>{
wx.hideLoading()
this.setData(res.data)
}).catch(wx.hideLoading())
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()
)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
@ -54,14 +76,17 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.getList(1)
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
if(!this.data.isLoadedAll){
this.data.page=this.data.page+1
this.getList(this.data.page)
}
},
/**

View File

@ -1,3 +1,4 @@
{
"usingComponents": {}
"usingComponents": {},
"enablePullDownRefresh":true
}

View File

@ -2,7 +2,7 @@
<view class="weui-panel weui-panel_access">
<view class="weui-panel__hd">已发布的考试,共{{count}}场</view>
<view class="weui-panel__bd">
<view class="weui-media-box weui-media-box_text" wx:for="{{results}}" wx:key="unique">
<navigator class="weui-media-box weui-media-box_text" wx:for="{{results}}" wx:key="unique" url="detail?id={{item.id}}">
<h4 class="weui-media-box__title">
<text style="color:blue;font-weight:bold;">{{item.workscope_name}}</text>
{{item.name}}
@ -16,8 +16,11 @@
<view class="weui-media-box__desc">
监考人:{{item.proctor_name}}-{{item.proctor_phone}}
</view>
</view>
</navigator>
</view>
<view class="weui-loadmore weui-loadmore_line" wx:if="{{isLoadedAll}}">
<text class="weui-loadmore__tips">到底了</text>
</view>
<!-- <view class="weui-panel__ft">
<a class="weui-cell weui-cell_active weui-cell_access weui-cell_link">
<view class="weui-cell__bd">查看更多</view>

View File

@ -176,6 +176,12 @@ class ExamListSerializer(serializers.ModelSerializer):
model = Exam
fields = '__all__'
@staticmethod
def setup_eager_loading(queryset):
""" Perform necessary eager loading of data. """
queryset = queryset.prefetch_related('workscope','create_admin')
return queryset
class ExamSimpleSerializer(serializers.ModelSerializer):
class Meta:
model = Exam

View File

@ -33,9 +33,10 @@ from .serializers import (
WorkScopeSerializer, ExamCreateUpdateSerializer, ExamListSerializer, ExamTestDetailSerializer)
from django.utils import timezone
from django.db.models import Q
from utils.pagination import PageOrNot
# Create your views here.
class ExamViewSet(ModelViewSet):
class ExamViewSet(PageOrNot, ModelViewSet):
"""
正式考试增删改查
"""

Binary file not shown.

View File

@ -9,8 +9,8 @@ class PageOrNot:
def paginate_queryset(self, queryset):
if (self.paginator is None):
return None
elif self.request.query_params.get('pageoff', None) and self.get_queryset().count()<500:
elif self.request.query_params.get('pageoff', None) and queryset.count()<500:
return None
elif self.request.query_params.get('pageoff', None) and self.get_queryset().count()>=500:
elif self.request.query_params.get('pageoff', None) and queryset.count()>=500:
return ParseError('单次请求数据量大,请求中止')
return self.paginator.paginate_queryset(queryset, self.request, view=self)