musicScore.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { defineComponent, ref, watch } from 'vue';
  2. import styles from './musicScore.module.less';
  3. import qs from 'query-string';
  4. import iconStart from '../image/icon-start.svg';
  5. import { listenerMessage, postMessage } from '@/helpers/native-message';
  6. import { Skeleton } from 'vant';
  7. import { usePageVisibility } from '@vant/use';
  8. import { useRoute } from 'vue-router';
  9. import { browser } from '@/helpers/utils';
  10. import { state } from '@/state';
  11. export default defineComponent({
  12. name: 'musicScore',
  13. props: {
  14. music: {
  15. type: Object,
  16. default: () => ({})
  17. },
  18. activeModel: {
  19. type: Boolean
  20. }
  21. },
  22. emits: ['setIframe'],
  23. setup(props, { emit }) {
  24. const browserInfo = browser();
  25. const route = useRoute();
  26. const isLoading = ref(false);
  27. const pageVisibility = usePageVisibility();
  28. /** 页面显示和隐藏 */
  29. watch(pageVisibility, value => {
  30. console.log('🚀 ~ value:', value);
  31. if (value == 'hidden') {
  32. isLoading.value = false;
  33. }
  34. });
  35. const iframeRef = ref();
  36. const isLoaded = ref(false);
  37. const renderError = ref(false);
  38. const renderSuccess = ref(false);
  39. const Authorization = sessionStorage.getItem('Authorization') || '';
  40. // const origin = /(localhost|192)/.test(location.host)
  41. // ? 'https://test.gym.lexiaoya.cn'
  42. // : location.origin;
  43. // const src = `${origin}/${
  44. // state.platformType === 'TEACHER' ? 'accompany-teacher' : 'accompany'
  45. // }/?Authorization=${Authorization}&liveConfig=1#/detail/${
  46. // props.music.content
  47. // }?isHideBack=true`;
  48. const origin = /(localhost|192)/.test(location.host)
  49. ? 'https://test.gym.lexiaoya.cn/'
  50. : location.origin;
  51. const src = `${origin}/gym-music-score/?id=${props.music.content}&hideMode=1&Authorization=${Authorization}&isHideBack=true&isHideMusicList=true&systemType=${ state.platformType === 'TEACHER' ? 'teacher' : 'student'}`
  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(props.music, () => {
  63. if (renderSuccess.value) return;
  64. renderError.value = false;
  65. if (props.music.display) {
  66. checkView();
  67. }
  68. });
  69. // 去云练习完整版
  70. const gotoAccomany = () => {
  71. if (isLoading.value) return;
  72. if (!browserInfo.ios) {
  73. isLoading.value = true;
  74. }
  75. const origin = /(localhost|192)/.test(location.host)
  76. ? 'https://test.gym.lexiaoya.cn'
  77. : location.origin;
  78. const src = `${origin}/accompany/?Authorization=${Authorization}#/detail/${props.music.content}?isHideBack=true`;
  79. postMessage(
  80. {
  81. api: 'openAccompanyWebView',
  82. content: {
  83. url: src,
  84. orientation: 0,
  85. isHideTitle: true,
  86. statusBarTextColor: false,
  87. isOpenLight: true
  88. }
  89. },
  90. () => {
  91. if (browserInfo.ios) {
  92. isLoading.value = true;
  93. }
  94. }
  95. );
  96. };
  97. listenerMessage('webViewOnResume', () => {
  98. isLoading.value = false;
  99. });
  100. return () => (
  101. <div class={styles.musicScore}>
  102. <iframe
  103. ref={iframeRef}
  104. onLoad={() => {
  105. emit('setIframe', iframeRef.value);
  106. isLoaded.value = true;
  107. }}
  108. class={[styles.container, 'musicIframe']}
  109. frameborder="0"
  110. src={src}></iframe>
  111. {/* {route.query.source == 'my-course' && isLoaded.value && (
  112. <div
  113. style={{
  114. display: props.activeModel ? '' : 'none'
  115. }}
  116. class={styles.startBtn}
  117. onClick={(e: Event) => {
  118. e.stopPropagation();
  119. gotoAccomany();
  120. }}>
  121. <img src={iconStart} />
  122. </div>
  123. )} */}
  124. <div class={styles.skeletonWrap}>
  125. <Skeleton class={styles.skeleton} row={8} />
  126. </div>
  127. </div>
  128. );
  129. }
  130. });