musicScore.tsx 4.4 KB

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