diff --git a/common/config.js b/common/config.js index 17288e5..fe28a57 100644 --- a/common/config.js +++ b/common/config.js @@ -280,11 +280,14 @@ class ConfigManager { * @returns {Boolean} 是否为微信版本 */ static GetVersion() { + //#ifdef MP-WEIXIN let version = this.get('version'); if (version == wx_version) { return true; } return false; + //#endif + return false; } } diff --git a/common/platform/AppPlatform.js b/common/platform/AppPlatform.js index 30a4fab..37cd38f 100644 --- a/common/platform/AppPlatform.js +++ b/common/platform/AppPlatform.js @@ -25,5 +25,109 @@ class AppPlatform extends BasePlatform { // 降级方案 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; \ No newline at end of file diff --git a/common/platform/BasePlatform.js b/common/platform/BasePlatform.js index fa2001c..77975b1 100644 --- a/common/platform/BasePlatform.js +++ b/common/platform/BasePlatform.js @@ -1,3 +1,4 @@ +import { navigateTo } from '@/common/router' /** * 多端平台抽象基类(父类) * 定义所有端必须实现的方法 @@ -71,8 +72,117 @@ class BasePlatform { getOrderNo() { throw new Error('子类必须实现 getOrderNo 方法'); } - delOrderNo(){ - + 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.navigateToPath.bind(this) + } + + ]; + + if (uni.getStorageSync('token') != null && uni.getStorageSync('token') != "") { + 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'); + uni.switchTab({ + url: '/pages/user/index' + }); + // window.location.href = window.location.href; + } + } + }); } } export default BasePlatform; \ No newline at end of file diff --git a/common/platform/H5Platform.js b/common/platform/H5Platform.js index a3b756b..1e40c3a 100644 --- a/common/platform/H5Platform.js +++ b/common/platform/H5Platform.js @@ -171,5 +171,30 @@ class H5Platform extends BasePlatform { resolve(pay_order_num); }); } + + /** + * 重写获取用户中心菜单列表,处理H5特有的菜单需求 + * @returns {Array} 菜单项数组 + */ + getUserMenuList() { + // 获取基础菜单列表 + const baseMenuList = super.getUserMenuList(); + + // H5环境下可能需要修改某些菜单项的行为 + return baseMenuList.map(item => { + // 示例:在H5环境下可能需要特殊处理某些菜单项 + if (item.id === 6) { // 加入福利群菜单 + return { + ...item, + // 重新绑定处理函数,可能需要增加H5特有的逻辑 + handler: (menuItem, context) => { + this.handleJoinGroup(menuItem, context); + // 在H5环境下可能需要额外的处理,比如尝试复制群号等 + } + }; + } + return item; + }); + } } export default H5Platform; \ No newline at end of file diff --git a/common/platform/MiniProgramPlatform.js b/common/platform/MiniProgramPlatform.js index 6f632de..c84c28e 100644 --- a/common/platform/MiniProgramPlatform.js +++ b/common/platform/MiniProgramPlatform.js @@ -140,5 +140,29 @@ class MiniProgramPlatform extends BasePlatform { }); } delOrderNo(){} + + /** + * 重写获取用户中心菜单列表,添加微信小程序特有菜单 + * @returns {Array} 菜单项数组 + */ + getUserMenuList() { + // 获取基础菜单列表 + const baseMenuList = super.getUserMenuList(); + + // 添加客服菜单项(仅微信小程序) + const customServiceMenu = { + id: 9, + show: true, + title: '客服', + icon: 'my/s9.png', + path: '', + isCustomService: true, + // 客服按钮不需要处理函数,由微信小程序原生组件处理 + handler: () => {} + }; + + // 将客服菜单插入到第二个位置 + return [...baseMenuList.slice(0, 1), customServiceMenu, ...baseMenuList.slice(1)]; + } } export default MiniProgramPlatform; \ No newline at end of file diff --git a/common/request.js b/common/request.js index 6d69d8a..fa3f33e 100644 --- a/common/request.js +++ b/common/request.js @@ -16,7 +16,7 @@ class RequestManager { * @returns {Boolean} 是否在白名单中 */ static isUrlInWhitelist(url) { - + // 检查URL是否包含白名单中的任一项 return apiWhiteList.some(whiteItem => url.indexOf(whiteItem) > -1); } @@ -63,8 +63,8 @@ class RequestManager { } } }) - - + + const url = param.url || '' const method = param.method || 'POST' const data = param.data || {} @@ -227,21 +227,29 @@ class RequestManager { icon: 'none' }) }, 100) - + reject(res.data) } else if (res.data.status < 0) { var pages = getCurrentPages() + if (res.data.msg != null) { + if (res.data.msg.indexOf("没有找到用户信息") > -1) { + uni.removeStorageSync('token'); + uni.removeStorageSync('userinfo'); + } + } + + // 获取当前页面路径和参数 var currentPage = pages[pages.length - 1]; if (currentPage) { var currentRoute = currentPage.route; var currentParams = currentPage.options || {}; - + // 只有非登录页面才保存重定向信息 if (currentRoute && currentRoute !== 'pages/user/login') { // 构建完整的重定向URL var redirectPath = '/' + currentRoute; - + // 如果有参数,拼接参数 if (Object.keys(currentParams).length > 0) { var paramString = Object.keys(currentParams) @@ -249,13 +257,13 @@ class RequestManager { .join('&'); redirectPath += '?' + paramString; } - + // 保存重定向URL到缓存 console.log('保存重定向URL:', redirectPath); uni.setStorageSync('redirect', redirectPath); } } - + console.log(requestUrl); if (RequestManager.isUrlInWhitelist(requestUrl)) { reject(res.data) @@ -274,7 +282,7 @@ class RequestManager { .catch(err => { console.error('登录页面跳转失败:', err); }); - + reject(res.data) } else { reject(res.data) diff --git a/pages/user/index.vue b/pages/user/index.vue index cc51373..ff95175 100644 --- a/pages/user/index.vue +++ b/pages/user/index.vue @@ -51,16 +51,13 @@ - + {{ $config.getAppSetting('currency1_name') }} {{ formatNumber(userinfo.integral) }} @@ -72,7 +69,7 @@ {{ formatNumber(userinfo.money2) }} - + @@ -113,7 +110,8 @@ 其他服务 - @@ -164,56 +161,8 @@ export default { z_imgPath: this.$z_img2, userinfo: '', moneyArr: [100, 200, 500, 1000, 3000], - menuList: [{ - id: 1, - show: true, - title: '消费记录', - icon: 'my/s1.png', - path: '/pages/other/order_list' - }, - - { - id: 3, - show: true, - title: '我的收藏', - icon: 'my/s3.png', - path: '/package/mine/collect' - }, - { - id: 4, - show: true, - title: '优惠券', - icon: 'my/s4.png', - path: '/pages/user/coupon' - }, - { - id: 5, - show: true, - title: '邀请好友', - icon: 'my/s5.png', - path: '/pages/user/tui-guang' - }, - { - id: 6, - show: true, - title: '加入福利群', - icon: 'my/s6.png', - path: '' - }, - { - id: 7, - show: true, - title: '用户协议', - icon: 'my/s7.png', - path: '/pages/guize/guize?type=4' - },{ - id: 8, - show: true, - title: '退出登录', - icon: 'my/exit.png', - path: '' - }, - ], + menuList: [], + zuanshi:false, // 星钻充值金额 money_1: '', // 二维码 @@ -269,6 +218,9 @@ export default { this.getdata() // this.getmycollect() let that = this + // 获取平台菜单列表 + this.menuList = this.$platform.getUserMenuList(); + this.zuanshi=this.$platform.code!="MP-WEIXIN"; const curPages = getCurrentPages()[0]; // 获取当前页面实例 if (typeof curPages.getTabBar === 'function' && curPages.getTabBar()) { this.$mp.page.getTabBar().setData({ @@ -288,14 +240,6 @@ export default { url: '/pages/user/change' }) }, - isShowKefu(index){ - if(index==0){ - if(this.$platform.code=='MP-WEIXIN'){ - return true; - } - } - return false; - }, receiveCoupon() { const coupon_id = uni.getStorageSync('_ou_coupon_id') @@ -352,17 +296,13 @@ export default { }) }, - menuTo(item) { - switch (item.id) { - case 6: - this.$refs.qunliao_show.open() - break - default: - this.$customRouter.navigateTo(item.path) - // this.$c.to({ - // url: item.path - // }) - break + /** + * 处理菜单项点击 + * @param {Object} item 菜单项 + */ + handleMenuClick(item) { + if (item.handler) { + item.handler(item, this); } },