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 = 'development'
const env = 'prod' // const env = 'prod'
const isMockEnabled = false // 默认禁用Mock优先模式,仅作为回退 const isMockEnabled = false // 默认禁用Mock优先模式,仅作为回退
const isDebug = false // 默认启用调试模式 const isDebug = false // 默认启用调试模式
const devurl = 'http://localhost:20080/api' const devurl = 'http://localhost:20080/api'

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

@ -1,12 +1,29 @@
<!--微信绑定WebView页面--> <!--微信绑定WebView页面-->
<template> <template>
<view class="webview-container"> <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 <web-view
v-if="webviewUrl"
:src="webviewUrl" :src="webviewUrl"
@message="onMessage" @message="onMessage"
@load="onLoad" @load="onWebviewLoad"
@error="onError"> @error="onError">
</web-view> </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> </view>
</template> </template>
@ -14,7 +31,10 @@
export default { export default {
data() { data() {
return { return {
webviewUrl: '' webviewUrl: '',
isLoading: true,
hasError: false,
errorMessage: ''
} }
}, },
onLoad(options) { onLoad(options) {
@ -23,14 +43,15 @@ export default {
if (options.url) { if (options.url) {
this.webviewUrl = decodeURIComponent(options.url) this.webviewUrl = decodeURIComponent(options.url)
console.log('webview URL:', this.webviewUrl) console.log('webview URL:', this.webviewUrl)
} else {
uni.showToast({ // 3使webviewload
title: '参数错误',
icon: 'none'
})
setTimeout(() => { setTimeout(() => {
uni.navigateBack() this.isLoading = false
}, 2000) }, 3000)
} else {
this.hasError = true
this.errorMessage = '缺少URL参数'
console.error('webview页面缺少URL参数')
} }
}, },
methods: { methods: {
@ -89,21 +110,22 @@ export default {
}, },
// webview // webview
onLoad() { onWebviewLoad(event) {
console.log('webview加载完成') console.log('webview加载完成:', event)
this.isLoading = false
}, },
// webview // webview
onError(error) { onError(error) {
console.error('webview加载错误:', error) console.error('webview加载错误:', error)
uni.showToast({ this.isLoading = false
title: '页面加载失败', this.hasError = true
icon: 'none' this.errorMessage = error.detail?.errMsg || '未知错误'
}) },
setTimeout(() => { //
uni.navigateBack() goBack() {
}, 2000) uni.navigateBack()
} }
} }
} }
@ -113,5 +135,73 @@ export default {
.webview-container { .webview-container {
width: 100%; width: 100%;
height: 100vh; 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> </style>

10
uniapp/pages-market/my/set_up.vue

@ -183,14 +183,14 @@ import apiRoute from '@/api/apiRoute.js'
try { try {
// H5 // H5
const baseUrl = Api_url const baseUrl = Api_url
const redirectUri = encodeURIComponent(`${baseUrl}/api/personnel/wechatCallback`) const redirectUri = encodeURIComponent(`${baseUrl}/personnel/wechatCallback`)
const state = encodeURIComponent(JSON.stringify({ const state = encodeURIComponent(JSON.stringify({
personnel_id: this.$store.state.userInfo.id, personnel_id: this.$store.state.userInfo.id,
from: 'h5', from: 'h5',
timestamp: Date.now() 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) console.log('H5授权URL:', authUrl)
uni.hideLoading() uni.hideLoading()
@ -335,7 +335,7 @@ import apiRoute from '@/api/apiRoute.js'
// webview URL // webview URL
buildWebviewUrl(miniOpenid) { buildWebviewUrl(miniOpenid) {
const baseUrl = Api_url const baseUrl = Api_url
const redirectUri = encodeURIComponent(`${baseUrl}/api/personnel/wechatCallback`) const redirectUri = encodeURIComponent(`${baseUrl}/personnel/wechatCallback`)
const state = encodeURIComponent(JSON.stringify({ const state = encodeURIComponent(JSON.stringify({
mini_openid: miniOpenid, mini_openid: miniOpenid,
personnel_id: this.$store.state.userInfo.id, personnel_id: this.$store.state.userInfo.id,
@ -343,7 +343,9 @@ import apiRoute from '@/api/apiRoute.js'
timestamp: Date.now() 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