替换获取船舶游艇的接口
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user