mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-30 12:01:20 -08:00
feat: refactor Artplayer component and add Player component with TypeScript support
This commit is contained in:
1 parent
6be0ea9542
commit
736a6c1973
3 files changed
+27
-29
No files matched your search
@@ -12,6 +12,9 @@
|
|||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"artplayer": "^5.3.0-beta.2",
|
||||||
|
"artplayer-plugin-danmuku": "^5.1.8",
|
||||||
|
"artplayer-plugin-document-pip": "^1.0.1",
|
||||||
"vue": "^3.5.18"
|
"vue": "^3.5.18"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
<script setup>
|
<script setup lang="ts">
|
||||||
import { reactive } from 'vue'
|
import { reactive } from 'vue'
|
||||||
import Artplayer from './Artplayer.vue'
|
import Artplayer, { type Option } from 'artplayer'
|
||||||
|
import Player from './Player.vue'
|
||||||
|
|
||||||
const option = reactive({
|
const option = reactive<Partial<Option>>({
|
||||||
url: 'https://artplayer.org/assets/sample/video.mp4',
|
url: 'https://artplayer.org/assets/sample/video.mp4',
|
||||||
autoSize: true,
|
autoSize: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
const style = reactive({
|
const style = reactive({
|
||||||
width: '600px',
|
width: '800px',
|
||||||
height: '400px',
|
height: '600px',
|
||||||
margin: '60px auto 0',
|
margin: '60px auto 0',
|
||||||
})
|
})
|
||||||
|
|
||||||
function getInstance(art) {
|
function getInstance(art: Artplayer) {
|
||||||
// eslint-disable-next-line no-console
|
console.log('Artplayer instance:', art)
|
||||||
console.log(art)
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<Artplayer :option="option" :style="style" @get-instance="getInstance" />
|
<Player :option="option" :style="style" @get-instance="getInstance" />
|
||||||
</template>
|
</template>
|
||||||
+15
-20
@@ -1,26 +1,21 @@
|
|||||||
<script setup>
|
<script setup lang="ts">
|
||||||
import Artplayer from 'artplayer'
|
import { onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'
|
||||||
|
|
||||||
// test i18n
|
// Test type
|
||||||
|
import Artplayer, { type Option } from 'artplayer'
|
||||||
|
|
||||||
|
// Test i18n
|
||||||
import fr from 'artplayer/i18n/fr'
|
import fr from 'artplayer/i18n/fr'
|
||||||
import id from 'artplayer/i18n/id'
|
import id from 'artplayer/i18n/id'
|
||||||
|
|
||||||
import { onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'
|
// Test plugins
|
||||||
|
import artplayerPluginDocumentPip from 'artplayer-plugin-document-pip'
|
||||||
// test plugins
|
import artplayerPluginDanmuku from 'artplayer-plugin-danmuku'
|
||||||
import artplayerPluginDanmuku from '../../../artplayer-plugin-danmuku'
|
|
||||||
import artplayerPluginDocumentPip from '../../../artplayer-plugin-document-pip'
|
|
||||||
|
|
||||||
const props = defineProps({
|
|
||||||
option: {
|
|
||||||
type: Object,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
|
const props = defineProps<{ option: Partial<Option> }>()
|
||||||
const emit = defineEmits(['getInstance'])
|
const emit = defineEmits(['getInstance'])
|
||||||
|
|
||||||
const art = shallowRef(null)
|
const art = shallowRef<Artplayer>(null)
|
||||||
const $container = ref(null)
|
const $container = ref(null)
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@@ -30,7 +25,9 @@ onMounted(() => {
|
|||||||
i18n: { id, fr },
|
i18n: { id, fr },
|
||||||
lang: 'fr',
|
lang: 'fr',
|
||||||
plugins: [
|
plugins: [
|
||||||
artplayerPluginDocumentPip(),
|
artplayerPluginDocumentPip({
|
||||||
|
//
|
||||||
|
}),
|
||||||
artplayerPluginDanmuku({
|
artplayerPluginDanmuku({
|
||||||
danmuku: 'https://artplayer.org/assets/sample/danmuku.xml',
|
danmuku: 'https://artplayer.org/assets/sample/danmuku.xml',
|
||||||
}),
|
}),
|
||||||
@@ -40,9 +37,7 @@ onMounted(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
if (art.value) {
|
art.value?.destroy(false)
|
||||||
art.value.destroy(false)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
Reference in new issue
Block a user