diff --git a/common/env.js b/common/env.js index e5433d1..8937f6c 100644 --- a/common/env.js +++ b/common/env.js @@ -32,6 +32,8 @@ const testing = { wxAppId: 'wx0e33d80d35e4a3b1' }; + + // 根据环境变量选择对应配置 let currentEnv = testing; diff --git a/common/platform/AppPlatform.js b/common/platform/AppPlatform.js new file mode 100644 index 0000000..30a4fab --- /dev/null +++ b/common/platform/AppPlatform.js @@ -0,0 +1,29 @@ +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}`); + } +} +export default AppPlatform; \ No newline at end of file diff --git a/common/platform/BasePlatform.js b/common/platform/BasePlatform.js new file mode 100644 index 0000000..71456ad --- /dev/null +++ b/common/platform/BasePlatform.js @@ -0,0 +1,46 @@ +/** + * 多端平台抽象基类(父类) + * 定义所有端必须实现的方法 + */ +class BasePlatform { + constructor() { + if (new.target === BasePlatform) { + throw new Error('BasePlatform 是抽象类,不能直接实例化'); + } + this.code = ''; // 平台代码(WEB/MP/APP) + this.env = ''; // 运行环境标识 + } + + getPayData(url,data) { + throw new Error('子类必须实现 getPayData 方法'); + } + + /** + * 支付方法(子类必须实现) + * @param {number} amount - 支付金额(分) + * @param {string} orderId - 订单号 + */ + pay({ data }) { + 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 || '' + }; + } +} +export default BasePlatform; \ No newline at end of file diff --git a/common/platform/H5Platform.js b/common/platform/H5Platform.js new file mode 100644 index 0000000..b448d8a --- /dev/null +++ b/common/platform/H5Platform.js @@ -0,0 +1,48 @@ +import BasePlatform from './BasePlatform'; + +class H5Platform extends BasePlatform { + constructor() { + super(); + this.code = 'WEB_H5'; + this.env = 'h5'; + } + getPayData(url, data) { + + data['quitUrl']=escape(window.location.href); + data['returnUrl']=escape(window.location.href); + console.log('处理数据',data); + return data; + } + pay({ data }) { + console.log('支付1111'); + + return new Promise((resolve) => { + console.log(data); + // 创建一个临时div元素 + const tempDiv = document.createElement('div'); + // 将data作为HTML插入到div中(假设data是表单的HTML字符串) + tempDiv.innerHTML = data; + // 将表单添加到body中 + document.body.appendChild(tempDiv.firstChild); + // 获取表单并提交 + const form = document.getElementById('alipaysubmit'); + if (form) { + form.submit(); + resolve({ success: true }); + } else { + resolve({ success: false, message: '表单创建失败' }); + } + }); + } + + share({ title, desc, image, url }) { + console.log(`H5分享:${title} - ${desc}`); + // 调用浏览器原生分享(如果可用) + if (navigator.share) { + return navigator.share({ title, text: desc, url }); + } + // 降级方案 + alert(`请手动分享:${url}`); + } +} +export default H5Platform; \ No newline at end of file diff --git a/common/platform/MiniProgramPlatform.js b/common/platform/MiniProgramPlatform.js new file mode 100644 index 0000000..1fbb102 --- /dev/null +++ b/common/platform/MiniProgramPlatform.js @@ -0,0 +1,64 @@ +import BasePlatform from './BasePlatform'; +/** + * 小程序平台 + */ +class MiniProgramPlatform extends BasePlatform { + constructor() { + super(); + this.code = 'MP-WEIXIN'; + this.env = 'miniProgram'; + } + getPayData(url, data) { + return data; + } + pay({ data }) { + return new Promise((resolve, reject) => { + let provider = "weixin"; + uni.requestPayment({ + provider, + ...data, + success: res => { + // console.log(res) + }, + fail: err => { + // console.log('common.wxMpPay-error', err) + }, + complete: res => { + console.log('complete (res)', res) + if (res.errMsg == 'requestPayment:fail cancel') { + this.toast({ + title: '取消支付', + icon: 'none', + duration: 500, + success: () => { + /* 取消订单 */ + } + }) + + resolve('cancel') + } + if (res.errMsg == 'requestPayment:ok') { + this.toast({ + title: '支付成功', + icon: 'success', + duration: 500, + success: () => { + resolve('success') + } + }) + } + } + }) + }) + } + + share({ title, desc, image, url }) { + wx.showShareMenu({ + withShareTicket: true, + menus: ['shareAppMessage', 'shareTimeline'] + }); + // 监听用户点击分享按钮 + wx.onShareAppMessage(() => ({ title, imageUrl: image })); + } +} +export default MiniProgramPlatform; \ No newline at end of file diff --git a/common/platform/PlatformFactory.js b/common/platform/PlatformFactory.js new file mode 100644 index 0000000..b64643b --- /dev/null +++ b/common/platform/PlatformFactory.js @@ -0,0 +1,29 @@ +import MiniProgramPlatform from './MiniProgramPlatform'; +import AppPlatform from './AppPlatform'; +import H5Platform from './H5Platform'; + +class PlatformFactory { + static create() { + // 判断小程序环境 + //#ifdef MP-WEIXIN + return new MiniProgramPlatform(); + //#endif + + // 判断 App 环境 + //#ifdef APP-ANDROID + return new AppPlatform(); + //#endif + // 判断 H5 环境 + //#ifdef WEB + return new H5Platform(); + //#endif + + // 默认返回 小程序 + return new MiniProgramPlatform(); + } +} + +// 使用示例 +const platform = PlatformFactory.create(); +console.log(platform.env); +export { platform }; \ No newline at end of file diff --git a/common/request.js b/common/request.js index d2f7bdd..923425b 100644 --- a/common/request.js +++ b/common/request.js @@ -8,6 +8,7 @@ import md5 from 'js-md5' import ConfigManager from '@/common/config.js' import { apiWhiteList } from '@/common/config.js' import RouterManager from '@/common/router.js' +import { platform } from '@/common/platform/PlatformFactory' class RequestManager { /** * 判断URL是否在白名单中 @@ -69,18 +70,14 @@ class RequestManager { } } }) - + + const url = param.url || '' const method = param.method || 'POST' const data = param.data || {} const Loading = param.Loading || false const token = uni.getStorageSync('token') - let client = "" - - // #ifdef H5 - client = "h5" - // #endif - + let client = platform.code // 获取API基础URL const apiBaseUrl = EnvConfig.apiBaseUrl diff --git a/components/detail-wuxian-lingzhu/detail-wuxian-lingzhu.vue b/components/detail-wuxian-lingzhu/detail-wuxian-lingzhu.vue index 478ed96..701c6a9 100644 --- a/components/detail-wuxian-lingzhu/detail-wuxian-lingzhu.vue +++ b/components/detail-wuxian-lingzhu/detail-wuxian-lingzhu.vue @@ -24,6 +24,13 @@ 查看更多 > + + + + + + @@ -324,7 +331,7 @@ export default { width: 75rpx; height: 76rpx; position: absolute; - bottom: 4rpx; + bottom: 8rpx; left: 50%; transform: translateX(-50%); z-index: 1; diff --git a/main.js b/main.js index 9779a00..0378f73 100644 --- a/main.js +++ b/main.js @@ -7,6 +7,7 @@ import router from '@/common/router.js' import ConfigManager from '@/common/config.js' import RequestManager from '@/common/request.js' import EnvConfig from '@/common/env.js' +import { platform } from '@/common/platform/PlatformFactory' // 全局注册uni-popup组件 import uniPopup from '@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue' @@ -22,7 +23,7 @@ Vue.prototype.$img1 = url => EnvConfig.iconBaseUrl + url Vue.prototype.$sys = () => uni.getSystemInfoSync() Vue.prototype.$loginPage = EnvConfig.loginPage Vue.prototype.$wxloginPage = EnvConfig.wxLoginUrl - +Vue.prototype.$platform = platform; // 公共方法 Vue.prototype.gotoPage = gotopage // 注册路由方法到Vue实例,改用自定义属性名 @@ -49,11 +50,11 @@ loadScript('https://res.wx.qq.com/open/js/jweixin-1.6.0.js') // #ifdef MP-WEIXIN const updateManager = wx.getUpdateManager() -updateManager.onCheckForUpdate(function(res) { +updateManager.onCheckForUpdate(function (res) { console.log(res.hasUpdate) }) -updateManager.onUpdateReady(function() { +updateManager.onUpdateReady(function () { wx.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', @@ -65,7 +66,7 @@ updateManager.onUpdateReady(function() { }) }) -updateManager.onUpdateFailed(function() { +updateManager.onUpdateFailed(function () { // 新版本下载失败 }) // #endif @@ -80,14 +81,14 @@ const app = new Vue({ // 创建全局数据对象 app.globalData = { - siteBaseUrl: EnvConfig.apiBaseUrl + siteBaseUrl: EnvConfig.apiBaseUrl } // 应用启动时加载全局配置 ConfigManager.init().then(config => { - console.log('全局配置加载完成') + console.log('全局配置加载完成') }).catch(err => { - console.error('全局配置加载失败', err) + console.error('全局配置加载失败', err) }) app.$mount() \ No newline at end of file diff --git a/pages/shouye/detail_wuxian.vue b/pages/shouye/detail_wuxian.vue index 53d3bb7..112a5f2 100644 --- a/pages/shouye/detail_wuxian.vue +++ b/pages/shouye/detail_wuxian.vue @@ -14,7 +14,7 @@ 倒计时:{{ secNum }}S - @@ -346,6 +346,7 @@ export default { onLoad(options) { this.optData = options; console.log(options); + this.getData(); uni.$on('chooseCoupon', data => { // console.log('data', data) @@ -360,6 +361,10 @@ export default { this.sendRuleData = res.data } }) + if (options != null && options['order_no'] != null) { + let order_num = options['order_no']; + this.getPrize(order_num); + } }, onShow() { @@ -368,7 +373,7 @@ export default { onReady() { // this.tabChange(this.tabCur) - this.getData(); + // this.getData(); }, onHide() { @@ -552,15 +557,6 @@ export default { }; let url = 'infinite_ordermoney' - console.log(type); - if (type == 1) { - url = 'infinite_orderbuy' - - if (this.$refs.buyNotice.getIsShow() && !flag) { - this.$refs.buyNotice.getRule(6) - return - } - } this.buyNum = num; @@ -571,18 +567,33 @@ export default { this.couponData = null; coupon_id = ''; } + console.log(type); + + + let postData = { + goods_id: this.pageData.goods.id, + prize_num: this.buyNum, + use_money_is: this.useMoney ? 1 : 2, + use_integral_is: this.useIntegral ? 1 : 2, + use_money2_is: this.useMoney2 ? 1 : 2, + coupon_id: coupon_id, + }; + if (type == 1) { + url = 'infinite_orderbuy' + + if (this.$refs.buyNotice.getIsShow() && !flag) { + this.$refs.buyNotice.getRule(6) + return + } + + postData = this.$platform.getPayData(url, postData); + // postData['quitUrl']=window.location.href; + // postData['returnUrl']=window.location.href; + } + this.req({ url, - data: { - goods_id: this.pageData.goods.id, - prize_num: this.buyNum, - use_money_is: this.useMoney ? 1 : 2, - use_integral_is: this.useIntegral ? 1 : 2, - use_money2_is: this.useMoney2 ? 1 : 2, - coupon_id: coupon_id, - - // ad_id: uni.getStorageSync('_ad_id') - }, + data: postData, success: async res => { if (res.status == 1) { if (type == 0) { @@ -605,7 +616,7 @@ export default { this.close('buyPop') if (res.data.status == 1) { - const status = await this.$c.wxMpPay({ + const status = await this.$platform.pay({ data: res.data.res }) diff --git a/unpackage/release/apk/20250429205226.apk b/unpackage/release/apk/20250429205226.apk new file mode 100644 index 0000000..f94afa8 Binary files /dev/null and b/unpackage/release/apk/20250429205226.apk differ