header.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { defineComponent } from 'vue'
  2. import { ElButton, ElMessageBox } from 'element-plus'
  3. import runtime, * as RuntimeUtils from './runtime'
  4. import { state } from '/src/state'
  5. import request from '/src/helpers/request'
  6. import styles from './header.module.less'
  7. export default defineComponent({
  8. name: 'LiveBroadcastHeader',
  9. methods: {
  10. async startLive() {
  11. try {
  12. await ElMessageBox.confirm('是否确认开始直播?', '提示', {
  13. confirmButtonText: '确定',
  14. cancelButtonText: '取消',
  15. type: 'warning',
  16. })
  17. await RuntimeUtils.startLive()
  18. } catch (error) {}
  19. },
  20. async closeLive() {
  21. try {
  22. await ElMessageBox.confirm('是否确认结束直播?', '提示', {
  23. confirmButtonText: '确定',
  24. cancelButtonText: '取消',
  25. type: 'warning',
  26. })
  27. await request.post('/api-im/user/statusImUser', {
  28. data: {
  29. os: 'IOS',
  30. status: '2',
  31. userid: state.user?.id
  32. }
  33. })
  34. await RuntimeUtils.closeLive()
  35. } catch (error) {}
  36. }
  37. },
  38. render() {
  39. return (
  40. <div class={styles.header}>
  41. <h3 class={styles.title}>直播内容:{ state.user?.liveRemark }</h3>
  42. {runtime.videoStatus === 'liveing' ? (
  43. <ElButton type="danger" color="#EA4132" onClick={this.closeLive}>关闭直播</ElButton>
  44. ) : (
  45. <ElButton type="primary" color="#01A79E" onClick={this.startLive}>开始直播</ElButton>
  46. )}
  47. </div>
  48. )
  49. }
  50. })