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<'' | 'video' | 'music' | 'live' | 'mall'>,
  35. default: ''
  36. }
  37. },
  38. data() {
  39. return {
  40. heardUrl: null as any
  41. }
  42. },
  43. computed: {
  44. getString() {
  45. if (this.shareType === 'music') {
  46. return '这首曲目挺不错!推荐给你~'
  47. } else if (this.shareType === 'mall') {
  48. return '这件商品挺不错!推荐给你~'
  49. } else {
  50. return '这个课程挺不错!推荐给你~'
  51. }
  52. }
  53. },
  54. mounted() {
  55. // alert(state.user.data.headUrl)
  56. // this.heardUrl =
  57. // state.user.data.headUrl +
  58. // '@base@tag=imgscale&m=0&w=100&et=1&eth=100&etw=100&etc=ccc'
  59. // this.heardUrl = state.user.data.heardUrl + '@base@tag=imgScale&p=25'
  60. this.heardUrl =
  61. state.user.data.heardUrl + '@base@tag=imgScale&h=80&w=80&m=1'
  62. // '@base@tag=imgscale&m=0&w=80&et=1&eth=100&etw=100&etc=cccccc'
  63. // ?time= +
  64. // new Date().valueOf()
  65. console.log(this.heardUrl, 'heardUrl')
  66. },
  67. render() {
  68. return (
  69. <div
  70. id={this.id}
  71. class={[
  72. styles.shareSection,
  73. styles.shareContainer,
  74. styles[this.shareType],
  75. styles[this.showType]
  76. ]}
  77. >
  78. <div class={styles.shareContent}>
  79. {this.$slots.default && this.$slots.default()}
  80. </div>
  81. <Cell
  82. center
  83. border={false}
  84. class={styles.shareTeacher}
  85. v-slots={{
  86. icon: () => (
  87. <div class={styles.teacherImg}>
  88. <img
  89. src={state.user.data.heardUrl ? this.heardUrl : iconTeacher}
  90. class={styles.img}
  91. style={{ objectFit: 'cover' }}
  92. crossorigin="anonymous"
  93. />
  94. <img
  95. class={styles.recommend}
  96. src={getAssetsHomeFile('recommend.png')}
  97. />
  98. </div>
  99. ),
  100. title: () => (
  101. <div>
  102. <p class={styles.name}>{this.getString}</p>
  103. <p class={styles.titleTips}>
  104. <span>{state.user.data.username}</span>
  105. 酷乐秀入驻老师
  106. </p>
  107. </div>
  108. )
  109. }}
  110. />
  111. <CodeDownload shareUrl={this.shareUrl} />
  112. </div>
  113. )
  114. }
  115. })