modeView.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { defineComponent, onMounted, watch, reactive, ref, nextTick } from "vue";
  2. import styles from "./index.module.less";
  3. import backImg from "./image/back.png";
  4. import nameImg from "./image/zt.png";
  5. import lxMode from "./image/lxMode.json";
  6. import glMode from "./image/glMode.json";
  7. import pcMode from "./image/pcMode.json";
  8. import { headTopData } from "./index";
  9. import TheVip from "../custom-plugins/the-vip";
  10. import { getQuery } from "/src/utils/queryString";
  11. import { storeData } from "/src/store";
  12. import state from "/src/state";
  13. import { studentQueryUserInfo } from "../api";
  14. import { usePageVisibility } from "@vant/use";
  15. import { Vue3Lottie } from "vue3-lottie";
  16. import { popImgs, hanldeConfirmPop, hanldeClosePop, evaluatingData } from "/src/view/evaluating"
  17. import { Popup } from "vant";
  18. import AbnormalPop from "/src/view/abnormal-pop";
  19. export default defineComponent({
  20. name: "modeView",
  21. setup() {
  22. const query = getQuery();
  23. const data = reactive({
  24. showPC: false,
  25. showStudent: false,
  26. showVip: false,
  27. });
  28. const modeImgDom1 = ref();
  29. const modeImgDom2 = ref();
  30. const modeImgDom3 = ref();
  31. const openGuid = () => {
  32. // 加载后 判断 端口号 加载对应的引导
  33. if (storeData.platformType !== "STUDENT" || storeData.user.clientType !== "STUDENT") {
  34. // PC
  35. data.showPC = true;
  36. } else {
  37. // 从课堂乐器学生端课件预览默认不显示会员
  38. if (storeData.user.vipMember || state.paymentType === "FREE" || query.showCourseMember === "true") {
  39. // 学生端
  40. data.showStudent = true;
  41. } else {
  42. // vip
  43. data.showVip = true;
  44. state.isVip = true;
  45. }
  46. }
  47. };
  48. const getUserInfo = async () => {
  49. const res = await studentQueryUserInfo();
  50. const student = res?.data || {};
  51. storeData.user.vipMember = student.vipMember;
  52. // console.log("🚀 ~ student:", student);
  53. if (storeData.user.vipMember) {
  54. data.showVip = false;
  55. state.isVip = false;
  56. openGuid();
  57. }
  58. };
  59. const pageVisible = usePageVisibility();
  60. watch(
  61. () => pageVisible.value,
  62. (val) => {
  63. if (val === "visible") {
  64. if (storeData.user.vipMember) return;
  65. console.log("页面显示");
  66. getUserInfo();
  67. }
  68. }
  69. );
  70. watch(
  71. () => headTopData.modeType,
  72. (value, oldValue) => {
  73. // headTopData.modeType 值 刚开始是 "" 所以 第一次切换时候不触发播放动画
  74. if (!oldValue) return;
  75. nextTick(() => {
  76. if (value === "show") {
  77. modeImgDom1.value?.pause();
  78. modeImgDom2.value?.pause();
  79. modeImgDom3.value?.pause();
  80. } else if (value === "init") {
  81. modeImgDom1.value?.play();
  82. modeImgDom2.value?.play();
  83. modeImgDom3.value?.play();
  84. }
  85. });
  86. }
  87. );
  88. onMounted(() => {
  89. openGuid();
  90. });
  91. watch(
  92. () => evaluatingData.socketErrorStatus,
  93. () => {
  94. if (evaluatingData.socketErrorStatus === 2) {
  95. setTimeout(() => {
  96. evaluatingData.socketErrorPop = false;
  97. }, 1000);
  98. }
  99. }
  100. );
  101. return () => (
  102. <div class={[styles.modeView, headTopData.modeType !== "init" && styles.hidden]}>
  103. <img
  104. src={backImg}
  105. class={styles.back}
  106. onClick={() => {
  107. headTopData.modeType = "show";
  108. }}
  109. />
  110. <img src={nameImg} class={styles.name} />
  111. <div class={[styles.modeBox, ((!state.isPercussion && !state.enableEvaluation) || (state.isPercussion && state.enableEvaluation) || (state.isPercussion && !state.enableEvaluation)) && styles.twoModeBox]}>
  112. <Vue3Lottie ref={modeImgDom1} class={styles.modeImg} animationData={lxMode} autoPlay={false} loop={true} onClick={() => headTopData.handleChangeModeType("practise")}></Vue3Lottie>
  113. {!state.isPercussion && <Vue3Lottie ref={modeImgDom2} class={styles.modeImg} animationData={glMode} autoPlay={false} loop={true} onClick={() => headTopData.handleChangeModeType("follow")}></Vue3Lottie>}
  114. {state.enableEvaluation && <Vue3Lottie ref={modeImgDom3} class={styles.modeImg} animationData={pcMode} autoPlay={false} loop={true} onClick={() => headTopData.handleChangeModeType("evaluating")}></Vue3Lottie>}
  115. </div>
  116. {data.showVip && <TheVip />}
  117. {/** 延迟检测中途,socket出错,网络提示弹窗 */}
  118. <div>
  119. <Popup teleport="body" closeOnClickOverlay={false} class={["popup-custom", "van-scale"]} transition="van-scale" v-model:show={evaluatingData.socketErrorPop}>
  120. <AbnormalPop onConfirm={hanldeConfirmPop} onClose={hanldeClosePop} />
  121. </Popup>
  122. </div>
  123. </div>
  124. );
  125. },
  126. });