fix: 中文全部换成英文。
This commit is contained in:
@@ -1,29 +1,29 @@
|
||||
<template>
|
||||
<view class="bluetooth-page">
|
||||
<!-- 导航栏 -->
|
||||
<uni-navbar title="搅拌器设备连接" :border="false" background-color="rgba(102, 126, 234, 0.9)" color="#fff" />
|
||||
<!-- Navigation Bar -->
|
||||
<uni-navbar title="Mixer Device Connection" :border="false" background-color="rgba(102, 126, 234, 0.9)" color="#fff" />
|
||||
|
||||
<view class="bluetooth-container">
|
||||
|
||||
<!-- 搜索状态和设置 -->
|
||||
<!-- Search Status and Settings -->
|
||||
<view class="search-status">
|
||||
<view class="status-row">
|
||||
<view class="status-item">
|
||||
<text class="status-label">蓝牙状态:</text>
|
||||
<text class="status-label">Bluetooth:</text>
|
||||
<text :class="['status-value', bluetoothEnabled ? 'status-on' : 'status-off']">
|
||||
{{ bluetoothEnabled ? '已开启' : '未开启' }}
|
||||
{{ bluetoothEnabled ? 'On' : 'Off' }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="status-item">
|
||||
<text class="status-label">搜索状态:</text>
|
||||
<text class="status-label">Search:</text>
|
||||
<text :class="['status-value', isSearching ? 'status-on' : 'status-off']">
|
||||
{{ isSearching ? '搜索中...' : '未搜索' }}
|
||||
{{ isSearching ? 'Searching...' : 'Idle' }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<!-- Action Buttons -->
|
||||
<view class="action-buttons">
|
||||
<u-button
|
||||
type="primary"
|
||||
@@ -31,7 +31,7 @@
|
||||
@click="startBluetoothSearch"
|
||||
:disabled="!bluetoothEnabled"
|
||||
>
|
||||
{{ isSearching ? '搜索中...' : '开始搜索' }}
|
||||
{{ isSearching ? 'Searching...' : 'Start Search' }}
|
||||
</u-button>
|
||||
<u-button
|
||||
type="warning"
|
||||
@@ -40,11 +40,11 @@
|
||||
:disabled="!isSearching"
|
||||
style="margin-left: 20rpx;"
|
||||
>
|
||||
停止搜索
|
||||
Stop Search
|
||||
</u-button>
|
||||
</view>
|
||||
|
||||
<!-- 预览按钮 -->
|
||||
<!-- Preview Button -->
|
||||
<view class="preview-button-wrapper">
|
||||
<u-button
|
||||
type="success"
|
||||
@@ -52,15 +52,15 @@
|
||||
@click="previewMixerPage"
|
||||
>
|
||||
<uni-icons type="eye" color="#52c41a" size="20" style="margin-right: 8rpx;"></uni-icons>
|
||||
预览搅拌器页面
|
||||
Preview Mixer Page
|
||||
</u-button>
|
||||
</view>
|
||||
|
||||
|
||||
<!-- 设备列表 -->
|
||||
<!-- Device List -->
|
||||
<view class="device-list">
|
||||
<view class="list-header">
|
||||
<text class="header-title">附近的设备</text>
|
||||
<text class="header-title">Nearby Devices</text>
|
||||
<text class="device-count">({{ deviceList.length }})</text>
|
||||
</view>
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
mode="aspectFit"
|
||||
/>
|
||||
</view>
|
||||
<text class="empty-text">暂无设备,点击上方按钮开始搜索</text>
|
||||
<text class="empty-text">No devices found, click above to start searching</text>
|
||||
</view>
|
||||
|
||||
<view v-else class="device-items">
|
||||
@@ -95,20 +95,20 @@
|
||||
/>
|
||||
</view>
|
||||
<text class="name-text">
|
||||
{{ device.name || device.localName || `未命名设备 (${device.deviceId.slice(-8)})` }}
|
||||
{{ device.name || device.localName || `Unnamed Device (${device.deviceId.slice(-8)})` }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="device-details">
|
||||
<text class="detail-text">设备ID: {{ device.deviceId }}</text>
|
||||
<text class="detail-text">信号强度: {{ device.RSSI }} dBm</text>
|
||||
<text class="detail-text">Device ID: {{ device.deviceId }}</text>
|
||||
<text class="detail-text">Signal: {{ device.RSSI }} dBm</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="device-action">
|
||||
<view v-if="device.deviceId === connectedDeviceId" class="connected-badge">
|
||||
<text class="badge-text">已连接</text>
|
||||
<text class="badge-text">Connected</text>
|
||||
</view>
|
||||
<view v-else-if="device.deviceId === connectingDeviceId" class="connecting-badge">
|
||||
<text class="connecting-text">连接中...</text>
|
||||
<text class="connecting-text">Connecting...</text>
|
||||
</view>
|
||||
<u-button
|
||||
v-else
|
||||
@@ -116,15 +116,15 @@
|
||||
size="small"
|
||||
@click.stop="connectDevice(device)"
|
||||
>
|
||||
连接
|
||||
Connect
|
||||
</u-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 已连接设备的详细信息,显示在对应设备下方 -->
|
||||
<!-- Connected device details, displayed below the corresponding device -->
|
||||
<view v-if="device.deviceId === connectedDeviceId && connectedDevice" class="device-connected-detail">
|
||||
<view class="detail-header">
|
||||
<text class="detail-title">连接成功,准备跳转...</text>
|
||||
<text class="detail-title">Connected successfully, preparing to navigate...</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -366,22 +366,22 @@ const guideToEnableGPS = () => {
|
||||
let content = ''
|
||||
|
||||
if (androidVersion >= 12) {
|
||||
content = '检测到您使用的是 Android 12+,不需要开启GPS即可使用蓝牙功能。'
|
||||
content = 'You are using Android 12+, GPS is not required for Bluetooth.'
|
||||
} else if (androidVersion >= 10) {
|
||||
content = `检测到您使用的是 Android ${androidVersion},系统要求必须开启位置服务(GPS)才能搜索蓝牙设备。
|
||||
content = `You are using Android ${androidVersion}. The system requires location service (GPS) to be enabled for Bluetooth device scanning.
|
||||
|
||||
这是 Android 系统的强制要求,即使不会真正定位您的位置。
|
||||
This is a mandatory Android system requirement, even though it won't actually track your location.
|
||||
|
||||
是否前往设置开启?`
|
||||
Go to settings to enable?`
|
||||
} else {
|
||||
content = '建议开启位置服务(GPS)以确保蓝牙搜索功能正常使用。\n\n是否前往设置开启?'
|
||||
content = 'It is recommended to enable location service (GPS) to ensure Bluetooth search function works properly.\n\nGo to settings to enable?'
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: androidVersion >= 12 ? '提示' : '需要开启GPS',
|
||||
title: androidVersion >= 12 ? 'Notice' : 'GPS Required',
|
||||
content: content,
|
||||
showCancel: androidVersion < 12,
|
||||
confirmText: androidVersion >= 12 ? '知道了' : '去设置',
|
||||
confirmText: androidVersion >= 12 ? 'OK' : 'Go to Settings',
|
||||
success: (res) => {
|
||||
if (res.confirm && androidVersion < 12) {
|
||||
// 跳转到位置设置页面
|
||||
@@ -395,7 +395,7 @@ const guideToEnableGPS = () => {
|
||||
} catch (e) {
|
||||
console.error('跳转设置失败:', e)
|
||||
uni.showToast({
|
||||
title: '请手动前往设置开启GPS',
|
||||
title: 'Please go to settings manually to enable GPS',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
@@ -411,14 +411,14 @@ const saveLastDevice = (device) => {
|
||||
try {
|
||||
const deviceInfo = {
|
||||
deviceId: device.deviceId,
|
||||
name: device.name || device.localName || '未命名设备',
|
||||
name: device.name || device.localName || 'Unnamed Device',
|
||||
localName: device.localName,
|
||||
RSSI: device.RSSI
|
||||
}
|
||||
uni.setStorageSync(LAST_DEVICE_KEY, JSON.stringify(deviceInfo))
|
||||
console.log('已保存上次连接的设备:', deviceInfo)
|
||||
console.log('Saved last connected device:', deviceInfo)
|
||||
} catch (e) {
|
||||
console.error('保存设备信息失败:', e)
|
||||
console.error('Failed to save device info:', e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,11 +428,11 @@ const getLastDevice = () => {
|
||||
const deviceStr = uni.getStorageSync(LAST_DEVICE_KEY)
|
||||
if (deviceStr) {
|
||||
const device = JSON.parse(deviceStr)
|
||||
console.log('读取到上次连接的设备:', device)
|
||||
console.log('Read last connected device:', device)
|
||||
return device
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('读取设备信息失败:', e)
|
||||
console.error('Failed to read device info:', e)
|
||||
}
|
||||
return null
|
||||
}
|
||||
@@ -441,7 +441,7 @@ const getLastDevice = () => {
|
||||
const tryAutoReconnectLastDevice = async () => {
|
||||
// 防止重复尝试
|
||||
if (hasTriedAutoReconnect) {
|
||||
console.log('已经尝试过自动重连,跳过')
|
||||
console.log('Already tried auto-reconnect, skipping')
|
||||
startBluetoothSearch()
|
||||
return
|
||||
}
|
||||
@@ -451,15 +451,15 @@ const tryAutoReconnectLastDevice = async () => {
|
||||
// 获取上次连接的设备
|
||||
const lastDevice = getLastDevice()
|
||||
if (!lastDevice) {
|
||||
console.log('没有上次连接的设备记录,开始正常搜索')
|
||||
console.log('No last connected device record, starting normal search')
|
||||
startBluetoothSearch()
|
||||
return
|
||||
}
|
||||
|
||||
console.log('尝试自动重连上次的设备:', lastDevice.name)
|
||||
console.log('Trying to auto-reconnect to last device:', lastDevice.name)
|
||||
|
||||
uni.showLoading({
|
||||
title: `正在连接 ${lastDevice.name}...`,
|
||||
title: `Connecting ${lastDevice.name}...`,
|
||||
mask: true
|
||||
})
|
||||
|
||||
@@ -468,7 +468,7 @@ const tryAutoReconnectLastDevice = async () => {
|
||||
await checkLocationService()
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
console.log('GPS未开启,无法自动重连')
|
||||
console.log('GPS not enabled, cannot auto-reconnect')
|
||||
guideToEnableGPS()
|
||||
return
|
||||
}
|
||||
@@ -483,7 +483,7 @@ const tryAutoReconnectLastDevice = async () => {
|
||||
})
|
||||
})
|
||||
|
||||
console.log('开始搜索上次连接的设备...')
|
||||
console.log('Starting to search for last connected device...')
|
||||
|
||||
// 等待3秒搜索设备
|
||||
await new Promise(resolve => setTimeout(resolve, 3000))
|
||||
@@ -500,7 +500,7 @@ const tryAutoReconnectLastDevice = async () => {
|
||||
const targetDevice = devices.find(d => d.deviceId === lastDevice.deviceId)
|
||||
|
||||
if (targetDevice) {
|
||||
console.log('找到上次连接的设备,尝试连接:', targetDevice)
|
||||
console.log('Found last connected device, trying to connect:', targetDevice)
|
||||
|
||||
// 尝试连接
|
||||
try {
|
||||
@@ -514,7 +514,7 @@ const tryAutoReconnectLastDevice = async () => {
|
||||
})
|
||||
|
||||
// 连接成功
|
||||
console.log('自动重连成功')
|
||||
console.log('Auto-reconnect successful')
|
||||
connectingDeviceId.value = ''
|
||||
connectedDeviceId.value = targetDevice.deviceId
|
||||
connectedDevice.value = targetDevice
|
||||
@@ -528,7 +528,7 @@ const tryAutoReconnectLastDevice = async () => {
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: '自动连接成功',
|
||||
title: 'Auto-connect successful',
|
||||
icon: 'success',
|
||||
duration: 1500
|
||||
})
|
||||
@@ -536,16 +536,16 @@ const tryAutoReconnectLastDevice = async () => {
|
||||
// 自动跳转到控制页面
|
||||
setTimeout(() => {
|
||||
const url = buildMixerPageUrl(targetDevice, bleInfo)
|
||||
console.log('🚀 跳转到搅拌器页面:', url)
|
||||
console.log('🚀 Navigating to mixer page:', url)
|
||||
uni.navigateTo({ url })
|
||||
}, 1500)
|
||||
|
||||
} catch (connectErr) {
|
||||
console.error('自动重连失败:', connectErr)
|
||||
console.error('Auto-reconnect failed:', connectErr)
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: '自动连接失败,请手动选择',
|
||||
title: 'Auto-connect failed, please select manually',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
@@ -558,11 +558,11 @@ const tryAutoReconnectLastDevice = async () => {
|
||||
}, 2000)
|
||||
}
|
||||
} else {
|
||||
console.log('未找到上次连接的设备,继续正常搜索')
|
||||
console.log('Last device not found, continuing normal search')
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: '未找到上次设备',
|
||||
title: 'Last device not found',
|
||||
icon: 'none',
|
||||
duration: 1500
|
||||
})
|
||||
@@ -722,11 +722,13 @@ const connectDevice = (device) => {
|
||||
return
|
||||
}
|
||||
|
||||
// 如果已经连接了其他设备,先提示用户
|
||||
// If already connected to another device, prompt user first
|
||||
if (connectedDeviceId.value && connectedDeviceId.value !== device.deviceId) {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '已连接其他设备,是否断开并连接新设备?',
|
||||
title: 'Notice',
|
||||
content: 'Already connected to another device. Disconnect and connect to new device?',
|
||||
confirmText: 'Confirm',
|
||||
cancelText: 'Cancel',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
// 先断开当前连接
|
||||
@@ -754,19 +756,19 @@ const connectDevice = (device) => {
|
||||
const doConnect = (device) => {
|
||||
connectingDeviceId.value = device.deviceId
|
||||
|
||||
console.log('开始连接设备:', device)
|
||||
console.log('Starting to connect device:', device)
|
||||
|
||||
uni.createBLEConnection({
|
||||
deviceId: device.deviceId,
|
||||
timeout: 10000, // 设置10秒超时
|
||||
timeout: 10000, // 10 seconds timeout
|
||||
success: async (res) => {
|
||||
console.log('连接成功', res)
|
||||
console.log('Connection successful', res)
|
||||
connectingDeviceId.value = ''
|
||||
connectedDeviceId.value = device.deviceId
|
||||
connectedDevice.value = device
|
||||
|
||||
uni.showToast({
|
||||
title: '连接成功',
|
||||
title: 'Connected',
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
@@ -782,41 +784,41 @@ const doConnect = (device) => {
|
||||
// 连接成功后跳转到控制页面
|
||||
setTimeout(() => {
|
||||
const url = buildMixerPageUrl(device, bleInfo)
|
||||
console.log('🚀 跳转到搅拌器页面:', url)
|
||||
console.log('🚀 Navigating to mixer page:', url)
|
||||
uni.navigateTo({ url })
|
||||
}, 800)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('连接失败', err)
|
||||
console.error('Connection failed', err)
|
||||
connectingDeviceId.value = ''
|
||||
|
||||
// 根据错误码提供更详细的错误信息
|
||||
let errorMsg = '无法连接到该设备'
|
||||
// Provide detailed error information based on error code
|
||||
let errorMsg = 'Unable to connect to this device'
|
||||
|
||||
if (err.errCode === 10003) {
|
||||
errorMsg = '连接失败:设备未找到或已关闭'
|
||||
errorMsg = 'Connection failed: Device not found or turned off'
|
||||
} else if (err.errCode === 10012) {
|
||||
errorMsg = '连接失败:连接超时,设备可能距离太远'
|
||||
errorMsg = 'Connection failed: Connection timeout, device may be too far away'
|
||||
} else if (err.errCode === 10004) {
|
||||
errorMsg = '连接失败:设备不支持连接'
|
||||
errorMsg = 'Connection failed: Device does not support connection'
|
||||
} else if (err.errCode === -1) {
|
||||
errorMsg = '连接失败:系统错误,请重启蓝牙后重试'
|
||||
errorMsg = 'Connection failed: System error, please restart Bluetooth and retry'
|
||||
} else if (err.errMsg) {
|
||||
errorMsg = `连接失败:${err.errMsg}`
|
||||
errorMsg = `Connection failed: ${err.errMsg}`
|
||||
}
|
||||
|
||||
uni.showModal({
|
||||
title: '连接失败',
|
||||
title: 'Connection Failed',
|
||||
content: `${errorMsg}
|
||||
|
||||
错误码: ${err.errCode || '未知'}
|
||||
Error Code: ${err.errCode || 'Unknown'}
|
||||
|
||||
提示:
|
||||
1. 确保设备在可连接范围内
|
||||
2. 确保设备未被其他应用连接
|
||||
3. 尝试重启设备蓝牙`,
|
||||
Tips:
|
||||
1. Ensure device is within connection range
|
||||
2. Ensure device is not connected by other apps
|
||||
3. Try restarting device Bluetooth`,
|
||||
showCancel: false,
|
||||
confirmText: '知道了'
|
||||
confirmText: 'OK'
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -826,7 +828,7 @@ const doConnect = (device) => {
|
||||
const disconnectDevice = () => {
|
||||
if (!connectedDeviceId.value) {
|
||||
uni.showToast({
|
||||
title: '没有已连接的设备',
|
||||
title: 'No connected device',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
@@ -844,14 +846,14 @@ const disconnectDevice = () => {
|
||||
characteristicId: char.uuid,
|
||||
state: false,
|
||||
success: () => {
|
||||
console.log('关闭notify成功:', char.uuid)
|
||||
console.log('Notify disabled successfully:', char.uuid)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('关闭notify失败:', char.uuid, err)
|
||||
console.error('Failed to disable notify:', char.uuid, err)
|
||||
}
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('关闭notify异常:', err)
|
||||
console.error('Notify exception:', err)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -859,20 +861,20 @@ const disconnectDevice = () => {
|
||||
uni.closeBLEConnection({
|
||||
deviceId: deviceId,
|
||||
success: (res) => {
|
||||
console.log('断开连接成功', res)
|
||||
// 清空连接状态和服务信息
|
||||
console.log('Disconnected successfully', res)
|
||||
// Clear connection status and service info
|
||||
cleanupConnection()
|
||||
uni.showToast({
|
||||
title: '已断开连接',
|
||||
title: 'Disconnected',
|
||||
icon: 'success'
|
||||
})
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('断开连接失败', err)
|
||||
// 即使断开失败,也清空状态(可能设备已经离线)
|
||||
console.error('Failed to disconnect', err)
|
||||
// Clear status even if disconnection fails (device may already be offline)
|
||||
cleanupConnection()
|
||||
uni.showToast({
|
||||
title: '断开连接',
|
||||
title: 'Disconnected',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
@@ -901,7 +903,7 @@ const getBLEDeviceServices = async (deviceId) => {
|
||||
})
|
||||
})
|
||||
|
||||
console.log('获取到的服务列表', res.services)
|
||||
console.log('Retrieved service list', res.services)
|
||||
services.value = res.services
|
||||
|
||||
// 计算所有服务的特征值总数
|
||||
@@ -1530,7 +1532,7 @@ const addToHistory = (type, data, hex, characteristicId = '') => {
|
||||
const toggleHistory = () => {
|
||||
if (dataHistory.value.length === 0) {
|
||||
uni.showToast({
|
||||
title: '暂无历史记录',
|
||||
title: 'No history records',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
@@ -1538,18 +1540,20 @@ const toggleHistory = () => {
|
||||
showHistory.value = !showHistory.value
|
||||
}
|
||||
|
||||
// 清空历史记录
|
||||
// Clear history
|
||||
const clearHistory = () => {
|
||||
uni.showModal({
|
||||
title: '确认',
|
||||
content: '确定要清空所有历史记录吗?',
|
||||
title: 'Confirm',
|
||||
content: 'Are you sure to clear all history records?',
|
||||
confirmText: 'Confirm',
|
||||
cancelText: 'Cancel',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
sendHistory.value = []
|
||||
receiveHistory.value = []
|
||||
showHistory.value = false
|
||||
uni.showToast({
|
||||
title: '已清空',
|
||||
title: 'Cleared',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
@@ -1560,12 +1564,12 @@ const clearHistory = () => {
|
||||
// 监听蓝牙适配器状态变化
|
||||
const onBluetoothAdapterStateChange = () => {
|
||||
uni.onBluetoothAdapterStateChange((res) => {
|
||||
console.log('蓝牙适配器状态变化', res)
|
||||
console.log('Bluetooth adapter state changed', res)
|
||||
bluetoothEnabled.value = res.available
|
||||
if (!res.available) {
|
||||
isSearching.value = false
|
||||
uni.showToast({
|
||||
title: '蓝牙已关闭',
|
||||
title: 'Bluetooth turned off',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
@@ -1577,10 +1581,10 @@ onMounted(() => {
|
||||
// 判断是否为H5环境
|
||||
// #ifdef H5
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: 'H5平台不支持蓝牙功能,请使用App或小程序版本',
|
||||
title: 'Notice',
|
||||
content: 'Bluetooth is not supported on H5 platform, please use App or Mini Program version',
|
||||
showCancel: false,
|
||||
confirmText: '我知道了'
|
||||
confirmText: 'OK'
|
||||
})
|
||||
bluetoothEnabled.value = false
|
||||
// #endif
|
||||
@@ -1620,10 +1624,10 @@ const cleanup = () => {
|
||||
// 关闭蓝牙适配器
|
||||
uni.closeBluetoothAdapter({
|
||||
success: (res) => {
|
||||
console.log('关闭蓝牙适配器成功', res)
|
||||
console.log('Bluetooth adapter closed successfully', res)
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('关闭蓝牙适配器失败', err)
|
||||
console.error('Failed to close Bluetooth adapter', err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user