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

133 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-05-20 01:18:27 +08:00
import { isEmpty } from "lodash";
2024-05-10 20:29:20 +08:00
2024-04-30 17:45:03 +08:00
// #ifdef H5
2024-05-20 01:18:27 +08:00
import { isWxBrowser } from "@/peach/helper/utils";
import share from "./share";
2024-04-30 17:45:03 +08:00
// #endif
2024-05-20 01:18:27 +08:00
const device = uni.getSystemInfoSync();
2024-04-30 17:45:03 +08:00
2024-05-20 01:18:27 +08:00
const os = device.platform;
2024-04-30 17:45:03 +08:00
2024-05-20 01:18:27 +08:00
let name = "";
let provider = "";
let platform = "";
let isWechatInstalled = true;
2024-04-30 17:45:03 +08:00
// #ifdef H5
if (isWxBrowser()) {
2024-05-20 01:18:27 +08:00
name = "WechatOfficialAccount";
provider = "wechat";
platform = "officialAccount";
2024-04-30 17:45:03 +08:00
} else {
2024-05-20 01:18:27 +08:00
name = "H5";
platform = "h5";
2024-04-30 17:45:03 +08:00
}
// #endif
// #ifdef APP-PLUS
2024-05-20 01:18:27 +08:00
name = "App";
platform = "openPlatform";
2024-04-30 17:45:03 +08:00
// 检查微信客户端是否安装否则AppleStore会因此拒绝上架
2024-05-20 01:18:27 +08:00
if (os === "ios") {
isWechatInstalled = plus.ios.import("WXApi").isWXAppInstalled();
2024-04-30 17:45:03 +08:00
}
// #endif
// #ifdef MP-WEIXIN
2024-05-20 01:18:27 +08:00
name = "WechatMiniProgram";
platform = "miniProgram";
provider = "wechat";
2024-04-30 17:45:03 +08:00
// #endif
2024-05-10 20:29:20 +08:00
if (isEmpty(name)) {
2024-05-20 01:18:27 +08:00
uni.showToast({
title: "暂不支持该平台",
icon: "none",
});
2024-05-10 20:29:20 +08:00
}
2024-04-30 17:45:03 +08:00
/**
* 检查网络
* @param {Boolean} silence - 静默检查
*/
async function checkNetwork() {
2024-05-20 01:18:27 +08:00
const networkStatus = await uni.getNetworkType();
if (networkStatus.networkType == "none") {
return Promise.resolve(false);
}
return Promise.resolve(true);
2024-04-30 17:45:03 +08:00
}
/**
* 检查更新 (只检查小程序和App)
* @param {Boolean} silence - 静默检查
*/
const checkUpdate = (silence = false) => {
2024-05-20 01:18:27 +08:00
let canUpdate;
// #ifdef MP-WEIXIN
// #endif
2024-04-30 17:45:03 +08:00
2024-05-20 01:18:27 +08:00
// #ifdef APP-PLUS
// TODO: 热更新
// #endif
};
2024-04-30 17:45:03 +08:00
// 获取小程序胶囊信息
const getCapsule = () => {
2024-05-20 01:18:27 +08:00
// #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();
2024-04-30 17:45:03 +08:00
// 标题栏高度
const getNavBar = () => {
2024-05-20 01:18:27 +08:00
return device.statusBarHeight + 44;
};
const navbar = getNavBar();
2024-04-30 17:45:03 +08:00
// 加载当前平台前置行为
const load = () => {
2024-05-20 01:18:27 +08:00
// if (provider === 'wechat') {
// wechat.load()
// }
};
2024-04-30 17:45:03 +08:00
const _platform = {
2024-05-20 01:18:27 +08:00
name,
device,
checkUpdate,
checkNetwork,
capsule,
navbar,
platform,
load,
share,
};
export default _platform;