From 21f87c8ed27d5f06f1fcdd807a8cb87960bc2fca Mon Sep 17 00:00:00 2001 From: zpc Date: Sun, 4 May 2025 16:55:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 468 +++++++++++++------------ common/env.js | 10 +- common/platform/BasePlatform.js | 18 + common/platform/H5Platform.js | 107 +++++- common/platform/MiniProgramPlatform.js | 52 +++ common/request.js | 9 +- common/server/userAddress.js | 64 ++++ pages.json | 50 +-- pages/mall/index.vue | 5 + pages/other/address_edit.vue | 366 +++++++++++++++++++ pages/other/choose_address.vue | 306 ++++++++++++++-- pages/sangdai/sangdai.vue | 7 +- pages/shouye/detail.vue | 16 +- pages/shouye/detail_wuxian.vue | 20 +- pages/user/login.vue | 12 +- pages/user/tui-guang.vue | 49 +-- 16 files changed, 1210 insertions(+), 349 deletions(-) create mode 100644 common/server/userAddress.js create mode 100644 pages/other/address_edit.vue diff --git a/App.vue b/App.vue index fb63f89..9012496 100644 --- a/App.vue +++ b/App.vue @@ -1,255 +1,259 @@ \ No newline at end of file diff --git a/common/env.js b/common/env.js index 8937f6c..5c0c3fa 100644 --- a/common/env.js +++ b/common/env.js @@ -39,11 +39,11 @@ let currentEnv = testing; // 判断当前环境 // #ifdef H5 -if (process.env.NODE_ENV === 'production') { - currentEnv = production; -} else if (process.env.NODE_ENV === 'testing') { - currentEnv = testing; -} +// if (process.env.NODE_ENV === 'production') { +// currentEnv = production; +// } else if (process.env.NODE_ENV === 'testing') { +// currentEnv = testing; +// } // #endif // #ifdef MP-WEIXIN diff --git a/common/platform/BasePlatform.js b/common/platform/BasePlatform.js index 5886c54..fa2001c 100644 --- a/common/platform/BasePlatform.js +++ b/common/platform/BasePlatform.js @@ -56,5 +56,23 @@ class BasePlatform { ua: navigator?.userAgent || '' }; } + + downloadFile(url) { + return new Promise((resolve, reject) => { + throw new Error('子类必须实现 downloadFile 方法'); + }); + } + AppLaunch(options) { + throw new Error('子类必须实现 AppLaunch 方法'); + } + /** + * 获取订单号 + */ + getOrderNo() { + throw new Error('子类必须实现 getOrderNo 方法'); + } + delOrderNo(){ + + } } export default BasePlatform; \ No newline at end of file diff --git a/common/platform/H5Platform.js b/common/platform/H5Platform.js index 317ead6..a3b756b 100644 --- a/common/platform/H5Platform.js +++ b/common/platform/H5Platform.js @@ -1,5 +1,24 @@ import BasePlatform from './BasePlatform'; + +function parseQueryString(queryString) { + // 如果以 ? 开头,先去掉 ? + if (queryString.startsWith('?')) { + queryString = queryString.substring(1); + } + + const params = {}; + const pairs = queryString.split('&'); + + for (const pair of pairs) { + const [key, value] = pair.split('='); + // 解码 URI 组件 + params[key] = decodeURIComponent(value); + } + + return params; +} + class H5Platform extends BasePlatform { constructor() { super(); @@ -55,13 +74,14 @@ class H5Platform extends BasePlatform { url: '/pages/other/choose_address', events: { // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据 - acceptDataFromOpenedPage: function (data) { - console.log(data) + 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向被打开页面传送数据 @@ -70,5 +90,86 @@ class H5Platform extends BasePlatform { }) }); } + downloadFile(url) { + return new Promise((resolve, reject) => { + try { + // 创建一个隐藏的a标签 + const a = document.createElement('a'); + a.href = url; + a.download = url.split('/').pop() || 'download'; // 使用URL中的文件名或默认名称 + a.style.display = 'none'; + document.body.appendChild(a); + a.click(); // 触发下载 + document.body.removeChild(a); // 清理DOM + resolve({ success: true }); + } catch (error) { + console.error('下载失败:', error); + // 降级方案,直接打开 + window.location.href = url; + resolve({ success: false, error: error.message }); + } + }); + } + AppLaunch(options) { + console.log("AppLaunch", options); + if (options.query) { + let query = options.query; + if (query['method'] != null && query['method'] == "alipay.trade.wap.pay.return" && query['out_trade_no'] != null) { + //支付宝跳转过来的 + //重定向url + let url = window.location.origin + window.location.pathname; + let out_trade_no = query['out_trade_no']; + uni.setStorageSync('pay_order_num', out_trade_no); + // alert('存入订单编号' + out_trade_no) + const delKey = ['charset', 'out_trade_no', 'method', 'total_amount', 'sign', 'trade_no', 'auth_app_id', 'version', 'app_id', 'sign_type', 'seller_id', 'timestamp']; + for (const key of delKey) { + delete query[key]; + } + let str = Object.entries(query) + .map(([key, value]) => `${key}=${value}`) + .join('&') + + url += "?" + str; + console.log('支付成功,重定向页面。',url); + window.location.href = url; + } + + // query[''] + // { + // "goods_id": "1081", + // "type_text": "%E6%97%A0%E9%99%90%E8%B5%8F", + // "order_no": "MH_ZFAH5ZFB2025050449989950960", + // "charset": "UTF-8", + // "out_trade_no": "MH_ZFAH5ZFB2025050449989950960", + // "method": "alipay.trade.wap.pay.return", + // "total_amount": "0.01", + // "sign": "JD2PDNDh2qTi/y4wiqtsyJSc5uPy1OgO5W7NaYRdc/ctHT85yVJP9fDVpJAIXRDj/xd8oWpT9a2BSrNfqIbZ0sT0Fa8ha15unfi9RX+jYEkKAa2Grz0rkcv3YOlMni9vThCRdmNPCzh0fKLCKFRBZiuxPIFW7qgoRxFkWvziR8dUi0GccleOSUV6Z3W+HG6b+Ru3fgZSRMm+8+d0UXrH5wi7KIgJja+ZbAnVYkh+4R7BjxS1zpUPMXNzej9fAFHO6UD8RBobYi1r6D3gYpKJaChVUJXaXkRqU/6ybgUbX7FsvviCYoEGUkukiq9HCaKZ/bfrD3TvoAicC4aXo6p7Dw==", + // "trade_no": "2025050422001402751446415564", + // "auth_app_id": "2021005141643914", + // "version": "1.0", + // "app_id": "2021005141643914", + // "sign_type": "RSA2", + // "seller_id": "2088170936712914", + // "timestamp": "2025-05-04 01:41:48" + // } + } + } + getOrderNo() { + return new Promise((resolve, reject) => { + //window.location.search + let query = parseQueryString(window.location.search); + if (query['method'] != null && query['method'] == "alipay.trade.wap.pay.return" && query['out_trade_no'] != null) { + //表示还在支付请求中,还未开始重定向 + console.log('window.location.search',window.location.search); + + resolve(null); + return; + } + let pay_order_num = uni.getStorageSync('pay_order_num'); + // alert("获取订单编号"+pay_order_num) + setTimeout(() => { uni.removeStorageSync('pay_order_num'); }, 2000) + resolve(pay_order_num); + }); + } } export default H5Platform; \ No newline at end of file diff --git a/common/platform/MiniProgramPlatform.js b/common/platform/MiniProgramPlatform.js index 792fe06..6f632de 100644 --- a/common/platform/MiniProgramPlatform.js +++ b/common/platform/MiniProgramPlatform.js @@ -88,5 +88,57 @@ class MiniProgramPlatform extends BasePlatform { }); }); } + downloadFile(url) { + return new Promise((resolve, reject) => { + // 下载图片到本地 + wx.downloadFile({ + url: url, + success: (res) => { + if (res.statusCode === 200) { + const tempFilePath = res.tempFilePath; // 获取临时文件路径 + // 保存图片到相册 + wx.saveImageToPhotosAlbum({ + filePath: tempFilePath, + success: () => { + uni.showToast({ + title: '保存成功', + icon: 'success', + }); + }, + fail: (err) => { + uni.showToast({ + title: '保存失败', + icon: 'none', + }); + console.error('保存失败', err); + }, + }); + } else { + uni.showToast({ + title: '图片下载失败', + icon: 'none', + }); + console.error('图片下载失败', res); + } + }, + fail: (err) => { + uni.showToast({ + title: '图片下载失败', + icon: 'none', + }); + console.error('图片下载失败', err); + }, + }); + }); + } + AppLaunch(options) { + console.log("AppLaunch", options); + } + getOrderNo() { + return new Promise((resolve, reject) => { + resolve(null); + }); + } + delOrderNo(){} } export default MiniProgramPlatform; \ No newline at end of file diff --git a/common/request.js b/common/request.js index 6567145..6d69d8a 100644 --- a/common/request.js +++ b/common/request.js @@ -16,14 +16,7 @@ class RequestManager { * @returns {Boolean} 是否在白名单中 */ static isUrlInWhitelist(url) { - // let iswx = ConfigManager.GetVersion(); - - // // 根据版本使用不同的白名单 - // if (!iswx) { - // // 非微信版本只允许 login_record - // return apiWhiteList.includes('login_record') && url.indexOf('login_record') > -1; - // } - + // 检查URL是否包含白名单中的任一项 return apiWhiteList.some(whiteItem => url.indexOf(whiteItem) > -1); } diff --git a/common/server/userAddress.js b/common/server/userAddress.js new file mode 100644 index 0000000..31cfdb2 --- /dev/null +++ b/common/server/userAddress.js @@ -0,0 +1,64 @@ + +import RequestManager from '../request'; + + +/** + * 添加收货地址 + * @param {Object} data 地址信息 + * @returns {Promise} + */ +export const addAddress = async (data) => { + return await RequestManager.post('/addAddress', data); +}; + +/** + * 更新收货地址 + * @param {Object} data 地址信息 + * @returns {Promise} + */ +export const updateAddress = async (data) => { + return await RequestManager.post('/updateAddress', data); +}; + +/** + * 获取默认收货地址 + * @returns {Promise} + */ +export const getDefaultAddress = async () => { + return await RequestManager.get('/getDefaultAddress'); +}; + +/** + * 获取收货地址列表 + * @returns {Promise} + */ +export const getAddressList = async () => { + return await RequestManager.get('/getAddressList'); +}; + +/** + * 删除收货地址 + * @param {Object} data 包含地址ID的对象 + * @returns {Promise} + */ +export const deleteAddress = async (data) => { + return await RequestManager.post('/deleteAddress', data); +}; + +/** + * 设置默认收货地址 + * @param {Object} data 包含地址ID的对象 + * @returns {Promise} + */ +export const setDefaultAddress = async (data) => { + return await RequestManager.post('/setDefaultAddress', data); +}; + +/** + * 获取地址详情 + * @param {Object} data 包含地址ID的对象 + * @returns {Promise} + */ +export const getAddressDetail = async (id) => { + return await RequestManager.get('/getAddressDetail', { id }); +}; \ No newline at end of file diff --git a/pages.json b/pages.json index 44f093b..fcd66ef 100644 --- a/pages.json +++ b/pages.json @@ -45,7 +45,7 @@ "navigationBarTextStyle": "black" } }, - + { "path": "pages/shouye/huanxiang", "style": { @@ -196,7 +196,7 @@ "navigationBarTextStyle": "black" } }, - + { "path": "pages/sangdai/sangdai", "style": { @@ -252,8 +252,8 @@ "navigationBarTextStyle": "black" } }, - - + + { "path": "pages/infinite/index", "style": { @@ -331,51 +331,50 @@ } }, { - "path" : "pages/infinite/reward_records", - "style" : - { + "path": "pages/infinite/reward_records", + "style": { "navigationStyle": "custom" } }, { - "path" : "pages/shouye/danye", - "style" : - { + "path": "pages/shouye/danye", + "style": { "navigationStyle": "custom" } }, { - "path" : "pages/other/prize_draw", - "style" : - { + "path": "pages/other/prize_draw", + "style": { "navigationStyle": "custom" } }, { - "path" : "pages/other/order_list", - "style" : - { + "path": "pages/other/order_list", + "style": { "navigationStyle": "custom" } }, { - "path" : "pages/other/order_info", - "style" : - { + "path": "pages/other/order_info", + "style": { "navigationStyle": "custom" } }, { - "path" : "pages/shouye/slots", - "style" : - { + "path": "pages/shouye/slots", + "style": { "navigationStyle": "custom" } }, { - "path" : "pages/other/choose_address", - "style" : - { + "path": "pages/other/choose_address", + "style": { + "navigationStyle": "custom" + } + }, + { + "path": "pages/other/address_edit", + "style": { "navigationStyle": "custom" } } @@ -464,6 +463,7 @@ "borderStyle": "black", "backgroundColor": "#FFFFFF", "iconWidth": "24px", + "iconHeight": "24px", "list": [{ "pagePath": "pages/shouye/index", "iconPath": "static/tabbar/m1.png", diff --git a/pages/mall/index.vue b/pages/mall/index.vue index a77a9c1..284d8de 100644 --- a/pages/mall/index.vue +++ b/pages/mall/index.vue @@ -183,6 +183,11 @@ export default { this.sendRuleData = res.data } }); + this.$platform.getOrderNo().then(order_num => { + if (order_num != null && order_num != "") { + that.$c.msg("购买成功!"); + } + }) }, onShow() { diff --git a/pages/other/address_edit.vue b/pages/other/address_edit.vue new file mode 100644 index 0000000..2293a59 --- /dev/null +++ b/pages/other/address_edit.vue @@ -0,0 +1,366 @@ +