欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

微信小程序--關(guān)于加快小程序開發(fā)的幾個小建議 - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開發(fā)/軟件開發(fā)

知識

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!

您當(dāng)前位置>首頁 » 新聞資訊 » 小程序相關(guān) >

微信小程序--關(guān)于加快小程序開發(fā)的幾個小建議

發(fā)表時間:2021-1-4

發(fā)布人:葵宇科技

瀏覽次數(shù):49

1.使用 app.json創(chuàng)建頁面

? 按照我們平常的開發(fā)習(xí)慣,創(chuàng)建一個新的頁面,一般都會先創(chuàng)建文件夾,再創(chuàng)建對應(yīng)page的形式,創(chuàng)建完成后,app.json中會自動注冊該頁面。實際上,我們還可以通過直接在app.json中注冊頁面來生成對應(yīng)的page。

"pages": [
    "pages/index/index",
    "pages/newpage/newpage"
 ],

? 如上所示,在配置文件中注冊該路徑,小程序就會自動創(chuàng)建該對應(yīng)路徑。


2.善用編譯模

? 我們想要調(diào)試某個頁面時,相當(dāng)一部分開發(fā)者習(xí)慣于直接修改app.json來調(diào)整首個入棧頁面,實際上完全可以使用編譯模式添加編譯頁面,來代替修改配置文件的行為。


3.組件復(fù)用小程序樣式

? 這一點經(jīng)常被遺忘,因為新建component的時候,小程序并不會展示該配置項。配置options如下,組件可以使用全局樣式(app.wxss)

Component({
  //繼承colorui樣式
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  ...
 }
4.app.js初始化內(nèi)容函數(shù)化

? 很多小程序onLaunch中寫著大量的內(nèi)容,混亂不堪,后期調(diào)試尤為痛苦??梢詫⒉煌某跏蓟瘍?nèi)容寫為不同的函數(shù),函數(shù)化、模塊化。

onLaunch: function(options) {
    //此處需要有對進(jìn)入小程序方式的處理
    this.InitCloud(); //初始化云服務(wù) / ESC
    this.InitCustom(); //初始化custom所需配置信息
    this.InitEdu(); //初始化教務(wù)系統(tǒng)配置
 },
5.善用template

? 對于內(nèi)容大量重復(fù)的wxml內(nèi)容,可以將之抽離為template模板文件,使用時直接導(dǎo)入使用即可。

<import src="template/NexuTemplate.wxml"/>
<view wx:for="{{dirlist}}" wx:key="item">
	<template is="dirshow" data="{{item}}"></template>
</view>
6.云開發(fā)混合開發(fā)

? 內(nèi)容安全識別,openid獲取,圖片鑒黃,支付流程,內(nèi)容推送這些東西如果使用自己的后臺實現(xiàn),并不是這么簡單,但是如果使用了云開發(fā)的技術(shù)替換這一部分,自己專注于業(yè)務(wù)邏輯,你會打開一片新天地。

云開發(fā)部分功能(后面我會專門寫一篇文章介紹云開發(fā)混合開發(fā)的內(nèi)容):

const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})


// 云函數(shù)入口函數(shù)
exports.main = async (event, context) => {
  // console.log(event)
  switch (event.action) {
    case 'getWXACode': {
      return getWXACode(event)
    }
    case 'getOpenData': {
      return getOpenData(event)
    }
    case 'msgSecCheck': {
      return msgSecCheck(event)
    }
    case 'imgSecCheck': {
      return imgSecCheck(event)
    }
    case 'submitPages': {
      return submitPages(event)
    }
    default: {
      return
    }
  }
}

//獲取小程序碼
async function getWXACode(event) {
  console.log(event.url)
  // 此處將獲取永久有效的小程序碼,并將其保存在云文件存儲中,最后返回云文件 ID 給前端使用

  const wxacodeResult = await cloud.openapi.wxacode.get({
    path: event.url || 'pages/index/index',
  })

  const fileExtensionMatches = wxacodeResult.contentType.match(/\/([^\/]+)/)
  const fileExtension = (fileExtensionMatches && fileExtensionMatches[1]) || 'jpg'

  const uploadResult = await cloud.uploadFile({
    // 云文件路徑,此處為演示采用一個固定名稱
    cloudPath: `wxCode/wxCode${Math.random() * 9999999}.${fileExtension}`,
    // 要上傳的文件內(nèi)容可直接傳入圖片 Buffer
    fileContent: wxacodeResult.buffer,
  })

  if (!uploadResult.fileID) {
    throw new Error(`上傳失敗,文件為空,存儲服務(wù)器狀態(tài)代碼為空 ${uploadResult.statusCode}`)
  }

  return uploadResult.fileID
}

// 獲取openid
async function getOpenData(event) {
  // 需 wx-server-sdk >= 0.5.0
  const wxContext = cloud.getWXContext()

  return {
    event,
    openid: wxContext.OPENID,
    appid: wxContext.APPID,
    unionid: wxContext.UNIONID,
  }
}

// 檢測文本是否合規(guī)
async function msgSecCheck(event) {
  // 需 wx-server-sdk >= 0.5.0
  return cloud.openapi.security.msgSecCheck({
    content: event.content,
  })
}

// 檢測圖片是否合規(guī)
async function imgSecCheck(event) {
  return cloud.openapi.security.imgSecCheck({
    media: {
      contentType: event.contentType,
      value: Buffer.from(event.value)
    }
  })
}

// 收錄頁面
async function submitPages(event) {
  return cloud.openapi.search.submitPages({
    pages: [{
      path: event.path,
      query: event.query
    }]
  })
}

//獲取日期
function getDateTime(sj) {
  var now = new Date(sj * 1000);
  var year = now.getFullYear();
  var month = now.getMonth() + 1;
  var date = now.getDate();
  var hour = now.getHours();
  var minute = now.getMinutes();
  // var second = now.getSeconds();
  return year + "年" + month + "月" + date + "日";
}
7.將個人配置數(shù)據(jù)集中到一個文件中

? 比如說服務(wù)器域名、接口令牌這些可能會變化,但經(jīng)常使用的數(shù)據(jù),集中到一個文件中。

module.exports={
  UseCloud:true,
  CloudId:'',   			//云開發(fā)環(huán)境id
  TraceUser:true,           //記錄用戶訪問日志
  AdaptStorge:true,         //允許緩存用戶數(shù)據(jù)
  SevDomain:'http://localhost'     //服務(wù)器的域名
}

8.善用開發(fā)者工具的版本管理工具

相關(guān)案例查看更多