FenceAppSetting.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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="isShowFence">平台预览</a>
  18. </div>
  19. </template>
  20. <script lang="ts" setup>
  21. import {
  22. updateFenceDisplayStatus,
  23. getCameraAlgoPresetList,
  24. choosePreset,
  25. getAppCameraAlgoPreset,
  26. CameraAlgoPresetResp,
  27. } from '@/api/camera/camera-preview';
  28. import { computed, onMounted, ref, watch } from 'vue';
  29. import useCameraDetailStore from '../../store/useCameraDetailStore';
  30. import { storeToRefs } from 'pinia';
  31. import { OptionType } from './constants';
  32. import { useGlobSetting } from '@/hooks/setting';
  33. const valuePreset = ref<[string, string]>();
  34. const cameraDetailStore = useCameraDetailStore();
  35. const { isShowFence, detail } = storeToRefs(cameraDetailStore);
  36. const appFenceCameraDetail = ref<CameraAlgoPresetResp | null>(null);
  37. const options = ref([]);
  38. const { appPCUrl } = useGlobSetting();
  39. const previewUrl = computed(() => {
  40. return appPCUrl + `#/shop?id=${detail.value?.workshopId}&cameraId=${detail.value?.code!}`;
  41. });
  42. watch(
  43. () => detail.value?.code,
  44. (newCode) => {
  45. if (!newCode) return;
  46. getCameraAlgoPresetList(newCode).then((res) => {
  47. options.value = renameKeys(res.algoInfoVOList);
  48. });
  49. getAppCameraAlgoPreset(newCode).then((res) => {
  50. appFenceCameraDetail.value = res;
  51. valuePreset.value = [res.algoCode, res.presetToken];
  52. });
  53. },
  54. );
  55. const renameKeys = (data: any) => {
  56. return data.map((item) => {
  57. const newItem: OptionType = {
  58. label: item.name,
  59. value: item.code,
  60. };
  61. if (item.presetInfoList) {
  62. newItem.children = item.presetInfoList.map((child) => ({
  63. label: child.presetName,
  64. value: child.presetToken,
  65. }));
  66. }
  67. return newItem;
  68. });
  69. };
  70. const changeShowFence = async () => {
  71. if (isShowFence.value) {
  72. const params = {
  73. cameraCode: cameraDetailStore.detail?.code!,
  74. status: 0,
  75. };
  76. await updateFenceDisplayStatus(params);
  77. } else {
  78. const params = {
  79. cameraCode: cameraDetailStore.detail?.code!,
  80. status: 1,
  81. };
  82. updateFenceDisplayStatus(params);
  83. }
  84. };
  85. const changePreset = (value) => {
  86. console.log('value', value);
  87. const params = {
  88. algoCode: value[0],
  89. cameraCode: cameraDetailStore.detail?.code!,
  90. presetToken: value[1],
  91. };
  92. choosePreset(params);
  93. };
  94. </script>
  95. <style scoped>
  96. .wrapper {
  97. display: flex;
  98. align-items: center;
  99. margin-left: 20px;
  100. }
  101. .checkbox {
  102. margin-right: 10px;
  103. }
  104. </style>