index.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { Button, Cell, Icon, Image, Toast } from 'vant'
  2. import styles from './index.module.less'
  3. import { defineComponent } from 'vue'
  4. import request from '@/helpers/request'
  5. import bars from '@common/svg/bars.svg'
  6. import TheTitle from '../the-title'
  7. export default defineComponent({
  8. name: 'recommend-sage',
  9. props: {
  10. title: {
  11. type: String,
  12. default: '推荐达人'
  13. },
  14. sage: {
  15. type: Array,
  16. default: () => {
  17. return []
  18. }
  19. }
  20. },
  21. setup(props) {
  22. const onStart = async (item: any) => {
  23. // 关注与取消关注
  24. try {
  25. await request.get('/api-student/teacher/starOrUnStar', {
  26. params: {
  27. userId: item.userId,
  28. starStatus: 1
  29. }
  30. })
  31. setTimeout(() => {
  32. Toast('关注成功')
  33. item.watch = true
  34. }, 100)
  35. } catch {
  36. //
  37. }
  38. }
  39. return () => (
  40. <>
  41. {props.sage.length > 0 && <TheTitle title={props.title} />}
  42. <div class={styles.sageContainer}>
  43. {props.sage.map((item: any) => (
  44. <div class={styles.sage} key={item.id} onClick={() => {}}>
  45. {item.living && <Image src={bars} class={styles.animation} />}
  46. <div class={styles.header}>
  47. <Image class={styles.img} src={item.avatar} fit="cover" />
  48. {item.living && <span class={styles.living}>直播中</span>}
  49. </div>
  50. <p class={styles.username}>{item.username}</p>
  51. <p class={styles.cert}>认证达人</p>
  52. <Button
  53. round
  54. size="mini"
  55. class={styles.btn}
  56. type={item.watch ? 'default' : 'primary'}
  57. disabled={item.watch}
  58. onClick={() => {
  59. onStart(item)
  60. }}
  61. >
  62. {item.watch ? '已关注' : '关注'}
  63. </Button>
  64. </div>
  65. ))}
  66. </div>
  67. </>
  68. )
  69. }
  70. })