From a72e455d1349133764053eb24e614a52ba0c8840 Mon Sep 17 00:00:00 2001 From: guonan <guonan201020@163.com> Date: 星期四, 24 七月 2025 09:15:18 +0800 Subject: [PATCH] 1 --- src/components/monifangzhen/schemeCard.vue | 190 ++++++++++++++++++++++++---------------------- 1 files changed, 99 insertions(+), 91 deletions(-) diff --git a/src/components/monifangzhen/schemeCard.vue b/src/components/monifangzhen/schemeCard.vue index b3d1b9d..a7ec320 100644 --- a/src/components/monifangzhen/schemeCard.vue +++ b/src/components/monifangzhen/schemeCard.vue @@ -134,8 +134,8 @@ async function startPlay(item) { simStore.openDia = false; clearAllPoints(); - const areaName = item.areaName; + const areaName = item.areaName; let districtCode; // 1. 鍒ゆ柇鏄惁鍖呭惈 鈥滃尯鈥� @@ -156,97 +156,107 @@ districtCode = matchedArea.value; } - // 1. 鑾峰彇涔¢晣鍖哄煙缂栫爜 - const areaRes = await getAeraTownCode(districtCode); - const districtCodes = areaRes.data.map((item) => item.districtCode); - - // 2. 娉ヤ綅璁$被鍨婭D - const ids = "1437295811"; - - // 3. 骞惰璇锋眰鎵�鏈夎澶囨暟鎹� - const requests = districtCodes.map((code) => - getDeviceNWJ(ids, code) - .then((res) => res.data?.pageData || []) // 瀹夊叏鎻愬彇 pageData - .catch((err) => { - console.error(`璇锋眰澶辫触 (code: ${code})`, err); - return []; // 鍑洪敊鏃朵篃杩斿洖绌烘暟缁勶紝閬垮厤 Promise.all 涓柇 - }) - ); - - // 4. 绛夊緟鎵�鏈夎姹傚畬鎴� - const allPageDataArrays = await Promise.all(requests); - - // 5. 鍚堝苟浜岀淮鏁扮粍涓轰竴缁存暟缁� - const mergedPageData = allPageDataArrays.flat(); - - // 6. 濡傛灉涓嶆槸鈥滃尯鈥濓紝鍒欒繃婊ゅ嚭 deviceName 鍖呭惈 "瀛欒儭娌�" 鐨勮澶� - const filteredPageData = areaName.includes("鍖�") - ? mergedPageData - : mergedPageData.filter((device) => device.deviceName.includes("瀛欒儭娌�")); - - // 瀛欒儭娌熻澶囩粡绾害鏄犲皠 - const deviceMapping = { - 鎬�鏌斿尯鐞夌拑搴欓晣瀛欒儭娌熸ご鏍戝簳涓嬩笢娌熸偿浣嶈5007: { - lon: 116.598891, - lat: 40.554979, - }, - 鎬�鏌斿尯鐞夌拑搴欓晣瀛欒儭娌熸潙涓婂彴瀛愭渤涓滃崡娌熸偿浣嶈5006: { - lon: 116.593215, - lat: 40.554399, - }, - }; - - let displayedData = filteredPageData; - - if (!areaName.includes("鍖�")) { - // 娣诲姞 lon 鍜� lan 瀛楁 - displayedData = filteredPageData.map((device) => { - const mapping = deviceMapping[device.deviceName]; - return { - ...device, - ...(mapping && { lon: mapping.lon, lat: mapping.lat }), // 濡傛灉 mapping 瀛樺湪锛屾墠娣诲姞 - }; - }); - - // 娣诲姞棰濆鐨勪袱涓偣浣� - const extraPoint1 = { - deviceName: "寮矡1", - longitude: 116.597836, - latitude: 40.564962, - // height: 530.14, - type: "娉ヤ綅璁�", - lon: 116.597836, - lat: 40.564962, - dictDeviceType: "1437295811", - deviceId: "custom_extraPoint1", // 鎵嬪姩鍔犱竴涓敮涓� ID - }; - - const extraPoint2 = { - deviceName: "寮矡2", - longitude: 116.591571, - latitude: 40.573093, - // height: 483.89, - type: "娉ヤ綅璁�", - lon: 116.591571, - lat: 40.573093, - dictDeviceType: "1437295811", - deviceId: "custom_extraPoint2", // 鎵嬪姩鍔犱竴涓敮涓� ID - }; - - displayedData = [...displayedData, extraPoint1, extraPoint2]; - // displayedData = [...displayedData, extraPoint1]; + let areaRes; + try { + areaRes = await getAeraTownCode(districtCode); + } catch (error) { + console.error("getAeraTownCode 璇锋眰澶辫触", error); + ElMessage.warning("涔¢晣鍖哄煙鏁版嵁鍔犺浇澶辫触锛岄儴鍒嗚澶囧彲鑳芥棤娉曟樉绀�"); + areaRes = { data: [] }; // 璧嬮粯璁ゅ�硷紝闃叉鍚庣画鍑洪敊 } - console.log( - displayedData, - areaName.includes("鍖�") - ? "鍏ㄩ儴娉ヤ綅璁¤澶囧垪琛�" - : "瀛欒儭娌熸偿浣嶈 + 棰濆鐐逛綅鍒楄〃" - ); + const districtCodes = areaRes.data.map((item) => item.districtCode); - // 7. 鍒涘缓鐐� + + let displayedData = []; + + if (districtCodes.length == 0) { + ElMessage.warning("鏈幏鍙栧埌涔¢晣缂栫爜锛岃烦杩囪澶囪姹�"); + } else { + const ids = "1437295811"; + + // 鏋勫缓璇锋眰鍒楄〃 + const requests = districtCodes.map((code) => + getDeviceNWJ(ids, code) + .then((res) => res.data?.pageData || []) + .catch((err) => { + console.error(`璇锋眰澶辫触 (code: ${code})`, err); + return []; + }) + ); + + // 浣跨敤 Promise.allSettled 閬垮厤涓柇 + const results = await Promise.allSettled(requests); + + // 鎻愬彇鎵�鏈夋垚鍔熺殑缁撴灉 + const mergedPageData = results + .filter((result) => result.status === "fulfilled") + .flatMap((result) => result.value || []); + + // 濡傛灉涓嶆槸鈥滃尯鈥濓紝鍒欒繃婊ゅ嚭 deviceName 鍖呭惈 "瀛欒儭娌�" 鐨勮澶� + const filteredPageData = areaName.includes("鍖�") + ? mergedPageData + : mergedPageData.filter((device) => device.deviceName.includes("瀛欒儭娌�")); + + // 瀛欒儭娌熻澶囩粡绾害鏄犲皠 + const deviceMapping = { + 鎬�鏌斿尯鐞夌拑搴欓晣瀛欒儭娌熸ご鏍戝簳涓嬩笢娌熸偿浣嶈5007: { + lon: 116.598891, + lat: 40.554979, + }, + 鎬�鏌斿尯鐞夌拑搴欓晣瀛欒儭娌熸潙涓婂彴瀛愭渤涓滃崡娌熸偿浣嶈5006: { + lon: 116.593215, + lat: 40.554399, + }, + }; + + displayedData = filteredPageData; + + if (!areaName.includes("鍖�")) { + displayedData = filteredPageData.map((device) => { + const mapping = deviceMapping[device.deviceName]; + return { + ...device, + ...(mapping && { lon: mapping.lon, lat: mapping.lat }), + }; + }); + + // 娣诲姞棰濆鐨勪袱涓偣浣� + const extraPoint1 = { + deviceName: "寮矡1", + longitude: 116.597836, + latitude: 40.564962, + type: "娉ヤ綅璁�", + lon: 116.597836, + lat: 40.564962, + dictDeviceType: "1437295811", + deviceId: "custom_extraPoint1", + }; + + const extraPoint2 = { + deviceName: "寮矡2", + longitude: 116.591571, + latitude: 40.573093, + type: "娉ヤ綅璁�", + lon: 116.591571, + lat: 40.573093, + dictDeviceType: "1437295811", + deviceId: "custom_extraPoint2", + }; + + displayedData = [...displayedData, extraPoint1, extraPoint2]; + } + + console.log( + displayedData, + areaName.includes("鍖�") + ? "鍏ㄩ儴娉ヤ綅璁¤澶囧垪琛�" + : "瀛欒儭娌熸偿浣嶈 + 棰濆鐐逛綅鍒楄〃" + ); + } + + // 鍒涘缓鐐癸紙鍗充娇 displayedData 涓虹┖涔熶笉浼氭姤閿欙級 displayedData.forEach((item) => { - // 鏍规嵁闇�姹傚彲澧炲垹 item.type = getDictName(deviceDictList, item.dictDeviceType); item.name = item.deviceName; item.id = item.deviceId; @@ -256,6 +266,7 @@ createPoint(item); }); + // 鍚庣画妯℃嫙娴佺▼缁х画鎵ц锛屼笉鍙楀奖鍝� if (item.status === 2) { ElMessage.warning("褰撳墠鏂规姝e湪鍒嗘瀽涓�,鏃犳硶杩涘叆妯℃嫙锛�"); return; @@ -266,7 +277,6 @@ return; } - // 濡傛灉鏄凡瀹屾垚鐨勬柟妗堬紙status == 10锛� if (item.status === 10) { const flyHeight = item.areaType === 1 ? 100000 : 50000; simStore.setSelectedScheme(item); @@ -288,7 +298,6 @@ return; } - // 鏂板缓鏂规锛屾病鏈� status 鍜� serviceName 涓� type != 2 if (!item.status && !item.serviceName && item.type !== 2) { try { await getSimStart(item.id); @@ -304,7 +313,6 @@ return; } - // 榛樿鎯呭喌锛氭湁鏈嶅姟鍚嶇О simStore.setSelectedScheme(item); } -- Gitblit v1.9.3