记《高校考勤系统》小程序(2)
发布时间:2020-12-14 19:04:44 所属栏目:资源 来源:网络整理
导读:这是其他几篇的地址: 记《高校考勤系统》小程序(1) 前面讲了用户注册和首页天气功能,下面讲讲课程表页的实现. 五.课程表页 这里参考了简书上面?轩辕夜空?位作者的案例,以及其参考?极乐叔?的课程表的思路. 同样制作课程表需要用到云开发来存储数据,以及
这是其他几篇的地址: 记《高校考勤系统》小程序(1)前面讲了用户注册和首页天气功能,下面讲讲课程表页的实现.五.课程表页
先来看看完成后的效果图
<!-- 星期 -->
<view class="top">
<"top-text">
<text>节日</text>
</view>
<text>一</text>二</text>三</text>四</text>五</text>六</text>日</view>
</view>
<!-- 课程 -->
<"cont">
<"cont-left">
<"left"> 1 </view>
<"left"> 2 </"left"> 3 </"left"> 4 </"left"> 5 </"left"> 6 </"left"> 7 </"left"> 8 </view>
</"cont-right">
</view>
<"bottom">
————<text>读万卷书 行万里路</text>————
</view>
复制代码
点击查看wxss代码
page {
width: 100%;
height: position: relative;
}
.top {
padding: 16rpx 0;
border-top: 1px solid #e9e9e9;
border-bottom: 1px dashed #d3d3d3;
display: flex;
justify-content: flex-start;
}
.top-text {
12.5%;
text-align: center;
font-size: 32rpx;
font-weight: 600;
align-items: center;
}
.top border-left: #d3d3d3;
}
.top-text:nth-child(1) {
24rpx;
border-left: none;
line-height: 46rpx;
}
.cont {
justify-content: start;
}
.cont-left {
display: inline-block;
}
.left {
90rpx;
120rpx;
justify-content: center;
align-items: center;
box-sizing: border-box;
color: #666;
28rpx;
600;
}
.cont-right {
width: calc(100% - 90rpx);
}
.bottom {
position: absolute;
bottom: 20rpx;
#ddd;
.bottom text {
margin-left: margin-right: #9b9b9b;
}
复制代码
单个数据结构 {
//"_id": "296065c95da529b2055b57301b5afa75",云开发导入数据会直接生成_id,这里不用自己编写
"data_name": "Java高级开发技术(JavaEE)",//课程名
"address": "@康庄行知楼301",96);">//地点
"weekNum": "10-15周",96);">//周数
"pitchNum": "3-4",96);">//节数
"teacher": "赵老师",96);">//任课老师
"_openid": "oQnNa5NJfKqSZntKFLGZWnZuXNbo" //修改者的openid,本来是想做判断,后面使用了云函数,发现可有可无
}
复制代码
点击查看js代码
data: {
colorArr: ["rgb(229,188,76,0.8)","rgb(104,172,0);">"rgb(183,135,242,0);">"rgb(149,226,48,0);">"#ff7070",0);">"#e54d42",0);">"#0081ff",0);">"#7DC67D",0);">"#E17572",0);">"#C35CFF",0);">"#33BCBA",0);">"#FF8533",0);">"#6E6E6E",0);">"#ebd4ef",0);">"#428BCA",0);">"#39b54a",0);">"#FF674F",0);">"#e03997",0);">"#00CED1",0);">"#9F79EE",0);">"#FFC125",0);">"#32CD32",0);">"#00BFFF",0);">"#8799a3",0);">"#FF69B4"
],// 存储随机颜色
randomColorArr: [],randomColorArr2: [],i: 25,random: '',random2: this.data.randomColorArr = [] // 重置颜色数组1为空
data.randomColorArr2 = [] // 重置颜色数组2为空
const db = wx.cloud.database({
env: '*****' //你的云开发环境名
})
//获取课程表上午数据
db.collection('数据集合中你的表名').get().then((res) => {
this.kechengbiao = res.data
for (let j = 0; j <= 13; j++) { //for循环判断课名和地名为空则不加颜色
if (this.kechengbiao[j].data_name == '' && this.kechengbiao[j].address == '') {
this.random = 'none'
data.randomColorArr.push(this.random)
} else {
this.random = data.colorArr[Math.floor(Math.random() * data.i)] //随机颜色
this.random)
}
}
this.setData({
loding: true,kechengbiao: this.kechengbiao,randomColorArr: data.randomColorArr
})
})
//获取课程表下午
db.collection(this.kechengbiao2 = res.this.kechengbiao2[j].data_name == this.kechengbiao2[j].address == this.random2 = data.randomColorArr2.push(this.random2)
} this.random2 = this.random2)
}
}
this.setData({
kechengbiao2: this.kechengbiao2,randomColorArr2: data.randomColorArr2
})
})
},复制代码
<"cont-right">
<'appointent-date'> //上午
<"appointent-date-div" bindtap="select_date" wx:for="{{kechengbiao}}" wx:key={{index}}" data-key='}' style="background-color:{{randomColorArr[index]}}">
<"flex-item" >
<text class='data_name'>{{item.data_name}}</text>
<'address'>{{item.address}}</text>
</view>
</view>
</'appointent-date'> //下午
<"select_date2" wx:for={{kechengbiao2}{{randomColorArr2[index]}"flex-item">
<text>
</view>
复制代码
点击查看wxss代码
.appointent-date {
justify-content: space-around;
flex-wrap: wrap;
}
.appointent-date-div {
236rpx;
border-radius: 10rpx;
margin-bottom: 6rpx;
color: white;
}
.flex-item {
justify-content: flex-start;
flex-direction: column;
76rpx;
212rpx;
border: 1rpx solid transparent;
text-align: left;
cursor: pointer;
overflow: hidden;
}
.data_name {
.address {
display: inline-block;
}
复制代码
查
})
db.collection('***').get().then(res => {
console.log(res.data[this.id]) //获取点击时课程表数据
})
},复制代码
删首先我们在云函数中创建一个新的?云函数?,修改index.js文件
)
cloud.init({
env: '***',136);">//你的开发环境
traceUser: true
})
const db = cloud.database();
exports.main = async (event,context) => { // 云函数入口函数
try {
return await db.collection('***').doc(event.id).update({ //需要修改的数据库
data: {
data_name: event.data_name,address: event.address,weekNum: event.weekNum,pitchNum: event.pitchNum,teacher: event.teacher
},})
} catch (e) {
console.error(e)
}
return {
然后在js文件中编写对应的代码
改,增
wxml <!-- 编辑页 -->
<"edit" hidden={{ editShow }}">
<van-nav-bar title="编辑课程" right-text="完成" left-arrow bind:click-left="editLeft" bind:click-right="editRight" />
<"label className">
<text>课名</text>
<input value={{ nowClass.data_name }}" bindinput="bindKeyInput1"></input>
</"label">
<text>教室</{{ nowClass.address }"bindKeyInput2"></text>周数</{{ nowClass.weekNum }"bindKeyInput3"></text>节数</{{ nowClass.pitchNum }"bindKeyInput4"></text>老师</{{ nowClass.teacher }"bindKeyInput5"></view>
复制代码
新建修改课程表数据的云函数 // 1.首先获取输入框的值,存在data中
bindKeyInput1(e) { //课名
this.editClassName = e.detail.value
},bindKeyInput2(e) { //教室
this.editAddress = e.detail.value
},bindKeyInput3(e) { //周数
this.editWeekNum = e.detail.value
},bindKeyInput4(e) { //节数
this.editPitchNum = e.detail.value
},bindKeyInput5(e) { //老师
this.editTeacher = e.detail.value
},editRight() { // 2.编辑完成,点击提交按钮时将输入框的值赋值给对应的字段名
wx.cloud.callFunction({
name: // 修改课程表数据的云函数名称
data: {
id: this.editClassName,51); font-weight: 700;">this.editAddress,51); font-weight: 700;">this.editWeekNum,51); font-weight: 700;">this.editPitchNum,51); font-weight: 700;">this.editTeacher
},success: res => {
},fail: console.error
})
},复制代码
到这里课程表功能就做完了,如果有什么不懂得地方欢迎留言,或者写的不好的地方,请大家指出一起探讨,之后会继续分享后面的内容。大家也可以提前扫码查看小程序,欢迎指出不足,谢谢 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |