43 lines
1.1 KiB
Vue
43 lines
1.1 KiB
Vue
<script setup lang="ts">
|
|
import { IconPaperclip } from "@tabler/icons-vue";
|
|
import { ref, onBeforeUnmount } from "vue";
|
|
import { Button, Spinner } from "@heroui-vue/components";
|
|
const isLoading = ref(false),
|
|
message = ref("");
|
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
function upload() {
|
|
if (isLoading.value) return;
|
|
isLoading.value = true;
|
|
message.value = "";
|
|
timer = setTimeout(() => {
|
|
isLoading.value = false;
|
|
message.value = "上传完成,可以再次上传。";
|
|
}, 2000);
|
|
}
|
|
onBeforeUnmount(() => clearTimeout(timer));
|
|
</script>
|
|
<template>
|
|
<div class="upload-demo">
|
|
<Button :is-pending="isLoading" @click="upload">
|
|
<Spinner v-if="isLoading" color="current" size="sm" />
|
|
<IconPaperclip v-else aria-hidden="true" />
|
|
{{ isLoading ? "上传中…" : "上传文件" }}
|
|
</Button>
|
|
<p class="upload-status" role="status">{{ message }}</p>
|
|
</div>
|
|
</template>
|
|
<style scoped>
|
|
.upload-demo {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
.upload-status {
|
|
font-size: 12px;
|
|
color: var(--muted);
|
|
min-height: 20px;
|
|
margin: 0;
|
|
}
|
|
</style>
|