index.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { defineComponent, reactive, computed, onMounted, watch } from "vue"
  2. import { Button, Popup } from "vant"
  3. import state from "/src/state"
  4. import TipsIcon from "./tips.png"
  5. import styles from "./index.module.less"
  6. import dayjs from "dayjs"
  7. import { storeData } from "/src/store"
  8. import { postMessage } from "/src/utils/native-message"
  9. import { usePageVisibility } from "@vant/use"
  10. import { studentQueryUserInfo } from "/src/page-instrument/api"
  11. import { api_back } from "/src/helpers/communication";
  12. export const vipData = reactive({
  13. show: false
  14. })
  15. export const isVip = computed(() => {
  16. return dayjs().isBefore(dayjs(storeData.user?.membershipEndTime))
  17. })
  18. export default defineComponent({
  19. name: "vip-popup",
  20. setup() {
  21. const getContent = computed(() => {
  22. if (state.isHomeWork) {
  23. return "您还不是团练宝会员,请开通服务后使用该功能"
  24. } else if (state.isSchool) {
  25. return "VIP曲目暂不可用"
  26. } else {
  27. return "您尚未开通云练习服务,请联系乐团老师开通"
  28. }
  29. })
  30. onMounted(() => {
  31. if (state.isHomeWork && !isVip.value && state.paymentType === "VIP") {
  32. vipData.show = true
  33. }
  34. })
  35. function vaildMusicScoreUrl() {
  36. const url = window.location.hostname
  37. let returnUrl = ""
  38. if (/dev/.test(url) || /192.168/.test(url)) {
  39. returnUrl = "https://test.gym.lexiaoya.cn"
  40. } else if (/test/.test(url)) {
  41. // test 环境
  42. returnUrl = "https://test.gym.lexiaoya.cn"
  43. } else {
  44. returnUrl = "https://gym.lexiaoya.cn"
  45. }
  46. return returnUrl
  47. }
  48. function hanldeOpen() {
  49. if (state.isHomeWork) {
  50. postMessage({
  51. api: "openWebView",
  52. content: {
  53. url: vaildMusicScoreUrl() + `/mdaya/#/member?id=${state.examSongId}`,
  54. orientation: 1
  55. }
  56. })
  57. } else {
  58. vipData.show = false
  59. }
  60. }
  61. function handleClose() {
  62. if (state.isHomeWork) {
  63. api_back()
  64. } else {
  65. vipData.show = false
  66. }
  67. }
  68. const pageVisibility = usePageVisibility()
  69. watch(pageVisibility, value => {
  70. if (state.isHomeWork && value === "visible") {
  71. if (!isVip.value) {
  72. studentQueryUserInfo().then(res => {
  73. if (res.code === 200) {
  74. storeData.user.membershipEndTime = res?.data?.membershipEndTime
  75. if (isVip.value) {
  76. vipData.show = false
  77. }
  78. }
  79. })
  80. }
  81. }
  82. })
  83. return () => (
  84. <>
  85. <Popup zIndex={9999999} show={vipData.show} get-container="body" closeable onClickCloseIcon={handleClose} round>
  86. <div class={styles.vip}>
  87. <img src={TipsIcon} />
  88. <p>{getContent.value}</p>
  89. <Button class={styles.btn} round color="#01C1B5" onClick={hanldeOpen}>
  90. {state.isHomeWork ? "开通" : " 确定"}
  91. </Button>
  92. </div>
  93. </Popup>
  94. </>
  95. )
  96. }
  97. })