index.tsx 3.6 KB

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