feat:国际化多语言适配
This commit is contained in:
+55
-49
@@ -12,7 +12,7 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="device-id">
|
||||
<text class="id-label">设备号:</text>
|
||||
<text class="id-label">{{ $t('device.deviceNo') }}:</text>
|
||||
<text class="id-value">{{ deviceId }}</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -20,17 +20,17 @@
|
||||
<!-- 计费规则 -->
|
||||
<view class="card pricing-card">
|
||||
<view class="card-header">
|
||||
<text class="card-title">计费规则</text>
|
||||
<text class="card-title">{{ $t('device.pricingRules') }}</text>
|
||||
</view>
|
||||
|
||||
<view class="pricing-banner">
|
||||
<view class="pricing-main">
|
||||
<text class="price-symbol">¥</text>
|
||||
<text class="price">{{ deviceFeeConfig.maxHourPrice || '5.00' }}</text>
|
||||
<text class="unit">/小时</text>
|
||||
<text class="unit">/{{ $t('time.hour') }}</text>
|
||||
</view>
|
||||
<view class="cap-badge">
|
||||
<text class="cap-text">{{ deviceInfo.depositAmount || '99' }}元封顶</text>
|
||||
<text class="cap-text">{{ deviceInfo.depositAmount || '99' }}{{ $t('device.capLimit') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -51,20 +51,20 @@
|
||||
<!-- 使用说明 -->
|
||||
<view class="card notice-card">
|
||||
<view class="card-header">
|
||||
<text class="card-title">使用说明</text>
|
||||
<text class="card-title">{{ $t('device.usageInstructions') }}</text>
|
||||
</view>
|
||||
<view class="notice-items">
|
||||
<view class="notice-item">
|
||||
<view class="notice-dot"></view>
|
||||
<text class="notice-text">请在使用前检查设备是否完好</text>
|
||||
<text class="notice-text">{{ $t('device.checkBeforeUse') }}</text>
|
||||
</view>
|
||||
<view class="notice-item">
|
||||
<view class="notice-dot"></view>
|
||||
<text class="notice-text">超出使用时间将自动按小时计费</text>
|
||||
<text class="notice-text">{{ $t('device.autoChargeOvertime') }}</text>
|
||||
</view>
|
||||
<view class="notice-item">
|
||||
<view class="notice-dot"></view>
|
||||
<text class="notice-text">请在指定区域内使用设备</text>
|
||||
<text class="notice-text">{{ $t('device.useInDesignatedArea') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -73,11 +73,11 @@
|
||||
<view class="footer">
|
||||
<button class="rent-button" :class="{ 'return-button': hasActiveOrder }"
|
||||
@click="handleRent('wx-score-pay')">
|
||||
<text>{{ hasActiveOrder ? '归还设备' : '免押金租借' }}</text>
|
||||
<text>{{ hasActiveOrder ? $t('order.returnDevice') : $t('device.rentDepositFree') }}</text>
|
||||
</button>
|
||||
<view class="wechat-credit">
|
||||
<image src="/static/images/wxpayflag.png" mode="aspectFit" class="wx-icon"></image>
|
||||
<text class="credit-text">微信支付分 <text class="divider">|</text> 550分以上优享</text>
|
||||
<text class="credit-text">{{ $t('device.wxPayScoreDesc') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -86,17 +86,17 @@
|
||||
<view class="popup-mask" @click.stop></view>
|
||||
<view class="popup-content">
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">授权获取手机号</text>
|
||||
<text class="popup-title">{{ $t('auth.authTitle') }}</text>
|
||||
</view>
|
||||
<view class="popup-body">
|
||||
<view class="auth-desc">
|
||||
<text>为了提供更好的服务,需要授权获取您的手机号</text>
|
||||
<text>{{ $t('auth.authDescShort') }}</text>
|
||||
</view>
|
||||
<button class="auth-btn" open-type="getPhoneNumber" @getphonenumber="onGetPhoneNumber">
|
||||
一键获取手机号
|
||||
{{ $t('auth.getPhoneNumber') }}
|
||||
</button>
|
||||
<view class="auth-cancel" @click="showPhoneAuthPopup = false">
|
||||
<text>暂不授权</text>
|
||||
<text>{{ $t('auth.notNow') }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -133,6 +133,9 @@
|
||||
getUserInfo,
|
||||
getUserPhoneNumber
|
||||
} from '@/util/index.js'
|
||||
import { useI18n } from '@/utils/i18n.js'
|
||||
|
||||
const { t: $t } = useI18n()
|
||||
|
||||
// 响应式状态
|
||||
const deviceInfo = ref({})
|
||||
@@ -143,7 +146,7 @@
|
||||
const batteryLevel = ref(95)
|
||||
const hasActiveOrder = ref(false)
|
||||
const deviceStatus = reactive({
|
||||
text: '可使用',
|
||||
get text() { return $t('device.available') },
|
||||
class: 'available'
|
||||
})
|
||||
const isLoggedIn = ref(true)
|
||||
@@ -164,6 +167,9 @@
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
uni.setNavigationBarTitle({
|
||||
title: $t('device.deviceInfo')
|
||||
})
|
||||
await checkUserPhone()
|
||||
await fetchDeviceInfo()
|
||||
})
|
||||
@@ -195,7 +201,7 @@
|
||||
// 用户拒绝授权的情况
|
||||
if (e.detail.errMsg && e.detail.errMsg.includes('deny')) {
|
||||
uni.showToast({
|
||||
title: '需要授权手机号才能使用设备',
|
||||
title: $t('auth.phoneRequired'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
@@ -204,7 +210,7 @@
|
||||
// 获取到授权code
|
||||
if (e.detail.code) {
|
||||
uni.showLoading({
|
||||
title: '获取中...'
|
||||
title: $t('auth.getting')
|
||||
})
|
||||
|
||||
console.log('获取到的授权code:', e.detail.code)
|
||||
@@ -236,15 +242,15 @@
|
||||
showPhoneAuthPopup.value = false
|
||||
|
||||
uni.showToast({
|
||||
title: '手机号获取成功',
|
||||
title: $t('auth.phoneSuccess'),
|
||||
icon: 'success'
|
||||
})
|
||||
} else {
|
||||
// 记录详细信息,不抛出错误
|
||||
console.warn('获取手机号响应异常:', res.msg || '未知错误')
|
||||
uni.showModal({
|
||||
title: '获取手机号异常',
|
||||
content: `状态码: ${res.code}, 消息: ${res.msg || '无'}`,
|
||||
title: $t('auth.phoneError'),
|
||||
content: `${$t('common.statusCode')}: ${res.code}, ${$t('common.message')}: ${res.msg || $t('common.none')}`,
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
@@ -256,8 +262,8 @@
|
||||
// 显示更详细的错误信息
|
||||
let errMsg = err.message || err.toString()
|
||||
uni.showModal({
|
||||
title: '获取手机号失败',
|
||||
content: '错误信息: ' + errMsg,
|
||||
title: $t('auth.phoneGetFailed'),
|
||||
content: $t('common.errorInfo') + ': ' + errMsg,
|
||||
showCancel: false
|
||||
})
|
||||
})
|
||||
@@ -265,14 +271,14 @@
|
||||
uni.hideLoading()
|
||||
console.error('获取手机号外部错误:', outerError)
|
||||
uni.showModal({
|
||||
title: '意外错误',
|
||||
content: '处理过程发生异常: ' + (outerError.message || outerError),
|
||||
title: $t('common.unexpectedError'),
|
||||
content: $t('common.processException') + ': ' + (outerError.message || outerError),
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '获取授权码失败',
|
||||
title: $t('auth.authCodeFailed'),
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
@@ -296,16 +302,16 @@
|
||||
deviceLocation.value = res.data.position.name
|
||||
}
|
||||
|
||||
// 更新设备状态
|
||||
if (deviceInfo.value.status) {
|
||||
if (deviceInfo.value.status === 'online') {
|
||||
deviceStatus.text = '可使用'
|
||||
deviceStatus.class = 'available'
|
||||
} else if (deviceInfo.value.status === 'offline') {
|
||||
deviceStatus.text = '离线'
|
||||
deviceStatus.class = 'offline'
|
||||
}
|
||||
// 更新设备状态
|
||||
if (deviceInfo.value.status) {
|
||||
if (deviceInfo.value.status === 'online') {
|
||||
deviceStatus.text = $t('device.available')
|
||||
deviceStatus.class = 'available'
|
||||
} else if (deviceInfo.value.status === 'offline') {
|
||||
deviceStatus.text = $t('device.offline')
|
||||
deviceStatus.class = 'offline'
|
||||
}
|
||||
}
|
||||
if (deviceInfo.value.feeConfig) {
|
||||
deviceFeeConfig.value = JSON.parse(deviceInfo.value.feeConfig)[0] || {}
|
||||
} else {
|
||||
@@ -321,9 +327,9 @@
|
||||
// 显示登录提示
|
||||
const showLoginTip = () => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '请先登录后再操作',
|
||||
confirmText: '去登录',
|
||||
title: $t('common.tips'),
|
||||
content: $t('common.loginRequired'),
|
||||
confirmText: $t('auth.goToLogin'),
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.navigateTo({
|
||||
@@ -358,7 +364,7 @@
|
||||
}
|
||||
} catch (error) {
|
||||
uni.showToast({
|
||||
title: '订单状态查询失败',
|
||||
title: $t('order.getOrderStatusFailed'),
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
@@ -444,6 +450,9 @@
|
||||
// 提交租借订单
|
||||
const submitRentOrder = async (payWay) => {
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: $t('common.processing')
|
||||
})
|
||||
// --- 第一步:先请求订阅消息(必须在用户点击的同步上下文中)---
|
||||
if (payWay === 'wx-score-pay') {
|
||||
console.log('准备请求订阅消息(在异步操作之前),时间:', new Date().toLocaleTimeString());
|
||||
@@ -471,14 +480,11 @@
|
||||
}
|
||||
// --- 订阅消息请求完成 ---
|
||||
|
||||
uni.showLoading({
|
||||
title: '处理中'
|
||||
})
|
||||
console.log(deviceId.value);
|
||||
// 调用设备租借接口
|
||||
const rentResult = await rentPowerBank(deviceId.value, phoneNumber.value)
|
||||
if (rentResult.code !== 200) {
|
||||
throw new Error(rentResult.msg || '设备租借失败')
|
||||
throw new Error(rentResult.msg || $t('device.rentFailed'))
|
||||
}
|
||||
|
||||
// 获取后端返回的订单信息
|
||||
@@ -556,14 +562,14 @@
|
||||
// 用户取消授权,需要取消订单
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '取消订单中'
|
||||
title: $t('order.cancelling')
|
||||
});
|
||||
const cancelRes = await cancelOrder({ orderId: order.orderNo });
|
||||
console.log('订单取消结果:', cancelRes);
|
||||
uni.hideLoading();
|
||||
|
||||
uni.showToast({
|
||||
title: '已取消订单',
|
||||
title: $t('order.orderCancelled'),
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
@@ -578,7 +584,7 @@
|
||||
console.error('取消订单失败:', cancelError);
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '取消订单失败,请联系客服',
|
||||
title: $t('order.cancelFailedContactService'),
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
@@ -589,7 +595,7 @@
|
||||
// 支付分调用异常,也需要取消订单
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '取消订单中'
|
||||
title: $t('order.cancelling')
|
||||
});
|
||||
const cancelRes = await cancelOrder({ orderId: order.orderNo });
|
||||
console.log('订单取消结果:', cancelRes);
|
||||
@@ -600,7 +606,7 @@
|
||||
}
|
||||
|
||||
uni.showToast({
|
||||
title: '支付分调用失败,订单已取消',
|
||||
title: $t('device.payScoreFailedCancelled'),
|
||||
icon: 'none'
|
||||
});
|
||||
|
||||
@@ -612,7 +618,7 @@
|
||||
}
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res?.msg || '获取支付参数失败',
|
||||
title: res?.msg || $t('device.getPayParamsFailed'),
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
@@ -620,7 +626,7 @@
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: error.message || '租借失败,请重试',
|
||||
title: error.message || $t('device.rentFailedRetry'),
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user