项目概图如下所示
核心代码:
图一是search
search.wxml
<!-- 外面大框 -->
<view class="container">
<!-- 标题 -->
<view class="title">课程查询</view>
<form bindsubmit="submit">
<view class="search">
授课名称:<input type="text" name="course_name"/>
</view>
<view class="search">
授课教师:<input type="text" name="teacher_name"/>
</view>
<button form-type="submit" style="width:100%" type="default">查询</button>
</form>
</view>
search.wxss
.container{
margin-top: 30%;
background-color: rgb(122, 209, 180);
height: 308px;
color: white;
justify-content: center;
}
.title{
font-size: 25px;
text-align: center;
margin-bottom: 5%;
}
.search{
display: flex;
justify-content: space-evenly;
margin-bottom: 6%;
}
.search_btn{
margin-top: 5%;
width: 800px;
}
search.js
// pages/search/search.js
Page({
/**
* 页面的初始数据
*/
data: {
course_name:'',
teacher_name:''
},
submit(e) {
console.log(e);
wx.navigateTo({
url: '/pages/index/index?course_name=' + e.detail.value.course_name + '&teacher_name=' + e.detail.value.teacher_name,
})
},
})
图二是index
index.wxml
<view class="top">
<view wx:for="{{['一','二','三','四','五','六','日']}}" class='top-text'>周{{item}}</view>
</view>
<scroll-view scroll-y="true" class="scroll">
<view style="height:1200rpx;width:730rpx;display:flex;">
<view style='background-color:#d2e6b3;color:#7cba23;'>
<view wx:for="{{[1,2,3,4,5,6,7,8,9,10,11,12,13]}}" class='left'>{{item}}</view>
</view>
<view wx:for="{{[1,2,3,4,5,6,7,8,9,10,11,12,13]}}">
<view style="width:750rpx;margin-top:{{(index+1)*100}}rpx; position: absolute;border-bottom:1rpx solid {{index==4?'red':'lightgray'}};">
</view>
</view>
<!--课表-->
<view wx:for="{{courseInfo}}">
<view class="flex-item kcb-item" bindtap="showCardView" id='0' data-statu="open" data-index="{{index}}" style="margin-left:{{(item.day-1)*100}}rpx;margin-top:{{(item.start-1)*100+5}}rpx;height:{{item.length*100-5}}rpx;background-color:{{colorArrays[index%8]}}">
<!-- day代表星期几上课,start是上课时间,length上课长度,detail课程信息-->
<view class="smalltext">{{item.detail}}</view>
</view>
</view>
</view>
</scroll-view>
index.wxss
/* pages/subject/subject.wxss */
.top{
display: flex;
flex-direction: row;
margin-left: 35rpx;
background-color: #d2e6b3;
color: #7cba23;
}
.top-text{
width: 100rpx;
height: 35rpx;
font-size: 9pt;
justify-content: center;
display: flex;
align-items: center;
}
.left{
width: 35rpx;
height: 100rpx;
font-size: 9pt;
justify-content: center;
display: flex;
align-items: center;
}
.flex-item {
width: 95rpx;
height: 100px;
}
.kcb-item {
position: absolute;
justify-content: center;
display: flex;
align-items: center;
border-radius: 5px;
}
.smalltext {
font-size: 8pt;
color: #fff;
padding-left: 2px;
}
.scroll {
height: 1170rpx;
z-index: 101;
/* position: fixed; */
}
.box1 .dateBox{
width: 100%;
height: 50px;
line-height: 50px;
text-align: center;
margin-top: 20px;
font-size: 40rpx;
}
.box1{
display: flex;
flex-wrap: wrap;
margin: 0 auto;
}
.box1>view{
height: 30px;
line-height: 30px;
text-align: center;
font-size: 34rpx;
}
.dateOn{
border-radius: 50%;
background-color: hotpink;
color: #fff;
}
.ball {
box-shadow:2px 2px 10px #AAA;
border-radius: 20px;
position: absolute;
}
.font-color{
color:#a9a9a9;
}
index.js
const db = wx.cloud.database();
Page({
data: {
colorArrays: ["#85B8CF", "#90C652", "#D8AA5A", "#FC9F9D", "#0A9A84", "#61BC69", "#12AEF3", "#E29AAD"],
courseInfo:[],
course_name:'',
teacher_name:''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
course_name: options.course_name,
teacher_name: options.teacher_name
})
console.log(options.course_name)
const _ = db.command
db.collection('courses')
.where(_.or([{
course_name: db.RegExp({
regexp: '.*' + options.course_name,
options: 'i',
})
},
{
teacher_name: db.RegExp({
regexp: '.*' + options.teacher_name,
options: 'i',
})
}
])
.and([{
course_name: db.RegExp({
regexp: '.*' + options.course_name,
options: 'i',
}),
teacher_name: db.RegExp({
regexp: '.*' + options.teacher_name,
options: 'i',
})
}]))
.get()
.then(res => {//formData是数据库里面集合的名称
console.log(res); //如果更新数据成功则输出成功信息
var that = this;
that.setData({
courseInfo: res.data //数据赋值
});
console.log(res.data);
}).catch(err => {
console.log(err); //如果更新数据失败则输出失败信息
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
数据库结构图
over