index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div class="map-home">
  3. <map-box v-if="showMap && floorId" :projectId="projectId" :floorId="floorId"></map-box>
  4. <space-box
  5. v-else
  6. :spaceData="spaceData"
  7. @changeSpace="changeSpace"
  8. ></space-box>
  9. </div>
  10. </template>
  11. <script lang="ts">
  12. import {
  13. defineComponent,
  14. reactive,
  15. toRefs,
  16. onBeforeMount,
  17. onMounted,
  18. ref,
  19. watch,
  20. } from "vue";
  21. import SpaceBox from "./SpaceBox.vue";
  22. import MapBox from "./MapBox.vue";
  23. import { useRouter } from "vue-router";
  24. import { newNumber, parseImgUrl } from "@/utils";
  25. import { UserActionTypes } from "@/store/modules/user/action-types";
  26. import { useStore } from "@/store";
  27. import { login } from "@/apis/user";
  28. import { Form, Field, CellGroup, Button, Toast } from "vant";
  29. import { setToken } from "@/utils/cookies";
  30. import { getMapInfo } from "@/apis/envmonitor";
  31. export default defineComponent({
  32. props: {
  33. spaceData: {
  34. type: Array,
  35. default: () => [],
  36. },
  37. projectId: {
  38. type: String,
  39. default: () => "",
  40. },
  41. floorId: {
  42. type: String,
  43. default: () => "",
  44. },
  45. spaceInfo: {
  46. type: Object,
  47. default: () => {},
  48. },
  49. },
  50. components: {
  51. vanForm: Form,
  52. vanField: Field,
  53. CellGroup,
  54. vanButton: Button,
  55. SpaceBox,
  56. MapBox,
  57. },
  58. setup(props, contex) {
  59. let router: any = useRouter();
  60. const store = useStore();
  61. const proxyData = reactive({
  62. spaceData: props.spaceData,
  63. showMap: false, // 是否展示地图
  64. changeSpace(item: any) {
  65. contex.emit("changeSpace", item, 1);
  66. },
  67. floorId:props.floorId,
  68. /**
  69. * 获取地图信息
  70. */
  71. getMapInfo() {
  72. let params: any = {
  73. projectId: props.projectId,
  74. floorId: proxyData.floorId,
  75. };
  76. getMapInfo(params)
  77. .then((res) => {
  78. let resData: any = res;
  79. if (resData.result === "success") {
  80. let data: any = resData?.data ?? null;
  81. // debugger
  82. if (data) {
  83. proxyData.showMap = true;
  84. } else {
  85. proxyData.showMap = false;
  86. }
  87. } else {
  88. proxyData.showMap = false;
  89. }
  90. })
  91. .catch(() => {
  92. proxyData.showMap = false;
  93. });
  94. },
  95. });
  96. onMounted(() => {
  97. });
  98. watch(
  99. props,
  100. (newProps: any) => {
  101. proxyData.spaceData = newProps.spaceData;
  102. proxyData.floorId = newProps.floorId;
  103. console.log("proxyData.floorId===")
  104. console.log(proxyData.floorId)
  105. proxyData.getMapInfo();
  106. },
  107. {
  108. deep: false,
  109. immediate: true,
  110. }
  111. );
  112. return {
  113. ...toRefs(proxyData),
  114. };
  115. },
  116. });
  117. </script>
  118. <style lang="scss" scoped>
  119. .map-home {
  120. width: 100%;
  121. height: 100%;
  122. background: $elBg;
  123. }
  124. </style>