WeChat Mini Program Practical Mini Program Examples

高洛峰
Release: 2017-01-10 09:44:54
Original
1975 people have browsed it

微信小程序 实战小程序实例

The basic components and API of the WeChat mini program have been finished, and we have to get back to the topic. I spent most of the day making a streamlined version of Baisi Bujie, including jokes and pictures. , audio, video, four modules. This article will give you a brief introduction to this small APP. The source code will be put on GitHub and you are welcome to start.

What can I learn from the project?

tabbar usage

Network call real interface

loading uses

scroll-view to implement pull-down refresh and pull-up loading

image component Processing of pictures,

Use of music and video components

Use of jump value transfer

etc. . . .

app.json global configuration file

{ "pages":[ "pages/word/word", "pages/image/image", "pages/voice/voice", "pages/video/video", "pages/detail/detail" ], "tabBar": { "color": "#a9b7b7", "selectedColor": "#eb4f38", "borderStyle": "white", "backgroundColor": "#ffffff", "list": [ { "pagePath": "pages/word/word", "text": "段子", "iconPath": "image/wordN.png", "selectedIconPath": "image/wordS.png" }, { "pagePath": "pages/image/image", "text": "图片", "iconPath": "image/imageN.png", "selectedIconPath": "image/imageS.png" }, { "pagePath": "pages/voice/voice", "text": "声音", "iconPath": "image/voiceN.png", "selectedIconPath": "image/voiceS.png" }, { "pagePath": "pages/video/video", "text": "视频", "iconPath": "image/videoN.png", "selectedIconPath": "image/videoS.png" } ] }, "window":{ "backgroundTextStyle":"light", "navigationBarBackgroundColor": "#eb4f38", "navigationBarTextStyle":"white" } }
Copy after login

微信小程序 实战小程序实例

Here we only need to configure the global properties of the program. Each page needs to be introduced in the pags attribute, sometimes tabbar The reason why it is not displayed may be because of this. The bottom navigation Item of the tabbar is divided into four, which are in the list. The main configuration here is the selected and unselected color, background color, page introduction and picture introduction of each bottom option page. The window attribute mainly configures the overall color, text color and background color of the form. The window attribute here will be overridden by the window attribute of each page.

app.wxss

/*整体view样式*/ .containsView{ padding: 15rpx 15rpx 15rpx 15rpx; margin-top: 15rpx; margin-bottom: 15rpx; background-color: white; } /*头部整体样式*/ .topContainsView{ display: flex; flex-direction: row; align-items: center; margin-bottom: 18rpx; } /** * 头像样式 */ .profileImage{ width: 60rpx; height: 60rpx; border-radius: 30rpx; } /*头部显示名字和时间整体样式*/ .topRightView{ margin-left: 15rpx; display: flex; flex-direction: column; } /*用户名称样式*/ .topRightName{ font-size: 18rpx; } /*时间样式*/ .topRightTime{ font-size: 14rpx; color: #b8b2b2; margin-top: 10rpx; } /*因为中间部分不一样不放在整体样式中*/ /*底部view整体样式*/ .bottomView{ display: flex; flex-direction: row; justify-content: space-between; align-items: center; } /*每个Item样式*/ .bottomItemView{ display: flex; flex-direction: row; align-items: center; justify-content: center; margin-top: 18rpx; padding-left: 10rpx; padding-right: 10rpx; } /*Item样式中的图标样式 顶 踩 分享 评论*/ .bottomItemImage{ width: 45rpx; height: 45rpx; } /*Item中的文字样式 顶 踩 分享 评论*/ .bottomItemText{ font-size: 15rpx; color: #b8b2b2; margin-left: 10rpx; margin-top: 8rpx; } /*分割线样式*/ .divLine{ background: #f3f3f3; width: 100%; height: 15rpx; }
Copy after login

微信小程序 实战小程序实例

app.wxss I divided the four modules into three parts: header, content area, bottom because each page header The bottom and bottom styles are the same but the middle part is different, so I extracted 1 and 3 into the global, and the comments are clearer

paragraph module

word.wxml

          {{item.name}} {{item.passtime}}    {{item.text}}     {{item.ding}}    {{item.cai}}    {{item.repost}}    {{item.comment}}     
Copy after login

Outside We wrap the layer with scroll-view to load more and pull up to refresh. bindscrolltoupper="bindscrolltoupper" This attribute will call this method when sliding to the top. bindscrolltolower="bindscrolltolower" will be called when sliding to the bottom. You can also move the header here. Extract the top and bottom layouts and use them through the introduction method, so you don’t need to write all four pages. You can get them yourself

word.js

Page({ data: { list: [], maxtime: '', loadingHidden: false }, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 //加载最新 this.requestData('newlist'); }, /** * 上拉刷新 */ bindscrolltoupper: function () { //加载最新 // this.requestData('newlist'); }, /** * 加载更多 */ bindscrolltolower: function () { console.log('到底部') //加载更多 this.requestData('list'); }, /** * 请求数据 */ requestData: function (a) { var that = this; console.log(that.data.maxtime) wx.request({ url: 'http://api.budejie.com/api/api_open.php', data: { a: a, c: 'data', maxtime: that.data.maxtime, type: '29', }, method: 'GET', success: function (res) { console.log(res) console.log('上一页', that.data.list) that.setData({ // 拼接数组 list: that.data.list.concat(res.data.list), loadingHidden: true, maxtime: res.data.info.maxtime }) } }) }, onReady: function () { // 页面渲染完成 }, onShow: function () { // 页面显示 }, onHide: function () { // 页面隐藏 }, onUnload: function () { // 页面关闭 } })
Copy after login

微信小程序 实战小程序实例

## here Load data through the requestData method. This method accepts a parameter, which is to load the latest or more through this parameter. Use the maxtime parameter to load the next page. The maxtime of the previous page is used as the condition for loading the next page. Load the next page of data. We use the concat method to splice the arrays and change the loading status. One of word.wxml and word.json sets the content font size, and the other sets the navigation bar text, so I won’t post it here.

Image module

微信小程序 实战小程序实例

image.wxml

          {{item.name}} {{item.passtime}}   {{item.text}}            点击查看全图       {{item.ding}}    {{item.cai}}    {{item.repost}}    {{item.comment}}     
Copy after login

微信小程序 实战小程序实例

微信小程序 实战小程序实例

Here we mainly look at the middle part. We distinguish and process the image by whether it is a gif. If it is not a gif, you can click to view the larger image. There is a view floating effect here. Combine the interface and image.wxss to see

image.wxss

/*中间文字样式*/ .centerContent{ margin-top: 20rpx; width: 100%; height: 600rpx; } /*中间浮动文字样式*/ .flexView{ display: flex; justify-content: center; align-items: center; width: 100%; height: 80rpx; position: absolute; z-index: 2; top: 540rpx; background: #000000; opacity: 0.6 } /*浮动文字*/ .flexText{ color: white; font-size: 35rpx; }
Copy after login

image.js

var detail = '../detail/detail' Page({ data: { list: [], maxtime: '', loadingHidden: false }, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 this.requestData('newlist'); }, /** * 滚动到底部时加载下一页 */ bindscrolltolower: function () { console.log('到底部') this.requestData('list'); }, /** * 加载数据 */ requestData: function (a) { var that = this; wx.request({ url: 'http://api.budejie.com/api/api_open.php', data: { a: a, c: 'data', // 上一页的maxtime作为加载下一页的条件, maxtime: this.data.maxtime, type: '10', }, method: 'GET', success: function (res) { console.log(res) console.log('上一页', that.datalist) that.setData({ // 拼接数组 list: that.data.list.concat(res.data.list), loadingHidden: true, maxtime: res.data.info.maxtime }) } }) }, /** * 查看大图 */ lookBigPicture: function (e) { console.log(e); console.log(e.currentTarget.id) //图片url 对应wxml中data-url="{{item.url}}" var url = e.currentTarget.dataset.url; //获取图片高度 对应wxml中data-height="{{item.height}}" var height = e.currentTarget.dataset.height; //获取图片高度 对应wxml中data-width="{{item.width}}" var width = e.currentTarget.dataset.width; // 传参方式向GET请求 wx.navigateTo({ url: detail + '?' + 'url=' + url + "&height=" + height + "&width=" + width, success: function (res) { console.log(res) }, fail: function (err) { console.log(err) }, }) }, onReady: function () { // 页面渲染完成 }, onShow: function () { // 页面显示 }, onHide: function () { // 页面隐藏 }, onUnload: function () { // 页面关闭 } })
Copy after login

Here we mainly look at the lookBigPicture method view data-url=”{{item.cdn_img}}” data-height=” {{item.height}}” data-width=”{{item.width}}” will be installed in the logic code. The syntax is var url = e.currentTarget.dataset.url; if the value is transferred, it will be sent to GET Just follow the format of the request.

The audio and video modules are roughly the same. Just look at the code! ! !

Thank you for reading, I hope it can help you, thank you for your support of this site!

For more articles related to WeChat mini programs and practical mini program examples, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!