当前位置:   article > 正文

“婚礼邀请函”小程序开发过程_婚礼邀请函小程序

婚礼邀请函小程序

一、开发前准备

(一)需求分析

要求该小程序有以下功能:

1.邀请函页面:新郎和新娘的电话、婚礼时间、婚礼地点

2.照片页面:新郎和新娘的幸福照

3.美好时光页面:采用视频的方式记录新人的相历程

4.地图页面:通导航查看婚礼地点的路线图

5.宾客信息页面:参加婚礼的宾客填写个人信息,送给一些祝福语等

该小程序所用技术的扩展用途

1.照片、视频:记录父母的婚纱照、自己的童年照、家人的游玩视频

2.地图:旅游小程序的重要组成部分

3.信息录入:登录、注册功能的实现

(二)项目结构

(三)项目初始化(app.json配置文件的编写)

通过编写app.json文件,完成项目的基本配置

  1. {
  2. "pages": [
  3. "pages/index/index",
  4. "pages/picture/picture",
  5. "pages/video/video",
  6. "pages/map/map",
  7. "pages/guest/guest"
  8. ],
  9. "window": {
  10. "backgroundTextStyle": "light",
  11. "navigationBarBackgroundColor": "#ff4c91",
  12. "navigationBarTextStyle": "white",
  13. "enablePullDownRefresh": false
  14. },
  15. "tabBar": {
  16. "color": "#ccc",
  17. "selectedColor": "#ff4c91",
  18. "borderStyle": "white",
  19. "backgroundColor": "#ffffff",
  20. "list": [
  21. {
  22. "pagePath": "pages/index/index",
  23. "iconPath": "images/invite.png",
  24. "selectedIconPath": "images/invite.png",
  25. "text": "邀请函"
  26. },
  27. {
  28. "pagePath": "pages/picture/picture",
  29. "iconPath": "images/marry.png",
  30. "selectedIconPath": "images/marry.png",
  31. "text": "照片"
  32. },
  33. {
  34. "pagePath": "pages/video/video",
  35. "iconPath": "images/video.png",
  36. "selectedIconPath": "images/video.png",
  37. "text": "美好时光"
  38. },
  39. {
  40. "pagePath": "pages/map/map",
  41. "iconPath": "images/map.png",
  42. "selectedIconPath": "images/map.png",
  43. "text": "婚礼地点"
  44. },
  45. {
  46. "pagePath": "pages/guest/guest",
  47. "iconPath": "images/guest.png",
  48. "selectedIconPath": "images/guest.png",
  49. "text": "宾客信息"
  50. }
  51. ]
  52. }
  53. }

当前效果图

 二、邀请函界面

主要是页面的实现和音乐播放器的实现,不是重点,以下为效果图

(对于毫无艺术细胞的我来说,开发前端真是要老命,能Copy就Copy吧)

音乐播放器鉴于已经做过,这里放一下模板,以后直接套即可

(1)index.wxml文件如下:

  1. <view class="player player-{{isPlayingMusic ? 'play' : 'pause'}}" bindtap="play">
  2. <image src="/images/music_icon.png" />
  3. <image src="/images/music_play.png" />
  4. </view>

(2)index.js文件如下 

  1. Page({
  2. data: {
  3. isPlayingMusic: false
  4. },
  5. bgm: null,
  6. music_url: 'http://localhost:3000/1.mp3',
  7. music_coverImgUrl: 'http://localhost:3000/cover.jpg',
  8. onReady: function() {
  9. // 创建getBackgroundAudioManager实例对象
  10. this.bgm = wx.getBackgroundAudioManager()
  11. // 音频标题
  12. this.bgm.title = 'merry me'
  13. // 专辑名称
  14. this.bgm.epname = 'wedding'
  15. // 歌手名
  16. this.bgm.singer = 'singer'
  17. // 专辑封面
  18. this.bgm.coverImgUrl = this.music_coverImgUrl
  19. this.bgm.onCanplay(() => {
  20. this.bgm.pause()
  21. })
  22. // 指定音频的数据源
  23. this.bgm.src = this.music_url
  24. },
  25. // 播放器的单击事件
  26. play: function() {
  27. if (this.data.isPlayingMusic) {
  28. this.bgm.pause()
  29. } else {
  30. this.bgm.play()
  31. }
  32. this.setData({
  33. isPlayingMusic: !this.data.isPlayingMusic
  34. })
  35. }
  36. })

两者的绑定通过bingtap="play"实现(绑定点击事件) 

(3)存放音视频文件的服务器通过node.js搭建,下面附上其代码

关于node.js的使用,对其完全不了解的可参考我的博客Node.js学习笔记_清风何渡的博客-CSDN博客

  1. var express = require('express')
  2. var serveIndex = require('serve-index')
  3. var serveStatic = require('serve-static')
  4. var multiparty = require('multiparty')
  5. var finalhandler = require('finalhandler')
  6. var util = require('util')
  7. var LOCAL_BIND_PORT = 3000
  8. var app = express()
  9. app.post('/upload', function(req, res) {
  10. var form = new multiparty.Form()
  11. form.encoding = 'utf-8'
  12. form.uploadDir = './htdocs/upfile'
  13. form.maxFilesSize = 4 * 1024 * 1024
  14. form.parse(req, function(err, fields, files) {
  15. if(err) {
  16. console.log('parse error: ' + err)
  17. } else {
  18. console.log('parse files: ' + JSON.stringify(files))
  19. }
  20. res.writeHead(200, {'content-type': 'text/plain;charset=utf-8'})
  21. res.write('received upload')
  22. res.end()
  23. })
  24. })
  25. //配置媒体文件夹
  26. var serve = serveStatic('./htdocs')
  27. app.use('/', serveIndex('./htdocs', {'icons': true}))
  28. app.get('/*', function(req, res) {
  29. serve(req, res, finalhandler(req, res))
  30. });
  31. console.log(`Start static file server at ::${LOCAL_BIND_PORT}, Press ^ + C to exit`)
  32. app.listen(LOCAL_BIND_PORT)

效果图如下

 背景音乐放的是《告白气球》,太甜了呜呜~

三、照片页面

有用(打算做一个爸妈的婚纱照小程序哈哈~),新颖

采用纵向轮播的方式展示图片,滑动图片可纵向切换

纵向轮播图的实现如下

(1)picture.wxml文件

  1. <swiper indicator-color="white" indicator-active-color="#ff4c91"
  2. indicator-dots autoplay interval="3500" duration="1000" vertical circular>
  3. <swiper-item wx:for="{{imgUrls}}" wx:key="*this">
  4. <image src="{{item}}" mode="aspectFill"/>
  5. </swiper-item>
  6. </swiper>

swiper组件实现页面可滑动,swip中的标签想必对于英语很好的各位看官来说必然能望名知意叭(主要就是设置轮播时间、指示点颜色、轮播图方向啥的)

注意遍历采用wx:for实现

(2)picture.js文件

  1. Page({
  2. data: {
  3. imgUrls: [
  4. '/images/timg1.jpg',
  5. '/images/timg2.jpg',
  6. '/images/timg3.jpg',
  7. '/images/timg4.jpg'
  8. ]
  9. }
  10. })

(3)picture.wxss文件

  1. swiper{height: 100vh;}
  2. image{width: 100vw;height: 100vh;}

效果图如下

迫不及待要做一个自己的图册了哈哈~ 

四、美好时光页面

在小程序中播放视频有两种方式,一种是使用video插件,一种是使用腾讯视频插件

(一)使用video插件

很简单(相较于音乐播放来说)

(1)video.wxml文件

<video id="myVideo" src="{{src}}">

(2)video.wxss文件

video{width:100vx;}

(3)video.js文件

  1. Page({
  2. data:{
  3. src:'http://······/xxx.mp4'
  4. }
  5. })

(二)使用腾讯视频插件

优点是可以不用自己的服务器存视频,但缺点也很明显,视频时长受限,因此这里不选择该方式

五、婚礼地点页面

地图map组件,很实用

map组件需要给定经纬度,可通过腾讯位置服务网站提供的坐标拾取器获取

腾讯位置服务 - 立足生态,连接未来 (qq.com)

简单的地图页面功能实现如下

(1)map.wxml文件

  1. <map latitude="{{latitude}}" longitude="{{longitude}}"
  2. markers="{{markers}}" bindmarkertap="markertap"/>

(2)map.wxss文件

map{width: 100vw;height: 100vh;}

(3)map.js文件

  1. // pages/map/map.js
  2. Page({
  3. data:{
  4. latitude:41.655044,longitude:123.424681,
  5. markers:[{
  6. iconPath:'/images/navi.png',id:0,
  7. latitude:41.655044,longitude:123.424681,
  8. width:50,height:50
  9. }]
  10. },
  11. markertap:function(){
  12. wx.openLocation({
  13. latitude: this.data.latitude,
  14. longitude: this.data.longitude,
  15. name:'东北大学浑南校区图书馆',
  16. address:'辽宁省沈阳市浑南区捷迁路'
  17. })
  18. }
  19. })

效果如下

 

 六、宾客信息页面

表单提交比较简单,模板消息emm······,先放放叭(鼓捣了半个小时没整好)

(1)guest,wxml文件

  1. <image class="bg" src="/images/bj_2.png">
  2. </image>
  3. <form bindsubmit="formSubmit">
  4. <view class="content">
  5. <view>
  6. <input name="name" bindblur="nameChange" bindtap="allowSubscribe" placeholder-class="phcolor" placeholder="输入您的姓名" />
  7. </view>
  8. <view>
  9. <input name="phone" bindblur="phoneChange" placeholder-class="phcolor" placeholder="输入您的手机号码" />
  10. </view>
  11. <view>
  12. <picker name="num" bindchange="pickerChange" value="{{picker.index}}" range="{{picker.arr}}">
  13. 参加婚礼人数:{{picker.arr[picker.index]}}</picker>
  14. </view>
  15. <view>
  16. <input name="wish" placeholder-class="phcolor" placeholder="输入您的祝福语" />
  17. </view>
  18. <button form-type="submit">提交</button>
  19. </view>
  20. </form>

(2)guest.wxss文件

  1. /* pages/guest/guest.wxss */
  2. .bg {
  3. width: 100vw;
  4. height: 100vh;
  5. }
  6. .content {
  7. width: 80vw;
  8. position: fixed;
  9. left: 10vw;
  10. bottom: 6vh;
  11. }
  12. .content > view {
  13. font-size: 2.8vh;
  14. border: 1rpx solid #ff4c91;
  15. border-radius: 10rpx;
  16. padding: 1.5vh 40rpx;
  17. margin-bottom: 1.5vh;
  18. color: #ff4c91;
  19. }
  20. .content button {
  21. font-size: 3vh;
  22. height: 7.5vh;
  23. line-height: 7.5vh;
  24. background: #ff4c91;
  25. color: #fff;
  26. }
  27. .content picker {
  28. padding: 0.7vh 0;
  29. }
  30. .content .phcolor {
  31. color: #ff4c91;
  32. }

 (3)guest.js文件

  1. // pages/guest/guest.js
  2. Page({
  3. data:{
  4. picker:{
  5. arr:['0','1','2','3','4','5','6'],
  6. index:1
  7. }
  8. },
  9. pickerChange:function(e){
  10. this.setData({
  11. 'picker.index':e.detail.value
  12. })
  13. },
  14. // 验证姓名
  15. nameChange: function(e) {
  16. this.checkName(e.detail.value)
  17. },
  18. // 验证手机号
  19. phoneChange: function(e) {
  20. this.checkPhone(e.detail.value)
  21. },
  22. // checkName()方法
  23. checkName: function(data) {
  24. var reg = /^[\u4E00-\u9FA5A-Za-z]+$/;
  25. return this.check(data, reg, '姓名输入错误!')
  26. },
  27. // checkPhone()方法
  28. checkPhone: function(data) {
  29. var reg = /^(((13)|(15)|(17)|(18))\d{9})$/;
  30. return this.check(data, reg, '手机号码输入有误!')
  31. },
  32. // check()方法
  33. check: function(data, reg, errMsg) {
  34. if (!reg.test(data)) {
  35. wx.showToast({
  36. title: errMsg,
  37. icon: 'none',
  38. duration: 1500
  39. })
  40. return false
  41. }
  42. return true
  43. }
  44. })

效果图如下

 通篇做下来,还是蛮有趣的,要说复杂的,可能就是服务器的交互和模板消息的使用了,这个以后再说叭~

用时:7h

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号