Files
Ubuntu deb3e72750
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库:jxc/ai-fresh-delivery
来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d
快照树:  09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件)

按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据
(生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、
deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

146 lines
3.8 KiB
JavaScript

let runtimeMapKey = '';
function parseCoord(lat, lng) {
const latitude = Number(lat);
const longitude = Number(lng);
if (!Number.isFinite(latitude) || !Number.isFinite(longitude)) return null;
if (Math.abs(latitude) < 0.000001 && Math.abs(longitude) < 0.000001) return null;
return { latitude, longitude };
}
function applyMapClientConfig(row) {
const provider = String(row && row.provider || '').trim();
const key = String(row && row.key || '').trim();
runtimeMapKey = provider === 'tencent' ? key : '';
}
function tencentMapKey() {
return runtimeMapKey;
}
function openWxLocation(name, address, point) {
wx.openLocation({
latitude: point.latitude,
longitude: point.longitude,
name,
address: String(address || ''),
scale: 16,
});
}
function openTencentNavigation(input) {
const point = parseCoord(input && input.lat, input && input.lng);
if (!point) {
wx.showToast({ title: '该站点暂无坐标', icon: 'none' });
return;
}
const name = String(input.name || input.address || '配送点').slice(0, 20);
openWxLocation(name, input.address, point);
}
function pointsFromPlan(plan) {
const points = [];
const stops = (plan && plan.stops) || [];
stops.forEach((stop) => {
const point = parseCoord(stop.lat, stop.lng);
if (point) points.push(point);
});
return points;
}
function isOpenNavTask(task) {
const status = Number(task && task.task_status);
return (status === 10 || status === 20) && Boolean(task && task.can_navigate);
}
function findNextNavTask(tasks) {
const list = tasks || [];
const open = list.filter(isOpenNavTask);
const entered = open.find(
(task) => Number(task.task_status) === 20 && task.geofence_entered_at
);
if (entered) return entered;
const ranked = open.filter((task) => {
const seq = Number(task.route_sequence);
return Number.isFinite(seq);
});
if (ranked.length) {
ranked.sort((a, b) => Number(a.route_sequence) - Number(b.route_sequence));
return ranked[0];
}
if (open.length) return open[0];
return list.find((task) => task.can_navigate) || null;
}
function buildDeliveryMap(tasks, plan) {
const markers = [];
const includePoints = [];
const markerTaskCodes = {};
(tasks || []).forEach((task, idx) => {
const point = parseCoord(task.lat, task.lng);
if (!point) return;
const id = idx + 1;
const seq = task.route_sequence != null ? Number(task.route_sequence) : idx + 1;
const title = String(task.company_name || task.order_code || '站点');
markers.push({
id,
latitude: point.latitude,
longitude: point.longitude,
width: 28,
height: 28,
callout: {
content: `${seq}. ${title}`,
display: 'BYCLICK',
padding: 8,
borderRadius: 8,
fontSize: 12,
},
});
includePoints.push(point);
markerTaskCodes[id] = task.task_code;
});
const linePoints = pointsFromPlan(plan);
const polyline = linePoints.length >= 2
? [{
points: linePoints,
color: '#047857',
width: 4,
dottedLine: false,
arrowLine: true,
}]
: [];
const center = (linePoints[0] || includePoints[0]);
if (!includePoints.length && !linePoints.length) {
return {
show: false,
latitude: 31.2304,
longitude: 121.4737,
scale: 12,
markers: [],
includePoints: [],
polyline: [],
markerTaskCodes: {},
};
}
const fit = includePoints.length ? includePoints : linePoints;
return {
show: true,
latitude: (center && center.latitude) || 31.2304,
longitude: (center && center.longitude) || 121.4737,
scale: fit.length === 1 ? 15 : 12,
markers,
includePoints: fit,
polyline,
markerTaskCodes,
};
}
module.exports = {
parseCoord,
tencentMapKey,
applyMapClientConfig,
openTencentNavigation,
buildDeliveryMap,
findNextNavTask,
};