liveroomEdit.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <avue-form :option="option" v-model="form" @submit="onSubmit" />
  3. </template>
  4. <script lang="ts">
  5. import Vue from 'vue'
  6. import formOption from "@/avue/form/liveroominfo"
  7. import { isInteger } from 'lodash'
  8. import httpx from '@/utils/httpx'
  9. import dayjs from 'dayjs'
  10. export default Vue.extend({
  11. data() {
  12. return {
  13. form: {
  14. title: "",
  15. imageShare: [""],
  16. imageCover: [""],
  17. startTime: "",
  18. videoKind: "",
  19. livePushUrl: "",
  20. livePullRtmpUrl: "",
  21. livePullHlsUrl: "",
  22. jmessageRoomId: "",
  23. replayVideoUrl: "",
  24. desc: "",
  25. summary: "",
  26. showInList: false,
  27. hours: 0,
  28. },
  29. id: 0,
  30. new: false,
  31. }
  32. },
  33. mounted() {
  34. const id_str = this.$route.params.id
  35. const id = parseInt(id_str)
  36. if (isNaN(id) || !isInteger(id)) {
  37. if (id_str === "new") {
  38. this.new = true
  39. } else {
  40. this.notFound()
  41. }
  42. } else {
  43. this.new = false
  44. this.id = id
  45. this.getRoomInfo(id)
  46. }
  47. },
  48. computed: {
  49. option() {
  50. //@ts-ignore
  51. return formOption(this.new)
  52. }
  53. },
  54. methods: {
  55. getRoomInfo(id?: number) {
  56. id = id || this.id
  57. return httpx.post("/rooms/getRoom", { id }).then(({ data }) => {
  58. const roominfo = data.roomInfo
  59. this.form = {
  60. title: roominfo.title,
  61. imageShare: [roominfo.imageShare],
  62. imageCover: [roominfo.imageCover],
  63. startTime: roominfo.startTime,
  64. videoKind: roominfo.videoKind,
  65. livePushUrl: roominfo.livePushUrl,
  66. livePullHlsUrl: roominfo.livePullHlsUrl,
  67. livePullRtmpUrl: roominfo.livePullRtmpUrl,
  68. jmessageRoomId: roominfo.jmessageRoomId,
  69. replayVideoUrl: roominfo.replayVideoUrl,
  70. desc: roominfo.desc,
  71. summary: roominfo.summary,
  72. showInList: roominfo.showInList,
  73. hours: roominfo.hours,
  74. }
  75. }).catch(this.notFound)
  76. },
  77. onSubmit(form: any, done: Function) {
  78. const path = this.new ? "/rooms/addLiveRoom" : "/rooms/updateRoom"
  79. const postdata = {
  80. id: this.new ? undefined : this.id,
  81. adminId: this.new ? 0 : undefined,
  82. viewCount: this.new ? 0 : undefined,
  83. hours: 0,
  84. title: form.title,
  85. imageShare: form.imageShare[0] || "",
  86. imageCover: form.imageCover[0] || "",
  87. startTime: dayjs(form.startTime).format("YYYY-MM-DD HH:mm:ss"),
  88. livePushUrl: form.livePushUrl,
  89. livePullHlsUrl: form.livePullHlsUrl,
  90. livePullRtmpUrl: form.livePullRtmpUrl,
  91. jmessageRoomId: form.jmessageRoomId,
  92. replayVideoUrl: form.replayVideoUrl,
  93. videoKind: form.videoKind,
  94. desc: form.desc,
  95. summary: form.summary,
  96. showInList: form.showInList,
  97. }
  98. httpx.post(path, postdata).then((data) => {
  99. console.log(data)
  100. this.$message({
  101. message: '操作成功',
  102. type: 'success',
  103. duration: 1500
  104. })
  105. this.$router.back()
  106. })
  107. done()
  108. },
  109. notFound() {
  110. this.$router.replace("/404")
  111. }
  112. }
  113. })
  114. </script>