From 1d9873b225f1d5584feba8cf47627053fd680982 Mon Sep 17 00:00:00 2001 From: xwj Date: Thu, 12 Mar 2026 16:32:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E8=8E=B7=E5=8F=96=E8=88=B9?= =?UTF-8?q?=E8=88=B6=E6=B8=B8=E8=89=87=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.ts | 30 ++++++++++ src/views/main/Main.vue | 127 +++++++++++++++++++++++++++++++++++++++- vue.config.js | 4 ++ 3 files changed, 158 insertions(+), 3 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 0cce3ec..3792bcd 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -5,6 +5,27 @@ import md5 from 'md5'; const prefix = '/zero2/myships' const icdPrefix = 'https://sinoagent.i.sinotrans.com' // 生产 // const icdPrefix = 'http://sinoicd.i.sinotrans.com' // 测试 + +function getQueryParam(name: string) { + // 1. 获取 '?' 之后的查询字符串,并去掉开头的 '?' + const queryString = window.location.href.split('?')[1]; + // 2. 将字符串按 '&' 分割成键值对数组 + const queryParams = queryString.split('&'); + + for (const param of queryParams) { + // 3. 将每个键值对按 '=' 分割 + const [key, value] = param.split('='); + // 4. 进行URL解码并比较参数名 + if (decodeURIComponent(key) === name) { + return decodeURIComponent(value || ''); // 返回解码后的值 + } + } + // 5. 如果未找到,返回 null + return null; +} + +const token = getQueryParam('token'); + class Api { public getInfoByDestPort(data: any) { @@ -668,6 +689,15 @@ class Api { return res.data }) } + public getZeroShips(data: any) { + return Http.post('/freetrade/api/getShipMarinaInfoMmsiCode', data, { + headers: { + token: token || '' + } + }).then((res: any) => { + return res.data + }) + } } const HttpApi = new Api() diff --git a/src/views/main/Main.vue b/src/views/main/Main.vue index 23f8459..64d482f 100644 --- a/src/views/main/Main.vue +++ b/src/views/main/Main.vue @@ -170,6 +170,123 @@ export default class Main extends Vue { // 设置船舶警告(注释掉) // this.setShipWarning(ships); } + private mergeShipIds = (str1 = '', str2 = '') => { + // 1. 处理空值+拆分字符串+去除空格+过滤空项(避免多余逗号导致的空字符串) + const arr1 = str1.split(',').map(item => item.trim()).filter(Boolean); + const arr2 = str2.split(',').map(item => item.trim()).filter(Boolean); + + // 2. 合并+去重(Set自动去重),再转回逗号分隔的字符串 + const mergedSet = new Set([...arr1, ...arr2]); + return Array.from(mergedSet).join(','); + }; + + private async getZeroShips() { + const ships: any = [] + let shipsMmsi = '' + let yachtMmsi = '' + await HttpApi.getZeroShips({ + spmType: '船舶' + }).then(res => { + if (res.code === 0) { + shipsMmsi = res.data.shipId + } + }) + await HttpApi.getZeroShips({ + spmType: '游艇' + }).then(res => { + if (res.code === 0) { + yachtMmsi = res.data.shipId + } + }) + const mergedMmsi = this.mergeShipIds(shipsMmsi, yachtMmsi); + let shipIds: string[] = [] + + // 处理船舶数据 + if (shipsMmsi) { + await HttpApi.getShipIdByMmmsi(shipsMmsi).then((res: any) => { + res.data.map((item: any) => { + if (item.shipId) { + item.color = '#BD3154' + ships.push(item) + shipIds.push(item.shipId) + } + return item + }) + }) + } + + // 处理游艇数据 + if (yachtMmsi) { + await HttpApi.getShipIdByMmmsi(yachtMmsi).then((res: any) => { + + res.data.map((item: any) => { + if (item.shipId) { + item.color = '#ffc24d' + ships.push(item) + shipIds.push(item.shipId) + } + return item + }) + }) + } + + if (shipIds.length <= 110) { + await HttpApi.getShipMessage({shipId: shipIds.toString()}).then((res: any[]) => { + for (let i = 0; i < ships.length; i++) { + res.forEach((item: any) => { + if (ships[i].shipId === item.shipId.toString()) { + Object.keys(item).forEach((key) => { + ships[i][key] = item[key] + }) + } + }) + } + }) + } else { + const p: any[] = [] + const idGroup = this.spArray(shipIds, 100); + for (let i = 0; i < idGroup.length; i++) { + const ids = idGroup[i]; + p.push(new Promise((resolve) => { + HttpApi.getShipMessage({shipId: ids.toString()}).then((res) => { + resolve(res) + }) + })) + } + + const newGetShips: any[] = [] + await Promise.all(p).then((res) => { + for (let i = 0; i < res.length; i++) { + const shipG: any[] = res[i]; + for (let j = 0; j < shipG.length; j++) { + newGetShips.push(shipG[j]) + } + } + }) + + for (let i = 0; i < ships.length; i++) { + newGetShips.forEach((item: any) => { + if (ships[i].shipId === item.shipId) { + Object.keys(item).forEach((key) => { + ships[i][key] = item[key] + }) + } + }) + } + } + console.log(ships) + // 确保数据结构与原方法一致 + // ships.forEach((ship: any) => { + // if (!ship.groupName) { + // ship.groupName = ship.shipTypeName === '其他' ? '游艇' : '船舶'; + // } + // }); + + this.shipData = ships + this.jiexiRanks(ships); + storeUtil.setShipFleet(ships); + } + /** * 获取车辆数据并添加到地图 * 1. 从API获取车辆数据 @@ -424,7 +541,9 @@ export default class Main extends Vue { this.map.updateSize() }) // 获取初始船舶数据 - this.getShips() + // this.getShips() + + this.getZeroShips() // 获取初始车辆数据 this.getCars() // 监听全局事件,重新显示所有数据 @@ -466,9 +585,11 @@ export default class Main extends Vue { }) this.jiexiRanks(filteredShips) } else { - // 只隐藏船舶,保留游艇 + // 只隐藏船舶,保留游艇,同时隐藏特定 MMSI 的船舶 const shipIds = this.shipData - .filter((ship: any) => ship.shipTypeName !== '其他') + .filter((ship: any) => { + return ship.shipTypeName !== '其他' || ship.mmsi === '413280830' || ship.mmsi === '414873000' + }) .map((ship: any) => ship.shipId) ShipFun.hideShips(shipIds) DialogUtil.closeCom(DialogType.SHIP_INFO) diff --git a/vue.config.js b/vue.config.js index ea88310..3e39614 100644 --- a/vue.config.js +++ b/vue.config.js @@ -31,6 +31,10 @@ module.exports = { pathRewrite: { '/zeroi/free': '' } + }, + '/freetrade': { + target: 'https://www.zerotariff-hn.cn:15381/', + changOrigin: true } } },