add downloading

This commit is contained in:
jxxghp
2023-07-02 18:05:57 +08:00
parent 3db84fe9b9
commit 67b21d60f7
+26 -13
View File
@@ -1,4 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import api from "@/api";
import { DownloadingInfo } from "@/api/types"; import { DownloadingInfo } from "@/api/types";
// 输入参数 // 输入参数
@@ -6,6 +7,9 @@ const props = defineProps({
info: Object as PropType<DownloadingInfo>, info: Object as PropType<DownloadingInfo>,
}); });
// 是否显示卡版
const cardState = ref(true);
// 进度条 // 进度条
const getPercentage = () => { const getPercentage = () => {
return props.info?.progress || 0; return props.info?.progress || 0;
@@ -16,28 +20,37 @@ const getSpeedText = () => {
return `${props.info?.upspeed}B/s ↓${props.info?.dlspeed}B/s`; return `${props.info?.upspeed}B/s ↓${props.info?.dlspeed}B/s`;
}; };
// 暂述状态 // 下载状态
const isDownloading = () => { const isDownloading = ref(props.info?.state === "downloading" ? true : false);
return props.info?.state === "downloading";
};
// 下载状态控制 // 下载状态控制
const toggleDownload = () => { const toggleDownload = async () => {
if (isDownloading()) { let operation = isDownloading.value ? "pause" : "start";
// 暂停 try {
} else { const result: { [key: string]: any } = await api.put(`download/${props.info?.hash}`, {
// 开始 params: {
open: operation,
},
});
isDownloading.value = !isDownloading.value;
} catch (error) {
console.error(error);
} }
}; };
// 删除下截 // 删除下截
const deleteDownload = () => { const deleteDownload = () => {
// 删除 try {
api.delete(`download/${props.info?.hash}`);
cardState.value = false;
} catch (error) {
console.error(error);
}
}; };
</script> </script>
<template> <template>
<VCard :key="props.info?.hash"> <VCard :key="props.info?.hash" v-if="cardState">
<div class="d-flex justify-space-between flex-nowrap flex-row"> <div class="d-flex justify-space-between flex-nowrap flex-row">
<div class="ma-auto pa-5 pe-0" v-if="props.info?.media.image"> <div class="ma-auto pa-5 pe-0" v-if="props.info?.media.image">
<VImg <VImg
@@ -65,9 +78,9 @@ const deleteDownload = () => {
<VProgressLinear v-if="getPercentage() > 0" :model-value="getPercentage()" /> <VProgressLinear v-if="getPercentage() > 0" :model-value="getPercentage()" />
</VCardText> </VCardText>
<VCardActions class="justify-space-t"> <VCardActions class="justify-space-between">
<VBtn @click="toggleDownload"> <VBtn @click="toggleDownload">
<span class="ms-2">{{ isDownloading() ? "暂停" : "开始" }}</span> <span class="ms-2">{{ isDownloading ? "暂停" : "开始" }}</span>
</VBtn> </VBtn>
<VBtn color="error" icon="mdi-trash-can-outline" @click="deleteDownload" /> <VBtn color="error" icon="mdi-trash-can-outline" @click="deleteDownload" />
</VCardActions> </VCardActions>