index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <a-spin :spinning="state.loading" >
  3. <a-card
  4. style="min-height: 600px;"
  5. >
  6. <a-row justify="space-between" style="margin-bottom: 20px;" >
  7. <a-col span="12" >
  8. <a-select placeholder="请选择协议" v-model:value="state.name" style="width: 170px;" >
  9. <a-select-option
  10. v-for="item in protocolList"
  11. :key="item"
  12. >
  13. {{item}}
  14. </a-select-option>
  15. </a-select>
  16. </a-col>
  17. <a-col >
  18. <a-space>
  19. <a-button type="primary" @click="saveProtocol"> 保存 </a-button>
  20. <a-button type="primary" @click="reloadProtocol"> 更新 </a-button>
  21. </a-space>
  22. </a-col>
  23. </a-row>
  24. <code-mirror-tsx
  25. :key="state.name"
  26. v-if="state.bodyJson"
  27. :body-json="state.bodyJson"
  28. body-type="json"
  29. ref="codeMirrorRef"
  30. />
  31. <a-empty style="margin-top: 200px;" v-else :image="Empty.PRESENTED_IMAGE_SIMPLE" description="请在左上角选择协议"/>
  32. </a-card>
  33. </a-spin>
  34. </template>
  35. <script lang="ts" setup >
  36. import { RtsController } from '@/controller/rts'
  37. import { onMounted, reactive, ref, watch } from 'vue'
  38. import { CodeMirrorTsx } from '@/components/CodeMirror/index'
  39. import { useScheduler } from '@/hooks'
  40. import { Empty } from 'ant-design-vue'
  41. const protocolList = ['RTSP', 'RTMP', 'HLS', 'HDL', 'GB28181']
  42. const codeMirrorRef = ref()
  43. const state = reactive<{
  44. name: RTS.protocol | '',
  45. bodyJson: string
  46. loading: boolean
  47. }>({
  48. name: 'RTSP',
  49. bodyJson: '',
  50. loading: false
  51. })
  52. watch(
  53. () => state.name,
  54. () => getProtocol()
  55. )
  56. const { start, stop } = useScheduler(() => state.loading = false, 2000)
  57. const reloadProtocol = async () => {
  58. await RtsController.updateProtocol(state.name as RTS.protocol)
  59. }
  60. const saveProtocol = async () => {
  61. await RtsController.postProtocol(state.name as RTS.protocol, codeMirrorRef.value.getValue())
  62. }
  63. const getProtocol = async () => {
  64. state.loading = true
  65. const { data } = await RtsController.protocol(state.name as RTS.protocol)
  66. start()
  67. state.bodyJson = JSON.stringify(data)
  68. }
  69. onMounted(() => {
  70. getProtocol()
  71. })
  72. </script>
  73. <style lang="less" scoped >
  74. </style>