mall-app-b/peach/platform/index.js

122 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// #ifdef H5
import { isWxBrowser } from '@/peach/helper/utils'
// #endif
const device = uni.getSystemInfoSync()
const os = device.platform
let name = ''
let provider = ''
let platform = ''
let isWechatInstalled = true
// #ifdef H5
if (isWxBrowser()) {
name = 'WechatOfficialAccount'
provider = 'wechat'
platform = 'officialAccount'
} else {
name = 'H5'
platform = 'h5'
}
// #endif
// #ifdef APP-PLUS
name = 'App'
platform = 'openPlatform'
// 检查微信客户端是否安装否则AppleStore会因此拒绝上架
if (os === 'ios') {
isWechatInstalled = plus.ios.import('WXApi').isWXAppInstalled()
}
// #endif
// #ifdef MP-WEIXIN
name = 'WechatMiniProgram'
platform = 'miniProgram'
provider = 'wechat'
// #endif
/**
* 检查网络
* @param {Boolean} silence - 静默检查
*/
async function checkNetwork() {
const networkStatus = await uni.getNetworkType()
if (networkStatus.networkType == 'none') {
return Promise.resolve(false)
}
return Promise.resolve(true)
}
/**
* 检查更新 (只检查小程序和App)
* @param {Boolean} silence - 静默检查
*/
const checkUpdate = (silence = false) => {
let canUpdate
// #ifdef MP-WEIXIN
// #endif
// #ifdef APP-PLUS
// TODO: 热更新
// #endif
}
// 获取小程序胶囊信息
const getCapsule = () => {
// #ifdef MP
let capsule = uni.getMenuButtonBoundingClientRect()
if (!capsule) {
capsule = {
bottom: 56,
height: 32,
left: 278,
right: 365,
top: 24,
width: 87,
}
}
return capsule
// #endif
// #ifndef MP
return {
bottom: 56,
height: 32,
left: 278,
right: 365,
top: 24,
width: 87,
}
// #endif
}
const capsule = getCapsule()
// 标题栏高度
const getNavBar = () => {
return device.statusBarHeight + 44
}
const navbar = getNavBar()
// 加载当前平台前置行为
const load = () => {
// if (provider === 'wechat') {
// wechat.load()
// }
}
const _platform = {
name,
device,
checkUpdate,
checkNetwork,
capsule,
navbar,
platform,
load,
}
export default _platform