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

111 lines
2.1 KiB
JavaScript

import share from './share'
import android from './provider/android'
const device = uni.getSystemInfoSync()
const os = device.platform
let name = ''
let provider = ''
let platform = ''
let isWechatInstalled = true
// #ifdef APP-PLUS
name = 'App'
platform = 'openPlatform'
// 检查微信客户端是否安装,否则 AppleStore 会因此拒绝上架
if (os === 'ios') {
provider = 'ios'
isWechatInstalled = plus.ios.import('WXApi').isWXapiInstalled()
} else {
provider = 'android'
}
// #endif
function useProvider() {
if (provider === 'android') {
return android
}
}
/**
* @author Ankkaya
* @description 检查更新
* @param {Type} -
* @returns {Type}
*/
function checkUpdate() {
useProvider().checkUpdate()
}
/**
* @author Ankkaya
* @description 标题栏高度
* @param {Type} -
* @returns {Type}
*/
function getNavBar() {
return device.statusBarHeight + 44
}
const navBar = getNavBar()
/**
* @author Ankkaya
* @description 胶囊高度
* @param {Type} -
* @returns {Type}
*/
function 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()
/**
* @author Ankkaya
* @description 判断网络状态
* @param {Type} -
* @returns {Type}
*/
async function checkNetwork() {
const networkStatus = await uni.getNetworkType()
if (networkStatus.networkType == 'none') {
return Promise.resolve(false)
}
return Promise.resolve(true)
}
const _platform = {
device,
share,
navBar,
capsule,
checkNetwork,
checkUpdate,
}
export default _platform