1. 程式人生 > >微信小程式(看文件寫例項十)微信小程式課堂寶APP實現我的模組相關介面及邏輯

微信小程式(看文件寫例項十)微信小程式課堂寶APP實現我的模組相關介面及邏輯

繼上篇博文,這篇完成最後一個模組,即我的模組。

一、頁面效果

這個模組是和使用者型別相關的,因此老師賬號和學生賬號能看的功能不一樣,老師端效果如下:

點選頭像到達個人資訊如下:

點選後可以做相應的修改。學生端的介面如下:

修改密碼的頁面如下:

 其他頁面就不一一列出,下面用一個表來說明功能。

序號 描述 功能
1 課堂提問 點選後跳轉到課堂提問頁面
2 結束簽到

由老師賬號結束簽到,點選彈出一個模態彈窗,確定後更新最新簽到表signComplete為true,本次簽到學生再也不能簽到

3 課堂測試收卷

由老師賬號收卷,點選彈出一個模態彈窗,確定後老師提交最新課堂測試到submit_record表,本次課堂測試學生再也不能提交

4 模擬測試收卷 由老師賬號收卷,點選彈出一個模態彈窗,確定後老師提交最新模擬測試到submit_record表,本次模擬測試學生再也不能提交
5 錯題練習 點選後跳轉到錯題練習頁面,這些錯題是在練習頁面做題時的錯題,然後可以答題,重新提交
6 測試記錄 點選後跳轉到測試記錄頁面,有兩個頂部tabBar,一個是課堂測試另一個模擬測試,然後以列表顯示提交的課堂測試的日期及老師在後臺給的成績
7 問答記錄 跳轉到問答記錄頁面
8 通知中心 跳轉到通知頁面(簡單的聊天頁面),只有老師才能發起通知
9 關於我們 跳轉到關於我們介面,使用者可以提交反饋

二、頁面程式碼

1、我的頁面

<view class="section">

<navigator url='../mine/info/info' class="user-info-container" hover-class='weui-cell_active'>

<view class="user-img-wrap">

<image class="user-img" mode="scaleToFill" src="{{weChatUserInfo.avatarUrl}}" style="background-size: 100% 100%; background-position: 0% 0%; background-repeat: no-repeat; " />

</view>

<view class="user-info-wrap">

<text class="c-block user-info-name">{{weChatUserInfo.nickName}}</text>

<text class="c-block user-info-follower">學號: {{bmobUserInfo.username}}</text>

</view>

<view class="user-info-arrow-wrap">

<view class="user-info-arrow" />

</view>

</navigator>

<view hidden='{{bmobUserInfo.userType==1}}'>

<view class="boundary" />

<view class="user-bbs-info-container">

<navigator class="user-post-wrap" hover-class='btn_active' url='{{errorInfo.errorPath}}'>

<view class="user-post-icon" />

<view class="user-post-text-wrap">

<text class="user-text">錯題練習</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{errorInfo.errorCount}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</navigator>

<navigator url='{{testRecordInfo.testRecordPath}}' class="user-post-wrap" hover-class='btn_active'>

<view class="user-join-icon" />

<view class="user-post-text-wrap">

<text class="user-text">測試記錄</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{testRecordInfo.testRecordCount}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</navigator>

<navigator url='' class="user-post-wrap" hover-class='btn_active'>

<view class="user-mine-answer" />

<view class="c-minheight wx-view_yg2I9A">

<text class="user-text">問答記錄</text>

</view>

<view class="user-list-container">

<view class="post-list-num">2</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</navigator>

</view>

</view>

<view hidden='{{bmobUserInfo.userType==0}}'>

<view class="boundary" />

<view class="user-bbs-info-container">

<view class="user-bbs-info-container">

<view class="user-post-wrap" hover-class='btn_active' bindtap='classQuestion'>

<view class="user-post-question" />

<view class="user-post-text-wrap">

<text class="user-text">課堂提問</text>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

<view class="user-post-wrap" hover-class='btn_active' bindtap='endSign'>

<view class="user-mine-answer" />

<view class="user-post-text-wrap">

<text class="user-text">結束簽到</text>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

<view class="user-post-wrap" hover-class='btn_active' bindtap='classTestEnd'>

<view class="user-join-icon" />

<view class="user-post-text-wrap">

<text class="user-text">課堂測試收卷</text>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

<view class="user-post-wrap" hover-class='btn_active' bindtap='modelTestEnd'>

<view class="user-post-icon" />

<view class="user-post-text-wrap">

<text class="user-text">模擬測試收卷</text>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

 

</view>

</view>

</view>

<view class="boundary" />

<view class="user-bbs-info-container">

<view class="user-bbs-info-container">

<navigator url='{{chatInfo.path}}' class="user-post-wrap" hover-class='btn_active'>

<view class="user-post-chat" />

<view class="user-post-text-wrap">

<text class="user-text">通知中心</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{chatInfo.newMessageCount}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</navigator>

<navigator url='./aboutUs/aboutUs' class="user-post-wrap" hover-class='btn_active'>

<view class="user-post-aboutus" />

<view class="user-post-text-wrap">

<text class="user-text">關於我們</text>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</navigator>

</view>

</view>

</view>

@import "../../utils/weui.wxss";

 

.user-info-container {

padding: 10px 15px;

width: 100%;

display: flex;

border-width: 10px;

border-bottom-style: none;

border-bottom-color: rgb(245, 245, 245);

position: relative;

}

 

.user-info-wrap {

height: 60px;

width: 60%;

margin-left: 10px;

margin-right: 10px;

}

 

.user-img-wrap {

height: 60px;

width: 60px;

border-radius: 5px;

}

 

.user-edit-wrap {

height: 60px;

width: 63px;

display: flex;

position: absolute;

right: 10px;

}

 

.wx-image_bkrIYH {

width: 100%;

height: 100%;

position: relative;

}

 

/* 使用者頭像 */

.user-img {

position: relative;

width: 100%;

height: 100%;

border-radius: 5px;

border-bottom-right-radius: 5px;

border-bottom-left-radius: 5px;

border-top-right-radius: 5px;

border-top-left-radius: 5px;

}

 

.wx-text_qUYxY6 {

position: relative;

}

 

.user-info-name {

position: relative;

height: 60%;

width: 100%;

font-size: 1rem;

text-indent: 0px;

text-align: left;

line-height: 200%;

overflow: hidden;

}

 

.user-info-follower {

height: 40%;

width: 100%;

position: relative;

font-size: 1rem;

color: rgb(133, 133, 133);

line-height: 120%;

}

 

.user-update {

color: rgb(136, 136, 136);

font-size: 1rem;

padding-top: 20px;

position: relative;

height: 100%;

width: 56px;

}

/* 箭頭 */

.user-info-arrow {

width: 7px;

height: 7px;

border-width: 1px;

border-color: rgb(136, 136, 136);

border-style: none solid solid none;

transform: rotate(315deg) scale(1) translate(0%, 0%);

transition: All 0s ease;

-ms-transform: rotate(315deg) scale(1) translate(0%, 0%);

-o-transform: rotate(315deg) scale(1) translate(0%, 0%);

-moz-transform: rotate(315deg) scale(1) translate(0%, 0%);

-webkit-transform: rotate(315deg) scale(1) translate(0%, 0%);

-ms-transition: All 0s ease;

-o-transition: All 0s ease;

-moz-transition: All 0s ease;

-webkit-transition: All 0s ease;

}

 

.user-info-arrow-wrap {

position: absolute;

right: 15px;

height: 100%;

margin-left: 0px;

padding-top: 26px;

width: 7px;

}

 

.boundary {

height: 10px;

width: 100%;

background-color: rgba(245, 245, 245, 1);

}

 

.user-bbs-info-container {

width: 100%;

background-color: rgba(255, 255, 255, 1);

}

 

.user-post-wrap {

width: auto;

height: 49px;

padding: 12px 15px 12px 0px;

display: flex;

/* margin-left: 15px; */

border-width: 1px;

border-bottom-style: solid;

border-bottom-color: rgba(245, 245, 245, 1);

}

 

.user-post-text-wrap {

display: inline-block;

height: 25px;

position: static;

padding-top: 2px;

padding-bottom: 2px;

}

 

.user-text {

position: static;

font-size: 1rem;

line-height: 100%;

margin-left: 5px;

}

 

.user-list-container {

height: 25px;

position: absolute;

right: 10px;

/* width: 37px; */

display: flex;

}

/* 提示數字 */

.post-list-num {

position: relative;

height: 100%;

font-size: 14px;

font-style: normal;

/* font-family: "Microsoft YaHei", Arial; */

line-height: 25px;

text-align: right;

margin-right: 20px;

}

.user-arrow-wrap {

height: 100%;

width: 7px;

padding: 9px 5px 9px 0px;

text-align: right;

position: absolute;

right: 15px;

}

/* 我的錯題icon */

.user-post-icon {

width: 25px;

height: 25px;

background: url("http://i.pengxun.cn/static/vzan/web/post-big-pic-09.png") 0px 0px / 100% no-repeat;

vertical-align: middle;

margin-left: 15px;

margin-right: 5px;

display: inline-block;

}

/* 我的測試icon */

.user-join-icon {

width: 25px;

height: 25px;

background: url(http://i.pengxun.cn/static/vzan/web/post-big-pic-09.png) no-repeat 0 -25px;

vertical-align: middle;

margin-right: 5px;

margin-left: 15px;

display: inline-block;

background-size: 100%;

}

/* 我的回答icon */

.user-mine-answer {

width: 25px;

height: 25px;

background: url("http://i.pengxun.cn/static/vzan/web/post-big-pic-09.png") 0px -350px / 100% no-repeat;

vertical-align: middle;

margin-right: 5px;

margin-left: 15px;

display: inline-block;

}

/* 我的聊天icon */

.user-mine-chat {

width: 25px;

height: 25px;

background: url("http://i.pengxun.cn/static/vzan/web/post-big-pic-09.png") 0px -75px / 100% no-repeat;

vertical-align: middle;

margin-right: 5px;

margin-left: 15px;

display: inline-block;

}

/* 訊息中心 */

.user-post-chat {

width: 25px;

height: 25px;

background: url("http://i.pengxun.cn/static/vzan/web/post-big-pic-09.png") 0px -100px / 100% no-repeat;

vertical-align: middle;

margin-right: 5px;

margin-left: 15px;

display: inline-block;

}

/* 關於我們icon */

.user-post-aboutus {

width: 25px;

height: 25px;

background: url("http://i.pengxun.cn/static/vzan/web/post-big-pic-09.png") 0px -200px / 100% no-repeat;

vertical-align: middle;

margin-right: 5px;

margin-left: 15px;

display: inline-block;

}

/* 課堂提問icon */

.user-post-question {

width: 25px;

height: 25px;

background: url("http://i.pengxun.cn/static/vzan/web/post-big-pic-09.png") 0px -250px / 100% no-repeat;

vertical-align: middle;

margin-right: 5px;

margin-left: 15px;

display: inline-block;

}

2、個人資訊頁面

<!--pages/mine/info.wxml-->

<view class="boundary" />

<view class="user-bbs-info-container">

<view bindtap="powerDrawer" id='school' data-statu="open" class="user-post-wrap" hover-class='btn_active'>

<view class="user-post-text-wrap">

<text class="user-text">學校</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{bmobUserInfo.school}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

<view bindtap="powerDrawer" class="user-post-wrap" id='college' hover-class='btn_active' data-statu="open">

<view class="user-post-text-wrap">

<text class="user-text">學院</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{bmobUserInfo.college}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

<view class="user-post-wrap">

 

<view class="c-minheight wx-view_yg2I9A">

<text class="user-text">學號</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{bmobUserInfo.username}}</view>

</view>

</view>

<view bindtap="powerDrawer" class="user-post-wrap" id='name' hover-class='btn_active' data-statu="open">

<view class="c-minheight wx-view_yg2I9A">

<text class="user-text">姓名</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{bmobUserInfo.name}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

</view>

<view class="boundary" />

<view class="user-bbs-info-container">

<view bindtap="powerDrawer" class="user-post-wrap" id='major' hover-class='btn_active' data-statu="open">

<view class="user-post-text-wrap">

<text class="user-text">專業</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{bmobUserInfo.major}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

<view bindtap="powerDrawer" class="user-post-wrap" id='class' hover-class='btn_active' data-statu="open">

<view class="user-post-text-wrap">

<text class="user-text">班級</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{bmobUserInfo.class}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

<view class="user-post-wrap">

<view class="c-minheight wx-view_yg2I9A">

<text class="user-text">性別</text>

</view>

<view class="user-list-container">

<!-- <picker range="{{sexArray}}" value="{{sexIndex}}" bindchange="bindSexChange" class="post-list-num">

{{sexArray[sexIndex]}}</picker> -->

<view class="post-list-num" wx:if='{{weChatUserInfo.gender==1}}'>男</view>

<view class="post-list-num" wx:else>女</view>

</view>

</view>

<view class="user-post-wrap" hover-class='btn_active'>

<view class="c-minheight wx-view_yg2I9A">

<text class="user-text">出生日期</text>

</view>

<view class="user-list-container">

<picker mode="date" start="1970-1-1" end="2017-12-31" value="{{bmobUserInfo.birthday}}" fields="day" bindchange="bindDateChange" class="post-list-num">

<view wx:if='{{bmobUserInfo.birthday==null}}'>{{date}}</view>

<view wx:else>{{bmobUserInfo.birthday}}</view>

</picker>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

</view>

<view class="boundary" />

<view class="user-bbs-info-container">

<view class="user-post-wrap" id='area'>

<view class="user-post-text-wrap">

<text class="user-text">地區</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{weChatUserInfo.province}} {{weChatUserInfo.city}}</view>

</view>

</view>

<view bindtap="powerDrawer" class="user-post-wrap" id='mobilePhoneNumber' hover-class='btn_active' data-statu="open">

<view class="c-minheight wx-view_yg2I9A">

<text class="user-text">手機號</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{bmobUserInfo.mobilePhoneNumber}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

<view bindtap="powerDrawer" class="user-post-wrap" id='email' hover-class='btn_active' data-statu="open">

<view class="c-minheight wx-view_yg2I9A">

<text class="user-text">郵箱</text>

</view>

<view class="user-list-container">

<view class="post-list-num">{{bmobUserInfo.email}}</view>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</view>

 

<navigator url='./updatepas/updatepas' class="user-post-wrap" hover-class='btn_active'>

<view class="c-minheight wx-view_yg2I9A">

<text class="user-text">修改密碼</text>

</view>

<view class="user-arrow-wrap">

<view class="user-info-arrow" />

</view>

</navigator>

</view>

<!--mask-->

<view class="drawer_screen" bindtap="powerDrawer" data-statu="close" wx:if="{{showModalStatus}}"></view>

<!--使用animation屬性指定需要執行的動畫-->

<view animation="{{animationData}}" class="drawer_box" wx:if="{{showModalStatus}}">

<!--drawer content-->

<view class="drawer_title" id='title'>更新{{desc}}</view>

<form bindsubmit='powerDrawer' class="drawer_content">

<view class="top grid">

<label class="title col-0">{{desc}}</label>

<input class="input_base input_h30 col-1" name='inputText' placeholder='您的{{desc}}...'></input>

</view>

<button form-type='submit' class="btn_ok" bindtap="powerDrawer" data-statu="close">修改</button>

</form>

</view>

/* pages/mine/info.wxss */

@import "../mine.wxss";

 

.user-text {

position: static;

font-size: 1rem;

line-height: 100%;

margin-left: 15px;

}

 

/*mask*/

 

.drawer_screen {

width: 100%;

height: 100%;

position: fixed;

top: 0;

left: 0;

z-index: 1000;

background: #000;

opacity: 0.5;

overflow: hidden;

}

 

/*content*/

 

.drawer_box {

width: 650rpx;

overflow: hidden;

position: fixed;

top: 50%;

left: 0;

z-index: 1001;

background: #fafafa;

margin: -150px 50rpx 0 50rpx;

border-radius: 3px;

}

 

.drawer_title {

padding: 15px;

font: 22px;

text-align: center;

color: royalblue;

}

 

.drawer_content {

height: 90px;

overflow-y: scroll; /*超出父盒子高度可滾動*/

}

 

.btn_ok {

margin: 35px;

text-align: center;

border-top: 1px solid #e8e8ea;

color: #3cc51f;

font-size: 18px;

border-radius: 5%;

}

 

.top {

padding-top: 8px;

}

 

.bottom {

padding-bottom: 8px;

}

 

.title {

height: 40px;

line-height: 40px;

width: 160rpx;

text-align: center;

display: inline-block;

font: 300 28rpx/30px;

}

 

.input_base {

border: 2rpx solid #ccc;

padding-left: 10rpx;

margin-right: 50rpx;

}

 

.input_h30 {

height: 40px;

line-height: 40px;

}

 

.input_h60 {

height: 60px;

}

 

.input_view {

font: 16px;

background: #fff;

color: #000;

line-height: 40px;

}

 

input {

font: 16px;

background: #fff;

color: #000;

}

 

radio {

margin-right: 20px;

}

 

.grid {

display: -webkit-box;

display: box;

}

 

.col-0 {

-webkit-box-flex: 0;

box-flex: 0;

}

 

.col-1 {

-webkit-box-flex: 1;

box-flex: 1;

}

 

.fl {

float: left;

}

 

.fr {

float: right;

}

 

3、錯題練習頁面

<!-- pages/mine/errorTest/errorTest.wxml-->

 

<view class="page">

<view class='title'>

<image class='header-img' src="{{weChatUserInfo.avatarUrl}}" />

<view class='info'>

<text class='nick-name'>{{weChatUserInfo.nickName}}</text>

<view class='school-info'>

<image class='school-img' />

<text class='school-name'>{{bmobUserInfo.school}}</text>

</view>

</view>

</view>

<view class="page__bd">

<view class="weui-grids">

<block wx:for="{{grids}}" wx:key="unique">

<navigator url="{{item.path}}" class="weui-grid" hover-class="weui-grid_active">

 

<view class="weui-grid__label" style='font-size: 18px;color:royalblue;'>{{item.chapter}}</view>

<view class="weui-grid__label" style='color:#495056;'>{{item.name}}</view>

<view class="weui-grid__label" style='font-size: 12px;color:rebeccapurple;'>({{item.num}})</view>

</navigator>

</block>

</view>

</view>

</view>

/* pages/mine/errorTest/errorTest.wxss */

@import '../.././test/test.wxss';

4、測試記錄頁面

<view class="swiper-tab">

<view class="swiper-tab-list {{currentTab==0 ? 'on' : ''}}" data-current="0" bindtap="swichNav">課堂測試</view>

<view class="swiper-tab-list {{currentTab==1 ? 'on' : ''}}" data-current="1" bindtap="swichNav">模擬測試</view>

</view>

<swiper current="{{currentTab}}" class="swiper-box" duration="300" style="height:{{winHeight - 31}}px" bindchange="bindChange">

<swiper-item>

<view class='test-record-item'>

<view class='test-record-item-date'>測試日期</view>

<view class='test-record-item-series'>測試次別</view>

<view class='test-record-item-commit'>

<text>提交狀態</text>

</view>

<view class='test-record-item-score'>成績</view>

</view>

<block wx:for="{{testRecordInfo}}" wx:key="unique">

<view wx:if="{{item.types =='課堂測試'}}" class='test-record-item'>

<view class='test-record-item-date'>{{item.date}}</view>

<view class='test-record-item-series'>{{item.series}}</view>

<view class='test-record-item-commit'>

<icon type='success' class='test-record-item-commit-icon'></icon>

<text class='test-record-item-commit-text'>已簽到</text>

</view>

<view class='test-record-item-score'>{{item.score}}</view>

</view>

</block>

</swiper-item>

<swiper-item>

<view class='test-record-item'>

<view class='test-record-item-date'>測試日期</view>

<view class='test-record-item-series'>測試次別</view>

<view class='test-record-item-commit'>

<text>提交狀態</text>

</view>

<view class='test-record-item-score'>成績</view>

</view>

<block wx:for="{{testRecordInfo}}" wx:key="unique">

<view wx:if="{{item.types =='模擬測試'}}" class='test-record-item'>

<view class='test-record-item-date'>{{item.date}}</view>

<view class='test-record-item-series'>{{item.series}}</view>

<view class='test-record-item-commit'>

<icon type='success' class='test-record-item-commit-icon'></icon>

<text class='test-record-item-commit-text'>已簽到</text>

</view>

<view class='test-record-item-score'>{{item.score}}</view>

</view>

</block>

</swiper-item>

</swiper>

/* pages/mine/testRecord/testRecord.wxss */

 

.swiper-tab {

width: 100%;

border-bottom: 2rpx solid #777;

text-align: center;

line-height: 80rpx;

}

 

.swiper-tab-list {

font-size: 30rpx;

display: inline-block;

width: 50%;

color: #777;

}

 

.on {

color: #118fff;

border-bottom: 5rpx solid #118fff;

font-size: 35rpx;

}

 

.swiper-box {

display: block;

height: 100%;

width: 100%;

overflow: hidden;

}

 

.swiper-box view {

text-align: center;

}

 

.test-record-item{

display: flex;

flex-direction: row;

line-height: 80rpx;

border-bottom: 1rpx solid #777;

}

.test-record-item-date{

height: 100%;

width: 25%;

font-size: 28rpx;

line-height: 80rpx;

}

.test-record-item-series{

height: 100%;

width: 40%;

font-size: 28rpx;

line-height: 80rpx;

}

.test-record-item-commit{

height: 100%;

width: 20%;

font-size: 28rpx;

line-height: 80rpx;

}

.test-record-item-score{

height: 100%;

width: 15%;

font-size: 28rpx;

line-height: 80rpx;

color: red;

}

 

5、通知頁面

<!--pages/mine/chat/chat.wxml-->

<!-- <template name="temp">

<block wx:for="{{message}}" wx:key="unique">

<view>{{item.userId.objectId}} {{bmobUserInfo.objectId}}</view>

<block wx:if="{{item.userId.objectId != bmobUserInfo.objectId}}">

<view class="reply">

<view class="pic">

<image src="{{weChatUserInfo.avatarUrl}}"></image>

</view>

<view class='msg-info'>

<view class='user-nickname' style='text-align: left;'>

<text>{{bmobUserInfo.name}}</text>

</view>

<view class='user-nickname' style='text-align: left; font-size:12px'>

<text>{{item.updatedAt}}</text>

</view>

<view class="content">

<view class="text">

{{item.message}}

</view>

</view>

</view>

</view>

</block>

<block wx:elif="{{item.userId.objectId == bmobUserInfo.objectId}}">

<view class="send">

<view class='msg-info'>

<view class='user-nickname'>

<text>{{bmobUserInfo.name}}</text>

</view>

<view class='user-nickname' style=' font-size:12px'>

<text>{{item.updatedAt}}</text>

</view>

<view class="content">

<view class="text">

{{item.message}}

</view>

</view>

</view>

<view class="pic">

<image src="{{weChatUserInfo.avatarUrl}}"></image>

</view>

</view>

</block>

</block>

</template> -->

 

<scroll-view scroll-y="true" scroll-top="{{scrollTop}}">

<!-- <template is="temp" data="{{message}}"></template> -->

<block wx:for="{{message}}" wx:key="unique">

<block wx:if="{{item.userId.objectId != bmobUserInfo.objectId}}">

<view class="reply">

<view class="pic">

<image src="{{bmobUserInfo.avatarUrl}}"></image>

</view>

<view class='msg-info'>

<view class='user-nickname' style='text-align: left;'>

<text>{{item.userId.name}}</text>

</view>

<view class='user-nickname' style='text-align: left; font-size:12px'>

<text>{{item.updatedAt}}</text>

</view>

<view class="content">

<view class="text">

{{item.message}}

</view>

</view>

</view>

</view>

</block>

<block wx:elif="{{item.userId.objectId == bmobUserInfo.objectId}}">

<view class="send">

<view class='msg-info'>

<view class='user-nickname'>

<text>{{bmobUserInfo.name}}</text>

</view>

<view class='user-nickname' style=' font-size:12px'>

<text>{{item.updatedAt}}</text>

</view>

<view class="content">

<view class="text">

{{item.message}}

</view>

</view>

</view>

<view class="pic">

<image src="{{avatarUrl.avatarUrl}}"></image>

</view>

</view>

</block>

</block>

</scroll-view>

<form bindsubmit="sendMessage" hidden='{{bmobUserInfo.userType ==0}}'>

<view class="sendMessage">

<textarea auto-height="true" name="input" class="inputMsg" value="{{inputMsg}}" />

<button form-type="submit" class="send">傳送</button>

</view>

</form>

page{

background-color:#ececec;

}

scroll-view{

height:1150rpx;

padding-bottom:50px;

}

.reply .pic,

.send .pic{

padding:10px;

}

.reply,

.send{

display: flex;

}

.reply .pic image,

.send .pic image{

width:80rpx;

height:80rpx;

border-radius: 5%;

}

.send{ justify-content:flex-end; }

.reply .content{

padding:10px 10px 10px 0;

max-width:480rpx;

}

.send .content{

padding:10px 0 10px 10px;

max-width:480rpx;

}

.reply .content .text,

.send .content .text{

background-color: #fff;

border-radius: 5px;

padding:10px;

font-size:16px;

word-break: keep-all;

word-wrap: break-word;

}

.send .content .text{

background-color: #78fd75;

}

.sendMessage{

display: flex;

position: fixed;

bottom:0;

left:0;

right: 0;

padding:10px;

background-color: #ececec;

}

.inputMsg{

flex: 2;

background-color:#fff;

height: 30px;

font-size: 16px;

padding:5px 10px;

}

.sendMessage .send{

background-color:#64b162;

color:#fff;

height: 30px;

line-height: 30px;

margin-left: 10px;

align-self: flex-end;

}

.msg-info{

display: flex;

flex-direction: column;

padding: 5px;

}

.user-nickname{

text-align: right;

font-size: 14px;

color: royalblue;

}

6、關於我們介面

<!--pages/mine/aboutUs/aboutUs.wxml-->

<text class='title'>反饋</text>

<form bindsubmit='feedback' class='feedback-form'>

<textarea name='content' class='content' placeholder='你的反饋...'></textarea>

<button class='btn-submit' form-type='submit'>提交反饋</button>

</form>

<view class='info'>

<text>本軟體作為計算機網路課程資訊化輔助使用,當前版本為v1.0,如果您在使用過程中有任何問題,請給我們提交您寶貴的意見,也可以傳送到郵箱:[email protected]。</text>

</view>

/* pages/mine/aboutUs/aboutUs.wxss */

 

.title {

padding: 4%;

margin-top: 5%;

color: #118fff;

}

 

.feedback-form {

display: flex;

flex-direction: column;

justify-content: center;

}

 

.content {

height: 150px;

width: 92%;

margin: 2%;

padding: 2%;

white-space: pre-wrap;

background: whitesmoke;

color: #118fff;

border-radius: 3%;

border: 1px solid rgb(214, 214, 214);

}

 

.btn-submit {

width: 96%;

margin: 2%;

background: #118fff;

color: white;

border-radius: 3%;

}

.info{

width: 96%;

margin-left: 2%;

margin-top: 20%;

padding: 2%;

color: #118fff;

font-size: 32rpx;

}

 

三、頁面對應的程式碼

由於點名功能需要實時推送,這個功能是收費的,所以現在這個功能作為最後的開發完成收尾,下面是所有已經完成的功能的程式碼邏輯。

我的mine.js

var Bmob = require("../../utils/Bmob-1.6.3.min.js");

var Util = require("../../utils/util.js");

var that;

var app = getApp();

Page({

data: {

weChatUserInfo: null,

bmobUserInfo: null,

// 錯題資訊

errorInfo: {},

// 測試記錄

testRecordInfo: {},

// 課堂問答記錄

answerRecordInfo: {},

// 通知資訊

chatInfo: {

newMessageCount: 0,

path: null

}

},

// 課堂提問

classQuestion: function() {

// 彈出從底部彈出選單

 

},

// 結束簽到

endSign: function() {

// 確定結束最新一次簽到嗎?點選確定即結束

wx.showModal({

title: '結束簽到提示',

content: '您確定要結束本次簽到嗎',

success: function (resModal) {

if(resModal.confirm){

wx.showToast({

title: '結束簽到中...',

icon:'loading',

duration:10000

})

let query = Bmob.Query('sign_record');

let userIdPointer = Bmob.Pointer('_User');

let pointerUserId = userIdPointer.set(that.data.bmobUserInfo.objectId);

query.equalTo('userId','==',pointerUserId);

query.order('-numberNo');

query.limit(3);//只查詢最新的三條記錄

query.find().then(res=>{

query.get(res[0].objectId).then(res1=>{

wx.hideToast();

if(res1.signComplete == false){

res1.set('signComplete',true);

res1.save();

wx.showToast({

title: '已結束本次簽到',

duration:3000

})

}

else{

wx.showToast({

title: '本次簽到已結束',

duration: 3000

})

}

});

});

}

}

})

},

// 課堂測試收卷

classTestEnd: function() {

// 確定結束本次課堂測試嗎?點選確定即結束

// 查詢主觀表最新測試是否有老師,如果有,提示已經收卷,沒有則寫入

wx.showModal({

title: '課堂測試收卷提示',

content: '您確定要收卷嗎',

success: function (resModal) {

if (resModal.confirm) {

wx.showToast({

title: '收卷中...',

icon: 'loading',

duration: 10000

})

let queryNumberNo = Bmob.Query('subjective_item');

queryNumberNo.equalTo('type','==','課堂測試');

queryNumberNo.order('-numberNo');

queryNumberNo.limit(3);

queryNumberNo.find().then(resNumberNo=>{

if (resNumberNo.length==0){

wx.hideToast();

wx.showToast({

title: '還沒有釋出課堂測試噢',

duration:2500

})

return;

}

// 得到最新的第幾次測試

let numberNo = resNumberNo[0].numberNo;

// 去查詢submit_record表是是否有這次測試的記錄

let querySubmitRecord = Bmob.Query('submit_record');

querySubmitRecord.equalTo('type', '==', '課堂測試');

querySubmitRecord.equalTo('numberNo','==',numberNo);

let userIdPointer = Bmob.Pointer('_User');

let pointerUserId = userIdPointer.set(that.data.bmobUserInfo.objectId);

querySubmitRecord.equalTo('userId', '==', pointerUserId);

querySubmitRecord.find().then(resSubmitRecord=>{

// 如果找到說明已經完成收卷

if(resSubmitRecord.length>0){

wx.hideToast()

wx.showToast({

title: '您已經收捲過了...',

duration:2500

})

}

else{

// 沒有找到說明要提交個新的記錄已經完成收卷

let newQuerySubmitRecord = Bmob.Query('submit_record');

newQuerySubmitRecord.set('numberNo',numberNo);

newQuerySubmitRecord.set('type','課堂測試');

newQuerySubmitRecord.save().then(resNewQuerySubmitRecord=>{

newQuerySubmitRecord.get(resNewQuerySubmitRecord.objectId).then(resGetNewQuerySubmitRecord=>{

resGetNewQuerySubmitRecord.set('userId', pointerUserId);

resGetNewQuerySubmitRecord.save();

wx.hideToast()

});

});

}

});

});

}

}

})

},

// 模擬測試收卷

modelTestEnd: function() {

// 確定結束本次模擬測試嗎?點選確定即結束

// 確定結束本次課堂測試嗎?點選確定即結束

// 查詢主觀表最新測試是否有老師,如果有,提示已經收卷,沒有則寫入

wx.showModal({

title: '課堂測試收卷提示',

content: '您確定要收卷嗎',

success: function (resModal) {

if (resModal.confirm) {

wx.showToast({

title: '收卷中...',

icon: 'loading',

duration: 10000

})

let queryNumberNo = Bmob.Query('subjective_item');

queryNumberNo.equalTo('type', '==', '模擬測試');

queryNumberNo.order('-numberNo');

queryNumberNo.limit(3);

queryNumberNo.find().then(resNumberNo => {

if (resNumberNo.length == 0) {

wx.hideToast();

wx.showToast({

title: '還沒有釋出模擬測試噢',

duration: 2500

})

return;

}

// 得到最新的第幾次測試

let numberNo = resNumberNo[0].numberNo;

// 去查詢submit_record表是是否有這次測試的記錄

let querySubmitRecord = Bmob.Query('submit_record');

querySubmitRecord.equalTo('type', '==', '模擬測試');

querySubmitRecord.equalTo('numberNo', '==', numberNo);

let userIdPointer = Bmob.Pointer('_User');

let pointerUserId = userIdPointer.set(that.data.bmobUserInfo.objectId);

querySubmitRecord.equalTo('userId', '==', pointerUserId);

querySubmitRecord.find().then(resSubmitRecord => {

// 如果找到說明已經完成收卷

if (resSubmitRecord.length > 0) {

wx.hideToast()

wx.showToast({

title: '您已經收捲過了...',

duration: 2500

})

}

else {

// 沒有找到說明要提交個新的記錄已經完成收卷

let newQuerySubmitRecord = Bmob.Query('submit_record');

newQuerySubmitRecord.set('numberNo', numberNo);

newQuerySubmitRecord.set('type', '模擬測試');

newQuerySubmitRecord.save().then(resNewQuerySubmitRecord => {

newQuerySubmitRecord.get(resNewQuerySubmitRecord.objectId).then(resGetNewQuerySubmitRecord => {

resGetNewQuerySubmitRecord.set('userId', pointerUserId);

resGetNewQuerySubmitRecord.save();

wx.hideToast()

});

});

}

});

});

}

}

})

},

 

// 獲得通知資訊,只有老師端才能發通知,學生端只能檢視

getChatInfo: function() {

wx.showToast({

title: '正在載入...',

icon: 'loading',

duration: 10000

})

// 只有老師賬號才能發起通知

// 查詢表的最新一條資料

let queryNewMessageCount = Bmob.Query('chat');

let message = wx.getStorageSync('lastMessage');

// 有快取訊息

if (message != null || message != undefined) {

queryNewMessageCount.equalTo('createdAt', '>', message.updatedAt);

}

//queryNewMessageCount.order('-createdAt');

queryNewMessageCount.count().then(resNewMessageCount => {

let queryNewMessage = Bmob.Query('chat');

queryNewMessage.include('userId', '_User');

queryNewMessage.order('createdAt');

queryNewMessage.find().then(resNewMessage => {

wx.hideToast();

that.setData({

chatInfo: {

newMessageCount: resNewMessageCount,

path: './chat/chat?chatInfo=' + JSON.stringify(resNewMessage)

}

});

}).catch();

}).catch();

// let queryMyMessages = Bmob.Query('chat');

// // queryMyMessages.include('userId', '_User');

// // 設定使用者關聯物件

// let userIdPointer = Bmob.Pointer('_User');

// let pointerUserId = userIdPointer.set(that.data.bmobUserInfo.objectId);

// queryMyMessages.equalTo('userId', '==', pointerUserId);

// queryMyMessages.order('-createdAt');

// queryMyMessages.find().then(resMyMessages => {

// let newMessageCount = 0;

// //console.log(resMyMessages);

// // 如果自己發過訊息

// if (resMyMessages.length > 0) {

// // 找到最後一條訊息的時間

// // 查詢列表中是否有比自己最後一條訊息更新的訊息

// let queryNewMessage = Bmob.Query('chat');

// queryNewMessage.equalTo('createdAt', '>', resMyMessages[0].updatedAt);

// queryNewMessage.order('-createdAt');

// queryNewMessage.find().then(resNewMessage => {

// //console.log(resNewMessage);

// newMessageCount = resNewMessage.length;

// // 查詢表中所有訊息

// let queryAllMessage = Bmob.Query('chat');

// queryAllMessage.find().then(resAllMessage => {

// wx.hideToast();

// that.setData({

// chatInfo: {

// newMessageCount: newMessageCount,

// path: './chat/chat?chatInfo=' + JSON.stringify(resAllMessage)

// }

// });

// }).catch();

 

// }).catch();

// }

// // 如果自己開啟過通知視窗,記錄上次最後一條訊息

// else {

// // 檢視聊天快取是否有訊息

// let message = wx.getStorageSync('lastMessage');

// // 有快取訊息

// if (messages.length > 0) {

// // 找到最後一條訊息的時間

// // 查詢列表中是否有比最後一條訊息更新的訊息

// let queryNewMessage = Bmob.Query('chat');

// queryNewMessage.equalTo('createdAt', '>', message.updatedAt);

// queryNewMessage.order('-createdAt');

// queryNewMessage.find().then(resNewMessage => {

// newMessageCount = resNewMessage.length;

// // 查詢表中所有訊息

// let queryAllMessage = Bmob.Query('chat');

// queryAllMessage.find().then(resAllMessage => {

// wx.hideToast();

// that.setData({

// chatInfo: {

// newMessageCount: newMessageCount,

// path: './chat/chat?chatInfo=' + JSON.stringify(resAllMessage)

// }

// });

// }).catch();

// }).catch();

// }

// // 沒有快取訊息

// else {

// // 直接查詢所有訊息

// let queryAllMessage = Bmob.Query('chat');

// queryAllMessage.find().then(resAllMessage => {

// wx.hideToast();

// that.setData({

// chatInfo: {

// newMessageCount: resAllMessage.length,

// path: './chat/chat?chatInfo=' + JSON.stringify(resAllMessage)

// }

// });

// }).catch();

// }

// }

// }).catch();

},

// 獲得錯題列表

getErrorCount: function() {

wx.showToast({

title: '正在載入...',

icon: 'loading',

duration: 10000

})

let query = Bmob.Query('test_error_item');

query.include('choose_item_id', 'choose_item');

query.find().then(res => {

let errorArray = [];

let errorCount = 0;

res.forEach((item, index) => {

if (item.userId.objectId == that.data.bmobUserInfo.objectId) {

if (!item.result) {

errorCount += 1;

errorArray.unshift(item);

}

}

});

wx.hideToast();

that.setData({

errorInfo: {

errorPath: './errorTest/errorTest?error=' + JSON.stringify(errorArray),

errorCount: errorCount

}

});

}).catch();

},

// 獲得測試記錄

getTestRecord: function() {

wx.showToast({

title: '正在載入...',

icon: 'loading',

duration: 10000

});

let query = Bmob.Query('submit_record');

let userIdPointer = Bmob.Pointer('_User');

let pointerUserId = userIdPointer.set(that.data.bmobUserInfo.objectId);

query.equalTo('userId', '==', pointerUserId);

query.find().then(res => {

wx.hideToast();

that.setData({

testRecordInfo: {

testRecordCount: res.length,

testRecordPath: './testRecord/testRecord?testRecordInfo=' + JSON.stringify(res)

}

});

}).catch();

},

onLoad: function(options) {

// 頁面初始化 options為頁面跳轉所帶來的引數

that = this;

//that.getErrorCount();

that.setData({

bmobUserInfo: wx.getStorageSync('bmobUserInfo'),

weChatUserInfo: wx.getStorageSync('weChatUserInfo')

});

},

onReady: function() {

// // 頁面渲染完成

 

},

onShow: function() {

// 頁面顯示

that.getChatInfo();

// 當前使用者是學生

if (that.data.bmobUserInfo.userType == 0) {

that.getErrorCount();

that.getTestRecord();

}

},

onHide: function() {

// 頁面隱藏

 

},

onUnload: function() {

// 頁面關閉

}

})

測試記錄testRecord.js

// pages/mine/testRecord/testRecord.js

 

var that;

Page({

 

/**

* Page initial data

*/

data: {

//頁面配置

winWidth: 0,

winHeight: 0,

// tab切換

currentTab: 0,

// 測試記錄資訊

testRecordInfo:[]

},

// 滑動切換tab

bindChange: function (e) {

var that = this;

that.setData({ currentTab: e.detail.current });

},

//點選tab切換

swichNav: function (e) {

var that = this;

if (this.data.currentTab === e.target.dataset.current) {

return false;

} else {

that.setData({

currentTab: e.target.dataset.current

})

}

},

/**

* Lifecycle function--Called when page load

*/

onLoad: function (options) {

that = this;

let data = JSON.parse(options.testRecordInfo);

data.forEach((item)=>{

let i = {

date:item.createdAt.split(' ')[0],

series:item.series,

types:item.type,

score:item.score

}

that.data.testRecordInfo.push(i);

});

that.setData({

testRecordInfo: that.data.testRecordInfo

});

// 獲取系統資訊

wx.getSystemInfo({

success: function (res) {

that.setData({

winWidth: res.windowWidth,

winHeight: res.windowHeight

});

}

});

},

 

/**

* Lifecycle function--Called when page is initially rendered

*/

onReady: function () {

 

},

 

/**

* Lifecycle function--Called when page show

*/

onShow: function () {

 

},

 

/**

* Lifecycle function--Called when page hide

*/

onHide: function () {

 

},

 

/**

* Lifecycle function--Called when page unload

*/

onUnload: function () {

 

},

 

/**

* Page event handler function--Called when user drop down

*/

onPullDownRefresh: function () {

 

},

 

/**

* Called when page reach bottom

*/

onReachBottom: function () {

 

},

 

/**

* Called when user click on the top right corner to share

*/

onShareAppMessage: function () {

 

}

})

個人資訊info.js

// pages/mine/info.js

var Bmob = require("../../../utils/Bmob-1.6.3.min.js");

var Util = require("../../../utils/util.js");

var that;

var app = getApp();

Page({

 

data: {

// 是否顯示彈窗

showModalStatus: false,

// 彈窗描述

desc: null,

descList: {

'school': '學校',

'college': '學院',

'name': '姓名',

'major': '專業',

'class': '班級',

'mobilePhoneNumber': '手機號',

'email': '郵箱'

},

weChatUserInfo: null,

bmobUserInfo: null,

date: '1988-08-08',

},

onLoad:function(){

that = this;

that.setData({

weChatUserInfo:wx.getStorageSync('weChatUserInfo'),

bmobUserInfo: wx.getStorageSync('bmobUserInfo')

});

},

bindDateChange: function (e) {

wx.showToast({

title: '更新中...',

icon: 'loading',

duration: 10000

});

var query = Bmob.Query('_User');

query.get(that.data.bmobUserInfo.objectId).then(res => {

res.set('birthday', e.detail.value);

res.save();

wx.hideToast();

//更新bombuser快取

that.data.bmobUserInfo['birthday'] = e.detail.value;

that.setData({ bmobUserInfo: that.data.bmobUserInfo });

// 把bmob使用者資訊快取到本地

wx.setStorageSync('bmobUserInfo', that.data.bmobUserInfo);

app.setGlobalData({ currentUser: wx.getStorageSync('bmobUserInfo') });

}).catch(err => {

console.log(err)

})

},

powerDrawer: function(e) {

// 彈窗效果

if (e.type == 'tap') {

// 更新title

for (var key in this.data.descList) {

if (key == e.currentTarget.id) {

this.setData({

desc: this.data.descList[key]

});

break;

}

}

// 顯示彈窗

var currentStatu = e.currentTarget.dataset.statu;

this.util(currentStatu);

}

// 如果是提交上來的更改資訊

if (e.type == 'submit') {

// 做資料更改操作

var value = e.detail.value.inputText;

// 驗證手機號的合法性

if (that.data.desc =='手機號'){

if (!Util.checkMobile(value)){

wx.showToast({

title: '手機號格式錯誤~',

duration:2500

});

return;

}

}

// 驗證手機號的合法性

if (that.data.desc == '郵箱') {

if (!Util.checkEmail(value)) {

wx.showToast({

title: '郵箱格式錯誤~',

duration: 2500

});

return;

}

}

// 上傳value值

for (var key in this.data.descList) {

if (that.data.descList[key] == that.data.desc) {

wx.showToast({

title: '更新中...',

icon: 'loading',

duration: 10000

});

var query = Bmob.Query('_User');

//query.set('objectId',) //需要修改的objectId

query.get(that.data.bmobUserInfo.objectId).then(res => {

res.set(key, value);

res.save();

wx.hideToast();

//更新bombuser快取

that.data.bmobUserInfo[key] = value;

that.setData({bmobUserInfo: that.data.bmobUserInfo});

// 把bmob使用者資訊快取到本地

wx.setStorageSync('bmobUserInfo', that.data.bmobUserInfo);

app.setGlobalData({currentUser: wx.getStorageSync('bmobUserInfo') });

}).catch(err => {

console.log(err)

})

break;

}

}

}

},

util: function(currentStatu) {

/* 動畫部分 */

// 第1步:建立動畫例項

var animation = wx.createAnimation({

duration: 200, //動畫時長

timingFunction: "linear", //線性

delay: 0 //0則不延遲

});

// 第2步:這個動畫例項賦給當前的動畫例項

this.animation = animation;

// 第3步:執行第一組動畫

animation.opacity(0).rotateX(-100).step();

// 第4步:匯出動畫物件賦給資料物件儲存

this.setData({

animationData: animation.export()

})

// 第5步:設定定時器到指定時候後,執行第二組動畫

setTimeout(function() {

// 執行第二組動畫

animation.opacity(1).rotateX(0).step();

// 給資料物件儲存的第一組動畫,更替為執行完第二組動畫的動畫物件

this.setData({

animationData: animation

})

//關閉

if (currentStatu == "close") {

this.setData({

showModalStatus: false

});

}

}.bind(this), 200)

// 顯示

if (currentStatu == "open") {

this.setData({

showModalStatus: true

});

}

}

})

密碼修改updatepas.js

// pages/mine/info/updatepas/updatepas.js

var Bmob = require("../../../../utils/Bmob-1.6.3.min.js");

var Util = require("../../../../utils/util.js");

var md5 = require("../../../../utils/md5.js");

import WxValidate from '../../../../utils/WxValidate.js';

var wxValidate = "";

var that;

var app = getApp();

Page({

 

/**

* 頁面的初始資料

*/

data: {

bmobUserInfo: null

},

updatePasswordSubmit:function(e){

//驗證form表單格式是否合法

var rules = {

oldPassword: {

required: true,

},

newPassword: {

required: true,

minlength: 8,

},

newPasswordAgain: {

required: true,

minlength: 8,

}

};

var message = {

oldPassword: {

required: '舊密碼不能為空',

},

newPassword: {

required: '新密碼不能為空',

minlength: '新密碼長度8-16位',

},

newPasswordAgain: {

required: '確認密碼不能為空',

minlength: '確認密碼長度8-16位',

}

};

// 獲得驗證例項

wxValidate = new WxValidate(rules, message);

if (!wxValidate.checkForm(e)) {

var error = wxValidate.errorList[0]

//提示資訊

console.log(error);

wx.showToast({

title: error.msg,

icon: 'success',

duration: 3000

});

return false;

}

// 再次驗證密碼

var oldPassword = e.detail.value.oldPassword;

var newPassword = e.detail.value.newPassword;

var newPasswordAgain = e.detail.value.newPasswordAgain;

if (!Util.checkPassword(newPassword)){

wx.showToast({

title: '密碼為字母數字組合',

icon: 'success',

duration: 3000

});

return;

}

if (!Util.checkPassword(newPasswordAgain)) {

wx.showToast({

title: '密碼為字母數字組合',

icon: 'success