From f028a8278d4631ac6b6eb6de0533b7514dd03295 Mon Sep 17 00:00:00 2001 From: zeyan <258785420@qq.com> Date: Fri, 15 Aug 2025 19:01:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uniapp/common/config.js | 4 +- uniapp/pages-common/webview/wechat_bind.vue | 128 +++++++++++++++++--- uniapp/pages-market/my/set_up.vue | 10 +- 3 files changed, 117 insertions(+), 25 deletions(-) diff --git a/uniapp/common/config.js b/uniapp/common/config.js index 2459f37b..c98a2253 100644 --- a/uniapp/common/config.js +++ b/uniapp/common/config.js @@ -1,6 +1,6 @@ // 环境变量配置 -// const env = 'development' -const env = 'prod' +const env = 'development' +// const env = 'prod' const isMockEnabled = false // 默认禁用Mock优先模式,仅作为回退 const isDebug = false // 默认启用调试模式 const devurl = 'http://localhost:20080/api' diff --git a/uniapp/pages-common/webview/wechat_bind.vue b/uniapp/pages-common/webview/wechat_bind.vue index 0688e9b3..ce0683be 100644 --- a/uniapp/pages-common/webview/wechat_bind.vue +++ b/uniapp/pages-common/webview/wechat_bind.vue @@ -1,12 +1,29 @@ @@ -14,7 +31,10 @@ export default { data() { return { - webviewUrl: '' + webviewUrl: '', + isLoading: true, + hasError: false, + errorMessage: '' } }, onLoad(options) { @@ -23,14 +43,15 @@ export default { if (options.url) { this.webviewUrl = decodeURIComponent(options.url) console.log('webview URL:', this.webviewUrl) - } else { - uni.showToast({ - title: '参数错误', - icon: 'none' - }) + + // 3秒后隐藏加载状态(即使webview没有触发load事件) setTimeout(() => { - uni.navigateBack() - }, 2000) + this.isLoading = false + }, 3000) + } else { + this.hasError = true + this.errorMessage = '缺少URL参数' + console.error('webview页面缺少URL参数') } }, methods: { @@ -89,21 +110,22 @@ export default { }, // webview加载完成 - onLoad() { - console.log('webview加载完成') + onWebviewLoad(event) { + console.log('webview加载完成:', event) + this.isLoading = false }, // webview加载错误 onError(error) { console.error('webview加载错误:', error) - uni.showToast({ - title: '页面加载失败', - icon: 'none' - }) - - setTimeout(() => { - uni.navigateBack() - }, 2000) + this.isLoading = false + this.hasError = true + this.errorMessage = error.detail?.errMsg || '未知错误' + }, + + // 返回按钮 + goBack() { + uni.navigateBack() } } } @@ -113,5 +135,73 @@ export default { .webview-container { width: 100%; height: 100vh; + position: relative; +} + +.loading-container { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #fff; + z-index: 10; +} + +.loading-text { + font-size: 16px; + color: #333; + margin-bottom: 20px; +} + +.debug-info { + padding: 10px; + background-color: #f5f5f5; + border-radius: 4px; + max-width: 90%; + font-size: 12px; + color: #666; + word-break: break-all; +} + +.error-container { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + background-color: #fff; + z-index: 10; +} + +.error-text { + font-size: 18px; + color: #f56c6c; + margin-bottom: 10px; +} + +.error-detail { + font-size: 14px; + color: #999; + margin-bottom: 20px; + text-align: center; + padding: 0 20px; +} + +.back-btn { + background-color: #29d3b4; + color: white; + border: none; + padding: 10px 20px; + border-radius: 4px; + font-size: 16px; } \ No newline at end of file diff --git a/uniapp/pages-market/my/set_up.vue b/uniapp/pages-market/my/set_up.vue index 9f6043ac..4d85853e 100644 --- a/uniapp/pages-market/my/set_up.vue +++ b/uniapp/pages-market/my/set_up.vue @@ -183,14 +183,14 @@ import apiRoute from '@/api/apiRoute.js' try { // H5环境直接跳转到公众号授权 const baseUrl = Api_url - const redirectUri = encodeURIComponent(`${baseUrl}/api/personnel/wechatCallback`) + const redirectUri = encodeURIComponent(`${baseUrl}/personnel/wechatCallback`) const state = encodeURIComponent(JSON.stringify({ personnel_id: this.$store.state.userInfo.id, from: 'h5', timestamp: Date.now() })) - const authUrl = `${baseUrl}/api/personnel/wechatAuthorize?redirect_uri=${redirectUri}&state=${state}` + const authUrl = `${baseUrl}/personnel/wechatAuthorize?redirect_uri=${redirectUri}&state=${state}` console.log('H5授权URL:', authUrl) uni.hideLoading() @@ -335,7 +335,7 @@ import apiRoute from '@/api/apiRoute.js' // 构建webview URL buildWebviewUrl(miniOpenid) { const baseUrl = Api_url - const redirectUri = encodeURIComponent(`${baseUrl}/api/personnel/wechatCallback`) + const redirectUri = encodeURIComponent(`${baseUrl}/personnel/wechatCallback`) const state = encodeURIComponent(JSON.stringify({ mini_openid: miniOpenid, personnel_id: this.$store.state.userInfo.id, @@ -343,7 +343,9 @@ import apiRoute from '@/api/apiRoute.js' timestamp: Date.now() })) - return `${baseUrl}/api/personnel/wechatAuthorize?redirect_uri=${redirectUri}&state=${state}` + const authUrl = `${baseUrl}/personnel/wechatAuthorize?redirect_uri=${redirectUri}&state=${state}` + console.log('构建的授权URL:', authUrl) + return authUrl }, // 检测是否为微信环境