11<script setup lang="ts">
22import { ref } from ' vue'
3+ import { toast } from ' @qingfeng346/ui-kit/composables/message'
34import { openLogin , logout , listDevices , type XiaoaiCreds , type XiaoaiDevice } from ' ./tauri'
45
56type Phase = ' idle' | ' logging_in' | ' fetching_devices' | ' done' | ' logging_out'
67
78const phase = ref <Phase >(' idle' )
8- const error = ref (' ' )
99const creds = ref <XiaoaiCreds | null >(null )
1010const devices = ref <XiaoaiDevice []>([])
1111const copiedKey = ref (' ' )
1212
1313async function start() {
14- error .value = ' '
1514 copiedKey .value = ' '
1615 phase .value = ' logging_in'
1716 try {
1817 creds .value = await openLogin ()
1918 } catch (e : any ) {
2019 phase .value = ' idle'
21- error . value = String (e ?.message || e )
20+ toast . show ( ' error ' , String (e ?.message || e ) )
2221 return
2322 }
2423
@@ -27,12 +26,12 @@ async function start() {
2726 devices .value = await listDevices (creds .value )
2827 } catch (e : any ) {
2928 phase .value = ' idle'
30- error . value = ` 已拿到登录凭据,但拉设备列表失败: ${String (e ?.message || e )} `
29+ toast . show ( ' warning ' , ` 已拿到登录凭据,但拉设备列表失败: ${String (e ?.message || e )} ` )
3130 return
3231 }
3332
3433 if (devices .value .length === 0 ) {
35- error . value = ' 该账号下未发现小爱音箱'
34+ toast . show ( ' warning ' , ' 该账号下未发现小爱音箱' )
3635 phase .value = ' idle'
3736 return
3837 }
@@ -47,26 +46,24 @@ async function copyValue(key: string, value: string) {
4746 if (copiedKey .value === key ) copiedKey .value = ' '
4847 }, 2000 )
4948 } catch (e : any ) {
50- error . value = ` 复制失败: ${String (e ?.message || e )} `
49+ toast . show ( ' error ' , ` 复制失败: ${String (e ?.message || e )} ` )
5150 }
5251}
5352
5453function reset() {
5554 phase .value = ' idle'
5655 creds .value = null
5756 devices .value = []
58- error .value = ' '
5957 copiedKey .value = ' '
6058}
6159
6260async function switchAccount() {
6361 const prev = phase .value
6462 phase .value = ' logging_out'
65- error .value = ' '
6663 try {
6764 await logout ()
6865 } catch (e : any ) {
69- error . value = ` 登出失败: ${String (e ?.message || e )} `
66+ toast . show ( ' error ' , ` 登出失败: ${String (e ?.message || e )} ` )
7067 phase .value = prev
7168 return
7269 }
@@ -85,7 +82,6 @@ async function switchAccount() {
8582 <button class =" btn btn-outline" @click =" switchAccount" >清除登录缓存</button >
8683 </div >
8784 <p class =" hint" >支持账号密码 / 短信 / 扫码 / 图形验证(按小米页面引导)。如果点击登录后自动登上的是上次的账号,先点「清除登录缓存」。</p >
88- <p v-if =" error" class =" error" >{{ error }}</p >
8985 </section >
9086
9187 <section v-else-if =" phase === 'logging_in'" class =" card" >
@@ -164,7 +160,6 @@ async function switchAccount() {
164160 <div class =" actions" >
165161 <button class =" btn btn-outline" @click =" reset" >返回</button >
166162 </div >
167- <p v-if =" error" class =" error" >{{ error }}</p >
168163 </section >
169164 </div >
170165</template >
@@ -179,7 +174,6 @@ async function switchAccount() {
179174.status { font-size : 14px ; margin-bottom : 12px ; }
180175.status.success { color : var (--success ); font-weight : 500 ; margin-bottom : 16px ; }
181176.hint { font-size : 12px ; color : var (--fg-muted ); margin : 12px 0 0 ; }
182- .error { color : var (--danger ); margin : 12px 0 0 ; font-size : 13px ; }
183177
184178.field-group { margin-bottom : 20px ; }
185179.field-group :last-of-type { margin-bottom : 12px ; }
0 commit comments