fix:修复bug
This commit is contained in:
+141
-34
@@ -1,40 +1,118 @@
|
||||
<template>
|
||||
<view class="loading-page">
|
||||
<!-- 加载状态 -->
|
||||
<view v-if="loading" class="loading-page">
|
||||
<view class="loading-content">
|
||||
<view class="loading-spinner"></view>
|
||||
<text>{{ $t('common.loading') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 错误状态 -->
|
||||
<view v-else-if="error" class="error-page">
|
||||
<view class="error-content">
|
||||
<text class="error-icon">⚠️</text>
|
||||
<text class="error-message">{{ errorMessage }}</text>
|
||||
<button class="retry-btn" @click="loadAgreement">{{ $t('common.retry') }}</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 内容显示 -->
|
||||
<view v-else class="legal-page">
|
||||
<view class="header">
|
||||
<text class="title">{{ agreementData.title || $t('legal.agreement') }}</text>
|
||||
<text v-if="agreementData.remark" class="subtitle">{{ agreementData.remark }}</text>
|
||||
</view>
|
||||
|
||||
<scroll-view class="content" scroll-y>
|
||||
<rich-text :nodes="agreementData.content"></rich-text>
|
||||
</scroll-view>
|
||||
|
||||
<view class="footer">
|
||||
<text>{{ $t('legal.footerNotice') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted } from 'vue'
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { useI18n } from '@/utils/i18n.js'
|
||||
import { URL } from '@/config/url.js'
|
||||
|
||||
const { t: $t } = useI18n()
|
||||
|
||||
onMounted(() => {
|
||||
// 获取当前语言设置
|
||||
const currentLang = uni.getStorageSync('language') || 'zh-CN'
|
||||
|
||||
// 根据语言跳转到对应页面
|
||||
const targetPage = currentLang === 'en-US'
|
||||
? '/pages/legal/agreement-en'
|
||||
: '/pages/legal/agreement-zh'
|
||||
|
||||
console.log('当前语言:', currentLang, '跳转到:', targetPage)
|
||||
|
||||
// 使用 redirectTo 替换当前页面
|
||||
uni.redirectTo({
|
||||
url: targetPage,
|
||||
fail: (err) => {
|
||||
console.error('跳转失败:', err)
|
||||
// 如果跳转失败,默认跳转到中文版
|
||||
uni.redirectTo({
|
||||
url: '/pages/legal/agreement-zh'
|
||||
// 响应式数据
|
||||
const loading = ref(true)
|
||||
const error = ref(false)
|
||||
const errorMessage = ref('')
|
||||
const agreementData = ref({
|
||||
title: '',
|
||||
content: '',
|
||||
remark: ''
|
||||
})
|
||||
|
||||
// 将语言代码转换为后端接受的格式
|
||||
const convertLanguageCode = (lang) => {
|
||||
// zh-CN -> zh-CN (保持不变)
|
||||
// en-US -> en_US (转换下划线)
|
||||
return lang.replace(/-/g, '_')
|
||||
}
|
||||
|
||||
// 加载协议内容
|
||||
const loadAgreement = async () => {
|
||||
loading.value = true
|
||||
error.value = false
|
||||
errorMessage.value = ''
|
||||
|
||||
try {
|
||||
// 获取当前语言设置
|
||||
const currentLang = uni.getStorageSync('language') || 'zh-CN'
|
||||
const languageCode = convertLanguageCode(currentLang)
|
||||
|
||||
console.log('加载用户协议,语言:', currentLang, '转换后:', languageCode)
|
||||
|
||||
// 调用接口获取协议内容
|
||||
const res = await uni.request({
|
||||
url: `${URL}/device/agreementConfig/current`,
|
||||
method: 'GET',
|
||||
header: {
|
||||
'Content-Language': languageCode,
|
||||
'Authorization': 'Bearer ' + uni.getStorageSync('token'),
|
||||
'Clientid': uni.getStorageSync('client_id')
|
||||
},
|
||||
data: {
|
||||
agreementCode: 'USER_AGREEMENT',
|
||||
appPlatform: 'wechat',
|
||||
appType: 'user'
|
||||
}
|
||||
})
|
||||
|
||||
console.log('用户协议响应:', res)
|
||||
|
||||
if (res.statusCode === 200 && res.data.code === 200 && res.data.data) {
|
||||
agreementData.value = {
|
||||
title: res.data.data.title || $t('legal.agreement'),
|
||||
content: res.data.data.content || '',
|
||||
remark: res.data.data.remark || ''
|
||||
}
|
||||
|
||||
// 设置页面标题
|
||||
uni.setNavigationBarTitle({
|
||||
title: agreementData.value.title
|
||||
})
|
||||
} else {
|
||||
throw new Error(res.data.msg || $t('common.loadFailed'))
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('加载用户协议失败:', err)
|
||||
error.value = true
|
||||
errorMessage.value = err.message || $t('common.loadFailed')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadAgreement()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -67,10 +145,41 @@
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
text {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
|
||||
.error-page {
|
||||
min-height: 100vh;
|
||||
background: #f8f8f8;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40rpx;
|
||||
}
|
||||
|
||||
.error-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 24rpx;
|
||||
|
||||
.error-icon {
|
||||
font-size: 80rpx;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.retry-btn {
|
||||
margin-top: 20rpx;
|
||||
padding: 20rpx 60rpx;
|
||||
background: #07c160;
|
||||
color: #fff;
|
||||
border-radius: 8rpx;
|
||||
font-size: 28rpx;
|
||||
border: none;
|
||||
}
|
||||
}
|
||||
|
||||
.legal-page {
|
||||
@@ -83,33 +192,31 @@
|
||||
|
||||
.header {
|
||||
margin-bottom: 16rpx;
|
||||
|
||||
.title {
|
||||
font-size: 40rpx;
|
||||
font-weight: 600;
|
||||
color: #222;
|
||||
margin-bottom: 8rpx;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 24rpx;
|
||||
color: #888;
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
// width: 100%;
|
||||
background: #fff;
|
||||
border-radius: 16rpx;
|
||||
padding: 16rpx 20rpx;
|
||||
padding: 20rpx;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
box-sizing: border-box;
|
||||
box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.04);
|
||||
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.h1 { font-size: 30rpx; font-weight: 600; color: #222; margin: 18rpx 0 12rpx; }
|
||||
.p { font-size: 26rpx; color: #444; line-height: 1.8; margin-bottom: 10rpx; }
|
||||
.bold { font-weight: 600; color: #222; }
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
margin-top: 16rpx;
|
||||
|
||||
Reference in New Issue
Block a user