diff --git a/common/platform/AppPlatform.js b/common/platform/AppPlatform.js index a2d432d..962db65 100644 --- a/common/platform/AppPlatform.js +++ b/common/platform/AppPlatform.js @@ -1,261 +1,261 @@ import BasePlatform from './BasePlatform'; import RequestManager from '@/common/request.js' import { - sleep, - parseQueryString + sleep, + parseQueryString } from '@/common/util.js' import { - getOrderStatus + getOrderStatus } from '@/common/server/order.js' class AppPlatform extends BasePlatform { - constructor() { - super(); - this.code = 'APP_ANDROID'; - this.env = 'app'; - } - getPayData(url, data) { - return data; - } - AppLaunch(options) { - console.log("AppLaunch", options); + constructor() { + super(); + this.code = 'APP_ANDROID'; + this.env = 'app'; + } + getPayData(url, data) { + return data; + } + AppLaunch(options) { + console.log("AppLaunch", options); - } - async getConfig() { - if (this.config) { - return this.config; - } - this.config = { - isWebPay: true - }; - return this.config; - } - getOrderNo(event) { - return new Promise((resolve, reject) => { + } - resolve(null); - }); - } + getOrderNo(event) { + return new Promise((resolve, reject) => { - pay({ - data - }, event) { - console.log(this, event); + resolve(null); + }); + } - return new Promise(async (resolve, reject) => { - let config = await this.getConfig(); - if (config.isWebPay) { + pay({ + data + }, event) { + console.log(this, event); - console.log(data); - let fullPath = event.$scope.$page.fullPath; - //页面路径 - console.log(fullPath, "fullPath"); + return new Promise(async (resolve, reject) => { + let config = await this.getConfig(); + if (config.isWebPay) { - let url = data.requestPay; - let payPostData = data.data; - payPostData['return_url'] = fullPath; - let respay = await RequestManager.post(url, payPostData); - if (respay.status === 1) { - console.log(respay); - plus.runtime.openURL(respay.data); - event.$refs.payDialog.showDialogHand("支付提示", - "支付成功后,请点击「支付已完成」按钮查看所购商品。如支付完成1分钟后仍显示异常,请关闭当前窗口,前往「我的」-「消费记录」查看订单状态。", - "支付已完成", "关闭", async () => { - let resPayStatus = await getOrderStatus(data.data['order_num']); - if (resPayStatus.data == 1) { - event.$refs.payDialog.closeHand(); - resolve('success'); - } else { - uni.showToast({ - title: resPayStatus.msg, - icon: 'none', - duration: 1000 - }); - } - }); + console.log(data); + let fullPath = event.$scope.$page.fullPath; + //页面路径 + console.log(fullPath, "fullPath"); - } - return; - } + let url = data.requestPay; + let payPostData = data.data; + payPostData['return_url'] = fullPath; + let respay = await RequestManager.post(url, payPostData); + if (respay.status === 1) { + console.log(respay); + plus.runtime.openURL(respay.data); + event.$refs.payDialog.showDialogHand("支付提示", + "支付成功后,请点击「支付已完成」按钮查看所购商品。如支付完成1分钟后仍显示异常,请关闭当前窗口,前往「我的」-「消费记录」查看订单状态。", + "支付已完成", "关闭", async () => { + let resPayStatus = await getOrderStatus(data.data['order_num']); + if (resPayStatus.data == 1) { + event.$refs.payDialog.closeHand(); + resolve('success'); + } else { + uni.showToast({ + title: resPayStatus.msg, + icon: 'none', + duration: 1000 + }); + } + }); - let provider = "weixin"; - uni.requestPayment({ - provider, - ...data, - success: res => { - // console.log(res) - }, - fail: err => { + } + return; + } + let orderInfo = data; + console.log('orderInfo orderInfo orderInfo orderInfo ', orderInfo); + let provider = "alipay"; + uni.requestPayment({ + provider, + "orderInfo": orderInfo, + success: res => { + // console.log(res) + }, + fail: err => { - }, - complete: res => { - console.log('complete (res)', res) - if (res.errMsg == 'requestPayment:fail cancel') { - uni.showToast({ - title: '取消支付', - icon: 'none', - duration: 500, - success: () => { - /* 取消订单 */ - resolve('cancel') - } - }) + }, + complete: res => { + console.log('complete (res)', res) + if (res.errMsg == 'requestPayment:fail cancel') { + uni.showToast({ + title: '取消支付', + icon: 'none', + duration: 500, + success: () => { + /* 取消订单 */ + resolve('cancel') + } + }) - } - if (res.errMsg == 'requestPayment:ok') { - uni.showToast({ - title: '支付成功', - icon: 'success', - duration: 500, - success: () => { - resolve('success') - } - }) - } - } - }) - }) - } - /** - * 选择地址 - * @returns - */ - chooseAddress() { - return new Promise((resolve, reject) => { - uni.navigateTo({ - url: '/pages/other/choose_address', - events: { - // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据 - selectAddress: function (data) { - console.log(data, { - userName: data.address.receiver_name, - telNumber: data.address.receiver_phone, - detailed_address: data.address.detailed_address - }) - resolve({ - userName: data.address.receiver_name, - telNumber: data.address.receiver_phone, - detailed_address: data.address.detailed_address - }); - }, - someEvent: function (data) { - console.log(data) - } + } + if (res.errMsg == 'requestPayment:ok') { + uni.showToast({ + title: '支付成功', + icon: 'success', + duration: 500, + success: () => { + resolve('success') + } + }) + } + } + }) + }) + } + /** + * 选择地址 + * @returns + */ + chooseAddress() { + return new Promise((resolve, reject) => { + uni.navigateTo({ + url: '/pages/other/choose_address', + events: { + // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据 + selectAddress: function(data) { + console.log(data, { + userName: data.address.receiver_name, + telNumber: data.address.receiver_phone, + detailed_address: data.address.detailed_address + }) + resolve({ + userName: data.address.receiver_name, + telNumber: data.address.receiver_phone, + detailed_address: data.address.detailed_address + }); + }, + someEvent: function(data) { + console.log(data) + } - }, - success: function (res) { - // 通过eventChannel向被打开页面传送数据 - res.eventChannel.emit('acceptDataFromOpenerPage', { - data: 'data from starter page' - }) - } - }) - }); - } - share({ title, desc, image, url }) { - console.log(`H5分享:${title} - ${desc}`); - // 调用浏览器原生分享(如果可用) - if (navigator.share) { - return navigator.share({ title, text: desc, url }); - } - // 降级方案 - alert(`请手动分享:${url}`); - } + }, + success: function(res) { + // 通过eventChannel向被打开页面传送数据 + res.eventChannel.emit('acceptDataFromOpenerPage', { + data: 'data from starter page' + }) + } + }) + }); + } + 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特有的菜单需求 + * @returns {Array} 菜单项数组 + */ + getUserMenuList() { + // 获取基础菜单列表 + const baseMenuList = super.getUserMenuList(); - // 添加App特有的菜单项 - const appSpecificMenus = [ - { - id: 12, - show: true, - title: '检查更新', - icon: 'my/s11.png', - path: '', - handler: this.handleCheckUpdate.bind(this) - } - ]; + // 添加App特有的菜单项 + const appSpecificMenus = [{ + id: 12, + show: true, + title: '检查更新', + icon: 'my/s11.png', + path: '', + handler: this.handleCheckUpdate.bind(this) + }]; - // 返回合并后的菜单列表 - return [...baseMenuList]; - } + // 返回合并后的菜单列表 + return [...baseMenuList]; + } - /** - * 处理清除缓存 - */ - 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); + /** + * 处理清除缓存 + */ + 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' - }); - } - } - }); - } + uni.showToast({ + title: '缓存已清除', + icon: 'success' + }); + } + } + }); + } - /** - * 处理检查更新 - */ - handleCheckUpdate() { - // App特有的更新检查逻辑 - // #ifdef APP-PLUS - plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => { - const version = widgetInfo.version; + /** + * 处理检查更新 + */ + 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 + 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 - } + // 非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 3ec39f7..e631783 100644 --- a/common/platform/BasePlatform.js +++ b/common/platform/BasePlatform.js @@ -1,4 +1,5 @@ import { navigateTo } from '@/common/router' +import { getPlatform } from '../server/config'; /** * 多端平台抽象基类(父类) * 定义所有端必须实现的方法 @@ -11,12 +12,13 @@ class BasePlatform { this.code = ''; // 平台代码(WEB/MP/APP) this.env = ''; // 运行环境标识 } - /** - * 获取配置 - * @returns - */ async getConfig() { - return {}; + if (this.config) { + return this.config; + } + const res = await getPlatform(); + this.config = res; + return this.config; } getPayData(url, data) { throw new Error('子类必须实现 getPayData 方法'); diff --git a/common/platform/IOSPlatform.js b/common/platform/IOSPlatform.js index 1d8901b..e196aa9 100644 --- a/common/platform/IOSPlatform.js +++ b/common/platform/IOSPlatform.js @@ -1,169 +1,17 @@ import BasePlatform from './BasePlatform'; - + import { parseQueryString } from '@/common/util'; -class IOSPlatform extends BasePlatform { +class IOSPlatform extends AppPlatform { constructor() { super(); this.code = 'IOS'; this.env = 'ios'; - } - getPayData(url, data) { - data['quitUrl'] = escape(window.location.href); - data['returnUrl'] = escape(window.location.href); - console.log('处理数据', data); - return data; - } - pay({ - data - }, event) { - console.log('支付1111'); - - return new Promise((resolve) => { - console.log(data); - // 检查是否已存在同ID的表单,如果存在则先删除 - const existingForm = document.getElementById('alipaysubmit'); - if (existingForm) { - existingForm.parentNode.removeChild(existingForm); - } - - // 创建一个临时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}`); - } - - /** - * 选择地址 - * @returns - */ - chooseAddress() { - console.log('选择地址选择地址选择地址选择地址'); - - return new Promise((resolve, reject) => { - uni.navigateTo({ - url: '/pages/other/choose_address', - events: { - // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据 - selectAddress: function(data) { - console.log(data, { - userName: data.address.receiver_name, - telNumber: data.address.receiver_phone, - detailed_address: data.address.detailed_address - }) - resolve({ - userName: data.address.receiver_name, - telNumber: data.address.receiver_phone, - detailed_address: data.address.detailed_address - }); - }, - someEvent: function(data) { - console.log(data) - } - - }, - success: function(res) { - // 通过eventChannel向被打开页面传送数据 - res.eventChannel.emit('acceptDataFromOpenerPage', { - data: 'data from starter page' - }) - } - }) - }); - } - downloadFile(url) { - return new Promise((resolve, reject) => { - resolve({ - success: true - }); - }); - } - AppLaunch(options) { - console.log("AppLaunch", options); - - } - getOrderNo(event) { - return new Promise((resolve, reject) => { - resolve(null); - }); - } - - /** - * 重写获取用户中心菜单列表,处理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; - }); - } - - /** - * 开启调试 - */ - startDeb() { - - } - /** - * 关闭调试 - */ - closeDeb() { - } getVersion() { return '1.0.0'; diff --git a/common/platform/MiniProgramPlatform.js b/common/platform/MiniProgramPlatform.js index f68f879..e1321d1 100644 --- a/common/platform/MiniProgramPlatform.js +++ b/common/platform/MiniProgramPlatform.js @@ -12,21 +12,11 @@ import { */ class MiniProgramPlatform extends BasePlatform { constructor() { - super(); this.code = 'MP-WEIXIN'; this.env = 'miniProgram'; - this.config = null; + super(); + } - } - async getConfig() { - if (this.config) { - return this.config; - } - this.config = { - isWebPay: true - }; - return this.config; - } getPayData(url, data) { return data; } @@ -87,7 +77,7 @@ class MiniProgramPlatform extends BasePlatform { // console.log(res) }, fail: err => { - + }, complete: res => { console.log('complete (res)', res) @@ -199,11 +189,11 @@ class MiniProgramPlatform extends BasePlatform { AppLaunch(options) { console.log("AppLaunch", options); const updateManager = uni.getUpdateManager(); - updateManager.onCheckForUpdate(function(res) { + updateManager.onCheckForUpdate(function (res) { // 请求完新版本信息的回调 console.log(res.hasUpdate); }); - updateManager.onUpdateReady(function(res) { + updateManager.onUpdateReady(function (res) { uni.showModal({ title: "更新提示", content: "新版本已经准备好,是否重启应用?", @@ -215,7 +205,7 @@ class MiniProgramPlatform extends BasePlatform { }, }); }); - updateManager.onUpdateFailed(function(res) { + updateManager.onUpdateFailed(function (res) { // 新的版本下载失败 }); } @@ -247,7 +237,7 @@ class MiniProgramPlatform extends BasePlatform { } }); } - delOrderNo() {} + delOrderNo() { } /** * 重写获取用户中心菜单列表,添加微信小程序特有菜单 @@ -266,7 +256,7 @@ class MiniProgramPlatform extends BasePlatform { path: '', isCustomService: true, // 客服按钮不需要处理函数,由微信小程序原生组件处理 - handler: () => {} + handler: () => { } }; // 将客服菜单插入到第二个位置 diff --git a/common/server/config.js b/common/server/config.js new file mode 100644 index 0000000..24176eb --- /dev/null +++ b/common/server/config.js @@ -0,0 +1,20 @@ + +import RequestManager from '../request'; +import common from '../common'; +import { platform } from '@/common/platform/PlatformFactory' + +/** + * 获取系统配置 + * @returns + */ +export const getConfig = () => { + return RequestManager.get("config", {}); +} +/** + * 获取平台配置 + * @returns + */ +export const getPlatform = async () => { + const res = await RequestManager.get("getPlatformConfig", {}); + return res.data; +} \ No newline at end of file