share-item.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import { Cell } from 'vant'
  2. import { defineComponent, PropType } from 'vue'
  3. import styles from './index.module.less'
  4. // import QrCodeVue from 'qrcode.vue'
  5. // import { toPng } from 'html-to-image'
  6. import iconTeacher from '@/common/images/icon_teacher.png'
  7. import { state } from '@/state'
  8. import CodeDownload from './code-down-load'
  9. export const getAssetsHomeFile = (fileName: string) => {
  10. const path = `./images/${fileName}`
  11. const modules = import.meta.globEager('./images/*')
  12. return modules[path].default
  13. }
  14. export default defineComponent({
  15. name: 'share-item',
  16. props: {
  17. id: {
  18. type: String
  19. },
  20. teacherId: {
  21. type: Number
  22. },
  23. shareUrl: {
  24. type: String,
  25. default: ''
  26. },
  27. showType: {
  28. // 显示背景图
  29. type: String as PropType<'' | 'yellow' | 'pink' | 'defult'>,
  30. default: 'default'
  31. },
  32. shareType: {
  33. // 分享类型
  34. type: String as PropType<
  35. '' | 'video' | 'music' | 'live' | 'mall' | 'vip' | 'album'
  36. >,
  37. default: ''
  38. }
  39. },
  40. data() {
  41. return {
  42. heardUrl: null as any
  43. }
  44. },
  45. computed: {
  46. getString() {
  47. if (this.shareType === 'music') {
  48. return '这首曲目挺不错!推荐给你~'
  49. } else if (this.shareType === 'mall') {
  50. return '这件商品挺不错!推荐给你~'
  51. } else if (this.shareType === 'vip') {
  52. return '小酷Ai智能陪练!推荐给你~'
  53. } else if (this.shareType === 'album') {
  54. return '更多曲目扫码下载酷乐秀查看'
  55. } else {
  56. return '这个课程挺不错!推荐给你~'
  57. }
  58. }
  59. },
  60. mounted() {
  61. this.heardUrl = state.user.data.heardUrl + '?t=' + +new Date()
  62. },
  63. render() {
  64. return (
  65. <div
  66. id={this.id}
  67. class={[
  68. styles.shareSection,
  69. styles.shareContainer,
  70. styles[this.shareType],
  71. styles[this.showType]
  72. ]}
  73. >
  74. <div class={styles.shareContent}>
  75. {this.$slots.default && this.$slots.default()}
  76. </div>
  77. <Cell
  78. center
  79. border={false}
  80. class={[styles.shareTeacher, 'shareTeacherCustom']}
  81. v-slots={{
  82. icon: () => (
  83. <div class={styles.teacherImg}>
  84. <img
  85. src={state.user.data.heardUrl ? this.heardUrl : iconTeacher}
  86. class={styles.img}
  87. style={{ objectFit: 'cover' }}
  88. crossorigin="anonymous"
  89. />
  90. {state.platformType == 'TEACHER' && (
  91. <img
  92. class={styles.recommend}
  93. src={getAssetsHomeFile('recommend.png')}
  94. />
  95. )}
  96. </div>
  97. ),
  98. title: () => (
  99. <div>
  100. <p class={styles.name}>{this.getString}</p>
  101. <p class={styles.titleTips}>
  102. <span>{state.user.data.username}</span>
  103. {state.platformType == 'TEACHER'
  104. ? ' 酷乐秀入驻老师'
  105. : ' 为您推荐'}
  106. </p>
  107. </div>
  108. )
  109. }}
  110. />
  111. <CodeDownload shareUrl={this.shareUrl} />
  112. </div>
  113. )
  114. }
  115. })