import { PropType, Transition, computed, defineComponent, reactive, ref, watch } from 'vue'; import styles from './index.module.less'; import { NButton, NImage, NProgress, NSlider } from 'naive-ui'; import { IMusicItem } from '../../type'; import icon_pre from '../../images/icon_pre.svg'; import icon_next from '../../images/icon_next.svg'; import icon_play from '../../images/icon_play.svg'; import icon_pause from '../../images/icon_pause.svg'; import { getSecondRPM } from '/src/utils'; import icon_favitor from '/src/common/images/icon-collect-default.png'; import icon_favitorActive from '/src/common/images/icon-collect-active.png'; import TheNoticeBar from '/src/components/TheNoticeBar'; export default defineComponent({ name: 'playItem', props: { item: { type: Object as PropType, default: () => ({}) }, show: { type: Boolean, default: false }, playState: { type: String as PropType<'play' | 'pause'>, default: 'pause' } }, emits: ['change'], setup(props, { emit }) { let timer = null as any; const audioData = reactive({ isFirst: true, duration: 0, currentTime: 0 }); const audioRef = ref(); /** 加载成功 */ const onLoadedmetadata = () => { audioData.duration = audioRef.value.duration; if (audioData.isFirst) { audioData.isFirst = false; return; } if (props.playState === 'play') { audioRef.value.play(); } }; /** 改变时间 */ const handleChangeTime = (val: number) => { audioRef.value.pause(); audioData.currentTime = val; clearTimeout(timer); timer = setTimeout(() => { audioRef.value.currentTime = val; if (props.playState === 'play') { audioRef.value.play(); } timer = null; }, 300); }; const time = computed(() => { return `${getSecondRPM(audioData.currentTime)} / ${getSecondRPM( audioData.duration )}`; }); watch( () => props.playState, val => { if (val === 'play') { audioRef.value.play(); } else { audioRef.value.pause(); } } ); return () => (
{ (e.target as any).dataset.loaded = 'true'; }} />
{props.item.composer}
emit('change', 'pre')}> emit('change', props.playState === 'pause' ? 'play' : 'pause') }> emit('change', 'next')}>
handleChangeTime(val)} />
{time.value}
); } });