This commit is contained in:
moyayu
2026-05-15 19:33:56 +08:00
parent 139aa93c23
commit 50b3e2452c
5 changed files with 47 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install commitlint --edit ""
npx --no-install commitlint --edit "${1}"

View File

@@ -10,8 +10,12 @@ export function getOpenid({ code }) {
return req.get('/oauth/getopenid', { code })
}
export function getredirecturl({ url }) {
return req.get('/oauth/getredirecturl', { url })
export async function getredirecturl({ url }) {
const data = await req.get('/oauth/getredirecturl', { url })
/* 调试getredirecturl 已返回,调用方赋值 window.location 前暂停,可查看 data / redirect_url */
// eslint-disable-next-line no-debugger
debugger
return data
}
export function info(data) {

View File

@@ -189,23 +189,30 @@ export default (props = {}) => {
// 微信H5 JSDK
const wxpayjsPay = async (params, orderInfo) => {
// const $instance = getCurrentInstance() || {}
const { order_id, code } = router?.params
const route = router?.params || {}
const oid = route.order_id || orderInfo?.order_id || route.id
const { code, source: routeSource } = route
if (!code) {
// 微信客户端code授权
// 微信客户端 code 授权(订单详情页等场景 URL 仅有 order_id无 code
const loc = window.location
// const url = `${loc.protocol}//${loc.host}/pages/cart/cashier-result?order_id=${orderId}`
const url = `${loc.protocol}//${loc.host}/pages/cart/cashier-weapp?order_id=${orderId}&source=${source}`
let { redirect_url } = await api.wx.getredirecturl({ url })
const sourceQuery =
routeSource != null && String(routeSource) !== ''
? `&source=${encodeURIComponent(String(routeSource))}`
: ''
const url = `${loc.protocol}//${loc.host}/pages/cart/cashier-weapp?order_id=${oid}${sourceQuery}`
const { redirect_url } = await api.wx.getredirecturl({ url })
window.location.href = redirect_url
return
}
const { open_id } = await api.wx.getOpenid({ code })
const { pay_channel } = params
const { pay_type, order_type = 'normal' } = orderInfo
let query = {
pay_type,
pay_channel,
order_id,
order_id: oid,
order_type,
open_id
}
@@ -227,7 +234,7 @@ export default (props = {}) => {
function (res) {
console.log(res)
const loc = window.location
window.location.href = `${loc.protocol}//${loc.host}${cashierResultUrl}?order_id=${order_id}`
window.location.href = `${loc.protocol}//${loc.host}${cashierResultUrl}?order_id=${oid}`
}
)
}

View File

@@ -2,7 +2,7 @@
* Copyright © ShopeX http://www.shopex.cn. All rights reserved.
* See LICENSE file for license details.
*
* i18next 单例:语言资源通过 subpages/i18n/resources 分包异步加载。
* i18next 单例:weapp 经 subpages/i18n/resources 分包异步加载H5 主包同步 require 同目录 resources
*/
/* eslint-disable import/no-named-as-default-member -- i18next 默认导出即实例,需调用 .use / .changeLanguage */
import i18n from 'i18next'
@@ -126,7 +126,27 @@ function loadLocalePackage() {
})
}
return Promise.reject(new Error('i18n subPackage resource loading is only enabled for weapp'))
// H5语言包由 webpack 打进主包,同步 require 即可weapp 依赖分包异步加载,勿在此 require 以免主包膨胀)
if (process.env.TARO_ENV === 'h5') {
const Taro = getTaro()
try {
const resources = require('../subpages/i18n/resources')
if (Taro && resources && (resources.zhcn || resources.en || resources.ar)) {
Taro.__i18nResources = {
...(Taro.__i18nResources || {}),
...resources
}
return Promise.resolve()
}
return Promise.reject(new Error('i18n H5 resources empty'))
} catch (e) {
return Promise.reject(e)
}
}
return Promise.reject(
new Error(`i18n resource loading unsupported for TARO_ENV=${process.env.TARO_ENV}`)
)
}
if (!i18n.isInitialized) {

View File

@@ -378,6 +378,9 @@ function CartCheckout(props) {
params.pay_channel == 'wx_pub' &&
isWxWeb)
) {
/* 调试:公众号 JSAPI(wxpayjs) — 下单成功 → 跳转 OAuth/收银台前暂停 */
// eslint-disable-next-line no-debugger
debugger
// 微信客户端code授权
const loc = window.location
// const url = `${loc.protocol}//${loc.host}/pages/cart/cashier-result?order_id=${orderId}`