refactor(frontend): 重构前端代码以优化类型定义和组件逻辑

- 修改 ResponseData 类型定义,统一返回格式为数组类型
- 更新 API 函数签名以包含正确的返回类型注解
- 简化 AboutView 组件中的统计数据显示逻辑
- 移除未使用的变量和方法,精简组件代码
- 修复 HomeView 中的事件监听器类型定义问题
- 替换接口泛型中的 any 类型为 unknown 提高类型安全
- 注释掉未使用的全局变量避免潜在错误
This commit is contained in:
2026-05-07 20:20:06 +08:00
parent 8c0dca0dad
commit 72cb8c796f
5 changed files with 12 additions and 58 deletions
+4 -2
View File
@@ -1,5 +1,7 @@
import request from "../utils/request.ts" import request from "../utils/request.ts"
type ResponseData = Promise<{ code: number, message: Array<never> }>
export function book_download() { export function book_download() {
return request({ return request({
url: "/book/download", url: "/book/download",
@@ -24,7 +26,7 @@ export function video_hasTorrent() {
}) })
} }
export function file_rename() { export function file_rename(): ResponseData {
return request({ return request({
url: "/file/rename", url: "/file/rename",
}) })
@@ -60,7 +62,7 @@ export function test() {
}) })
} }
export function torrent_statistics(){ export function torrent_statistics(): ResponseData {
return request({ return request({
url: "/torrent/statistics", url: "/torrent/statistics",
}) })
+3 -3
View File
@@ -6,7 +6,7 @@ import axios, {
} from "axios" } from "axios"
// 定义响应数据结构 // 定义响应数据结构
interface ResponseData<T = any> { interface ResponseData<T = unknown> {
code: number code: number
msg: string msg: string
data?: T data?: T
@@ -18,8 +18,8 @@ interface RequestCache {
time: number time: number
} }
let downloadLoadingInstance: any // let downloadLoadingInstance: any
export let isRelogin: { show: boolean } = {show: false} // export let isRelogin: { show: boolean } = {show: false}
axios.defaults.headers["Content-Type"] = "application/json; charset=UTF-8" axios.defaults.headers["Content-Type"] = "application/json; charset=UTF-8"
const service: AxiosInstance = axios.create({ const service: AxiosInstance = axios.create({
+1 -49
View File
@@ -2,70 +2,22 @@
import {onMounted, ref} from 'vue' import {onMounted, ref} from 'vue'
import {torrent_statistics} from '@/api' import {torrent_statistics} from '@/api'
interface StatisticsData { const aa = ref([])
[key: string]: any
}
let aa = ref<StatisticsData>({})
let bb = ref("")
let cc = ref("")
let dd = ref("")
onMounted(async () => { onMounted(async () => {
const res = await torrent_statistics() const res = await torrent_statistics()
console.log(res.message) console.log(res.message)
aa.value = res.message
}) })
const getSecondLevelOptions = () => {
if (!bb.value || !aa.value[bb.value]) {
return []
}
return aa.value[bb.value]
}
const getThirdLevelOptions = () => {
if (!bb.value || !cc.value || !aa.value[bb.value] || !aa.value[bb.value][cc.value]) {
return []
}
console.log(aa.value[bb.value])
return aa.value[bb.value][cc.value]
}
</script> </script>
<template> <template>
<el-main> <el-main>
<el-card shadow="never"> <el-card shadow="never">
<template #default> <template #default>
<!-- <div v-for="(v,i) in getSecondLevelOptions()">-->
<!-- <div>{{i}}</div>-->
<!-- <el-button v-for="(v2,i2) in v" :key="i2">{{ v2 }}</el-button>-->
<!-- </div>-->
<div> <div>
<el-button v-for="(v,i) in aa" :key="i">{{ i }}</el-button> <el-button v-for="(v,i) in aa" :key="i">{{ i }}</el-button>
</div> </div>
</template> </template>
<template #footer> <template #footer>
<el-select style="width: 120px" placeholder="请选择" v-model="bb">
<el-option v-for="(v,i) in aa" :key="i" :label="i" :value="i"></el-option>
</el-select>
<el-select style="width: 120px" placeholder="请选择" v-model="cc">
<el-option v-for="(v,i) in getSecondLevelOptions()" :key="i" :label="i"
:value="i"></el-option>
</el-select>
<el-select style="width: 120px" placeholder="请选择" v-model="dd">
<el-option v-for="(v,i) in getThirdLevelOptions()" :key="i" :label="v"
:value="v"></el-option>
</el-select>
<el-button type="primary" @click="">
<el-icon>
<Plus/>
</el-icon>
添加
</el-button>
</template> </template>
</el-card> </el-card>
</el-main> </el-main>
+4 -4
View File
@@ -20,10 +20,10 @@ interface messageItem {
interface BtnItem { interface BtnItem {
id: number id: number
title: string title: string
handle?: () => Promise<any> handle?: () => Promise<never>
} }
let loading = ref(false) const loading = ref(false)
let eventSource: EventSource // 保存 EventSource 实例 let eventSource: EventSource // 保存 EventSource 实例
const status = ref('closed') // 连接状态:closed, connecting, connected const status = ref('closed') // 连接状态:closed, connecting, connected
const messages = ref<messageItem[]>([{id: Date.now(), text: '输出结果'}]) const messages = ref<messageItem[]>([{id: Date.now(), text: '输出结果'}])
@@ -74,7 +74,7 @@ const connect = (url: string) => {
} }
eventSource = new EventSource(url) eventSource = new EventSource(url)
// 连接成功 // 连接成功
eventSource.addEventListener("open", (event) => { eventSource.addEventListener("open", () => {
console.log('SSE 连接已打开') console.log('SSE 连接已打开')
status.value = 'connected' status.value = 'connected'
}) })
@@ -88,7 +88,7 @@ const connect = (url: string) => {
closeConnection() closeConnection()
}) })
// 错误处理 // 错误处理
eventSource.addEventListener('error', (event) => { eventSource.addEventListener('error', () => {
console.log('连接断开或失败', new Date()); console.log('连接断开或失败', new Date());
// 如果这里也频繁触发,确认了是断连重连 // 如果这里也频繁触发,确认了是断连重连
if (eventSource.readyState === EventSource.CLOSED) { if (eventSource.readyState === EventSource.CLOSED) {
BIN
View File
Binary file not shown.