index.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { Cell, Toast } from 'vant'
  2. import { defineComponent } from 'vue'
  3. import styles from './index.module.less'
  4. import { postMessage } from '@/helpers/native-message'
  5. import QrCodeVue from 'qrcode.vue'
  6. import { toPng } from 'html-to-image'
  7. import iconTeacher from '@/common/images/icon_teacher.png'
  8. import logo from '../../images/logo.png'
  9. import { state } from '@/state'
  10. export default defineComponent({
  11. name: 'share',
  12. props: {
  13. teacherId: {
  14. type: Number
  15. }
  16. },
  17. data() {
  18. return {
  19. qrCode: '',
  20. image: null as any
  21. }
  22. },
  23. mounted() {
  24. this.qrCode =
  25. location.origin + '/student/#/inviteTeacher?id=' + this.teacherId
  26. this.$nextTick(async () => {
  27. const container: any = document.getElementById('share-preview-container')
  28. let image = await toPng(container)
  29. image = await toPng(container)
  30. this.image = image
  31. })
  32. },
  33. methods: {
  34. async shareShow() {
  35. let image = this.image
  36. if (image) {
  37. postMessage(
  38. {
  39. api: 'shareAchievements',
  40. content: {
  41. title: '我在管乐迷使用AI智能云教练练习乐器',
  42. desc: '管乐迷AI智能云教练帮助我自主练习乐器,真的太好用啦!每天都要坚持练习哦~',
  43. image,
  44. video: '',
  45. type: 'image'
  46. }
  47. },
  48. (res: any) => {
  49. if (res && res.content) {
  50. Toast(
  51. res.content.message ||
  52. (res.content.status ? '分享成功' : '分享失败')
  53. )
  54. }
  55. }
  56. )
  57. }
  58. }
  59. },
  60. render() {
  61. return (
  62. <>
  63. <div
  64. class={styles.continue}
  65. onClick={() => {
  66. this.shareShow()
  67. }}
  68. >
  69. 分享
  70. </div>
  71. <div class={styles.shareSection} id="share-preview-container">
  72. <div class={styles.section}>
  73. <Cell
  74. center
  75. border={false}
  76. style={{ padding: 0 }}
  77. v-slots={{
  78. icon: () => (
  79. <img
  80. src={state.user.data.heardUrl || iconTeacher}
  81. class={styles.img}
  82. crossorigin="anonymous"
  83. />
  84. ),
  85. title: () => (
  86. <div>
  87. <p class={styles.name}>{state.user.data.username}</p>
  88. <p class={styles.titleTips}>酷乐秀入驻老师</p>
  89. </div>
  90. )
  91. }}
  92. />
  93. <p class={[styles.txt, styles.teacherName]}>
  94. <span>{state.user.data.username}</span>邀请您加入酷乐秀
  95. </p>
  96. <p class={styles.txt}>来与我一起踏入音乐殿堂吧!</p>
  97. </div>
  98. <div class={[styles.section, styles.download]}>
  99. <div class={styles.logo}>
  100. <img src={logo} />
  101. <p>扫码下载酷乐秀开启教学之旅</p>
  102. </div>
  103. <div class={styles.qrcode}>
  104. <QrCodeVue
  105. value={this.qrCode}
  106. style={{ width: '100%', height: '100%' }}
  107. />
  108. </div>
  109. </div>
  110. </div>
  111. </>
  112. )
  113. }
  114. })