46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
|
import { ref } from 'vue';
|
||
|
import { NProgress } from 'naive-ui';
|
||
|
import filesize from 'filesize';
|
||
|
import { Music, Video } from '@vicons/carbon';
|
||
|
import type { DialogApiInjection } from 'naive-ui/es/dialog/src/DialogProvider';
|
||
|
|
||
|
export default function createAudioVideoDialog(
|
||
|
dialog: DialogApiInjection,
|
||
|
video: boolean
|
||
|
) {
|
||
|
const progress = ref(0);
|
||
|
const total = ref(1);
|
||
|
const percentage = ref(0);
|
||
|
const dia = dialog.create({
|
||
|
title: video ? 'Loading video...' : 'Loading audio...',
|
||
|
closable: false,
|
||
|
closeOnEsc: false,
|
||
|
maskClosable: false,
|
||
|
icon: () => (video ? <Video /> : <Music />),
|
||
|
content: () => (
|
||
|
<NProgress
|
||
|
type="line"
|
||
|
percentage={percentage.value}
|
||
|
height={20}
|
||
|
status="info"
|
||
|
showIndicator={false}
|
||
|
/>
|
||
|
),
|
||
|
action: () => (
|
||
|
<div>
|
||
|
{filesize(progress.value, {
|
||
|
base: 2,
|
||
|
standard: 'jedec'
|
||
|
})}
|
||
|
/
|
||
|
{filesize(total.value, {
|
||
|
base: 2,
|
||
|
standard: 'jedec'
|
||
|
})}
|
||
|
- {Math.floor(percentage.value * 1000) / 1000}%
|
||
|
</div>
|
||
|
)
|
||
|
});
|
||
|
return { progress, total, percentage, dia };
|
||
|
}
|