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