Browse Source

修改 bug

master
王泽彦 8 months ago
parent
commit
f028a8278d
  1. 4
      uniapp/common/config.js
  2. 126
      uniapp/pages-common/webview/wechat_bind.vue
  3. 10
      uniapp/pages-market/my/set_up.vue

4
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'

126
uniapp/pages-common/webview/wechat_bind.vue

@ -1,12 +1,29 @@
<!--微信绑定WebView页面-->
<template>
<view class="webview-container">
<!-- 显示加载状态 -->
<view v-if="!webviewUrl || isLoading" class="loading-container">
<view class="loading-text">正在加载微信授权页面...</view>
<view class="debug-info" v-if="webviewUrl">
<text>URL: {{ webviewUrl }}</text>
</view>
</view>
<!-- webview -->
<web-view
v-if="webviewUrl"
:src="webviewUrl"
@message="onMessage"
@load="onLoad"
@load="onWebviewLoad"
@error="onError">
</web-view>
<!-- 错误状态 -->
<view v-if="hasError" class="error-container">
<view class="error-text">页面加载失败</view>
<view class="error-detail">{{ errorMessage }}</view>
<button @click="goBack" class="back-btn">返回</button>
</view>
</view>
</template>
@ -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使webviewload
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'
})
this.isLoading = false
this.hasError = true
this.errorMessage = error.detail?.errMsg || '未知错误'
},
setTimeout(() => {
uni.navigateBack()
}, 2000)
//
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;
}
</style>

10
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
},
//

Loading…
Cancel
Save