import { navigateTo } from '@/common/router' import { getPlatform } from '../server/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; } /** * 获取是否需要审核 * @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: 7, show: true, title: '用户协议', icon: 'my/s7.png', // path: '/pages/guize/guize?type=4', handler: this.getUserAgreement.bind(this) } ]; if (uni.getStorageSync('token') != null && uni.getStorageSync('token') != "") { m.push({ id: 8, show: true, title: '注销账号', icon: 'my/s10.png', path: '/pages/user/cancel-account-page', handler: this.navigateToPath.bind(this) }), m.push({ id: 8, show: true, title: '退出登录', icon: 'my/exit.png', path: '', handler: this.handleLogout.bind(this) }) } return m; } /** * 导航到指定页面 * @param {Object} item 菜单项 */ navigateToPath(item) { 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(); } } /** * 处理退出登录 */ handleLogout() { uni.showModal({ title: '提示', content: '确定要退出登录吗?', success: (res) => { if (res.confirm) { uni.removeStorageSync('token'); uni.removeStorageSync('userinfo'); window.location.href = window.location.href; } } }); } /** * 开启调试 */ startDeb() { } /** * 关闭调试 */ closeDeb() { } getVersion() { return '1.0.0'; } getUserAgreement() { navigateTo('/pages/guize/guize', { type: 4 }) } getPrivacyAgreement() { navigateTo('/pages/guize/guize', { type: 5 }) } } export default BasePlatform;