App.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <!-- <div>地图页面</div> -->
  3. <div class="tabbar">
  4. <div class="nav">
  5. <el-button-group class="ml-4">
  6. <el-button :type="currentType(0) ? 'primary' : 'default'" @click="handleSelect(0)"
  7. >地图</el-button
  8. >
  9. <el-button :type="currentType(1) ? 'primary' : 'default'" @click="handleSelect(1)"
  10. >卡片</el-button
  11. >
  12. </el-button-group>
  13. </div>
  14. <el-form-item label="所属架构:" class="filter">
  15. <com-company v-model="state.deptId" :id="state.caseId" hideAll />
  16. </el-form-item>
  17. </div>
  18. <div ref="mapEl" class="map-container" v-show="currentType(0)"></div>
  19. <div class="card-container" v-show="currentType(1)">
  20. <div class="card-list">
  21. <template v-for="item of list" v-if="list.length > 0">
  22. <el-card style="width: 480px" shadow="hover" @click="handCardClick(item.caseId)">
  23. <img
  24. class="cover"
  25. :src="
  26. item.cover
  27. ? item.cover
  28. : 'https://test-mix3d.4dkankan.com/code/assets/pic.d5781b0c.jpg'
  29. "
  30. style="width: 100%"
  31. />
  32. <div class="card">
  33. <span> 项目: {{ item.projectName }}</span>
  34. <span> 地址: {{ item.projectAddress }}</span>
  35. <span> 类别: {{ item.projectSite }}</span>
  36. </div>
  37. </el-card>
  38. </template>
  39. <template v-else>
  40. <div class="no-data">
  41. <img :src="emptyBG" />
  42. <span>暂无数据</span>
  43. </div>
  44. </template>
  45. </div>
  46. </div>
  47. </template>
  48. <script setup lang="ts">
  49. import { onMounted, ref, computed, onBeforeMount } from "vue";
  50. // import { useRouteQuery } from "@vueuse/router";
  51. import AMapLoader from "@amap/amap-jsapi-loader";
  52. import axios from "axios";
  53. import { getFuseCodeLink } from "../../view/case/help";
  54. import comCompany from "./company-select/index.vue";
  55. import { reactive } from "vue";
  56. import { watch } from "vue";
  57. import { ElLoading } from "element-plus";
  58. import linkIco from "@/assets/image/fire.ico";
  59. import { useUrlSearchParams } from "@vueuse/core";
  60. import emptyBG from "@/assets/image/empty__empty.png";
  61. const params = useUrlSearchParams("history");
  62. console.log("params", params.deptId);
  63. const current = ref(0);
  64. const list = ref<any>([]);
  65. const state = reactive({
  66. deptId: params.deptId || "",
  67. // caseId: params.caseId || "",
  68. });
  69. const link = document.querySelector<HTMLLinkElement>("#app-icon")!;
  70. link.setAttribute("href", linkIco);
  71. document.title = "案件显示";
  72. const currentType = computed(() => (type: number) => current.value === type);
  73. const handleSelect = (type: number) => {
  74. current.value = type;
  75. };
  76. const getQuery = (caseId: number, share: boolean = false, single: boolean = false) =>
  77. `${getFuseCodeLink(caseId, true)}${share ? "&share=1" : ""}${
  78. single ? "&single=1" : ""
  79. }#show/summary`;
  80. const request = axios.create({
  81. baseURL: "",
  82. timeout: 1000,
  83. headers: {
  84. share: 1,
  85. "Content-Type": "application/json",
  86. },
  87. });
  88. const mapEl = ref<HTMLDivElement>();
  89. const getDataQuest = () => {
  90. return new Promise(async (reslove, reject) => {
  91. const res = await request.post(
  92. "https://xj-mix3d.4dkankan.com/fusion-xj/web/fireProject/queryProject",
  93. {
  94. pageNum: 1,
  95. pageSize: 10000,
  96. deptId: state.deptId,
  97. }
  98. );
  99. console.log("res.data", res);
  100. if (res.status === 200 && res.data.code === 0) {
  101. reslove(res.data.data.list);
  102. } else {
  103. reslove([]);
  104. }
  105. });
  106. };
  107. const refresh = async () => {
  108. const loading = ElLoading.service({
  109. lock: true,
  110. text: "Loading",
  111. background: "rgba(0, 0, 0, 0.7)",
  112. });
  113. const data = ((await getDataQuest()) as any) as any[];
  114. console.log("data", data);
  115. list.value = data as any[];
  116. loading.close();
  117. };
  118. watch(
  119. () => state.deptId,
  120. () => {
  121. refresh();
  122. },
  123. {
  124. immediate: true,
  125. deep: true,
  126. }
  127. );
  128. const loadMap = async () => {
  129. const AMap = await AMapLoader.load({
  130. plugins: ["AMap.PlaceSearch"],
  131. key: "e661b00bdf2c44cccf71ef6070ef41b8",
  132. version: "2.0",
  133. });
  134. const map = new AMap.Map(mapEl.value, {
  135. WebGLParams: {
  136. preserveDrawingBuffer: true,
  137. },
  138. resizeEnable: true,
  139. });
  140. //添加插件
  141. AMap.plugin(
  142. ["AMap.ToolBar", "AMap.Scale", "AMap.HawkEye", "AMap.MapType"],
  143. function () {
  144. //异步同时加载多个插件
  145. // map.addControl(new AMap.HawkEye()); //显示缩略图
  146. map.addControl(new AMap.Scale()); //显示当前地图中心的比例尺
  147. map.addControl(new AMap.MapType()); //显示当前地图中心的比例尺
  148. }
  149. );
  150. console.log("map", map);
  151. const initMakers = async () => {
  152. const data = ((await getDataQuest()) as any) as any[];
  153. console.log("data", data);
  154. const positions: any[] = [];
  155. list.value = data as any[];
  156. Array.from(data).forEach((item: any) => {
  157. // console.log(item)
  158. const latlng = item.latlng;
  159. const coord = latlng.split(",");
  160. console.log("coord", coord, item.caseId);
  161. const url = getQuery(item.caseId, true);
  162. console.log("url", url);
  163. const icon = new AMap.Icon({
  164. image: "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  165. size: new AMap.Size(22, 28), //图标所处区域大小
  166. imageSize: new AMap.Size(22, 28), //图标大小
  167. });
  168. const pos = coord.reverse();
  169. positions.push(pos);
  170. const marker = new AMap.Marker({
  171. icon: icon,
  172. position: pos,
  173. title: item.title,
  174. label: item.title,
  175. extData: { url: url, id: item.caseId },
  176. // offset: new AMap.Pixel(-26, -54),
  177. });
  178. marker.setMap(map);
  179. marker.on("click", () => {
  180. const data = marker.getExtData();
  181. window.open(data.url);
  182. console.log("click", data);
  183. });
  184. });
  185. var polygon = new AMap.Polygon({
  186. path: positions,
  187. map: map,
  188. strokeOpacity: 0, //透明
  189. fillOpacity: 0, //透明
  190. bubble: true, //事件穿透到地图
  191. });
  192. var overlaysList = map.getAllOverlays("polygon"); //获取多边形图层
  193. map.setFitView(); //自适应显示
  194. };
  195. initMakers();
  196. };
  197. onMounted(() => {
  198. // console.log("caseId", caseId);
  199. loadMap();
  200. });
  201. const handCardClick = (id: number) => {
  202. const url = getQuery(id, true);
  203. console.log("url", url);
  204. window.open(url);
  205. };
  206. </script>
  207. <style>
  208. body {
  209. padding: 0;
  210. margin: 0;
  211. }
  212. .map-container {
  213. width: 100%;
  214. height: 100vh;
  215. }
  216. .tabbar {
  217. display: flex;
  218. width: 100%;
  219. position: fixed;
  220. top: 30px;
  221. z-index: 10000;
  222. justify-items: center;
  223. justify-content: center;
  224. }
  225. .tabbar .nav {
  226. display: flex;
  227. /* background: white; */
  228. justify-content: center;
  229. align-items: center;
  230. }
  231. .el-form-item {
  232. margin-bottom: 0px !important;
  233. }
  234. .tabbar .nav .nav_item {
  235. padding: 10px;
  236. cursor: pointer;
  237. }
  238. .card-container {
  239. width: 100%;
  240. padding-top: 100px;
  241. }
  242. .card-list {
  243. margin: 0 auto;
  244. display: flex;
  245. gap: 50px 25px;
  246. width: 90%;
  247. flex-direction: row;
  248. flex-wrap: wrap;
  249. }
  250. .cover {
  251. cursor: pointer;
  252. max-height: 220px;
  253. object-fit: cover;
  254. }
  255. .card {
  256. display: flex;
  257. flex-direction: column;
  258. cursor: pointer;
  259. gap: 10px;
  260. }
  261. .filter {
  262. margin: 0;
  263. margin-left: 20px;
  264. }
  265. .amap-ctrl-list-layer {
  266. z-index: 100000;
  267. }
  268. .no-data {
  269. width: 100%;
  270. height: 100%;
  271. /* background: red; */
  272. min-height: 530px;
  273. display: flex;
  274. justify-content: center;
  275. align-items: center;
  276. flex-direction: column;
  277. }
  278. .no-data span {
  279. color: #999;
  280. }
  281. </style>