帮我写一个微信小程序大学课程表

时间: 2023-07-01 09:07:49 浏览: 105
好的,下面是一个简单的微信小程序大学课程表的代码实现,你可以根据自己的需求进行修改和完善: 1. 在小程序开发者工具中创建一个新项目,选择小程序模板,命名为“课程表”。 2. 在 app.json 文件中添加页面路径和标签栏配置: ``` { "pages": [ "pages/index/index", "pages/course/course" ], "tabBar": { "list": [ { "pagePath": "pages/index/index", "text": "首页" }, { "pagePath": "pages/course/course", "text": "课程表" } ] } } ``` 3. 在 pages/index/index.wxml 中编写首页的布局和样式: ``` <view class="container"> <view class="title">欢迎使用课程表</view> <view class="subtitle">请点击下方按钮开始设置课程表</view> <button class="btn" bindtap="goToCourse">设置课程表</button> </view> ``` ``` .container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } .title { font-size: 28rpx; font-weight: bold; margin-bottom: 10rpx; } .subtitle { font-size: 18rpx; color: #999; margin-bottom: 20rpx; } .btn { width: 200rpx; height: 60rpx; border-radius: 30rpx; background-color: #007aff; color: #fff; font-size: 24rpx; font-weight: bold; border: none; outline: none; } ``` 4. 在 pages/index/index.js 中添加跳转到课程表页面的逻辑: ``` Page({ goToCourse: function() { wx.switchTab({ url: '../course/course', }) } }) ``` 5. 在 pages/course/course.wxml 中编写课程表的布局和样式: ``` <view class="container"> <view class="header"> <view class="cell"></view> <view class="cell">周一</view> <view class="cell">周二</view> <view class="cell">周三</view> <view class="cell">周四</view> <view class="cell">周五</view> <view class="cell">周六</view> <view class="cell">周日</view> </view> <view class="body"> <view class="row"> <view class="cell">第一节</view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> </view> <view class="row"> <view class="cell">第二节</view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> </view> <view class="row"> <view class="cell">第三节</view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> </view> <view class="row"> <view class="cell">第四节</view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> </view> <view class="row"> <view class="cell">第五节</view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> </view> <view class="row"> <view class="cell">第六节</view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> </view> <view class="row"> <view class="cell">第七节</view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> </view> <view class="row"> <view class="cell">第八节</view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> <view class="cell"></view> </view> </view> </view> ``` ``` .container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } .header { display: flex; flex-direction: row; justify-content: space-around; background-color: #007aff; color: #fff; font-size: 16rpx; font-weight: bold; } .cell { width: 80rpx; height: 40rpx; display: flex; align-items: center; justify-content: center; } .body { display: flex; flex-direction: column; justify-content: space-around; height: 480rpx; } .row { display: flex; flex-direction: row; justify-content: space-around; } .row:nth-child(even) { background-color: #f5f5f5; } ``` 6. 在 pages/course/course.js 中添加课程表数据的存储和显示逻辑: ``` Page({ data: { courses: {} }, onLoad: function () { var courses = wx.getStorageSync('courses') || {}; this.setData({ courses: courses }); }, onShow: function () { var courses = wx.getStorageSync('courses') || {}; this.setData({ courses: courses }); } }) ``` ``` <view class="container"> <view class="header"> <view class="cell"></view> <view class="cell">周一</view> <view class="cell">周二</view> <view class="cell">周三</view> <view class="cell">周四</view> <view class="cell">周五</view> <view class="cell">周六</view> <view class="cell">周日</view> </view> <view class="body"> <block wx:for="{{[1,2,3,4,5,6,7,8]}}" wx:key="index"> <view class="row"> <view class="cell">{{item}}节</view> <view class="cell">{{courses['1-'+item]}}</view> <view class="cell">{{courses['2-'+item]}}</view> <view class="cell">{{courses['3-'+item]}}</view> <view class="cell">{{courses['4-'+item]}}</view> <view class="cell">{{courses['5-'+item]}}</view> <view class="cell">{{courses['6-'+item]}}</view> <view class="cell">{{courses['7-'+item]}}</view> </view> </block> </view> </view> ``` 7. 在 pages/course/course.js 中添加课程表数据的编辑和保存逻辑: ``` Page({ data: { courses: {} }, onLoad: function () { var courses = wx.getStorageSync('courses') || {}; this.setData({ courses: courses }); }, onShow: function () { var courses = wx.getStorageSync('courses') || {}; this.setData({ courses: courses }); }, editCourse: function(event) { var day = event.currentTarget.dataset.day; var time = event.currentTarget.dataset.time; wx.navigateTo({ url: '../edit/edit?day=' + day + '&time=' + time, }) }, saveCourse: function(data) { var courses = wx.getStorageSync('courses') || {}; courses[data.day + '-' + data.time] = data.name; wx.setStorageSync('courses', courses); this.setData({ courses: courses }); } }) ``` 8. 在 pages/edit/edit.wxml 中编写编辑课程的布局和样式: ``` <view class="container"> <view class="form"> <view class="item"> <view class="label">课程名称:</view> <input type="text" class="input" placeholder="请输入课程名称" bindinput="inputName" value="{{name}}"/> </view> <view class="item"> <button class="btn" bindtap="saveCourse">保存</button> </view> </view> </view> ``` ``` .container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } .form { display: flex; flex-direction: column; align-items: center; justify-content: center; background-color: #fff; padding: 30rpx; border-radius: 10rpx; box-shadow: 0 0 10rpx rgba(0,0,0,.3); } .item { display: flex; flex-direction: row; align-items: center; justify-content: space-between; margin-bottom: 20rpx; } .label { font-size: 20rpx; font-weight: bold; } .input { width: 200rpx; height: 40rpx; border: none; outline: none; background-color: #f5f5f5; border-radius: 5rpx; padding: 5rpx; font-size: 16rpx; } .btn { width: 100rpx; height: 40rpx; border-radius: 20rpx; background-color: #007aff; color: #fff; font-size: 16rpx; font-weight: bold; border: none; outline: none; } ``` 9. 在 pages/edit/edit.js 中添加输入课程名称和保存课程的逻辑: ``` Page({ data: { name: '', day: '', time: '' }, onLoad: function (options) { this.setData({ day: options.day, time: options.time }); }, inputName: function(event) { this.setData({ name: event.detail.value }); }, saveCourse: function() { var pages = getCurrentPages(); var coursePage = pages[pages.length - 2]; coursePage.saveCourse({ day: this.data.day, time: this.data.time, name: this.data.name }); wx.navigateBack(); } }) ``` 以上就是一个简单的微信小程序大学课程表的实现,希望能够对你有所帮助。

相关推荐

最新推荐

recommend-type

微信小程序一周时间表功能实现

主要介绍了微信小程序一周时间表功能实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
recommend-type

微信小程序实现默认第一个选中变色效果

主要介绍了微信小程序实现默认第一个选中变色效果,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

微信小程序select下拉框实现

主要介绍了微信小程序select下拉框实现源码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
recommend-type

微信小程序实现多选功能

主要为大家详细介绍了微信小程序实现多选功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

如何获取别人微信小程序的源文件?

简单思考一下我们使用小程序的场景就会明白,当我们点开一个微信小程序的时候,其实是微信已经将它的从服务器上下载到了手机,然后再来运行的。所以,虽然我们没能力从服务器上获取到,但是我们应该可以从手机本地...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

SQL怎么实现 数据透视表

SQL可以通过使用聚合函数和GROUP BY子句来实现数据透视表。 例如,假设有一个销售记录表,其中包含产品名称、销售日期、销售数量和销售额等信息。要创建一个按照产品名称、销售日期和销售额进行汇总的数据透视表,可以使用以下SQL语句: ``` SELECT ProductName, SaleDate, SUM(SaleQuantity) AS TotalQuantity, SUM(SaleAmount) AS TotalAmount FROM Sales GROUP BY ProductName, SaleDate; ``` 该语句将Sales表按照ProductName和SaleDat
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。