diff --git a/components.d.ts b/components.d.ts index 7ef8bc4..6d74a5c 100644 --- a/components.d.ts +++ b/components.d.ts @@ -11,21 +11,16 @@ declare module 'vue' { RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] VanArea: typeof import('vant/es')['Area'] - VanButton: typeof import('vant/es')['Button'] VanCell: typeof import('vant/es')['Cell'] VanCellGroup: typeof import('vant/es')['CellGroup'] VanField: typeof import('vant/es')['Field'] VanForm: typeof import('vant/es')['Form'] VanIcon: typeof import('vant/es')['Icon'] VanNoticeBar: typeof import('vant/es')['NoticeBar'] - VanPopover: typeof import('vant/es')['Popover'] VanPopup: typeof import('vant/es')['Popup'] - VanSearch: typeof import('vant/es')['Search'] VanStepper: typeof import('vant/es')['Stepper'] VanSwipe: typeof import('vant/es')['Swipe'] VanSwipeItem: typeof import('vant/es')['SwipeItem'] VanSwitch: typeof import('vant/es')['Switch'] - VanTab: typeof import('vant/es')['Tab'] - VanTabs: typeof import('vant/es')['Tabs'] } } diff --git a/src/api/shop.ts b/src/api/shop.ts index ad8928e..758064c 100644 --- a/src/api/shop.ts +++ b/src/api/shop.ts @@ -6,6 +6,7 @@ const shop = { getReviewList: ['/comment/list'], // 获取评价接口 addCart: ['/shipping/cart/addOrUpdate'], // 添加购物车接口 order: ['/order/add'], // 下单 + getWxPayParams: ['/order/getWxPayParams'], // 下单获取微信支付参数接口 // 订单 orderList: ['/order/list'], // 订单列表 } diff --git a/src/utils/wx-minprogram.ts b/src/utils/wx-minprogram.ts index 702a21a..9081cad 100644 --- a/src/utils/wx-minprogram.ts +++ b/src/utils/wx-minprogram.ts @@ -23,10 +23,10 @@ export const h5OpenMinProgram = (type = 'index', h5Url = '') => { } if (h5Url && !h5Url.startsWith('https')) { Object.assign(params, { - query: `url=${encodeURIComponent(`${window.location.origin}${h5Url}`)}` + query: `url=${encodeURIComponent(`${window.location.origin}${h5Url}`)}`, }) } - api.getSchemeUrl.post(params).then(res => { + api.getSchemeUrl.post(params).then((res) => { if (res.data) { window.location.href = res.data as any } else { @@ -34,3 +34,29 @@ export const h5OpenMinProgram = (type = 'index', h5Url = '') => { } }) } + +/** + * H5页面调用小程序支付 + * @param {Object} paymentParams - 支付参数(由后端接口返回) + * @param {string} paymentParams.timeStamp - 时间戳 + * @param {string} paymentParams.nonceStr - 随机字符串 + * @param {string} paymentParams.package - 统一下单接口返回的prepay_id参数值 + * @param {string} paymentParams.signType - 签名类型,默认为MD5 + * @param {string} paymentParams.paySign - 签名 + */ +export const requestPayment = (paymentParams) => { + // 向小程序发送支付请求 + console.warn('----- my data is window.wx111: ', window.wx) + if (window.wx && window.wx.miniProgram) { + // 微信环境 + window.wx.miniProgram.postMessage({ + data: { + type: 'pay', + data: paymentParams, + }, + }) + } else { + console.error('不在小程序环境中') + alert('请在微信小程序中打开') + } +} diff --git a/src/views/commodity-detail/components/​​shopping-cart​.vue b/src/views/commodity-detail/components/​​shopping-cart​.vue index 43cac53..9c27068 100644 --- a/src/views/commodity-detail/components/​​shopping-cart​.vue +++ b/src/views/commodity-detail/components/​​shopping-cart​.vue @@ -48,6 +48,7 @@