fix:兼容普通二维码跳转

This commit is contained in:
2026-03-18 16:41:40 +08:00
parent a79cf10bd4
commit 802aee59cb
3 changed files with 48 additions and 26 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
// export const URL = "https://my.gxfs123.com/api" //正式服务器-弃用 // export const URL = "https://my.gxfs123.com/api" //正式服务器-弃用
// export const URL = "https://manager.fdzpower.com/api" //正式服务器 export const URL = "https://manager.fdzpower.com/api" //正式服务器
// export const URL = "https://fansdev.gxfs123.com/api" //测试服务器 // export const URL = "https://fansdev.gxfs123.com/api" //测试服务器
export const URL = "http://192.168.5.58:8080" //本地调试 // export const URL = "http://192.168.5.58:8080" //本地调试
// export const URL = "http://127.0.0.1:8080" //本地调试 // export const URL = "http://127.0.0.1:8080" //本地调试
export const appid = "wx2165f0be356ae7a9" //微信小程序appid export const appid = "wx2165f0be356ae7a9" //微信小程序appid
+21 -1
View File
@@ -181,6 +181,27 @@
// 生命周期 onLoad 钩子 // 生命周期 onLoad 钩子
onLoad(async (options) => { onLoad(async (options) => {
console.log('options', options)
// 普通链接二维码进入时,参数通常在 options.q(且为编码后的完整 URL
if (!options.deviceNo && options.q) {
const fullUrl = decodeURIComponent(options.q)
const queryStr = fullUrl.includes('?') ? fullUrl.split('?')[1] : ''
if (queryStr) {
const params = queryStr.split('&').reduce((acc, pair) => {
if (!pair) return acc
const idx = pair.indexOf('=')
const rawKey = idx >= 0 ? pair.slice(0, idx) : pair
const rawVal = idx >= 0 ? pair.slice(idx + 1) : ''
const key = decodeURIComponent(rawKey || '').trim()
const val = decodeURIComponent(rawVal || '').trim()
if (key) acc[key] = val
return acc
}, {})
if (params.deviceNo) options.deviceNo = params.deviceNo
}
}
if (options.deviceNo != uni.getStorageSync('deviceId') || !uni.getStorageSync('deviceId')) { if (options.deviceNo != uni.getStorageSync('deviceId') || !uni.getStorageSync('deviceId')) {
deviceId.value = options.deviceNo deviceId.value = options.deviceNo
uni.setStorageSync('deviceId', options.deviceNo) uni.setStorageSync('deviceId', options.deviceNo)
@@ -427,7 +448,6 @@
if (inUseRes && inUseRes.code === 200 && inUseRes.data) { if (inUseRes && inUseRes.code === 200 && inUseRes.data) {
const order = inUseRes.data const order = inUseRes.data
// 如果有正在进行的订单,跳转到归还页面,带上设备ID // 如果有正在进行的订单,跳转到归还页面,带上设备ID
console.log('1111111111');
uni.redirectTo({ uni.redirectTo({
url: `/subPackages/service/return/index?deviceId=${deviceId.value}` url: `/subPackages/service/return/index?deviceId=${deviceId.value}`
}) })
+14 -12
View File
@@ -100,10 +100,10 @@
} catch (error) { } catch (error) {
// 只处理真正的错误,不是"没有订单"的情况 // 只处理真正的错误,不是"没有订单"的情况
if (error.message && ( if (error.message && (
error.message.includes('未识别到设备编号') || error.message.includes('未识别到设备编号') ||
error.message.includes('网络请求失败') || error.message.includes('网络请求失败') ||
error.message.includes('服务器错误') error.message.includes('服务器错误')
) ) { )) {
console.error('扫码检查订单失败:', error); console.error('扫码检查订单失败:', error);
uni.showToast({ uni.showToast({
title: error.message || this.$t('device.processFailed'), title: error.message || this.$t('device.processFailed'),
@@ -117,17 +117,19 @@
// 无论什么情况,都跳转到一个可用页面 // 无论什么情况,都跳转到一个可用页面
setTimeout(() => { setTimeout(() => {
if (option && option.deviceNo) { if (option && option.deviceNo) {
uni.redirectTo({ uni.redirectTo({
url: `/pages/device/detail?deviceNo=${option.deviceNo}` url: `/pages/device/detail?deviceNo=${option.deviceNo}`
}); });
} else { } else {
// uni.switchTab({ // uni.switchTab({
// url:'/pages/index/index' // url:'/pages/index/index'
// }) // })
// 如果连deviceNo都没有,则返回首页 // 如果连deviceNo都没有,则返回首页
uni.reLaunch({ url: '/pages/index/index' }); uni.reLaunch({
} url: '/pages/index/index'
});
}
}, 2000); }, 2000);
} finally { } finally {
uni.hideLoading(); uni.hideLoading();