App.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <!-- <div>地图页面</div> -->
  3. <div class="tabbar">
  4. <!-- <div class="nav">
  5. <el-button-group class="ml-4">
  6. <el-button
  7. :type="currentType(0) ? 'primary' : 'default'"
  8. @click="handleSelect(0)"
  9. >地图</el-button
  10. >
  11. <el-button
  12. :type="currentType(1) ? 'primary' : 'default'"
  13. @click="handleSelect(1)"
  14. >卡片</el-button
  15. >
  16. </el-button-group>
  17. </div> -->
  18. <div class="left">
  19. <el-form-item label="" class="filter">
  20. <com-company
  21. v-model="state.deptId"
  22. :id="state.caseId"
  23. hideAll
  24. />
  25. </el-form-item>
  26. <el-form-item label="" class="filter">
  27. <el-input
  28. v-model:modelValue="keywordSearch"
  29. placeholder="输入关键字"
  30. ></el-input>
  31. </el-form-item>
  32. </div>
  33. <div class="right">
  34. <el-select
  35. style="width: 100px"
  36. v-model:modelValue="currentMaptype"
  37. v-if="currentType(0)"
  38. >
  39. <el-option key="2d" label="矢量图" :value="0" />
  40. <el-option key="state" label="卫星图" :value="1" />
  41. </el-select>
  42. <el-select style="width: 100px" v-model:modelValue="current">
  43. <el-option key="map" label="地图" :value="0" />
  44. <el-option key="card" label="卡片" :value="1" />
  45. </el-select>
  46. </div>
  47. </div>
  48. <div ref="mapEl" class="map-container" v-show="currentType(0)"></div>
  49. <div class="card-container" v-show="currentType(1)">
  50. <div class="card-list">
  51. <template
  52. v-for="item of keywordSearch ? searchList : list"
  53. v-if="keywordSearch ? searchList.length > 0 : list.length > 0"
  54. >
  55. <el-card
  56. class="card"
  57. shadow="hover"
  58. @click="handCardClick(item.caseId)"
  59. >
  60. <img
  61. class="cover"
  62. :src="item.cover ? item.cover : emptyCover"
  63. style="width: 100%"
  64. />
  65. <div class="label-list">
  66. <span>
  67. 项目:
  68. <el-tooltip placement="top" :content="item.projectName">
  69. {{
  70. item.projectName.length > 20
  71. ? item.projectName.slice(0, 20) + "..."
  72. : item.projectName
  73. }}
  74. </el-tooltip>
  75. </span>
  76. <span>
  77. 地址:
  78. <el-tooltip placement="bottom" :content="item.projectAddress">
  79. {{
  80. item.projectAddress.length > 20
  81. ? item.projectAddress.substr(0, 20) + "..."
  82. : item.projectAddress
  83. }}
  84. </el-tooltip></span
  85. >
  86. <!-- <span> 类别: {{ item.projectSite }}</span> -->
  87. </div>
  88. </el-card>
  89. </template>
  90. <template v-else>
  91. <div class="no-data">
  92. <img :src="emptyBG" />
  93. <span>暂无数据</span>
  94. </div>
  95. </template>
  96. </div>
  97. </div>
  98. </template>
  99. <script setup lang="ts">
  100. import { onMounted, ref, computed, onBeforeMount } from "vue";
  101. import { getSysSetting } from "@/request";
  102. // import { useRouteQuery } from "@vueuse/router";
  103. import AMapLoader from "@amap/amap-jsapi-loader";
  104. import axios from "axios";
  105. import { getFuseCodeLink } from "../../view/case/help";
  106. import comCompany from "./company-select/index.vue";
  107. import { reactive } from "vue";
  108. import { watch } from "vue";
  109. import { ElLoading } from "element-plus";
  110. import linkIco from "@/assets/image/fire.ico";
  111. import { useUrlSearchParams } from "@vueuse/core";
  112. import emptyBG from "@/assets/image/empty__empty.png";
  113. import emptyCover from "@/assets/image/pic.jpg";
  114. import { changeThemeColor } from "./theme";
  115. const params = useUrlSearchParams("history");
  116. console.log("params", params.deptId);
  117. // const el = ref(document.documentElement);
  118. // const primaryColor = useCssVar("--el-color-primary", document.documentElement);
  119. // primaryColor.value = "#00C8AF";
  120. // const primaryColor = useCssVar("--el-color-primary", el, {
  121. // initialValue: "#00C8AF",
  122. // });
  123. const current = ref(0);
  124. const currentMaptype = ref(0);
  125. const keywordSearch = ref("");
  126. const list = ref<any>([]);
  127. const searchList = ref<any>([]);
  128. const state = reactive({
  129. deptId: String(params.deptId) || "",
  130. caseId: "",
  131. });
  132. const link = document.querySelector<HTMLLinkElement>("#app-icon")!;
  133. link.setAttribute("href", linkIco);
  134. document.title = "案件显示";
  135. const currentType = computed(() => (type: number) => current.value === type);
  136. const handleSelect = (type: number) => {
  137. current.value = type;
  138. };
  139. const markers = ref<any>([]);
  140. const getQuery = (
  141. caseId: number,
  142. share: boolean = false,
  143. single: boolean = false
  144. ) =>
  145. `${getFuseCodeLink(caseId, true)}${share ? "&share=1" : ""}${
  146. single ? "&single=1" : ""
  147. }#show/summary`;
  148. const request = axios.create({
  149. baseURL: "",
  150. timeout: 1000,
  151. headers: {
  152. share: 1,
  153. "Content-Type": "application/json",
  154. },
  155. });
  156. const mapEl = ref<HTMLDivElement>();
  157. let AMap, map;
  158. const domain = location.protocol + "//" + location.host;
  159. const queryURL = `${domain}/api/fusion/web/fireProject/queryProject`;
  160. axios.get(getSysSetting).then((data) => {
  161. const { themeColour } = data.data;
  162. const setColor = themeColour ? `#${themeColour}` : "#00C8AF";
  163. console.log("setColor", setColor);
  164. changeThemeColor(setColor);
  165. });
  166. // debugger;
  167. const getDataQuest = () => {
  168. return new Promise(async (reslove, reject) => {
  169. const res = await request.post(queryURL, {
  170. pageNum: 1,
  171. pageSize: 10000,
  172. deptId: state.deptId,
  173. });
  174. console.log("res.data", res);
  175. if (res.status === 200 && res.data.code === 0) {
  176. reslove(res.data.data.list);
  177. } else {
  178. reslove([]);
  179. }
  180. });
  181. };
  182. const refresh = async () => {
  183. const loading = ElLoading.service({
  184. lock: true,
  185. text: "Loading",
  186. background: "rgba(0, 0, 0, 0.7)",
  187. });
  188. map.remove(markers.value);
  189. markers.value = [];
  190. initMakers();
  191. loading.close();
  192. };
  193. watch(
  194. () => state.deptId,
  195. () => {
  196. refresh();
  197. },
  198. {
  199. immediate: false,
  200. deep: true,
  201. }
  202. );
  203. const initMakers = async () => {
  204. const data = (await getDataQuest()) as any as any[];
  205. const positions: any[] = [];
  206. list.value = data.filter((i) => i.latAndLong) as any[];
  207. console.log("list", list.value);
  208. Array.from(list.value).forEach((item: any) => {
  209. // console.log(item)
  210. const latlng = item.latAndLong;
  211. const coord = latlng.split(",");
  212. console.log("coord", coord, item.caseId);
  213. const url = getQuery(item.caseId, true);
  214. console.log("url", url);
  215. const icon = new AMap.Icon({
  216. image:
  217. "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  218. size: new AMap.Size(22, 28), //图标所处区域大小
  219. imageSize: new AMap.Size(22, 28), //图标大小
  220. });
  221. const pos = coord.reverse();
  222. positions.push(pos);
  223. const marker = new AMap.Marker({
  224. icon: icon,
  225. position: pos,
  226. title: item.projectName,
  227. label: item.projectName,
  228. extData: { url: url, id: item.caseId },
  229. // offset: new AMap.Pixel(-26, -54),
  230. });
  231. markers.value.push(marker);
  232. marker.setMap(map);
  233. marker.on("click", () => {
  234. const data = marker.getExtData();
  235. window.open(data.url);
  236. console.log("click", data);
  237. });
  238. });
  239. // var polygon = new AMap.Polygon({
  240. // path: positions,
  241. // map: map,
  242. // strokeOpacity: 0, //透明
  243. // fillOpacity: 0, //透明
  244. // bubble: true, //事件穿透到地图
  245. // });
  246. // var overlaysList = map.getAllOverlays("polygon"); //获取多边形图层
  247. map.setFitView(); //自适应显示
  248. };
  249. const initKeywordMakers = async () => {
  250. const data = searchList.value;
  251. const positions: any[] = [];
  252. map.remove(markers.value);
  253. markers.value = [];
  254. // list.value = data.filter((i) => i.latAndLong) as any[];
  255. // console.log("list", list.value);
  256. Array.from(data).forEach((item: any) => {
  257. // console.log(item)
  258. const latlng = item.latAndLong;
  259. const coord = latlng.split(",");
  260. console.log("coord", coord, item.caseId);
  261. const url = getQuery(item.caseId, true);
  262. console.log("url", url);
  263. const icon = new AMap.Icon({
  264. image:
  265. "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png",
  266. size: new AMap.Size(22, 28), //图标所处区域大小
  267. imageSize: new AMap.Size(22, 28), //图标大小
  268. });
  269. const pos = coord.reverse();
  270. positions.push(pos);
  271. const marker = new AMap.Marker({
  272. icon: icon,
  273. position: pos,
  274. title: item.projectName,
  275. label: item.projectName,
  276. extData: { url: url, id: item.caseId },
  277. // offset: new AMap.Pixel(-26, -54),
  278. });
  279. markers.value.push(marker);
  280. marker.setMap(map);
  281. marker.on("click", () => {
  282. const data = marker.getExtData();
  283. window.open(data.url);
  284. console.log("click", data);
  285. });
  286. });
  287. // var polygon = new AMap.Polygon({
  288. // path: positions,
  289. // map: map,
  290. // strokeOpacity: 0, //透明
  291. // fillOpacity: 0, //透明
  292. // bubble: true, //事件穿透到地图
  293. // });
  294. // var overlaysList = map.getAllOverlays("polygon"); //获取多边形图层
  295. map.setFitView(); //自适应显示
  296. };
  297. const loadMap = async () => {
  298. AMap = await AMapLoader.load({
  299. plugins: ["AMap.PlaceSearch"],
  300. key: "e661b00bdf2c44cccf71ef6070ef41b8",
  301. version: "2.0",
  302. });
  303. (window as any).map = map = new AMap.Map(mapEl.value, {
  304. WebGLParams: {
  305. preserveDrawingBuffer: true,
  306. },
  307. mapStyle: "amap://styles/normal", // 默认地图样式,
  308. resizeEnable: true,
  309. });
  310. //添加插件
  311. AMap.plugin(
  312. ["AMap.ToolBar", "AMap.Scale", "AMap.HawkEye", "AMap.MapType"],
  313. function () {
  314. //异步同时加载多个插件
  315. // map.addControl(new AMap.HawkEye()); //显示缩略图
  316. map.addControl(new AMap.Scale()); //显示当前地图中心的比例尺
  317. const type = new AMap.MapType({
  318. defaultType: 0,
  319. });
  320. map.addControl(type); //显示当前地图中心的比例尺
  321. }
  322. );
  323. console.log("map", map);
  324. initMakers();
  325. };
  326. watch(
  327. keywordSearch,
  328. (val) => {
  329. searchList.value = list.value.filter((item) =>
  330. String(item.projectName).includes(val)
  331. );
  332. initKeywordMakers();
  333. console.log("searchList", searchList);
  334. },
  335. {
  336. immediate: true,
  337. }
  338. );
  339. watch(currentMaptype, (val) => {
  340. console.log("currentMaptype", val);
  341. if (val === 0) {
  342. const btn = document.querySelector(
  343. "input[data-id='AMap.TileLayer']"
  344. ) as any as HTMLInputElement;
  345. btn && btn.click();
  346. }
  347. if (val === 1) {
  348. const btn = document.querySelector(
  349. "input[data-id='AMap.TileLayer.Satellite']"
  350. ) as any as HTMLInputElement;
  351. btn && btn.click();
  352. }
  353. });
  354. onMounted(() => {
  355. // console.log("caseId", caseId);
  356. loadMap();
  357. // primaryColor.value = "#ff9800";
  358. });
  359. const handCardClick = (id: number) => {
  360. const url = getQuery(id, true);
  361. console.log("url", url);
  362. window.open(url);
  363. };
  364. </script>
  365. <style>
  366. body {
  367. padding: 0;
  368. margin: 0;
  369. background-color: #f0f2f5;
  370. }
  371. .map-container {
  372. width: 100%;
  373. height: 100vh;
  374. }
  375. .tabbar {
  376. display: flex;
  377. width: calc(100% - 60px);
  378. position: fixed;
  379. top: 30px;
  380. z-index: 10000;
  381. justify-items: center;
  382. justify-content: space-between;
  383. padding: 0 30px;
  384. }
  385. .tabbar .left,
  386. .tabbar .right {
  387. display: flex;
  388. flex-direction: row;
  389. gap: 0 20px;
  390. }
  391. .tabbar .left {
  392. gap: 0 10px;
  393. }
  394. .tabbar .nav {
  395. display: flex;
  396. /* background: white; */
  397. justify-content: center;
  398. align-items: center;
  399. }
  400. .el-form-item {
  401. margin-bottom: 0px !important;
  402. }
  403. .tabbar .nav .nav_item {
  404. padding: 10px;
  405. cursor: pointer;
  406. }
  407. .card-container {
  408. width: 100%;
  409. padding-top: 100px;
  410. padding-bottom: 100px;
  411. }
  412. .card-list {
  413. margin: 0 auto;
  414. display: flex;
  415. gap: 50px 25px;
  416. width: 90%;
  417. flex-direction: row;
  418. flex-wrap: wrap;
  419. justify-content: flex-start;
  420. align-items: center;
  421. }
  422. .cover {
  423. cursor: pointer;
  424. height: 220px;
  425. width: 100%;
  426. object-fit: cover;
  427. margin-bottom: 20px;
  428. }
  429. .card {
  430. display: flex;
  431. flex-direction: column;
  432. cursor: pointer;
  433. gap: 10px;
  434. width: 382px;
  435. border-radius: 10px 10px 10px 10px;
  436. }
  437. .label-list {
  438. display: inline-flex;
  439. flex-direction: column;
  440. font-weight: 400;
  441. font-size: 14px;
  442. color: #282222;
  443. line-height: 16px;
  444. text-align: left;
  445. font-style: normal;
  446. gap: 10px;
  447. }
  448. .filter {
  449. margin: 0;
  450. margin-left: 20px;
  451. }
  452. .amap-ctrl-list-layer {
  453. z-index: 100000;
  454. }
  455. .no-data {
  456. width: 100%;
  457. height: 100%;
  458. /* background: red; */
  459. min-height: 530px;
  460. display: flex;
  461. justify-content: center;
  462. align-items: center;
  463. flex-direction: column;
  464. }
  465. .no-data span {
  466. color: #999;
  467. }
  468. .amap-maptype {
  469. display: none;
  470. }
  471. </style>