teacher-header.tsx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. import { Button, Cell, Icon, Image, Popup, Rate, Toast } from 'vant'
  2. import { defineComponent } from 'vue'
  3. import styles from './teacher-header.module.less'
  4. import { postMessage } from '@/helpers/native-message'
  5. import iconTeacher from '@common/images/icon_teacher.png'
  6. import request from '@/helpers/request'
  7. // import IconXueli from '@common/images/icon-xueli.png'
  8. // import IconJiaozi from '@common/images/icon-jiaozi.png'
  9. // import IconChat from '../images/icon-chat.png'
  10. import iconSmallLive from '../images/icon-small-live.png'
  11. export const getAssetsHomeFile = (fileName: string) => {
  12. const path = `../images/${fileName}`
  13. const modules = import.meta.globEager('../images/*')
  14. return modules[path].default
  15. }
  16. export default defineComponent({
  17. name: 'teacher-header',
  18. props: {
  19. userInfo: {
  20. type: Object,
  21. default: () => ({})
  22. },
  23. teacherId: {
  24. type: String || Number,
  25. default: ''
  26. }
  27. },
  28. emits: ['star'],
  29. data() {
  30. return {
  31. iconShow: false
  32. }
  33. },
  34. computed: {
  35. subjectNameList() {
  36. const userInfo: any = this.userInfo
  37. const subjectName = userInfo.subjectName
  38. return subjectName ? subjectName.split(',') : []
  39. },
  40. starGrade() {
  41. const { starGrade } = this.userInfo as any
  42. return Number(starGrade) || 0
  43. }
  44. },
  45. methods: {
  46. async onStart() {
  47. // 关注与取消关注
  48. try {
  49. const star = this.userInfo.isStar ? 0 : 1
  50. await request.get('/api-student/teacher/starOrUnStar', {
  51. params: {
  52. userId: this.teacherId,
  53. starStatus: star
  54. }
  55. })
  56. // const str = star ? '关注成功' : '已取消关注'
  57. // this.userInfo.isStar = star
  58. const count = star
  59. ? this.userInfo.fansNum + 1
  60. : this.userInfo.fansNum - 1
  61. // this.userInfo.fansNum = count <= 0 ? 0 : count
  62. this.$emit('star', {
  63. isStar: star,
  64. fansNum: count <= 0 ? 0 : count
  65. })
  66. // Toast(str)
  67. } catch {
  68. //
  69. }
  70. },
  71. // 检验是否有对应徽章
  72. checkBadge(type: string) {
  73. // tag : 老师点亮图标
  74. // STYLE:个人风采
  75. // VIDEO:视频课
  76. // LIVE:直播课,
  77. // MUSIC:曲目 逗号隔开
  78. let status = false
  79. const { userInfo } = this
  80. switch (type) {
  81. case 'STYLE':
  82. case 'VIDEO':
  83. case 'LIVE':
  84. case 'MUSIC':
  85. if (userInfo.tag) {
  86. status = userInfo.tag.indexOf(type) > -1
  87. }
  88. break
  89. case 'VIP':
  90. status = userInfo.userVip?.vipType === 'VIP'
  91. break
  92. case 'SVIP':
  93. status =
  94. userInfo.userVip?.vipType === 'SVIP' ||
  95. userInfo.userVip?.vipType === 'PERMANENT_SVIP'
  96. break
  97. default:
  98. status = false
  99. break
  100. }
  101. return status
  102. },
  103. openTeacherIcon() {
  104. this.iconShow = true
  105. }
  106. },
  107. render() {
  108. const iconList = [
  109. {
  110. icon: 'cert_active.png',
  111. title: '演奏Mlog老师',
  112. des: '个人风采中上传老师风采视频并通过审核'
  113. },
  114. {
  115. icon: 'video_active.png',
  116. title: '教学视频老师',
  117. des: '发布您制作的教学视频课程并通过审核'
  118. },
  119. {
  120. icon: 'live_active.png',
  121. title: '直播up老师',
  122. des: '达到开通直播权限标准并开通直播功能'
  123. },
  124. {
  125. icon: 'music_active.png',
  126. title: '乐谱歌单老师',
  127. des: '上传您制作的乐谱并通过审核'
  128. }
  129. ]
  130. return (
  131. <>
  132. <div class={styles.headerContent}>
  133. <div class={styles.headerCount}>
  134. <div class={styles.teacherContent}>
  135. <div
  136. class={styles.teacherIcon}
  137. onClick={() => {
  138. // 判断是否在直播中
  139. if (this.userInfo.liveing === 1) {
  140. postMessage({
  141. api: 'joinLiveRoom',
  142. content: {
  143. roomId: this.userInfo.roomUid,
  144. teacherId: this.userInfo.userId
  145. }
  146. })
  147. }
  148. }}
  149. >
  150. {/* iy */}
  151. <Image
  152. class={[
  153. styles.avatar,
  154. (this.checkBadge('SVIP') || this.checkBadge('VIP')) &&
  155. styles.avatarActive
  156. ]}
  157. round
  158. src={this.userInfo.heardUrl || iconTeacher}
  159. fit="cover"
  160. />
  161. {this.userInfo.liveing === 1 && (
  162. <img src={iconSmallLive} class={styles.liveTag} />
  163. )}
  164. {(this.checkBadge('SVIP') || this.checkBadge('VIP')) && (
  165. <Image
  166. class={styles.teacherIconVip}
  167. src={
  168. this.checkBadge('SVIP')
  169. ? getAssetsHomeFile('svip_active.png')
  170. : this.checkBadge('VIP')
  171. ? getAssetsHomeFile('vip_active.png')
  172. : ''
  173. }
  174. />
  175. )}
  176. </div>
  177. <div class={styles.teacherUs}>
  178. <div class={styles.teacherInfo}>
  179. <div class={styles.teacherInfoName}>
  180. {this.userInfo.username ||
  181. `游客${this.userInfo.userId || ''}`}
  182. </div>
  183. <div class={styles.teacherHonor}>
  184. <div class={styles.level}>
  185. {this.starGrade ? (
  186. <Rate
  187. readonly
  188. modelValue={this.starGrade}
  189. iconPrefix="iconfont"
  190. color="#FFC459"
  191. void-icon="star_default"
  192. icon="star_active"
  193. size={15}
  194. />
  195. ) : (
  196. ''
  197. )}
  198. </div>
  199. </div>
  200. </div>
  201. <div class={styles['teacher-bottom']}>
  202. <img src={getAssetsHomeFile('icon-cert.png')} class={styles.iconCert} />
  203. <div class={styles['teacher-data']}>
  204. <div class={styles['teacher-data_item']}>
  205. 粉丝 <span>{this.userInfo.fansNum || 0}</span>
  206. </div>
  207. <div class={styles['teacher-data_item']}>
  208. 已上课时 <span>{this.userInfo.expTime || 0}</span>
  209. </div>
  210. </div>
  211. </div>
  212. </div>
  213. </div>
  214. <div class={styles.piNameSubject}>
  215. <Image
  216. class={styles.subjectSection}
  217. src={getAssetsHomeFile('icon_subject1.png')}
  218. fit="contain"
  219. />
  220. <div class={styles.subjectList}>
  221. {this.subjectNameList.map((item: any) => (
  222. <span class={styles.subject}>{item}</span>
  223. ))}
  224. </div>
  225. </div>
  226. <div class={styles.teacherOperation}>
  227. <Button
  228. type="primary"
  229. size="small"
  230. class={[styles.btn, !this.userInfo.isStar && styles.btnStar]}
  231. onClick={this.onStart}
  232. >
  233. {!this.userInfo.isStar ? <img src={getAssetsHomeFile('icon-add.png')} /> : <img src={getAssetsHomeFile('icon-add-star.png')} />}
  234. {/* <img src={getAssetsHomeFile('icon-add.png')} /> */}
  235. {this.userInfo.isStar ? '已关注' : '关注'}
  236. </Button>
  237. <Button
  238. type="primary"
  239. size="small"
  240. class={styles.btn}
  241. onClick={() => {
  242. postMessage({
  243. api: 'joinChatGroup',
  244. content: {
  245. type: 'single', // single 单人 multi 多人
  246. id: this.userInfo.imUserId
  247. // id: this.teacherId
  248. }
  249. })
  250. }}
  251. >
  252. <img src={getAssetsHomeFile('icon-message.png')} />
  253. 聊天
  254. </Button>
  255. </div>
  256. </div>
  257. </div>
  258. {/* <Popup class={styles['teaherPopup']} v-model:show={this.iconShow}>
  259. <Image src={getAssetsHomeFile('teacher-icon.png')} />
  260. <div class={styles.teacherIconWrap}>
  261. {iconList.map(n => {
  262. return (
  263. <div class={styles.teacherIconItem}>
  264. <div class={styles.teacherIconItemTop}>
  265. <Image src={getAssetsHomeFile(n.icon)} />
  266. <div class={styles.teacherIconTitle}>{n.title}</div>
  267. </div>
  268. <div class={styles.teacherIconDes}>{n.des}</div>
  269. </div>
  270. )
  271. })}
  272. </div>
  273. <Image
  274. onClick={() => (this.iconShow = false)}
  275. class={styles.closeIcon}
  276. src={getAssetsHomeFile('icon-close.png')}
  277. />
  278. </Popup> */}
  279. </>
  280. )
  281. }
  282. })