yfs/common/platform/AppPlatform.js
2025-05-12 14:58:41 +08:00

133 lines
4.2 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.

import BasePlatform from './BasePlatform';
class AppPlatform extends BasePlatform {
constructor() {
super();
this.code = 'APP_ANDROID';
this.env = 'app';
}
getPayData(url,data) {
return data;
}
pay({ data }) {
return new Promise((resolve) => {
console.log(`App支付${data.amount}分,订单号:${data.orderId}`);
// 模拟调用H5支付SDK
// window.H5PaySDK?.pay(data.amount, data.orderId, resolve);
});
}
share({ title, desc, image, url }) {
console.log(`H5分享${title} - ${desc}`);
// 调用浏览器原生分享(如果可用)
if (navigator.share) {
return navigator.share({ title, text: desc, url });
}
// 降级方案
alert(`请手动分享:${url}`);
}
/**
* 重写获取用户中心菜单列表处理App特有的菜单需求
* @returns {Array} 菜单项数组
*/
getUserMenuList() {
// 获取基础菜单列表
const baseMenuList = super.getUserMenuList();
// 添加App特有的菜单项
const appSpecificMenus = [
{
id: 10,
show: true,
title: '清除缓存',
icon: 'my/s10.png',
path: '',
handler: this.handleClearCache.bind(this)
},
{
id: 11,
show: true,
title: '检查更新',
icon: 'my/s11.png',
path: '',
handler: this.handleCheckUpdate.bind(this)
}
];
// 返回合并后的菜单列表
return [...baseMenuList, ...appSpecificMenus];
}
/**
* 处理清除缓存
*/
handleClearCache() {
uni.showModal({
title: '提示',
content: '确定要清除缓存吗?',
success: (res) => {
if (res.confirm) {
// 清除除了登录信息外的缓存
const token = uni.getStorageSync('token');
const userinfo = uni.getStorageSync('userinfo');
uni.clearStorageSync();
uni.setStorageSync('token', token);
uni.setStorageSync('userinfo', userinfo);
uni.showToast({
title: '缓存已清除',
icon: 'success'
});
}
}
});
}
/**
* 处理检查更新
*/
handleCheckUpdate() {
// App特有的更新检查逻辑
// #ifdef APP-PLUS
plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
const version = widgetInfo.version;
uni.request({
url: 'https://your-api-url/check-update',
data: {
version: version,
platform: uni.getSystemInfoSync().platform
},
success: (res) => {
if (res.data && res.data.hasUpdate) {
uni.showModal({
title: '发现新版本',
content: res.data.updateDesc || '有新版本可用,是否立即更新?',
success: (modalRes) => {
if (modalRes.confirm) {
// 打开下载页面或应用商店
plus.runtime.openURL(res.data.downloadUrl);
}
}
});
} else {
uni.showToast({
title: '已是最新版本',
icon: 'none'
});
}
}
});
});
// #endif
// 非APP环境下的处理
// #ifndef APP-PLUS
uni.showToast({
title: '当前已是最新版本',
icon: 'none'
});
// #endif
}
}
export default AppPlatform;