index.jsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { onMounted, ref, watch, markRaw, computed } from 'vue'
  2. import MuiPlayer from 'mui-player'
  3. import 'mui-player/dist/mui-player.min.css'
  4. import './index.less'
  5. import { getValueByTemplate } from '@cip/utils/util'
  6. import apiConfig from '@cip/request/apiConfig'
  7. export default {
  8. props: {
  9. height: {},
  10. autoplay: Boolean,
  11. src: {},
  12. preload: String // ['none','auto']
  13. },
  14. setup (props) {
  15. const videoRef = ref()
  16. const instance = ref()
  17. const _src = computed(() => {
  18. return getValueByTemplate(props.src, apiConfig)
  19. })
  20. const isPlay = ref(false)
  21. const play = () => {
  22. instance.value.video().play()
  23. isPlay.value = true
  24. }
  25. onMounted(() => {
  26. if (!props.preload || props.preload === 'auto') isPlay.value = true
  27. instance.value = markRaw(new MuiPlayer({
  28. container: videoRef.value,
  29. src: _src.value,
  30. height: props.height || '750px',
  31. autoplay: props.autoplay,
  32. pageHead: false,
  33. preload: props.preload,
  34. customSetting: {
  35. show: false
  36. }
  37. }))
  38. })
  39. watch(_src, (val) => {
  40. if (instance.value) {
  41. instance.value.reloadUrl(val)
  42. }
  43. })
  44. return () => <div class={'cip-dynamic-video__container'} >
  45. {!isPlay.value && <div class={'cip-dynamic-video__mask'}>
  46. <div class={'cip-dynamic-video__play'} onClick={() => play()}>
  47. <svg width="100%" height="100%" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
  48. <rect width="48" height="48" fill="white" fill-opacity="0.01"/>
  49. <path d="M24 44C35.0457 44 44 35.0457 44 24C44 12.9543 35.0457 4 24 4C12.9543 4 4 12.9543 4 24C4 35.0457 12.9543 44 24 44Z" fill="" stroke="currentColor" stroke-width="4" stroke-linejoin="round"/>
  50. <path d="M20 24V17.0718L26 20.5359L32 24L26 27.4641L20 30.9282V24Z" fill="currentColor" stroke="currentColor" stroke-width="4" stroke-linejoin="round"/>
  51. </svg>
  52. </div>
  53. </div>}
  54. <div ref={videoRef}></div>
  55. </div>
  56. }
  57. }