share-item.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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智能陪练VIP!推荐给你~'
  53. } else if (this.shareType === 'album') {
  54. return '精选曲目专辑!推荐给你~'
  55. } else {
  56. return '这个课程挺不错!推荐给你~'
  57. }
  58. }
  59. },
  60. mounted() {
  61. // alert(state.user.data.headUrl)
  62. // this.heardUrl =
  63. // state.user.data.headUrl +
  64. // '@base@tag=imgscale&m=0&w=100&et=1&eth=100&etw=100&etc=ccc'
  65. // this.heardUrl = state.user.data.heardUrl + '@base@tag=imgScale&p=25'
  66. this.heardUrl =
  67. state.user.data.heardUrl + '@base@tag=imgScale&h=80&w=80&m=1'
  68. // '@base@tag=imgscale&m=0&w=80&et=1&eth=100&etw=100&etc=cccccc'
  69. // ?time= +
  70. // new Date().valueOf()
  71. // console.log(this.heardUrl, 'heardUrl')
  72. },
  73. render() {
  74. return (
  75. <div
  76. id={this.id}
  77. class={[
  78. styles.shareSection,
  79. styles.shareContainer,
  80. styles[this.shareType],
  81. styles[this.showType]
  82. ]}
  83. >
  84. <div class={styles.shareContent}>
  85. {this.$slots.default && this.$slots.default()}
  86. </div>
  87. <Cell
  88. center
  89. border={false}
  90. class={styles.shareTeacher}
  91. v-slots={{
  92. icon: () => (
  93. <div class={styles.teacherImg}>
  94. <img
  95. src={state.user.data.heardUrl ? this.heardUrl : iconTeacher}
  96. class={styles.img}
  97. style={{ objectFit: 'cover' }}
  98. crossorigin="anonymous"
  99. />
  100. <img
  101. class={styles.recommend}
  102. src={getAssetsHomeFile('recommend.png')}
  103. />
  104. </div>
  105. ),
  106. title: () => (
  107. <div>
  108. <p class={styles.name}>{this.getString}</p>
  109. <p class={styles.titleTips}>
  110. <span>{state.user.data.username}</span>
  111. {state.platformType == 'TEACHER'
  112. ? ' 酷乐秀入驻老师'
  113. : ' 为您推荐'}
  114. </p>
  115. </div>
  116. )
  117. }}
  118. />
  119. <CodeDownload shareUrl={this.shareUrl} />
  120. </div>
  121. )
  122. }
  123. })