Skip to content

Commit 757ced1

Browse files
committed
enhance: refactor App.vue for improved readability and consistency
1 parent ba439a1 commit 757ced1

1 file changed

Lines changed: 34 additions & 41 deletions

File tree

src/webui/FE/App.vue

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
<template>
2-
<el-container class='main-container'>
3-
<el-header class='header'>
4-
<h2 style='display:inline-block;'>LLTwoBot {{version}}</h2>
2+
<el-container class="main-container">
3+
<el-header class="header">
4+
<h2 style="display: inline-block">LLTwoBot {{ version }}</h2>
55
</el-header>
6-
<el-main v-loading='loading'>
7-
<el-row :gutter='24' justify='center'>
8-
<el-col :xs='24' :sm='22' :md='20' :lg='16' :xl='12'>
9-
<el-card shadow='hover' class='config-card'>
10-
<AccountInfo :accountNick='accountNick' :accountUin='accountUin' />
11-
<el-menu mode='horizontal' :default-active='activeIndex' @select='handleSelect'>
12-
<el-menu-item index='1'>OneBot 11 配置</el-menu-item>
13-
<el-menu-item index='2'>Satori 配置</el-menu-item>
14-
<el-menu-item index='3'>其他配置</el-menu-item>
15-
<el-menu-item index='4'>关于</el-menu-item>
6+
<el-main v-loading="loading">
7+
<el-row :gutter="24" justify="center">
8+
<el-col :xs="24" :sm="22" :md="20" :lg="16" :xl="12">
9+
<el-card shadow="hover" class="config-card">
10+
<AccountInfo :accountNick="accountNick" :accountUin="accountUin" />
11+
<el-menu mode="horizontal" :default-active="activeIndex" @select="handleSelect">
12+
<el-menu-item index="1">OneBot 11 配置</el-menu-item>
13+
<el-menu-item index="2">Satori 配置</el-menu-item>
14+
<el-menu-item index="3">其他配置</el-menu-item>
15+
<el-menu-item index="4">关于</el-menu-item>
1616
</el-menu>
17-
<el-form :model='form' label-width='160px' size='large' class='config-form'>
18-
<Ob11ConfigForm
19-
ref='ob11ConfigFormRef'
20-
v-if="activeIndex === '1'"
21-
v-model='form.ob11'
22-
/>
23-
<SatoriConfigForm v-if="activeIndex === '2'" v-model='form.satori' />
24-
<OtherConfigForm v-if="activeIndex === '3'" v-model='form' />
17+
<el-form :model="form" label-width="160px" size="large" class="config-form">
18+
<Ob11ConfigForm ref="ob11ConfigFormRef" v-if="activeIndex === '1'" v-model="form.ob11" />
19+
<SatoriConfigForm v-if="activeIndex === '2'" v-model="form.satori" />
20+
<OtherConfigForm v-if="activeIndex === '3'" v-model="form" />
2521
<About v-if="activeIndex === '4'" />
26-
<el-form-item class='form-actions' v-if="activeIndex != '4'">
27-
<el-button type='primary' @click='onSave' size='large' style='float: right;' :loading='loading'>
22+
<el-form-item class="form-actions" v-if="activeIndex != '4'">
23+
<el-button type="primary" @click="onSave" size="large" style="float: right" :loading="loading">
2824
保存配置
2925
</el-button>
3026
</el-form-item>
@@ -33,12 +29,18 @@
3329
</el-col>
3430
</el-row>
3531
</el-main>
36-
<TokenDialog v-model:visible='showTokenDialog' v-model:tokenInput='tokenInput' :loading='tokenDialogLoading'
37-
:error='tokenDialogError' @confirm='handleTokenDialogConfirm' @close='handleTokenDialogClose' />
32+
<TokenDialog
33+
v-model:visible="showTokenDialog"
34+
v-model:tokenInput="tokenInput"
35+
:loading="tokenDialogLoading"
36+
:error="tokenDialogError"
37+
@confirm="handleTokenDialogConfirm"
38+
@close="handleTokenDialogClose"
39+
/>
3840
</el-container>
3941
</template>
4042

41-
<script setup lang='ts'>
43+
<script setup lang="ts">
4244
import { ref, onMounted, watch, nextTick } from 'vue'
4345
import { ElMessage, ElDialog, ElInput, ElButton } from 'element-plus'
4446
import { QuestionFilled } from '@element-plus/icons-vue'
@@ -92,7 +94,7 @@ const defaultConfig: Config = {
9294
token: '',
9395
port: 3080,
9496
},
95-
receiveOfflineMsg: false
97+
receiveOfflineMsg: false,
9698
}
9799
98100
const form = ref(JSON.parse(JSON.stringify(defaultConfig)))
@@ -126,7 +128,6 @@ async function setToken(newToken: string) {
126128
127129
// 弹出密码输入框,直到用户输入非空密码并点击确定/回车才resolve
128130
async function promptPassword(tip: string): Promise<string> {
129-
130131
return new Promise<string>((resolve) => {
131132
tokenDialogError.value = ''
132133
tokenInput.value = ''
@@ -147,7 +148,6 @@ async function promptPassword(tip: string): Promise<string> {
147148
const stopShow = watch(showTokenDialog, (val) => {
148149
if (!val) {
149150
stopShow()
150-
151151
}
152152
})
153153
// 监听确定按钮
@@ -178,8 +178,7 @@ async function apiFetch(url: string, options: any = {}): Promise<Response> {
178178
throw new Error('设置密码失败')
179179
}
180180
tokenInput.value = ''
181-
}
182-
else if (resp.status === 403) {
181+
} else if (resp.status === 403) {
183182
token.value = ''
184183
localStorage.removeItem(tokenKey)
185184
const inputPwd = await promptPassword('密码校验失败,请输入密码')
@@ -198,7 +197,6 @@ async function apiFetch(url: string, options: any = {}): Promise<Response> {
198197
return resp
199198
}
200199
201-
202200
// 获取配置
203201
async function fetchConfig() {
204202
try {
@@ -211,16 +209,14 @@ async function fetchConfig() {
211209
form.value = data.data.config
212210
accountNick.value = data.data.selfInfo.nick || ''
213211
accountUin.value = data.data.selfInfo.uin || ''
214-
}
215-
else {
212+
} else {
216213
form.value = data.data
217214
accountNick.value = ''
218215
accountUin.value = ''
219216
}
220217
console.log('config接口返回:', data)
221218
ElMessage.success('配置加载成功')
222-
}
223-
else {
219+
} else {
224220
throw new Error(data.message || '获取配置失败')
225221
}
226222
} catch (error: any) {
@@ -251,8 +247,7 @@ async function onSave() {
251247
localStorage.setItem(tokenKey, form.value.webui.token)
252248
token.value = form.value.webui.token
253249
ElMessage.success('配置保存成功')
254-
}
255-
else {
250+
} else {
256251
throw new Error(data.message || '保存配置失败')
257252
}
258253
} catch (error: any) {
@@ -268,14 +263,12 @@ onMounted(() => {
268263
fetchConfig()
269264
})
270265
271-
272266
function handleSelect(key: string) {
273267
activeIndex.value = key
274268
}
275269
276270
// 修改handleTokenDialogConfirm为let变量,便于promptPassword里动态赋值
277-
let handleTokenDialogConfirm = async () => {
278-
}
271+
let handleTokenDialogConfirm = async () => {}
279272
280273
function handleTokenDialogClose() {
281274
tokenDialogError.value = ''

0 commit comments

Comments
 (0)