musicScore.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import { defineComponent, onMounted, onUnmounted, ref, watch } from 'vue';
  2. import { NSkeleton } from 'naive-ui';
  3. import styles from './musicScore.module.less';
  4. import { usePageVisibility } from '@vant/use';
  5. import { useUserStore } from '/src/store/modules/users';
  6. import { vaildMusicScoreUrl } from '/src/utils/urlUtils';
  7. export default defineComponent({
  8. name: 'musicScore',
  9. props: {
  10. music: {
  11. type: Object,
  12. default: () => ({})
  13. },
  14. activeModel: {
  15. type: Boolean
  16. },
  17. /** 当前是否为选中状态 */
  18. activeStatus: {
  19. type: Boolean
  20. }
  21. },
  22. emits: ['setIframe'],
  23. setup(props, { emit }) {
  24. const userStore = useUserStore();
  25. const isLoading = ref(false);
  26. const pageVisibility = usePageVisibility();
  27. /** 页面显示和隐藏 */
  28. watch(pageVisibility, value => {
  29. console.log('🚀 ~ value:', value);
  30. if (value == 'hidden') {
  31. isLoading.value = false;
  32. }
  33. });
  34. const iframeRef = ref();
  35. const isLoaded = ref(false);
  36. const renderError = ref(false);
  37. const renderSuccess = ref(false);
  38. // const origin = /(localhost|192)/.test(location.host)
  39. // ? 'https://test.lexiaoya.cn/instrument'
  40. // : // 'http://localhost:3000/instrument.html'
  41. // location.origin + '/instrument';
  42. const src = `${vaildMusicScoreUrl()}/instrument?v=${+new Date()}&showGuide=true&platform=pc&zoom=1.2&modelType=practise&id=${
  43. props.music.content
  44. }&Authorization=${userStore.getToken}`;
  45. const checkView = () => {
  46. fetch(src)
  47. .then(() => {
  48. renderSuccess.value = true;
  49. renderError.value = false;
  50. })
  51. .catch(() => {
  52. renderError.value = true;
  53. });
  54. };
  55. watch(
  56. () => props.music,
  57. () => {
  58. if (renderSuccess.value) return;
  59. renderError.value = false;
  60. if (props.music.display) {
  61. checkView();
  62. }
  63. }
  64. );
  65. // 去云教练完整版
  66. // const gotoAccomany = () => {
  67. // if (isLoading.value) return;
  68. // if (!browserInfo.ios) {
  69. // isLoading.value = true;
  70. // }
  71. // // const parmas = qs.stringify({
  72. // // id: props.music.content
  73. // // });
  74. // // let src = `${location.origin}/orchestra-music-score/?` + parmas
  75. // const src = `https://test.lexiaoya.cn/orchestra-music-score/?_t=1687590480955&id=11707&modelType=practice&modeType=json&Authorization=bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsib2F1dGgyLXJlc291cmNlIl0sImNsaWVudFR5cGUiOiJCQUNLRU5EIiwidXNlcl9uYW1lIjoiMTgxNjI4NTU4MDAiLCJzY29wZSI6WyJhbGwiXSwidXNlcklkIjoiMTAwMDE0OSIsImF1dGhvcml0aWVzIjpbIjE4MTYyODU1ODAwIl0sImp0aSI6IjY0MzA2NjllLTE5NGItNDk3Yy1hMDQ5LWM4YWUxMGU0NDNiOCIsImNsaWVudF9pZCI6ImptZWR1LWJhY2tlbmQifQ.aeJ0o-lSfx1Ok-YptZuC-AUY6M7k3LK9rr0Bmx7sj81pPt2HDiDqeT2PuriYdJacxWnxboyhdG_lwU0QK-W-vON97c45NQpSEFLVpZ0m1xdIqwllwf20xhyj5YJwdOFUzxf1TNEfGsHZg66J7wEJQBSzlmQwcxmEE5lqLVD8o_3f2SBqnWCj9RqE4air7FUemllMnZiu8HsS-TKtLDaGa_XW8Yb_Zjzzz6r5UcYNI-C1uKPXg18o1dhHBJ8O-Pl0U8WivPRub_opvO2NSn5L9YtPt7Dd50UeSwaIOdMeCGdii1bg__h77Stek1_5IaZLYkoo2gvmUA-xk09TwCQBpA`;
  76. // postMessage(
  77. // {
  78. // api: 'openAccompanyWebView',
  79. // content: {
  80. // url: src,
  81. // orientation: 0,
  82. // isHideTitle: true,
  83. // statusBarTextColor: false,
  84. // isOpenLight: true
  85. // }
  86. // },
  87. // () => {
  88. // if (browserInfo.ios) {
  89. // isLoading.value = true;
  90. // }
  91. // }
  92. // );
  93. // };
  94. watch(
  95. () => props.activeModel,
  96. () => {
  97. if (iframeRef.value.contentWindow && props.activeStatus) {
  98. // console.log(
  99. // iframeRef.value.contentWindow,
  100. // props.activeModel,
  101. // 'iframeRef'
  102. // );
  103. iframeRef.value.contentWindow.postMessage(
  104. {
  105. api: 'attendClassBarStatus',
  106. hideMenu: !props.activeModel
  107. },
  108. '*'
  109. );
  110. }
  111. }
  112. );
  113. return () => (
  114. <div class={styles.musicScore}>
  115. <iframe
  116. ref={iframeRef}
  117. onLoad={() => {
  118. emit('setIframe', iframeRef.value);
  119. isLoaded.value = true;
  120. }}
  121. class={[styles.container, 'musicIframe']}
  122. frameborder="0"
  123. src={src}></iframe>
  124. {isLoaded.value && (
  125. <div class={styles.skeletonWrap}>
  126. <div>
  127. <NSkeleton text repeat={8} />
  128. </div>
  129. </div>
  130. )}
  131. </div>
  132. );
  133. }
  134. });