屯一个实验题目

实验2个人简历小程序 (2学时)

2.1实验目的

掌握数据驱动的开发方式,事件类型和事件对象,以及事件绑定和捕获;

掌握基本布局和交互反馈

2.2实验工具

微信开发者工具

2.3知识点及练习

1. 编写以下代码,查看效果,自行修改字体颜色并给出截图

 

 

<!--index.wxml-->
<view class="btn-area">
<view class="body-view">
<text>{{text}}</text>
<button bindtap="add">add line</button>
<button bindtap="remove">remove line</button>
</view>
</view>

 

 

//index.js
//获取应用实例
const app = getApp()
var initData = 'this is first line\nthis is second line';
var extralLine = [];
Page({
data: {
text: initData
},
//事件处理函数
bindViewTap: function() {
wx.navigateTo({
url: '../logs/logs'
})
},
onLoad: function () {
if (app.globalData.userInfo) {
this.setData({
userInfo: app.globalData.userInfo,
hasUserInfo: true
})
} else if (this.data.canIUse){
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
app.userInfoReadyCallback = res => {
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
} else {
// 在没有 open-type=getUserInfo 版本的兼容处理
wx.getUserInfo({
success: res => {
app.globalData.userInfo = res.userInfo
this.setData({
userInfo: res.userInfo,
hasUserInfo: true
})
}
})
}
},
getUserInfo: function(e) {
console.log(e)
app.globalData.userInfo = e.detail.userInfo
this.setData({
userInfo: e.detail.userInfo,
hasUserInfo: true
})
},
add: function (e) {
extralLine.push('other line')
this.setData({

text: initData + '\n' + extralLine.join('\n')
})
}, remove: function (e) {
if (extralLine.length > 0) {
extralLine.pop()
this.setData({
text: initData + '\n' + extralLine.join('\n')
})
}
}

})

 

2. 编写以下代码,查看效果

 

 

<!--pages/audio/audio.wxml-->
<audio poster="{{poster}}" name="{{name}}" author="{{author}}" src="{{src}}" id="myAudio" controls loop></audio>
<button type="primary" bindtap="audioPlay">播放</button>
<button type="primary" bindtap="audioPause">暂停</button>
<button type="primary" bindtap="audio14">设置当前播放时间为14秒</button>
<button type="primary" bindtap="audioStart">回到开头</button>

 

// audio.js

Page({

  onReady: function (e) {

    // 使用 wx.createAudioContext 获取 audio 上下文 context

    this.audioCtx = wx.createAudioContext('myAudio')

  },

  data: {

    poster: 'http://y.gtimg.cn/music/photo_new/T002R300x300M000003rsKF44GyaSk.jpg?max_age=2592000',

    name: '此时此刻',

    author: '许巍',

    src: 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46',

  },

  audioPlay: function () {

    this.audioCtx.play()

  },

  audioPause: function () {

    this.audioCtx.pause()

  },

  audio14: function () {

    this.audioCtx.seek(14)

  },

  audioStart: function () {

    this.audioCtx.seek(0)

  }

})

 

3. 编写以下代码,查看效果,并将视频更换为自己的视频

<view class="section tc">

  <video src="{{src}}"   controls ></video>

  <view class="btn-area">

    <button bindtap="bindButtonTap">获取视频</button>

  </view>

</view>

 

<view class="section tc">

  <video id="myVideo" src="http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400" danmu-list="{{danmuList}}" enable-danmu danmu-btn controls></video>

  <view class="btn-area">

    <button bindtap="bindButtonTap">获取视频</button>

    <input bindblur="bindInputBlur"/>

    <button bindtap="bindSendDanmu">发送弹幕</button>

  </view>

</view> 

  

 

 

 

 

 

 

 

// pages/section/section.js
function getRandomColor(){
let rgb=[]
for(let i=0;i<3;++i){
let color = Math.floor(Math.rand()*256).toString(16)
color=color.length==1?'0'+color:color
rgb.push(color)
}
return '#'+rgb.join('')
}
Page({

/**
* 页面的初始数据
*/

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {

},

/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function (res) {
this.videoContext = wx.createVideoContext('myVideo')
},
inputValue:'',
data: {
src:'',
danmuList:
[{
text:'第1s出现的弹幕',
color:'#ff0000',
time:1
},{
text: '第3s出现的弹幕',
color: '#ff0000',
time: 3
}]
},
bindInputBlur:function(e){
this.inputValue=e.detail.value
},
bindButtonTap:function(){
var that=this
wx.chooseVideo({
souceType:['album','camera'],
maxDuration:60,
camera:['front','back'],
success:function(res){
that.setData({
src:res.tempFilePath
})
}
})
},
bindSendDanmu:function(){
this.videoContext.setDanmu({
text:this.inputValue,
color:getRandomColor()
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {

},

/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {

},

/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {

},

/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {

},

/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {

},

/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {

}
})

2.4实验题目

设计一个“个人简历”小程序,主要内容是通过视频、文字、图片等介绍自己的基本情况、学习经历、特点擅长、获奖奖励等。要求有tab标签、音视频播放、图片,界面美观。

部分参考代码:

app.json文件

 

 

个人简历主界面

 

 

 

 

 

 

2.5实验步骤  

1. 习题给出运行截图

2. 实验给出运行截图及源码

1)新建项目

2)编写界面

3)完成页面交互

2.6实验心得

查阅资料简述小程序的应用场景

 

posted @ 2019-10-29 21:29  SeasonBubble  阅读(299)  评论(0)    收藏  举报