HaniBlindBox/honey_box/common/platform/BasePlatform.js
zpc aa11230116 feat: 前端UI优化和后台管理功能修复
前端优化:
- 修复分享图片配置,使用API返回的share_image
- 新增设置页面,包含用户协议、隐私政策、退出登录、注销账号
- 调整用户中心菜单,将协议相关功能移至设置页面
- 隐藏首页和详情页的参与次数显示
- 商城页面价格显示改为哈尼券(价格x100)

后台管理修复:
- 修复用户列表货币字段映射错误(Diamond字段)
- 修复资金变动对话框,动态加载货币名称
- 修复ChangeDiamondAsync方法使用正确的Money2字段
2026-02-27 20:37:00 +08:00

293 lines
6.1 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 {
navigateTo
} from '@/common/router'
import {
getPlatform, getAdvert, getConfig, getDanYe
} from '../server/config';
import { logout, clearLoginTokens } from '../server/auth';
import ConfigManager from '../config';
/**
* 多端平台抽象基类(父类)
* 定义所有端必须实现的方法
*/
class BasePlatform {
constructor() {
if (new.target === BasePlatform) {
throw new Error('BasePlatform 是抽象类,不能直接实例化');
}
this.code = ''; // 平台代码WEB/MP/APP
this.env = ''; // 运行环境标识
this.config = null;
}
async getConfig() {
// return new Promise((resolve, reject) => {
console.log("获取配置", this.config);
if (this.config != null) {
return this.config;
}
const res = await getPlatform();
this.config = res;
return this.config;
}
async appData() {
await this.loadCacheData();
uni.switchTab({
url: '/pages/shouye/index'
});
}
/**
* 加载缓存
*/
async loadCacheData() {
this.cacheData = {};
await ConfigManager.init();
console.log('初始化成功.。。。。');
//首页轮播图
await getAdvert(1);
//推荐
await getAdvert(5);
//公告
await getDanYe(3);
}
/**
* 获取是否需要审核
* @returns {boolean} 是否需要审核
*/
getIsCheck(tag) {
return this.config?.isCheck ?? false;
}
getPayData(url, data) {
throw new Error('子类必须实现 getPayData 方法');
}
/**
*
*/
chooseAddress() {
return new Promise((resolve, reject) => {
throw new Error('子类必须实现 chooseAddress 方法');
});
}
/**
* 支付方法(子类必须实现)
* @param {number} amount - 支付金额(分)
* @param {string} orderId - 订单号
*/
pay({
data
}, event) {
throw new Error('子类必须实现 pay 方法');
}
/**
* 分享方法(子类必须实现)
* @param {object} params - 分享参数 { title, desc, image, url }
*/
share({
title,
desc,
link,
image
}) {
throw new Error('子类必须实现 share 方法');
}
/**
* 通用方法(所有端共用)
*/
getPlatformInfo() {
return {
code: this.code,
env: this.env,
ua: navigator?.userAgent || ''
};
}
downloadFile(url) {
return new Promise((resolve, reject) => {
throw new Error('子类必须实现 downloadFile 方法');
});
}
AppLaunch(options) {
throw new Error('子类必须实现 AppLaunch 方法');
}
/**
* 获取订单号
*/
getOrderNo(event) {
throw new Error('子类必须实现 getOrderNo 方法');
}
delOrderNo() {
}
/**
* 获取用户中心菜单列表
* @returns {Array} 菜单项数组每项包含id, show, title, icon, path和handler
*/
getUserMenuList() {
let m = [{
id: 1,
show: true,
title: '消费记录',
icon: 'my/s1.png',
path: '/pages/other/order_list',
handler: this.navigateToPath.bind(this)
},
{
id: 3,
show: true,
title: '我的收藏',
icon: 'my/s3.png',
path: '/package/mine/collect',
handler: this.navigateToPath.bind(this)
},
{
id: 4,
show: true,
title: '优惠券',
icon: 'my/s4.png',
path: '/pages/user/coupon',
handler: this.navigateToPath.bind(this)
},
{
id: 5,
show: true,
title: '邀请好友',
icon: 'my/s5.png',
path: '/pages/user/tui-guang',
handler: this.navigateToPath.bind(this)
},
{
id: 6,
show: true,
title: '加入福利群',
icon: 'my/s6.png',
path: '',
handler: this.handleJoinGroup.bind(this)
},
{
id: 11,
show: true,
title: '设置',
icon: 'my/settings.png',
path: '/pages/user/settings',
handler: this.navigateToPath.bind(this)
}
];
// "关于"菜单:如需显示可将 show 改为 true
const customServiceMenu = {
id: 10,
show: false,
title: '关于',
icon: 'my/about.png',
path: '/pages/other/about',
handler: this.navigateToPath.bind(this)
};
m.push(customServiceMenu);
return m;
}
/**
* 导航到指定页面
* @param {Object} item 菜单项
*/
navigateToPath(item) {
// 需要登录才能访问的页面路径
const needLoginPaths = [
'/pages/other/order_list', // 消费记录
'/package/mine/collect', // 我的收藏
'/pages/user/coupon', // 优惠券
'/pages/user/tui-guang', // 邀请好友
'/pages/user/cancel-account-page', // 注销账号
];
// 检查是否需要登录
const needLogin = needLoginPaths.some(path => item.path.startsWith(path));
if (needLogin) {
const token = uni.getStorageSync('token');
if (!token) {
uni.setStorageSync('redirect', item.path);
uni.showToast({
title: '请先登录',
icon: 'none'
});
setTimeout(() => {
navigateTo('/pages/user/login');
}, 100);
return;
}
}
navigateTo(item.path);
}
/**
* 处理加入福利群
* @param {Object} item 菜单项
* @param {Object} context 页面上下文
*/
handleJoinGroup(item, context) {
if (context && context.$refs && context.$refs.qunliao_show) {
context.$refs.qunliao_show.open();
}
}
/**
* 处理退出登录
* 清除所有TokenaccessToken、refreshToken、tokenExpireTime
* 可选调用后端撤销接口
*/
handleLogout() {
uni.showModal({
title: '提示',
content: '确定要退出登录吗?',
success: async (res) => {
if (res.confirm) {
try {
// 调用后端撤销接口并清除本地存储
await logout();
} catch (error) {
console.log('退出登录时发生错误:', error);
// 即使后端调用失败,也确保清除本地存储
clearLoginTokens();
}
// 刷新页面
// #ifdef H5
window.location.href = window.location.href;
// #endif
// #ifndef H5
uni.reLaunch({
url: '/pages/shouye/index'
});
// #endif
}
}
});
}
/**
* 开启调试
*/
startDeb() {
}
/**
* 关闭调试
*/
closeDeb() {
}
getVersion() {
return '1.0.0';
}
getUserAgreement() {
navigateTo('/pages/guize/guize', { type: 4 })
}
getPrivacyAgreement() {
navigateTo('/pages/guize/guize', { type: 5 })
}
}
export default BasePlatform;