musicScore.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. import { iframeDislableKeyboard } from '/src/utils';
  8. export default defineComponent({
  9. name: 'musicScore',
  10. props: {
  11. music: {
  12. type: Object,
  13. default: () => ({})
  14. },
  15. activeModel: {
  16. type: Boolean
  17. },
  18. instrumentId: {
  19. type: String
  20. },
  21. /** 当前是否为选中状态 */
  22. activeStatus: {
  23. type: Boolean
  24. },
  25. imagePos: {
  26. type: String,
  27. default: 'left'
  28. }
  29. },
  30. emits: ['setIframe'],
  31. setup(props, { emit }) {
  32. const userStore = useUserStore();
  33. const isLoading = ref(false);
  34. const pageVisibility = usePageVisibility();
  35. /** 页面显示和隐藏 */
  36. watch(pageVisibility, value => {
  37. console.log('🚀 ~ value:', value);
  38. if (value == 'hidden') {
  39. isLoading.value = false;
  40. }
  41. });
  42. const iframeRef = ref();
  43. const isLoaded = ref(false);
  44. const renderError = ref(false);
  45. const renderSuccess = ref(false);
  46. let src = `${vaildMusicScoreUrl()}/instrument/?v=${+new Date()}&showGuide=true&showWebGuide=false&platform=pc&zoom=1.2&modelType=practise&id=${
  47. props.music.content
  48. }&Authorization=${userStore.getToken}&imagePos=${props.imagePos}`;
  49. if (props.instrumentId) {
  50. src += `&instrumentId=${props.instrumentId}`;
  51. }
  52. const checkView = () => {
  53. fetch(src)
  54. .then(() => {
  55. renderSuccess.value = true;
  56. renderError.value = false;
  57. })
  58. .catch(() => {
  59. renderError.value = true;
  60. });
  61. };
  62. watch(
  63. () => props.music,
  64. () => {
  65. if (renderSuccess.value) return;
  66. renderError.value = false;
  67. if (props.music.display) {
  68. checkView();
  69. }
  70. }
  71. );
  72. // 去云教练完整版
  73. // const gotoAccomany = () => {
  74. // if (isLoading.value) return;
  75. // if (!browserInfo.ios) {
  76. // isLoading.value = true;
  77. // }
  78. // // const parmas = qs.stringify({
  79. // // id: props.music.content
  80. // // });
  81. // // let src = `${location.origin}/orchestra-music-score/?` + parmas
  82. // 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`;
  83. // postMessage(
  84. // {
  85. // api: 'openAccompanyWebView',
  86. // content: {
  87. // url: src,
  88. // orientation: 0,
  89. // isHideTitle: true,
  90. // statusBarTextColor: false,
  91. // isOpenLight: true
  92. // }
  93. // },
  94. // () => {
  95. // if (browserInfo.ios) {
  96. // isLoading.value = true;
  97. // }
  98. // }
  99. // );
  100. // };
  101. watch(
  102. () => props.activeModel,
  103. () => {
  104. if (iframeRef.value.contentWindow && props.activeStatus) {
  105. // console.log(
  106. // iframeRef.value.contentWindow,
  107. // props.activeModel,
  108. // 'iframeRef'
  109. // );
  110. iframeRef.value.contentWindow.postMessage(
  111. {
  112. api: 'attendClassBarStatus',
  113. hideMenu: !props.activeModel
  114. },
  115. '*'
  116. );
  117. }
  118. }
  119. );
  120. return () => (
  121. <div class={styles.musicScore}>
  122. <iframe
  123. ref={iframeRef}
  124. onLoad={(val: any) => {
  125. emit('setIframe', iframeRef.value);
  126. isLoaded.value = true;
  127. iframeDislableKeyboard(val.target);
  128. }}
  129. class={[styles.container, 'musicIframe']}
  130. frameborder="0"
  131. src={src}></iframe>
  132. {/* {isLoaded.value && (
  133. <div class={styles.skeletonWrap}>
  134. <div>
  135. <NSkeleton text repeat={8} />
  136. </div>
  137. </div>
  138. )} */}
  139. </div>
  140. );
  141. }
  142. });