Basic functions

This commit is contained in:
zhbaor 2023-02-24 00:57:26 +08:00
parent fd7d6b97de
commit e47a92b77e
2 changed files with 79 additions and 36 deletions

View file

@ -2,10 +2,13 @@
const props = defineProps({ const props = defineProps({
disabled: Boolean, disabled: Boolean,
}); });
const emit = defineEmits(["enable-download"]);
</script> </script>
<template> <template>
<button <button
@click="emit('enable-download')"
class="btn btn-lg btn-primary px-3 mb-4 z-3 shadow position-absolute bottom-0 start-50 translate-middle-x" class="btn btn-lg btn-primary px-3 mb-4 z-3 shadow position-absolute bottom-0 start-50 translate-middle-x"
:disabled="disabled" :disabled="disabled"
> >

View file

@ -1,31 +1,74 @@
<script setup> <script setup>
import { onMounted, ref, inject, computed } from "vue";
import AudioCard from "../components/AudioCard.vue"; import AudioCard from "../components/AudioCard.vue";
import TotalProgress from "../components/TotalProgress.vue"; import TotalProgress from "../components/TotalProgress.vue";
import DownloadButton from "../components/DownloadButton.vue"; import DownloadButton from "../components/DownloadButton.vue";
const p1 = { const axios = inject("axios");
number: "BV1es41127Fd",
received: 0, const state_list = ref([]);
total: 0,
}; const auto_download = ref(false);
const p2 = {
number: "BV1es41127Fd", onMounted(() => {
title: "【洛天依/乐正绫原创】霜雪千年【PV付/COP】", setInterval(() => {
received: 0, axios.get("http://localhost:8000/progress").then((resp) => {
total: 0, state_list.value = resp.data;
}; for (const [i, s] of state_list.value.entries()) {
const p3 = { if (
number: "BV1es41127Fd", auto_download.value &&
title: "【洛天依/乐正绫原创】霜雪千年【PV付/COP】", counter.value.downloading == 0 &&
received: 1314514, s.number &&
total: 1919810, s.title &&
}; s.total == 0
const p4 = { ) {
number: "BV1es41127Fd", axios.post("http://localhost:8000/download", {
title: "【洛天依/乐正绫原创】霜雪千年【PV付/COP】", id: i,
received: 1919810, parent_dir: "/home/zhao/Desktop/tmp",
total: 1919810, });
}; break;
}
}
});
}, 500);
});
const counter = computed(() => {
if (state_list.value.length == 0) {
return { fetching: true, downloading: false };
}
let ready = 0;
let downloading = 0;
let finished = 0;
state_list.value.forEach((s) => {
if (s.number && s.title && s.total == 0) {
ready++;
} else if (s.received < s.total) {
downloading++;
} else if (s.total <= s.received && s.total != 0) {
finished++;
}
});
return { ready: ready, downloading: downloading, finished: finished };
});
const progress_info = computed(() => {
const total = state_list.value.length;
const { ready, downloading, finished } = counter.value;
const fetch_info = "Fetching Information";
const download_info = "Downloading";
const finished_info = "Downloads Complete";
if (total == 0) {
return { display: fetch_info, finished: 0, total: 0 };
} else if (ready < total && downloading == 0 && finished == 0) {
return { display: fetch_info, finished: ready, total: total };
} else if (finished + downloading + ready == total && finished < total) {
return { display: download_info, finished: finished + downloading, total: total };
} else if (finished == total) {
return { display: finished_info, finished: finished, total: total };
}
});
</script> </script>
<template> <template>
@ -34,21 +77,18 @@ const p4 = {
> >
<div class="container overflow-y-scroll flex-grow-1"> <div class="container overflow-y-scroll flex-grow-1">
<div class="row g-3 py-3"> <div class="row g-3 py-3">
<div class="col-12 col-md-10 offset-md-1 col-xl-6 offset-xl-0"> <div
<AudioCard v-bind="p1"></AudioCard> v-for="state in state_list"
</div> class="col-12 col-md-10 offset-md-1 col-xl-6 offset-xl-0"
<div class="col-12 col-md-10 offset-md-1 col-xl-6 offset-xl-0"> >
<AudioCard v-bind="p2"></AudioCard> <AudioCard v-bind="state"></AudioCard>
</div>
<div class="col-12 col-md-10 offset-md-1 col-xl-6 offset-xl-0">
<AudioCard v-bind="p3"></AudioCard>
</div>
<div class="col-12 col-md-10 offset-md-1 col-xl-6 offset-xl-0">
<AudioCard v-bind="p4"></AudioCard>
</div> </div>
</div> </div>
</div> </div>
<!-- <TotalProgress display="Downloading" :finished="114514" :total="191981"></TotalProgress> --> <DownloadButton
<!-- <DownloadButton></DownloadButton> --> @enable-download="auto_download = true"
v-if="counter.ready == state_list.length"
></DownloadButton>
<TotalProgress v-else v-bind="progress_info"></TotalProgress>
</div> </div>
</template> </template>