亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

首頁(yè) 微信小程式 微信開(kāi)發(fā) 微信小程式 實(shí)戰(zhàn)小程式實(shí)例

微信小程式 實(shí)戰(zhàn)小程式實(shí)例

Dec 29, 2016 am 09:30 AM

微信小程式基本組件和API已擼完,總歸要回到正題的,花了大半天時(shí)間做了個(gè)精簡(jiǎn)版的百思不得姐,包括段子,圖片,音頻,視頻,四個(gè)模組。這篇就帶著大家簡(jiǎn)述下這個(gè)小小的APP,原始碼會(huì)放到GitHub上歡迎start。

計(jì)畫(huà)中我能學(xué)到什麼?

tabbar使用方式

網(wǎng)路呼叫真實(shí)介面

loading使用

scroll-view實(shí)現(xiàn)下拉刷新上拉加載

image組件對(duì)圖片的處理,

音樂(lè)和視頻組件的使用

image組件對(duì)圖片的處理,

音樂(lè)和視頻組件的使用

image組件對(duì)圖片的處理,

音樂(lè)和視頻組件的使用

image組件對(duì)圖片的處理,

音樂(lè)和視頻組件的使用

等等等。 。 。 。

app.json全域設(shè)定檔

{
 "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"
 }
}

這裡我們只要配置下程式全域?qū)傩裕總€(gè)頁(yè)面需要在pags屬性中引入,有時(shí)tabbar不顯示有可能是因?yàn)檫@個(gè),tabbar底部導(dǎo)覽四個(gè)就是list裡面的,這裡主要配置選取未選取顏色背景色及每個(gè)底部選項(xiàng)頁(yè)面頁(yè)面引入和圖片引入。 window 屬性主要配置窗體整體的顏色文字顏色和背景色,這裡的window屬性會(huì)被每個(gè)頁(yè)面的window屬性給覆蓋。

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;
}
 
/*頭部顯示名字和時(shí)間整體樣式*/
.topRightView{
 margin-left: 15rpx;
 display: flex;
 flex-direction: column;
}
/*用戶名稱樣式*/
.topRightName{
 font-size: 18rpx;
}
/*時(shí)間樣式*/
.topRightTime{
 font-size: 14rpx;
 color: #b8b2b2;
 margin-top: 10rpx;
}
 
/*因?yàn)橹虚g部分不一樣不放在整體樣式中*/
 
/*底部view整體樣式*/
.bottomView{
 display: flex;
 flex-direction: row;
 justify-content: space-between;
 align-items: center;
}
/*每個(gè)Item樣式*/
.bottomItemView{
 display: flex;
 flex-direction: row;
 align-items: center;
 justify-content: center;
 margin-top: 18rpx;
 padding-left: 10rpx;
 padding-right: 10rpx;
}
/*Item樣式中的圖標(biāo)樣式 頂 踩 分享 評(píng)論*/
.bottomItemImage{
 width: 45rpx;
 height: 45rpx;
}
/*Item中的文字樣式 頂 踩 分享 評(píng)論*/
.bottomItemText{
 font-size: 15rpx;
 color: #b8b2b2;
 margin-left: 10rpx;
 margin-top: 8rpx;
}
 
/*分割線樣式*/
.divLine{
 background: #f3f3f3;
 width: 100%;
 height: 15rpx;
}

app.wxss我將四個(gè)模組分為三個(gè)部分頭部,內(nèi)容區(qū)域, 底部因?yàn)槊總€(gè)頁(yè)面頭部,底部樣式都一樣而中間部分不一樣所以我把1,3抽到全局中,註解比較清晰

段子模組

word.wxml

<loading hidden="{{loadingHidden}}">正在加載...</loading>
<scroll-view scroll-y="true" bindscrolltoupper="bindscrolltoupper" bindscrolltolower="bindscrolltolower" style="height: 100%">
 <block wx:for-items="{{list}}">
  <!-- 分割線 -->
  <view class="divLine"></view>
  <!-- 整體item樣式 -->
  <view class="containsView">
   <view class="topContainsView">
    <image class="profileImage" src="{{item.profile_image}}" />
    <view class="topRightView">
     <text class="topRightName">{{item.name}}</text>
     <text class="topRightTime">{{item.passtime}}</text>
    </view>
   </view>
   <!-- 中間內(nèi)容 -->
   <text class="centerContent">{{item.text}}</text>
   <!-- 底部view樣式 -->
   <view class="bottomView">
    <view class="bottomItemView">
     <image class="bottomItemImage" src="../../image/ding.png" />
     <text class="bottomItemText">{{item.ding}}</text>
    </view>
    <view class="bottomItemView">
     <image class="bottomItemImage" src="../../image/cai.png" />
     <text class="bottomItemText">{{item.cai}}</text>
    </view>
    <view class="bottomItemView">
     <image class="bottomItemImage" src="../../image/share.png" />
     <text class="bottomItemText">{{item.repost}}</text>
    </view>
    <view class="bottomItemView">
     <image class="bottomItemImage" src="../../image/comment.png" />
     <text class="bottomItemText">{{item.comment}}</text>
    </view>
   </view>
  </view>
 </block>
</scroll-view>

外層我們用scroll-view包裹以實(shí)現(xiàn)加載更多和上拉刷新bindscrolltoupper=”bindscrolltoupper” 這個(gè)屬性當(dāng)滑動(dòng)到頂部會(huì)調(diào)用這個(gè)方法bindscrolltolower=”bindscrolltolower”這個(gè)則滑到底部會(huì)調(diào)用,起始這裡還可以將頭部和底部佈局抽出來(lái)通過(guò)引入方式使用,就不用四個(gè)頁(yè)面都寫(xiě)了,自己可以弄下

word.js

Page({
 data: {
  list: [],
  maxtime: &#39;&#39;,
  loadingHidden: false
 },
 onLoad: function (options) {
  // 頁(yè)面初始化 options為頁(yè)面跳轉(zhuǎn)所帶來(lái)的參數(shù)
  //加載最新
  this.requestData(&#39;newlist&#39;);
 },
 
 /**
  * 上拉刷新
  */
 bindscrolltoupper: function () {
  //加載最新
  // this.requestData(&#39;newlist&#39;);
 },
 
 /**
  * 加載更多
  */
 bindscrolltolower: function () {
  console.log(&#39;到底部&#39;)
  //加載更多
  this.requestData(&#39;list&#39;);
 },
 
 /**
  * 請(qǐng)求數(shù)據(jù)
  */
 requestData: function (a) {
  var that = this;
  console.log(that.data.maxtime)
  wx.request({
   url: &#39;http://api.budejie.com/api/api_open.php&#39;,
   data: {
    a: a,
    c: &#39;data&#39;,
    maxtime: that.data.maxtime,
    type: &#39;29&#39;,
   },
   method: &#39;GET&#39;,
   success: function (res) {
    console.log(res)
    console.log(&#39;上一頁(yè)&#39;, that.data.list)
    that.setData({
     // 拼接數(shù)組
     list: that.data.list.concat(res.data.list),
     loadingHidden: true,
     maxtime: res.data.info.maxtime
    })
 
   }
  })
 },
 onReady: function () {
  // 頁(yè)面渲染完成
 },
 onShow: function () {
  // 頁(yè)面顯示
 },
 onHide: function () {
  // 頁(yè)面隱藏
 },
 onUnload: function () {
  // 頁(yè)面關(guān)閉
 }
})

這裡透過(guò)requestData方法載入數(shù)據(jù),這個(gè)方法接受個(gè)參數(shù),就是透過(guò)這個(gè)參數(shù)載入最新還是更多,透過(guò)maxtime這個(gè)參數(shù)去載入下一頁(yè),上一頁(yè)的maxtime作為載入下一頁(yè)的條件, 載入下一頁(yè)資料我們透過(guò)concat方法將陣列進(jìn)行拼接,並改變載入狀態(tài)loading。 word.wxml和word.json中一個(gè)設(shè)定內(nèi)容字體大小,一個(gè)設(shè)定導(dǎo)航條字,就不貼了。

image.wxml

<loading hidden="{{loadingHidden}}">正在加載...</loading>
<scroll-view scroll-y="true" bindscrolltolower="bindscrolltolower" style="height: 100%">
 <block wx:for-items="{{list}}">
  <!-- 分割線 -->
  <view class="divLine"></view>
  <!-- 整體item樣式 -->
  <view class="containsView">
   <view class="topContainsView">
    <image class="profileImage" src="{{item.profile_image}}" />
    <view class="topRightView">
     <text class="topRightName">{{item.name}}</text>
     <text class="topRightTime">{{item.passtime}}</text>
    </view>
   </view>
   <text style="font-size: 30rpx">{{item.text}}</text>
   <!-- 當(dāng)時(shí)gif圖 -->
   <view wx:if="{{item.is_gif != 0}}" style="position: relative;">
    <image class="centerContent" src="{{item.cdn_img}}" mode="aspectFill" />
   </view>
   <!-- 普通大圖 可點(diǎn)擊查看全部圖片 -->
   <view data-url="{{item.cdn_img}}" data-height="{{item.height}}" data-width="{{item.width}}"
      bindtap="lookBigPicture" wx:elif="{{item.is_gif == 0}}" style="position: relative;">
    <!-- 圖片資源 -->
    <image class="centerContent" src="{{item.cdn_img}}" mode="aspectFill" />
    <!-- 圖片上浮動(dòng)的點(diǎn)擊查看詳情圖片view -->
    <view class="flexView">
     <image src="../../image/seeBigPicture.png" style="width: 60rpx; height: 60rpx;" />
     <text class="flexText">點(diǎn)擊查看全圖</text>
    </view>
   </view>
   <!-- 底部view樣式 -->
   <view class="bottomView">
    <view class="bottomItemView">
     <image class="bottomItemImage" src="../../image/ding.png" />
     <text class="bottomItemText">{{item.ding}}</text>
    </view>
    <view class="bottomItemView">
     <image class="bottomItemImage" src="../../image/cai.png" />
     <text class="bottomItemText">{{item.cai}}</text>
    </view>
    <view class="bottomItemView">
     <image class="bottomItemImage" src="../../image/share.png" />
     <text class="bottomItemText">{{item.repost}}</text>
    </view>
    <view class="bottomItemView">
     <image class="bottomItemImage" src="../../image/comment.png" />
     <text class="bottomItemText">{{item.comment}}</text>
    </view>
   </view>
  </view>
 </block>
</scroll-view>

這裡主要看中間部分我們透過(guò)是否是gif來(lái)區(qū)分處理圖片,不是gif可以點(diǎn)擊查看大圖,這裡有個(gè)view懸浮效果,結(jié)合界面和image.wxss看

image.wxss

/*中間文字樣式*/
.centerContent{
 margin-top: 20rpx;
 width: 100%;
 height: 600rpx;
 
}
/*中間浮動(dòng)文字樣式*/
.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
 
}
/*浮動(dòng)文字*/
.flexText{
 color: white;
 font-size: 35rpx;
}

image.js

var detail = &#39;../detail/detail&#39;
Page({
 data: {
  list: [],
  maxtime: &#39;&#39;,
  loadingHidden: false
 },
 onLoad: function (options) {
  // 頁(yè)面初始化 options為頁(yè)面跳轉(zhuǎn)所帶來(lái)的參數(shù)
  this.requestData(&#39;newlist&#39;);
 
 },
 /**
  * 滾動(dòng)到底部時(shí)加載下一頁(yè)
  */
 bindscrolltolower: function () {
  console.log(&#39;到底部&#39;)
  this.requestData(&#39;list&#39;);
 
 },
 
 /**
  * 加載數(shù)據(jù)
  */
 requestData: function (a) {
  var that = this;
  wx.request({
   url: &#39;http://api.budejie.com/api/api_open.php&#39;,
   data: {
    a: a,
    c: &#39;data&#39;,
    // 上一頁(yè)的maxtime作為加載下一頁(yè)的條件,
    maxtime: this.data.maxtime,
    type: &#39;10&#39;,
   },
   method: &#39;GET&#39;,
   success: function (res) {
    console.log(res)
    console.log(&#39;上一頁(yè)&#39;, that.datalist)
    that.setData({
     // 拼接數(shù)組
     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 對(duì)應(yīng)wxml中data-url="{{item.url}}"
  var url = e.currentTarget.dataset.url;
  //獲取圖片高度 對(duì)應(yīng)wxml中data-height="{{item.height}}"
  var height = e.currentTarget.dataset.height;
  //獲取圖片高度 對(duì)應(yīng)wxml中data-width="{{item.width}}"
  var width = e.currentTarget.dataset.width;
  // 傳參方式向GET請(qǐng)求
  wx.navigateTo({
   url: detail + &#39;?&#39; + &#39;url=&#39; + url + "&height=" + height + "&width=" + width,
   success: function (res) {
    console.log(res)
   },
   fail: function (err) {
    console.log(err)
   },
  })
 },
 onReady: function () {
  // 頁(yè)面渲染完成
 },
 onShow: function () {
  // 頁(yè)面顯示
 },
 onHide: function () {
  // 頁(yè)面隱藏
 },
 onUnload: function () {
  // 頁(yè)面關(guān)閉
 }
})

這裡主要看lookBigPicture方法view data-url=”{{item.cdn_img}}” data-height=”{{item.height}}” data-width=”{{item. width}}」會(huì)在邏輯代碼中裝換成.語(yǔ)法使用var url = e.currentTarget.dataset.url; 傳值調(diào)轉(zhuǎn)則向GET發(fā)送請(qǐng)求一樣按照格式來(lái)就行了


感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

????????更多微信小程式 實(shí)戰(zhàn)小程式實(shí)例相關(guān)文章請(qǐng)關(guān)注PHP中文網(wǎng)! ????????
本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開(kāi)發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺(jué)化網(wǎng)頁(yè)開(kāi)發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

熱門(mén)話題

Laravel 教程
1597
29
PHP教程
1488
72