index.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { defineComponent, ref, watch } from 'vue';
  2. import styles from './index.module.less';
  3. import { useUserStore } from '/src/store/modules/users';
  4. import { vaildMusicScoreUrl } from '/src/utils/urlUtils';
  5. export default defineComponent({
  6. name: 'song-modal',
  7. props: {
  8. item: {
  9. type: Object,
  10. default: () => ({})
  11. },
  12. activeStatus: {
  13. type: Boolean,
  14. default: false
  15. }
  16. },
  17. emits: ['setIframe'],
  18. setup(props, { emit }) {
  19. const userStore = useUserStore();
  20. const iframeRef = ref();
  21. const isLoaded = ref(false);
  22. let src = `${
  23. location.origin
  24. }/classroom-app/#/tempo-practice?v=${+new Date()}&platform=modal&dataJson=${
  25. props.item.dataJson
  26. }&Authorization=${userStore.getToken}&win=pc`;
  27. if (/(localhost)/.test(location.host)) {
  28. src = `http://localhost:9002/#/tempo-practice?v=${+new Date()}&platform=modal&dataJson=${
  29. props.item.dataJson
  30. }&Authorization=${userStore.getToken}&win=pc`;
  31. }
  32. watch(
  33. () => props.activeStatus,
  34. () => {
  35. if (!props.activeStatus) {
  36. iframeRef.value.contentWindow?.postMessage({ api: 'resetPlay' }, '*');
  37. }
  38. }
  39. );
  40. return () => (
  41. <div class={styles.musicScore}>
  42. <iframe
  43. ref={iframeRef}
  44. onLoad={() => {
  45. emit('setIframe', iframeRef.value);
  46. isLoaded.value = true;
  47. }}
  48. class={[styles.container, 'musicIframe']}
  49. frameborder="0"
  50. src={src}></iframe>
  51. </div>
  52. );
  53. }
  54. });