FenceAppSetting.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <!-- 电子围栏显示在前台的控制开关 -->
  3. <div class="wrapper">
  4. <el-checkbox
  5. label="平台是否显示电子围栏"
  6. v-model="isShowFence"
  7. @change="changeShowFence"
  8. class="checkbox"
  9. />
  10. <el-cascader
  11. v-model="valuePreset"
  12. :options="options"
  13. size="small"
  14. @change="changePreset"
  15. v-if="isShowFence"
  16. />
  17. <a :href="previewUrl" target="_blank" style="margin-left: 20px" v-if="previewUrl"
  18. >平台相机预览</a
  19. >
  20. </div>
  21. </template>
  22. <script lang="ts" setup>
  23. import {
  24. updateFenceDisplayStatus,
  25. getCameraAlgoPresetList,
  26. choosePreset,
  27. getAppCameraAlgoPreset,
  28. CameraAlgoPresetResp,
  29. } from '@/api/camera/camera-preview';
  30. import { computed, onMounted, ref, watch } from 'vue';
  31. import useCameraDetailStore from '../../store/useCameraDetailStore';
  32. import { storeToRefs } from 'pinia';
  33. import { OptionType } from './constants';
  34. import { useGlobSetting } from '@/hooks/setting';
  35. import { FenceDisplayStatus } from '@/types/camera/constant';
  36. const valuePreset = ref<[string, string]>();
  37. const cameraDetailStore = useCameraDetailStore();
  38. const { isShowFence, detail } = storeToRefs(cameraDetailStore);
  39. const options = ref([]);
  40. const { appPCUrl } = useGlobSetting();
  41. const previewUrl = computed(() => {
  42. if (!detail.value?.workshopId || !detail.value?.code) return '';
  43. return appPCUrl + `#/shop?id=${detail.value?.workshopId}&cameraId=${detail.value?.code!}`;
  44. });
  45. watch(
  46. () => detail.value?.id,
  47. (newId) => {
  48. if (!newId) return;
  49. getCameraAlgoPresetList(newId).then((res) => {
  50. options.value = renameKeys(res.algoInfoVOList);
  51. });
  52. getAppCameraAlgoPreset(newId).then((res) => {
  53. valuePreset.value = [res.algoId, res.presetToken];
  54. });
  55. },
  56. );
  57. const renameKeys = (data: any) => {
  58. return data.map((item) => {
  59. const newItem: OptionType = {
  60. label: item.name,
  61. value: item.id,
  62. };
  63. if (item.presetInfoList) {
  64. newItem.children = item.presetInfoList.map((child) => ({
  65. label: child.presetName,
  66. value: child.presetToken,
  67. }));
  68. }
  69. return newItem;
  70. });
  71. };
  72. const changeShowFence = async () => {
  73. const params = {
  74. cameraCode: cameraDetailStore.detail?.code!,
  75. isDisplayFence: isShowFence.value ? FenceDisplayStatus.enabled : FenceDisplayStatus.disabled,
  76. };
  77. updateFenceDisplayStatus(params);
  78. };
  79. const changePreset = (value) => {
  80. console.log('value', value);
  81. const params = {
  82. algoId: value[0],
  83. cameraId: cameraDetailStore.detail?.id!,
  84. presetToken: value[1],
  85. };
  86. choosePreset(params);
  87. };
  88. </script>
  89. <style scoped>
  90. .wrapper {
  91. display: flex;
  92. align-items: center;
  93. margin-left: 20px;
  94. }
  95. .checkbox {
  96. margin-right: 10px;
  97. }
  98. </style>