index.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. import { iframeDislableKeyboard } from '/src/utils';
  6. export default defineComponent({
  7. name: 'song-modal',
  8. props: {
  9. item: {
  10. type: Object,
  11. default: () => ({})
  12. },
  13. activeStatus: {
  14. type: Boolean,
  15. default: false
  16. },
  17. imagePos: {
  18. type: String,
  19. default: 'left'
  20. }
  21. },
  22. emits: ['setIframe'],
  23. setup(props, { emit }) {
  24. const userStore = useUserStore();
  25. const iframeRef = ref();
  26. const isLoaded = ref(false);
  27. let src = `${
  28. location.origin
  29. }/classroom-app/#/tempo-practice?v=${+new Date()}&platform=modal&dataJson=${
  30. props.item.dataJson
  31. }&Authorization=${userStore.getToken}&win=pc&imagePos=${props.imagePos}`;
  32. if (/(localhost|192)/.test(location.host)) {
  33. src = `https://test.kt.colexiu.com/classroom-app/#/tempo-practice?v=${+new Date()}&platform=modal&dataJson=${
  34. props.item.dataJson
  35. }&Authorization=${userStore.getToken}&win=pc&imagePos=${props.imagePos}`;
  36. }
  37. watch(
  38. () => props.activeStatus,
  39. () => {
  40. if (!props.activeStatus) {
  41. iframeRef.value.contentWindow?.postMessage({ api: 'resetPlay' }, '*');
  42. }
  43. }
  44. );
  45. return () => (
  46. <div class={styles.musicScore}>
  47. <iframe
  48. ref={iframeRef}
  49. onLoad={(val: any) => {
  50. emit('setIframe', iframeRef.value);
  51. isLoaded.value = true;
  52. iframeDislableKeyboard(val.target);
  53. }}
  54. class={[styles.container, 'musicIframe']}
  55. frameborder="0"
  56. src={src}></iframe>
  57. </div>
  58. );
  59. }
  60. });