微信小程序:教师评分系统(试题页)

本文介绍了微信小程序中如何实现教师评分系统的试题左右滑动功能,利用swiper组件处理用户交互。同时讲解了评教数据的处理,通过radio-group收集选择项,生成评教结果。最后阐述了提交功能,包括评教成功和已评教过的状态判断。
摘要由CSDN通过智能技术生成

一、实现试题左右滑动功能

试卷的试题页采用滑块视图容器(swiper)可以更方便查看试题。

 1.4.0 开始,change事件返回detail中包含一个source字段,表示导致变更的原因,可能值如下:

autoplay 自动播放导致swiper变化;

touch 用户划动引起swiper变化;

其他原因将用空字符串表示。

注意:其中只可放置<swiper-item/>组件,否则会导致未定义的行为。

swiper-item:仅可放置在<swiper/>组件中,宽高自动设置为100%。

示例页面:

<view class="header">
  <view class="head">
<view class="header-name"><text>被评老师:</text><text style='font-size:60rpx;'>{
  {teachername}}</text></view>
<view style="margin-top:10px;">{
  {papertype}}</view>
<view class="image">
    <image style="width:70px;height:70px;" src="../../images/teacher.jpg"></image>
</view>
</view>
</view>
 <view class="content"> 
<swiper indicator-dots="{
  {indicatorDots}}" bindchange="swiper_change" current="{
  {currentid}}">
  <swiper-item wx:for="{
  {papers}}">
  <view class="content-pj">{
  {index+1}}.{
  {item.content}}</view>
    <radio-group class="radio-group" bindchange="item_change" data-id="{
  {item.id}}">
    <label wx:if="{
  {item.itema!=''}}">
      <radio value='a#{
  {item.scorea}}' bindtap='next'><text>A {
  {item.itema}}</text></radio>
      </label>
      <label wx:if="{
  {item.itemb!=''}}">
      <radio value='b#{
  {item.scorea}}' bindtap='next'><text>B {
  {item.itemb}}</text></radio>
       </label>
      <label wx:if="{
  {item.itemc!=''}}">
      <radio value="c#{
  {item.scorec}}=" bindtap='next'><text>C {
  {item.itemc}}</text></radio>
       </label>
      <label wx:if="{
  {item.itemd!=''}}">
      <radio value="d#{
  {item.scored}}=" bindtap='next'><text>D {
  {item.itemd}}</text></radio>
      </label>
    </radio-group>
  </swiper-item>
</swiper>
</view> 
<button form-type='submit' type="default" disabled="{
  {btn_disabled}}" bindtap="mysubmit">提交</button>  

 

如果在 bindchange 的事件回调函数中使用 setData 改变 current 值,则有可能导致 setData 被不停地调用,因而通常情况下请在改变 current 值前检测 source 字段来判断是否是由于用户触摸引起。

代码如下:

swiper_change: function (e) {
    if (e.detail.source == 'touch') {
      this.setData({ currentid: e.detail.current })
    }
  }

二、实现评教数据的处理 {"4":"a","5":"b","6":"c"}

采用单项选择器(radio-group)可以实现选项的自由选择,内部由多个<radio/>组成。

Bindchange:<radio-group/> 中的选中项发生变化时触发 change 事件,event.detail = {value: 选中项radio的value}

每个选项都代表一个分值:A:10,B:8,C:6,D:4

最后结果:{"4":"a","5":"b","6":"c"}

参数:pjid 评教id  

        testpaperid 问卷id

        answer 评教结果 {"4":"a","5":"b","6":"c"}

        student 学生信息{"no":"1635050110", "name":"张三", "classid":"1000-1603"}

        message 留言

        score 分值

代码如下:

 data: {
    teachername: null,
    currentid: 0,
    count: 5,
    papertype: null,
    papers: null,
    pj:null,
    answer: {},
    score: {},
    btn_disabled: true

  },
  swiper_change: function (e) {
    if (e.detail.source == 'touch') {
      this.setData({ currentid: e.detail.current })
    }
  },
  item_change: function (e) {
    var value = e.detail.value;
    var arr=value.split('#');
    var _answer = this.data.answer;
    var _score = this.data.score;
    _answer[e.currentTarget.dataset.id]=arr[0];
    _score[e.currentTarget.dataset.id] = arr[1];
    this.setData({answer:_answer,score:_score});
    var len=0;
    for(var i in _answer){
      len++;
    }
    if(len<this.data.count){
      this.setData({btn_disabled:true});
    }else{
      this.setData({ btn_disabled: false });
    }
    // setTimeout(this.next, 2000);
  },
  //点击下一页按钮
  next: function (e) {
    var index = this.data.currentid;//独取变量的值
    index++;
    if (index >= this.data.count) {
      index = this.data.count - 1;
    }
    this.setData({ currentid: index });//给变量赋值
  }

三:提交功能,评教成功和已评教过功能

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值