1.0.5 • Published 3 years ago

@yangguoxin/mini-shim v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

小程序webview垫片

主要解决将url上__bf_params基础参数解析出来,自动存入cookie

env字段存入sessionStorage,方便同步判断小程序环境

使用

import miniShim from '@blackfish/mini-shim'
// 解析并写cookie
miniShim.init()

// 解析的key值
console.log(miniShim.getKeys()) // ['token', 'phoneNumber', 'env', 'pValue',
//  'appId', 'appName', 'appVersion', 'wxVersion', 'fingerPrint', 'normalId']

// 是否在小程序环境
miniShim.isMini() // true of false

小程序webview使用

let params = {
  token: app.globalData.loginInfo.token, // 当前用户token
  userId: 'userId', // 用户id
  phoneNumber: app.globalData.accessInfo.memberPhone, // 当前用户手机号
  env: 'miniprogram', // 运行环境标识,由于小程序api是异步,最好url直接标识
  pValue: 'p值',
  appId: 'appId',
  wxAppId: '微信小程序appId', // 如果 appId 传的是小程序appId,此字段可以不传
  appName: 'app名称',
  appVersion: 'app版本',
  wxVersion: '微信版本',
  openId: 'openId',
  normalId: 'normalId',
  fingerPrint: '设备指纹'
}
 
let url = `${h5URL}?__bf_params=${encodeURIComponent(JSON.stringify(params))}`
 
this.setData({
  url: url
})