小程序開發(fā)的難點(diǎn)分析

小編給大家分享一下小程序開發(fā)的難點(diǎn)分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

成都創(chuàng)新互聯(lián)公司專注于中大型企業(yè)的網(wǎng)站設(shè)計、做網(wǎng)站和網(wǎng)站改版、網(wǎng)站營銷服務(wù),追求商業(yè)策劃與數(shù)據(jù)分析、創(chuàng)意藝術(shù)與技術(shù)開發(fā)的融合,累計客戶千余家,服務(wù)滿意度達(dá)97%。幫助廣大客戶順利對接上互聯(lián)網(wǎng)浪潮,準(zhǔn)確優(yōu)選出符合自己需要的互聯(lián)網(wǎng)運(yùn)用,我們將一直專注成都品牌網(wǎng)站建設(shè)和互聯(lián)網(wǎng)程序開發(fā),在前進(jìn)的路上,與客戶一起成長!

1、小程序 生成二維碼

小程序生成二維碼 小程序生成二維碼其實(shí)是需要后端調(diào)用,然后前端調(diào)用后端接口即可。

在下面的例子中,我們傳給后端scene就是額外參數(shù)(長度最大為32個字符,只支持?jǐn)?shù)字,大小寫英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符請自行編碼為合法字符),在打開的小程序用到的。

    let scene = 't=3&n='+ this.inputVal+'&sale='+this.saleId;
    request(qcode,{isHyaline:false,qrcodeType:2,scene:scene,width:255,color:{r:'255',g:'255',b:'255'}})
      .then(res=>{})
    })

這里的坑在于前端如何獲取用戶通過掃二維碼如何獲取參數(shù)

  onLoad(opts){
    var scene = decodeURIComponent(opts.scene); // scene 需要使用 decodeURIComponent 才能獲取到生成二維碼時傳入的 scene
     
  }

2、小程序 跳小程序

小程序調(diào)用toMiniProgram,我這里做了個簡單的封裝

function toMiniProgram(appid, path, extraData) {
  wx.navigateToMiniProgram({
    appId: appid,  // 要打開的小程序 appId
    path: path,   // 打開的頁面路徑
    envVersion: 'develop',  //要打開的小程序版本。僅在當(dāng)前小程序?yàn)殚_發(fā)版或體驗(yàn)版時此參數(shù)有效。
    extraData: extraData,  // 需要傳遞給目標(biāo)小程序的數(shù)據(jù)
    success: function (res) {
      console.log('打開成功')
    },
    fail: function (res) {}
  })
}

在頁面中使用

 toMiniProgram('appid','pages/customer/goods-detail?id='+id+'&saleId='+this.saleId,{});

在另一個小程序中獲取參數(shù)

onLoad(opts){
    this.goodsId=opts.id
    this.saleId=opts.saleId
}

3、吸頂效果的實(shí)現(xiàn)

吸頂效果的原理是將滾動到一定高度的tab 重新布局為fixed

html

<view class="tab-ctn">
  <view class="tabs flex flex-justify {{isTabFixed?'fixed':''}}" id="tabs">
    <view class="item pr {{tabIndex===0?'on':''}}" @tap="toggleTab(0)">商品介紹</view>
    <view class="item pr {{tabIndex===1?'on':''}}" @tap="toggleTab(1)">規(guī)格參數(shù)</view>
  </view>
</view>

css

.tabs{  padding:0 176rpx;
        font-size:30rpx;
        height:90rpx;
        border-bottom:0.5px solid #E4E4E4;}
.item{
    height:100%;
    position:relative;
    padding-top:20rpx;
    color:#999;
    &.on{
    color:#FD343B;
    font-weight:bold;
    }
}
.fixed{
    position:fixed;
    top:0;
    left:0;
    right:0;
    z-index:9;
}

js

data={
    detailTopH:300, 
}
onLoad(){
    this.getElHeight('') // tab上面元素的高度
}
/**封裝根據(jù)id獲取元素高度 */
getElHeightById(id){
  return new Promise(function(resolve,reject){
    const query = wx.createSelectorQuery()
    query.select('#'+id).boundingClientRect()
    query.selectViewport().scrollOffset()
    query.exec(function (res) {
      resolve(res[0].height)
    })
  })
}
// 調(diào)用
  getElHeight(id){
    this.getElHeightById(id).then(res=>{
      this.detailTopH = res
    })
  }
/**監(jiān)聽頁面滾動事件 */
  onPageScroll(e){
    if(e.scrollTop>=this.detailTopH && !this.isTabFixed){
      this.isTabFixed=true
    }else if(e.scrollTop<=this.detailTopH && this.isTabFixed){
      this.isTabFixed=false
    }
  }

4、封裝時間戳

function formatTime(timestamp, type = "date") {
  var date = new Date(timestamp);
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()
 
  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()
  if (type == "date") {
    return [year, month, day].map(formatNumber).join('-');
  } else if (type == "all") {
    return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  } else if (type == "time") {
    return [hour, minute, second].map(formatNumber).join(':')
  } else if (type == "time2") {
    return [hour, minute].map(formatNumber).join(':')
  } else if (type == 'month') {
    return [month, day].map(formatNumber).join('-');
  }
 
}
/**niu 封裝時間戳格式化輔助,將年月日先轉(zhuǎn)為字符串,再判斷是否加0*/
function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}
 
formatTime(1236547891,'all') // 2019-11-02 03:11:11
formatTime(1236547891,'time')  // 03:11:22
formatTime(1236547891,'time2')  // 03:11
formatTime(1236547891,'month')  // 03-03
formatTime(1236547891,'date')  // 2019-11-02

以上是“小程序開發(fā)的難點(diǎn)分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站題目:小程序開發(fā)的難點(diǎn)分析
轉(zhuǎn)載來于:http://muchs.cn/article30/ihihso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、品牌網(wǎng)站設(shè)計品牌網(wǎng)站制作、網(wǎng)站排名、軟件開發(fā)、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計