mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-30 05:13:59 +08:00
fix: 修复设备配网成功没有自动退出配网模式
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { t } from '@/i18n'
|
||||
import { toast } from '@/utils/toast'
|
||||
|
||||
// 类型定义
|
||||
interface WiFiNetwork {
|
||||
@@ -19,9 +19,6 @@ interface Props {
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
// Toast 实例
|
||||
const toast = useToast()
|
||||
|
||||
// 响应式数据
|
||||
const configuring = ref(false)
|
||||
|
||||
@@ -45,7 +42,7 @@ async function checkESP32Connection() {
|
||||
return response.statusCode === 200
|
||||
}
|
||||
catch (error) {
|
||||
console.log(t('deviceConfig.esp32ConnectionCheckFailed') + ':', error)
|
||||
console.log(`${t('deviceConfig.esp32ConnectionCheckFailed')}:`, error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -63,7 +60,7 @@ async function submitConfig() {
|
||||
}
|
||||
|
||||
configuring.value = true
|
||||
console.log(t('deviceConfig.startWifiConfig') + ':', props.selectedNetwork.ssid)
|
||||
console.log(`${t('deviceConfig.startWifiConfig')}:`, props.selectedNetwork.ssid)
|
||||
|
||||
try {
|
||||
const response = await uni.request({
|
||||
@@ -83,6 +80,14 @@ async function submitConfig() {
|
||||
|
||||
if (response.statusCode === 200 && (response.data as any)?.success) {
|
||||
toast.success(`${t('deviceConfig.configSuccess')}!${t('deviceConfig.deviceWillConnectTo')} ${props.selectedNetwork.ssid},${t('deviceConfig.deviceWillRestart')}。${t('deviceConfig.pleaseDisconnectXiaozhiHotspot')}`)
|
||||
// 设备退出配网模式
|
||||
setTimeout(() => {
|
||||
uni.request({
|
||||
url: 'http://192.168.4.1/exit',
|
||||
method: 'POST',
|
||||
timeout: 15000,
|
||||
})
|
||||
}, 1500)
|
||||
}
|
||||
else {
|
||||
const errorMsg = (response.data as any)?.error || t('deviceConfig.configFailed')
|
||||
@@ -90,7 +95,7 @@ async function submitConfig() {
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error(t('deviceConfig.wifiConfigFailed') + ':', error)
|
||||
console.error(`${t('deviceConfig.wifiConfigFailed')}:`, error)
|
||||
toast.error(`${t('deviceConfig.configFailed')},${t('deviceConfig.pleaseCheckNetworkConnection')}`)
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, defineEmits, defineExpose, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import { t } from '@/i18n'
|
||||
|
||||
@@ -85,7 +85,7 @@ async function scanWifi() {
|
||||
timeout: 10000,
|
||||
})
|
||||
|
||||
console.log(t('deviceConfig.wifiScanResponse') + ':', response)
|
||||
console.log(`${t('deviceConfig.wifiScanResponse')}:`, response)
|
||||
|
||||
if (response.statusCode === 200 && response.data) {
|
||||
const data = response.data as any
|
||||
@@ -121,7 +121,7 @@ async function scanWifi() {
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.error(t('deviceConfig.wifiScanFailed') + ':', error)
|
||||
console.error(`${t('deviceConfig.wifiScanFailed')}:`, error)
|
||||
toast.error(t('deviceConfig.scanFailedCheckConnection'))
|
||||
}
|
||||
finally {
|
||||
@@ -323,7 +323,7 @@ onMounted(() => {
|
||||
</view>
|
||||
<view class="wifi-security">
|
||||
<text class="security-icon">
|
||||
{{ network.authmode === 0 ? t('deviceConfig.open') : t('deviceConfig.encrypted') }}
|
||||
{{ network.authmode === 0 ? t('deviceConfig.open') : t('deviceConfig.encryptedNetwork') }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user