musicScore.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { defineComponent, 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. emits: ['setIframe'],
  18. setup(props, { emit }) {
  19. const userStore = useUserStore();
  20. const isLoading = ref(false);
  21. const pageVisibility = usePageVisibility();
  22. /** 页面显示和隐藏 */
  23. watch(pageVisibility, value => {
  24. console.log('🚀 ~ value:', value);
  25. if (value == 'hidden') {
  26. isLoading.value = false;
  27. }
  28. });
  29. const iframeRef = ref();
  30. const isLoaded = ref(false);
  31. const renderError = ref(false);
  32. const renderSuccess = ref(false);
  33. const origin = /(localhost|192)/.test(location.host)
  34. ? 'https://dev.kt.colexiu.com'
  35. : location.origin;
  36. const src = `${origin}/instrument?platform=pc&zoom=1.2&modelType=practise&id=${props.music.content}&Authorization=${userStore.getToken}`;
  37. const checkView = () => {
  38. fetch(src)
  39. .then(() => {
  40. renderSuccess.value = true;
  41. renderError.value = false;
  42. })
  43. .catch(() => {
  44. renderError.value = true;
  45. });
  46. };
  47. watch(props.music, () => {
  48. if (renderSuccess.value) return;
  49. renderError.value = false;
  50. if (props.music.display) {
  51. checkView();
  52. }
  53. });
  54. // 去云教练完整版
  55. // const gotoAccomany = () => {
  56. // if (isLoading.value) return;
  57. // if (!browserInfo.ios) {
  58. // isLoading.value = true;
  59. // }
  60. // // const parmas = qs.stringify({
  61. // // id: props.music.content
  62. // // });
  63. // // let src = `${location.origin}/orchestra-music-score/?` + parmas
  64. // 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`;
  65. // postMessage(
  66. // {
  67. // api: 'openAccompanyWebView',
  68. // content: {
  69. // url: src,
  70. // orientation: 0,
  71. // isHideTitle: true,
  72. // statusBarTextColor: false,
  73. // isOpenLight: true
  74. // }
  75. // },
  76. // () => {
  77. // if (browserInfo.ios) {
  78. // isLoading.value = true;
  79. // }
  80. // }
  81. // );
  82. // };
  83. return () => (
  84. <div class={styles.musicScore}>
  85. <iframe
  86. ref={iframeRef}
  87. onLoad={() => {
  88. emit('setIframe', iframeRef.value);
  89. isLoaded.value = true;
  90. }}
  91. class={[styles.container, 'musicIframe']}
  92. frameborder="0"
  93. src={src}></iframe>
  94. {isLoaded.value && (
  95. <div class={styles.skeletonWrap}>
  96. <div>
  97. <NSkeleton text repeat={8} />
  98. </div>
  99. </div>
  100. )}
  101. </div>
  102. );
  103. }
  104. });