musicScore.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // const origin = /(localhost|192)/.test(location.host)
  47. // ? 'https://test.lexiaoya.cn/instrument'
  48. // : // 'http://localhost:3000/instrument.html'
  49. // location.origin + '/instrument';
  50. let src = `${vaildMusicScoreUrl()}/instrument/?v=${+new Date()}&showGuide=true&showWebGuide=false&platform=pc&zoom=1.2&modelType=practise&id=${
  51. props.music.content
  52. }&Authorization=${userStore.getToken}&imagePos=${props.imagePos}`;
  53. if (props.instrumentId) {
  54. src += `&instrumentId=${props.instrumentId}`;
  55. }
  56. const checkView = () => {
  57. fetch(src)
  58. .then(() => {
  59. renderSuccess.value = true;
  60. renderError.value = false;
  61. })
  62. .catch(() => {
  63. renderError.value = true;
  64. });
  65. };
  66. watch(
  67. () => props.music,
  68. () => {
  69. if (renderSuccess.value) return;
  70. renderError.value = false;
  71. if (props.music.display) {
  72. checkView();
  73. }
  74. }
  75. );
  76. // 去云教练完整版
  77. // const gotoAccomany = () => {
  78. // if (isLoading.value) return;
  79. // if (!browserInfo.ios) {
  80. // isLoading.value = true;
  81. // }
  82. // // const parmas = qs.stringify({
  83. // // id: props.music.content
  84. // // });
  85. // // let src = `${location.origin}/orchestra-music-score/?` + parmas
  86. // 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`;
  87. // postMessage(
  88. // {
  89. // api: 'openAccompanyWebView',
  90. // content: {
  91. // url: src,
  92. // orientation: 0,
  93. // isHideTitle: true,
  94. // statusBarTextColor: false,
  95. // isOpenLight: true
  96. // }
  97. // },
  98. // () => {
  99. // if (browserInfo.ios) {
  100. // isLoading.value = true;
  101. // }
  102. // }
  103. // );
  104. // };
  105. watch(
  106. () => props.activeModel,
  107. () => {
  108. if (iframeRef.value.contentWindow && props.activeStatus) {
  109. // console.log(
  110. // iframeRef.value.contentWindow,
  111. // props.activeModel,
  112. // 'iframeRef'
  113. // );
  114. iframeRef.value.contentWindow.postMessage(
  115. {
  116. api: 'attendClassBarStatus',
  117. hideMenu: !props.activeModel
  118. },
  119. '*'
  120. );
  121. }
  122. }
  123. );
  124. return () => (
  125. <div class={styles.musicScore}>
  126. <iframe
  127. ref={iframeRef}
  128. onLoad={(val: any) => {
  129. emit('setIframe', iframeRef.value);
  130. isLoaded.value = true;
  131. iframeDislableKeyboard(val.target);
  132. }}
  133. class={[styles.container, 'musicIframe']}
  134. frameborder="0"
  135. src={src}></iframe>
  136. {isLoaded.value && (
  137. <div class={styles.skeletonWrap}>
  138. <div>
  139. <NSkeleton text repeat={8} />
  140. </div>
  141. </div>
  142. )}
  143. </div>
  144. );
  145. }
  146. });