Merge branch 'master' into feature/bfi-api-rate
# Conflicts: # src/components/vehicle-attachment-table/main.vue # src/option/payment/paymentApplication.js # src/views/payment/payment-application.vue # src/views/payment/receipt-claim-record.vue # src/views/vehicle/customer-archive.vue
This commit is contained in:
@@ -0,0 +1,434 @@
|
||||
/**
|
||||
* 认证审核通用工具
|
||||
*
|
||||
* 认证对象(司机 / 车辆)每次提交产生一条不可变快照记录,「审核」针对的是**一条记录**。
|
||||
* 记录分两侧:本次**待审快照**与该对象**当前生效快照**(最后一次审核通过的那条)。
|
||||
* 待审内容在审核通过前不影响生效值,所以审核页必须逐字段对比两侧,而不是只看一条当前值。
|
||||
*
|
||||
* 本文件提供三件事:
|
||||
* 1. 审核状态文案与标签(与后端 statusText 同一套词表);
|
||||
* 2. 快照字段的展示元数据(中文名、控件类型、分组);
|
||||
* 3. 两侧快照的字段级 diff 计算,含「从未认证通过、无对比基准」的处理。
|
||||
*
|
||||
* 两侧快照字段名完全一致(同一套结构),故可逐键比较。
|
||||
*/
|
||||
|
||||
const EMPTY_TEXT = '—';
|
||||
|
||||
const TYPE_IMAGE = 'image';
|
||||
const TYPE_DATE = 'date';
|
||||
const TYPE_LONG_TERM = 'longTerm';
|
||||
|
||||
/** 审核状态取值 */
|
||||
export const CERT_RECORD_STATUS = {
|
||||
PENDING: 0,
|
||||
APPROVED: 1,
|
||||
REJECTED: 2,
|
||||
VOIDED: 3,
|
||||
};
|
||||
|
||||
/** 状态文案统一为:审核中 / 已通过 / 已驳回 / 已作废 */
|
||||
const CERT_STATUS_TAG = {
|
||||
0: { label: '审核中', type: 'warning' },
|
||||
1: { label: '已通过', type: 'success' },
|
||||
2: { label: '已驳回', type: 'danger' },
|
||||
3: { label: '已作废', type: 'info' },
|
||||
};
|
||||
|
||||
/** 变更类型 → 差异标签 */
|
||||
export const CERT_CHANGE_TAG = {
|
||||
added: { label: '新增', type: 'success' },
|
||||
modified: { label: '已修改', type: 'warning' },
|
||||
cleared: { label: '已清空', type: 'danger' },
|
||||
};
|
||||
|
||||
/**
|
||||
* 「最新提交状态」展示缓存 → 标签
|
||||
*
|
||||
* 缓存为空表示该对象从未提交过认证(即没有生效快照)。
|
||||
* 注意它只是最近一次提交的状态,不等于「是否已认证」——后者由生效快照指针决定。
|
||||
*/
|
||||
export const certStatusTag = status => {
|
||||
if (status === null || status === undefined || status === '') {
|
||||
return { label: '未认证', type: 'info' };
|
||||
}
|
||||
return CERT_STATUS_TAG[status] || { label: EMPTY_TEXT, type: 'info' };
|
||||
};
|
||||
|
||||
const pad = value => String(value).padStart(2, '0');
|
||||
|
||||
/** 后端若改用时间戳毫秒序列化日期,也能落成日期文案 */
|
||||
const EPOCH_PATTERN = /^\d{13}$/;
|
||||
|
||||
const isEpochText = text => EPOCH_PATTERN.test(text);
|
||||
|
||||
const toDate = text => {
|
||||
const date = new Date(Number(text));
|
||||
return Number.isNaN(date.getTime()) ? null : date;
|
||||
};
|
||||
|
||||
/** 提交时间等日期时间展示,兼容 `yyyy-MM-dd HH:mm:ss`、ISO 串与时间戳毫秒 */
|
||||
export const formatCertDateTime = value => {
|
||||
if (value === null || value === undefined || value === '') return EMPTY_TEXT;
|
||||
const text = String(value).trim();
|
||||
const matched = text.match(
|
||||
/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})[T ](\d{1,2}):(\d{1,2})(?::(\d{1,2}))?/
|
||||
);
|
||||
if (matched) {
|
||||
return (
|
||||
`${matched[1]}-${pad(matched[2])}-${pad(matched[3])} ` +
|
||||
`${pad(matched[4])}:${pad(matched[5])}:${pad(matched[6] || 0)}`
|
||||
);
|
||||
}
|
||||
const date = isEpochText(text) ? toDate(text) : null;
|
||||
if (!date) return text;
|
||||
return (
|
||||
`${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ` +
|
||||
`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 快照字段元数据
|
||||
*
|
||||
* 字段名与后端提交 DTO 的 JSON 键一致(司机 PersonCertSubmitRequest / 车辆 VehicleCertSubmitRequest),
|
||||
* 两侧快照共用同一套结构,故同时用于标签与比较规则。
|
||||
*
|
||||
* `longTermKey` 只挂在**被长期有效作废掉的那个字段**上,也就是各组的「有效期止」与强制报废日期:
|
||||
* 勾了长期有效,它们显示「长期有效」、比较时按同一个值算(避免每次审核都报「已变更」)。
|
||||
* 「有效期起」不挂:起期是一个独立的日期,长期有效并不会让它失效,
|
||||
* 挂上去等于把它自己的值藏起来、还让审核员看不到起期的改动。
|
||||
*/
|
||||
const CERT_SNAPSHOT_GROUPS = {
|
||||
driver: [
|
||||
{
|
||||
title: '身份信息',
|
||||
fields: [
|
||||
{ key: 'realName', label: '真实姓名' },
|
||||
{ key: 'idCardNo', label: '身份证号' },
|
||||
{ key: 'idCardFrontUrl', label: '身份证正面照', type: TYPE_IMAGE },
|
||||
{ key: 'idCardBackUrl', label: '身份证反面照', type: TYPE_IMAGE },
|
||||
{ key: 'idCardValidStart', label: '身份证有效期起', type: TYPE_DATE },
|
||||
{
|
||||
key: 'idCardValidEnd',
|
||||
label: '身份证有效期止',
|
||||
type: TYPE_DATE,
|
||||
longTermKey: 'idCardLongTerm',
|
||||
},
|
||||
{ key: 'idCardLongTerm', label: '身份证长期有效', type: TYPE_LONG_TERM },
|
||||
{ key: 'headPhoto', label: '大头照', type: TYPE_IMAGE },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '驾驶证信息',
|
||||
fields: [
|
||||
{ key: 'driverFileNo', label: '驾驶证档案编号' },
|
||||
{ key: 'driverClass', label: '准驾车型' },
|
||||
{ key: 'driverLicenseFrontUrl', label: '驾驶证主页照片', type: TYPE_IMAGE },
|
||||
{ key: 'driverLicenseBackUrl', label: '驾驶证副页照片', type: TYPE_IMAGE },
|
||||
{ key: 'driverValidStart', label: '驾驶证有效期起', type: TYPE_DATE },
|
||||
{
|
||||
key: 'driverValidEnd',
|
||||
label: '驾驶证有效期止',
|
||||
type: TYPE_DATE,
|
||||
longTermKey: 'driverLongTerm',
|
||||
},
|
||||
{ key: 'driverLongTerm', label: '驾驶证长期有效', type: TYPE_LONG_TERM },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '从业资格证信息',
|
||||
fields: [
|
||||
{ key: 'qualificationType', label: '从业资格认证类型' },
|
||||
{ key: 'qualificationNo', label: '从业资格证号' },
|
||||
{
|
||||
key: 'qualificationFront',
|
||||
label: '从业资格证封面页',
|
||||
type: TYPE_IMAGE,
|
||||
legacyKeys: ['qualificationUrl'],
|
||||
},
|
||||
{ key: 'qualificationBack', label: '从业资格证内容页', type: TYPE_IMAGE },
|
||||
{ key: 'qualificationValidStart', label: '从业资格证有效期起', type: TYPE_DATE },
|
||||
{
|
||||
key: 'qualificationValidEnd',
|
||||
label: '从业资格证有效期止',
|
||||
type: TYPE_DATE,
|
||||
longTermKey: 'qualificationLongTerm',
|
||||
},
|
||||
{ key: 'qualificationLongTerm', label: '从业资格证长期有效', type: TYPE_LONG_TERM },
|
||||
],
|
||||
},
|
||||
],
|
||||
/*
|
||||
* 车辆字段名以 VehicleCertSubmitRequest 为准,与 PersonCertSubmitRequest 不同。
|
||||
* 键名对不上不报错——每个字段都算「没有值」,两组全显示「—」且 diff 不出变更。
|
||||
*/
|
||||
vehicle: [
|
||||
{
|
||||
title: '车辆基本信息',
|
||||
fields: [
|
||||
{ key: 'plateNo', label: '车牌号' },
|
||||
{ key: 'vehicleType', label: '车辆类型' },
|
||||
{ key: 'plateColor', label: '车牌颜色' },
|
||||
{ key: 'ownerName', label: '所有人' },
|
||||
{ key: 'vin', label: '车辆识别代号(车架号)' },
|
||||
{ key: 'outerLength', label: '外廓长度(mm)' },
|
||||
{ key: 'outerWidth', label: '外廓宽度(mm)' },
|
||||
{ key: 'outerHeight', label: '外廓高度(mm)' },
|
||||
{ key: 'approvedLoadKg', label: '核定载质量(KG)' },
|
||||
{ key: 'tractionMassKg', label: '准牵引总质量(KG)' },
|
||||
{ key: 'energyType', label: '能源类型' },
|
||||
{ key: 'businessRelation', label: '业务关系' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '行驶证信息',
|
||||
fields: [
|
||||
{ key: 'compulsoryScrapDate', label: '强制报废日期', type: TYPE_DATE, longTermKey: 'compulsoryScrapLongTerm' },
|
||||
{ key: 'compulsoryScrapLongTerm', label: '强制报废长期有效', type: TYPE_LONG_TERM },
|
||||
{ key: 'drivingLicenseNo', label: '行驶证档案编号' },
|
||||
{ key: 'drivingLicenseImage', label: '行驶证主页正面', type: TYPE_IMAGE },
|
||||
{ key: 'drivingLicenseMainBack', label: '行驶证主页反面', type: TYPE_IMAGE },
|
||||
{ key: 'drivingLicenseViceFront', label: '行驶证副页正面', type: TYPE_IMAGE },
|
||||
{ key: 'drivingLicenseViceBack', label: '行驶证副页反面', type: TYPE_IMAGE },
|
||||
{ key: 'drivingLicenseStartDate', label: '行驶证有效期起', type: TYPE_DATE },
|
||||
{
|
||||
key: 'drivingLicenseEndDate',
|
||||
label: '行驶证有效期止',
|
||||
type: TYPE_DATE,
|
||||
longTermKey: 'drivingLicenseLongTerm',
|
||||
},
|
||||
{ key: 'drivingLicenseLongTerm', label: '行驶证长期有效', type: TYPE_LONG_TERM },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '道路运输证信息',
|
||||
fields: [
|
||||
{ key: 'roadTransportCertNo', label: '道路运输证号' },
|
||||
{ key: 'roadTransportCertImage', label: '道路运输证照片', type: TYPE_IMAGE },
|
||||
{ key: 'roadTransportCertStartDate', label: '道路运输证有效期起', type: TYPE_DATE },
|
||||
{
|
||||
key: 'roadTransportCertEndDate',
|
||||
label: '道路运输证有效期止',
|
||||
type: TYPE_DATE,
|
||||
longTermKey: 'roadTransportCertLongTerm',
|
||||
},
|
||||
{ key: 'roadTransportCertLongTerm', label: '道路运输证长期有效', type: TYPE_LONG_TERM },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '机动车登记本信息',
|
||||
fields: [
|
||||
{ key: 'registrationNo', label: '机动车登记编号' },
|
||||
{ key: 'registrationImage', label: '机动车登记本照片', type: TYPE_IMAGE },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
/** 提交元信息与主键不参与对比(两侧必相同,展示出来只是噪音) */
|
||||
const IGNORED_KEYS = [
|
||||
'id',
|
||||
'bizType',
|
||||
'bizId',
|
||||
'bizKey',
|
||||
'certificationStatus',
|
||||
'snapshotJson',
|
||||
'pendingSnapshotJson',
|
||||
'effectiveSnapshotJson',
|
||||
];
|
||||
|
||||
/**
|
||||
* 解析快照 JSON
|
||||
*
|
||||
* 后端把 null 序列化为空串,故空串 / 'null' 都按「没有快照」处理,不算解析失败。
|
||||
*/
|
||||
const readSnapshot = json => {
|
||||
if (json && typeof json === 'object') {
|
||||
return { value: Object.keys(json).length ? json : null, invalid: false };
|
||||
}
|
||||
const text = String(json === null || json === undefined ? '' : json).trim();
|
||||
if (!text || text === 'null') {
|
||||
return { value: null, invalid: false };
|
||||
}
|
||||
try {
|
||||
const parsed = JSON.parse(text);
|
||||
if (parsed && typeof parsed === 'object') {
|
||||
return { value: parsed, invalid: false };
|
||||
}
|
||||
return { value: null, invalid: true };
|
||||
} catch (error) {
|
||||
return { value: null, invalid: true };
|
||||
}
|
||||
};
|
||||
|
||||
/** 解析快照 JSON,无快照或解析失败时返回 null */
|
||||
export const parseSnapshot = json => readSnapshot(json).value;
|
||||
|
||||
const isEmptyValue = value => value === null || value === undefined || value === '';
|
||||
|
||||
const isLongTermOn = value => value === 1 || value === '1' || value === true;
|
||||
|
||||
/** 日期归一化到 yyyy-MM-dd,便于 `2026-01-01` 与 `2026-01-01T00:00:00` 判等 */
|
||||
const normalizeDate = value => {
|
||||
if (isEmptyValue(value)) return '';
|
||||
const text = String(value).trim();
|
||||
const matched = text.match(/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})/);
|
||||
if (matched) return `${matched[1]}-${pad(matched[2])}-${pad(matched[3])}`;
|
||||
const date = isEpochText(text) ? toDate(text) : null;
|
||||
if (date) {
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
/**
|
||||
* 取字段值,兼容字段改名前的旧键
|
||||
*
|
||||
* 后端把某字段改名后,改名之前提交的记录里存的仍是旧键(例:从业资格证封面页
|
||||
* 由 `qualificationUrl` 改为 `qualificationFront`)。只读新键会得到空,
|
||||
* 审核页就把已填的封面页显示成「—」,误导审核员以为对方没传。
|
||||
* 新旧键都存在时以新键为准。
|
||||
*/
|
||||
const readFieldValue = (snapshot, field) => {
|
||||
if (!snapshot) return undefined;
|
||||
const value = snapshot[field.key];
|
||||
if (!isEmptyValue(value)) return value;
|
||||
const legacyKeys = field.legacyKeys || [];
|
||||
for (let i = 0; i < legacyKeys.length; i += 1) {
|
||||
if (!isEmptyValue(snapshot[legacyKeys[i]])) return snapshot[legacyKeys[i]];
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
/** 比较用的归一化取值:展示相同即视为未变更 */
|
||||
const canonicalOf = (snapshot, field) => {
|
||||
const value = readFieldValue(snapshot, field);
|
||||
if (field.type === TYPE_LONG_TERM) {
|
||||
if (isEmptyValue(value)) return '';
|
||||
return isLongTermOn(value) ? '1' : '0';
|
||||
}
|
||||
if (field.type === TYPE_DATE) {
|
||||
if (field.longTermKey && isLongTermOn(snapshot && snapshot[field.longTermKey])) {
|
||||
return '长期有效';
|
||||
}
|
||||
return normalizeDate(value);
|
||||
}
|
||||
return isEmptyValue(value) ? '' : String(value).trim();
|
||||
};
|
||||
|
||||
/** 展示文案:日期型受「长期有效」影响,图片型返回 URL 由组件渲染缩略图 */
|
||||
const textOf = (snapshot, field) => {
|
||||
const value = readFieldValue(snapshot, field);
|
||||
if (field.type === TYPE_IMAGE) {
|
||||
return isEmptyValue(value) ? '' : String(value);
|
||||
}
|
||||
if (field.type === TYPE_LONG_TERM) {
|
||||
if (isEmptyValue(value)) return EMPTY_TEXT;
|
||||
return isLongTermOn(value) ? '是' : '否';
|
||||
}
|
||||
if (field.type === TYPE_DATE) {
|
||||
if (field.longTermKey && isLongTermOn(snapshot && snapshot[field.longTermKey])) {
|
||||
return '长期有效';
|
||||
}
|
||||
return normalizeDate(value) || EMPTY_TEXT;
|
||||
}
|
||||
return isEmptyValue(value) ? EMPTY_TEXT : String(value);
|
||||
};
|
||||
|
||||
const buildRow = (field, pendingSnapshot, effectiveSnapshot, hasBaseline) => {
|
||||
const type = field.type || 'text';
|
||||
const target = { ...field, type };
|
||||
const pendingCanonical = canonicalOf(pendingSnapshot, target);
|
||||
const effectiveCanonical = canonicalOf(effectiveSnapshot, target);
|
||||
let changeType = '';
|
||||
if (hasBaseline && pendingCanonical !== effectiveCanonical) {
|
||||
if (!effectiveCanonical) {
|
||||
changeType = 'added';
|
||||
} else if (!pendingCanonical) {
|
||||
changeType = 'cleared';
|
||||
} else {
|
||||
changeType = 'modified';
|
||||
}
|
||||
}
|
||||
return {
|
||||
key: field.key,
|
||||
label: field.label,
|
||||
type,
|
||||
effective: {
|
||||
raw: readFieldValue(effectiveSnapshot, target),
|
||||
text: textOf(effectiveSnapshot, target),
|
||||
},
|
||||
pending: {
|
||||
raw: readFieldValue(pendingSnapshot, target),
|
||||
text: textOf(pendingSnapshot, target),
|
||||
},
|
||||
changed: Boolean(changeType),
|
||||
changeType,
|
||||
};
|
||||
};
|
||||
|
||||
const unionKeys = (pendingSnapshot, effectiveSnapshot) => {
|
||||
const keys = [];
|
||||
[pendingSnapshot, effectiveSnapshot].forEach(snapshot => {
|
||||
Object.keys(snapshot || {}).forEach(key => {
|
||||
if (!keys.includes(key)) keys.push(key);
|
||||
});
|
||||
});
|
||||
return keys;
|
||||
};
|
||||
|
||||
/**
|
||||
* 构造「待审快照 vs 当前生效值」的字段级 diff
|
||||
*
|
||||
* @param {string} bizType 认证对象类型:driver / vehicle
|
||||
* @param {string} pendingJson 本次待审快照 JSON
|
||||
* @param {string} effectiveJson 该对象当前生效快照 JSON,从未认证通过时为空
|
||||
* @returns {Object} { hasBaseline, groups, totalCount, changedCount, ... }
|
||||
* hasBaseline 为 false 表示无对比基准(从未认证通过),此时不产出任何变更标记
|
||||
*/
|
||||
export const buildSnapshotDiff = (bizType, pendingJson, effectiveJson) => {
|
||||
const pending = readSnapshot(pendingJson);
|
||||
const effective = readSnapshot(effectiveJson);
|
||||
const hasBaseline = effective.value !== null;
|
||||
const groupsConfig = CERT_SNAPSHOT_GROUPS[bizType] || [];
|
||||
const knownKeys = [];
|
||||
|
||||
const groups = groupsConfig.map(group => {
|
||||
const rows = group.fields.map(field => {
|
||||
// 旧键已由所属字段并入展示,不能再作为独立字段出现,否则同一张封面页会出现两行
|
||||
knownKeys.push(field.key, ...(field.legacyKeys || []));
|
||||
return buildRow(field, pending.value, effective.value, hasBaseline);
|
||||
});
|
||||
return {
|
||||
title: group.title,
|
||||
rows,
|
||||
changedCount: rows.filter(row => row.changed).length,
|
||||
};
|
||||
});
|
||||
|
||||
// 元数据未登记的字段照样展示,避免后端新增字段时审核员看不到变化
|
||||
const extraKeys = unionKeys(pending.value, effective.value).filter(
|
||||
key => !knownKeys.includes(key) && !IGNORED_KEYS.includes(key)
|
||||
);
|
||||
if (extraKeys.length) {
|
||||
const rows = extraKeys.map(key =>
|
||||
buildRow({ key, label: key }, pending.value, effective.value, hasBaseline)
|
||||
);
|
||||
groups.push({
|
||||
title: '其他字段',
|
||||
rows,
|
||||
changedCount: rows.filter(row => row.changed).length,
|
||||
});
|
||||
}
|
||||
|
||||
const rows = groups.reduce((all, group) => all.concat(group.rows), []);
|
||||
return {
|
||||
hasBaseline,
|
||||
pendingInvalid: pending.invalid,
|
||||
effectiveInvalid: effective.invalid,
|
||||
groups,
|
||||
totalCount: rows.length,
|
||||
changedCount: rows.filter(row => row.changed).length,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 合同下拉/选择展示:合同编号/合同名称
|
||||
*
|
||||
* @param {Object} contract 合同对象
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatContractOptionLabel(contract = {}) {
|
||||
const contractNo = String(contract?.contractNo ?? '').trim();
|
||||
const contractName = String(contract?.contractName ?? '').trim();
|
||||
if (contractNo && contractName) {
|
||||
return `${contractNo}/${contractName}`;
|
||||
}
|
||||
return contractNo || contractName || '';
|
||||
}
|
||||
@@ -13,6 +13,92 @@ const coordinateRanges = {
|
||||
},
|
||||
};
|
||||
|
||||
/** WGS-84 → GCJ-02(高德)偏移算法常量 */
|
||||
const WGS84_TO_GCJ02_PI = Math.PI;
|
||||
const WGS84_TO_GCJ02_A = 6378245.0;
|
||||
const WGS84_TO_GCJ02_EE = 0.00669342162296594323;
|
||||
|
||||
const isOutOfChina = (longitude, latitude) =>
|
||||
longitude < 72.004 || longitude > 137.8347 || latitude < 0.8293 || latitude > 55.8271;
|
||||
|
||||
const transformLatitude = (longitude, latitude) => {
|
||||
let result =
|
||||
-100.0 +
|
||||
2.0 * longitude +
|
||||
3.0 * latitude +
|
||||
0.2 * latitude * latitude +
|
||||
0.1 * longitude * latitude +
|
||||
0.2 * Math.sqrt(Math.abs(longitude));
|
||||
result +=
|
||||
((20.0 * Math.sin(6.0 * longitude * WGS84_TO_GCJ02_PI) +
|
||||
20.0 * Math.sin(2.0 * longitude * WGS84_TO_GCJ02_PI)) *
|
||||
2.0) /
|
||||
3.0;
|
||||
result +=
|
||||
((20.0 * Math.sin(latitude * WGS84_TO_GCJ02_PI) +
|
||||
40.0 * Math.sin((latitude / 3.0) * WGS84_TO_GCJ02_PI)) *
|
||||
2.0) /
|
||||
3.0;
|
||||
result +=
|
||||
((160.0 * Math.sin((latitude / 12.0) * WGS84_TO_GCJ02_PI) +
|
||||
320 * Math.sin((latitude * WGS84_TO_GCJ02_PI) / 30.0)) *
|
||||
2.0) /
|
||||
3.0;
|
||||
return result;
|
||||
};
|
||||
|
||||
const transformLongitude = (longitude, latitude) => {
|
||||
let result =
|
||||
300.0 +
|
||||
longitude +
|
||||
2.0 * latitude +
|
||||
0.1 * longitude * longitude +
|
||||
0.1 * longitude * latitude +
|
||||
0.1 * Math.sqrt(Math.abs(longitude));
|
||||
result +=
|
||||
((20.0 * Math.sin(6.0 * longitude * WGS84_TO_GCJ02_PI) +
|
||||
20.0 * Math.sin(2.0 * longitude * WGS84_TO_GCJ02_PI)) *
|
||||
2.0) /
|
||||
3.0;
|
||||
result +=
|
||||
((20.0 * Math.sin(longitude * WGS84_TO_GCJ02_PI) +
|
||||
40.0 * Math.sin((longitude / 3.0) * WGS84_TO_GCJ02_PI)) *
|
||||
2.0) /
|
||||
3.0;
|
||||
result +=
|
||||
((150.0 * Math.sin((longitude / 12.0) * WGS84_TO_GCJ02_PI) +
|
||||
300.0 * Math.sin((longitude / 30.0) * WGS84_TO_GCJ02_PI)) *
|
||||
2.0) /
|
||||
3.0;
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* WGS-84(GPS / LBS)转 GCJ-02(高德/国测局),供高德地图绘制使用。
|
||||
* 中国境外坐标不做偏移,原样返回。
|
||||
* @param {number} longitude
|
||||
* @param {number} latitude
|
||||
* @returns {[number, number]} [经度, 纬度]
|
||||
*/
|
||||
export const wgs84ToGcj02 = (longitude, latitude) => {
|
||||
const lng = Number(longitude);
|
||||
const lat = Number(latitude);
|
||||
if (!Number.isFinite(lng) || !Number.isFinite(lat) || isOutOfChina(lng, lat)) {
|
||||
return [lng, lat];
|
||||
}
|
||||
let dLat = transformLatitude(lng - 105.0, lat - 35.0);
|
||||
let dLng = transformLongitude(lng - 105.0, lat - 35.0);
|
||||
const radLat = (lat / 180.0) * WGS84_TO_GCJ02_PI;
|
||||
let magic = Math.sin(radLat);
|
||||
magic = 1 - WGS84_TO_GCJ02_EE * magic * magic;
|
||||
const sqrtMagic = Math.sqrt(magic);
|
||||
dLat =
|
||||
(dLat * 180.0) /
|
||||
(((WGS84_TO_GCJ02_A * (1 - WGS84_TO_GCJ02_EE)) / (magic * sqrtMagic)) * WGS84_TO_GCJ02_PI);
|
||||
dLng = (dLng * 180.0) / ((WGS84_TO_GCJ02_A / sqrtMagic) * Math.cos(radLat) * WGS84_TO_GCJ02_PI);
|
||||
return [lng + dLng, lat + dLat];
|
||||
};
|
||||
|
||||
export const normalizeCoordinateInput = value => {
|
||||
const rawValue = String(value ?? '').replace(/[^\d.-]/g, '');
|
||||
const isNegative = rawValue.startsWith('-');
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
const CURRENCY_NAME_MAP = {
|
||||
CNY: '人民币',
|
||||
RMB: '人民币',
|
||||
USD: '美元',
|
||||
EUR: '欧元',
|
||||
JPY: '日元',
|
||||
GBP: '英镑',
|
||||
};
|
||||
|
||||
const CURRENCY_UNIT_MAP = {
|
||||
CNY: '元',
|
||||
RMB: '元',
|
||||
USD: '美元',
|
||||
EUR: '欧元',
|
||||
JPY: '日元',
|
||||
GBP: '英镑',
|
||||
};
|
||||
|
||||
const CURRENCY_NAME_TO_UNIT = {
|
||||
人民币: '元',
|
||||
美元: '美元',
|
||||
欧元: '欧元',
|
||||
日元: '日元',
|
||||
英镑: '英镑',
|
||||
};
|
||||
|
||||
/**
|
||||
* 归一化币种代码(CNY → RMB)
|
||||
*/
|
||||
export function normalizeCurrencyCode(value, fallback = 'RMB') {
|
||||
const raw =
|
||||
typeof value === 'object'
|
||||
? value?.dictKey || value?.value || value?.code || value?.dictValue || ''
|
||||
: value;
|
||||
const normalized = String(raw || fallback)
|
||||
.trim()
|
||||
.toUpperCase();
|
||||
const code = normalized.includes(' - ') ? normalized.split(' - ')[0].trim() : normalized;
|
||||
if (!code) return fallback;
|
||||
return code === 'CNY' ? 'RMB' : code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 币种中文名称
|
||||
*/
|
||||
export function currencyName(value) {
|
||||
const text = String(value || '');
|
||||
if (text.includes(' - ')) return text.slice(text.indexOf(' - ') + 3);
|
||||
return CURRENCY_NAME_MAP[text.toUpperCase()] || text;
|
||||
}
|
||||
|
||||
/**
|
||||
* 金额单位文案:RMB/CNY → 元,USD → 美元
|
||||
*/
|
||||
export function currencyUnit(value) {
|
||||
const text = String(value || '');
|
||||
let code = text;
|
||||
if (text.includes(' - ')) {
|
||||
code = text.split(' - ')[0].trim();
|
||||
}
|
||||
const upperCode = code.toUpperCase();
|
||||
if (CURRENCY_UNIT_MAP[upperCode]) {
|
||||
return CURRENCY_UNIT_MAP[upperCode];
|
||||
}
|
||||
if (CURRENCY_NAME_TO_UNIT[code]) {
|
||||
return CURRENCY_NAME_TO_UNIT[code];
|
||||
}
|
||||
return text || '元';
|
||||
}
|
||||
|
||||
/**
|
||||
* 将计价单位前缀替换为当前币种单位,如 元/吨 → 美元/吨
|
||||
*/
|
||||
export function remapPriceUnitCurrency(priceUnit, currency) {
|
||||
const text = String(priceUnit || '').trim();
|
||||
if (!text || !text.includes('/')) return text;
|
||||
const suffix = text.slice(text.indexOf('/'));
|
||||
return `${currencyUnit(currency)}${suffix}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 按数量单位生成默认计价单位
|
||||
*/
|
||||
export function resolvePriceUnitByQuantityUnit(quantityUnit, currency = 'RMB') {
|
||||
const unit = currencyUnit(currency);
|
||||
return (
|
||||
{
|
||||
吨: `${unit}/吨`,
|
||||
方: `${unit}/立方`,
|
||||
件: `${unit}/件`,
|
||||
}[String(quantityUnit || '').trim()] || ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字典中的计价单位选项映射到当前币种
|
||||
*/
|
||||
export function mapFeeUnitOptions(options = [], currency = 'RMB') {
|
||||
const unit = currencyUnit(currency);
|
||||
return (options || []).map(item => {
|
||||
const label = String(item.label || item.value || '');
|
||||
const value = String(item.value || item.label || '');
|
||||
return {
|
||||
...item,
|
||||
label: label.replace(/^元/, unit).replace(/^人民币/, unit),
|
||||
value: value.replace(/^元/, unit).replace(/^人民币/, unit),
|
||||
};
|
||||
});
|
||||
}
|
||||
+99
-22
@@ -6,7 +6,31 @@ import 'nprogress/nprogress.css';
|
||||
|
||||
const excelPattern = /\.(xls|xlsx)$/;
|
||||
|
||||
/** 是否为浏览器 Blob(含跨 realm 的 Blob-like) */
|
||||
const isBlobLike = value =>
|
||||
value != null &&
|
||||
typeof value === 'object' &&
|
||||
typeof value.size === 'number' &&
|
||||
typeof value.type === 'string' &&
|
||||
(typeof value.text === 'function' || typeof value.arrayBuffer === 'function');
|
||||
|
||||
/** axios 拦截器已把 JSON Blob 解析成的业务对象 */
|
||||
const isBusinessJson = value =>
|
||||
value != null &&
|
||||
typeof value === 'object' &&
|
||||
!isBlobLike(value) &&
|
||||
!(value instanceof ArrayBuffer) &&
|
||||
('code' in value || 'success' in value || 'msg' in value);
|
||||
|
||||
const isExcelResponse = res => {
|
||||
// 已是业务 JSON(导入成功/失败提示)时,绝不能当失败明细 Excel 处理
|
||||
if (isBusinessJson(res?.data)) {
|
||||
return false;
|
||||
}
|
||||
// 只有文件流才可能是失败明细;普通对象没有 .text/.arrayBuffer
|
||||
if (!isBlobLike(res?.data)) {
|
||||
return false;
|
||||
}
|
||||
const headers = res.headers || {};
|
||||
const contentType = String(headers['content-type'] || res.data?.type || '').toLowerCase();
|
||||
const contentDisposition = String(headers['content-disposition'] || '').toLowerCase();
|
||||
@@ -23,8 +47,34 @@ const isExcelResponse = res => {
|
||||
);
|
||||
};
|
||||
|
||||
const parseBlobJson = async blob => {
|
||||
const text = await blob.text();
|
||||
/**
|
||||
* 解析导入接口响应体为 JSON 对象。
|
||||
* <p>
|
||||
* axios 拦截器在 Content-Type 为 JSON 时,会把 `responseType: 'blob'` 的 Blob
|
||||
* 提前解析成普通对象;此处需同时兼容 Blob / 字符串 / 已解析对象,避免再调
|
||||
* `blob.text()` 时出现「blob.text is not a function」。
|
||||
*/
|
||||
const parseBlobJson = async data => {
|
||||
if (data == null) {
|
||||
return {};
|
||||
}
|
||||
if (isBusinessJson(data)) {
|
||||
return data;
|
||||
}
|
||||
if (typeof data === 'object' && !isBlobLike(data) && !(data instanceof ArrayBuffer)) {
|
||||
return data;
|
||||
}
|
||||
if (typeof data === 'string') {
|
||||
return data ? JSON.parse(data) : {};
|
||||
}
|
||||
let text = '';
|
||||
if (typeof data.text === 'function') {
|
||||
text = await data.text();
|
||||
} else if (typeof data.arrayBuffer === 'function') {
|
||||
text = new TextDecoder().decode(await data.arrayBuffer());
|
||||
} else if (data instanceof ArrayBuffer) {
|
||||
text = new TextDecoder().decode(data);
|
||||
}
|
||||
return text ? JSON.parse(text) : {};
|
||||
};
|
||||
|
||||
@@ -39,18 +89,21 @@ const parseBlobJson = async blob => {
|
||||
* 这里补上这一步:从错误响应的 Blob 里取出后端 `msg`,取不到再退回通用文案。
|
||||
*/
|
||||
const resolveErrorMessage = async error => {
|
||||
const blob = error?.response?.data ?? error?.data;
|
||||
if (blob instanceof Blob) {
|
||||
const payload = error?.response?.data ?? error?.data;
|
||||
if (isBusinessJson(payload) && payload.msg) {
|
||||
return payload.msg;
|
||||
}
|
||||
if (isBlobLike(payload) || typeof payload === 'string') {
|
||||
try {
|
||||
const result = await parseBlobJson(blob);
|
||||
const result = await parseBlobJson(payload);
|
||||
if (result?.msg) return result.msg;
|
||||
} catch (ignored) {
|
||||
// 响应体不是 JSON(如网关返回的 HTML 错误页),退回通用文案
|
||||
}
|
||||
}
|
||||
const fallback = error?.response?.data?.msg || error?.message;
|
||||
const fallback = payload?.msg || error?.message;
|
||||
// axios 的英文通用文案对用户没有意义,统一换成中文提示
|
||||
if (!fallback || /Request failed with status code/i.test(fallback)) {
|
||||
if (!fallback || /Request failed with status code|\.text is not a function/i.test(fallback)) {
|
||||
return '导入失败,请检查导入文件后重试';
|
||||
}
|
||||
return fallback;
|
||||
@@ -68,8 +121,11 @@ const resolveErrorMessage = async error => {
|
||||
*/
|
||||
const decorateFailExcel = async (blob, businessName, failDetailDecorator) => {
|
||||
if (typeof failDetailDecorator !== 'function') return blob;
|
||||
if (!isBlobLike(blob) && !(blob instanceof ArrayBuffer)) {
|
||||
return blob;
|
||||
}
|
||||
const ExcelJS = await import('exceljs');
|
||||
const buf = await blob.arrayBuffer();
|
||||
const buf = typeof blob.arrayBuffer === 'function' ? await blob.arrayBuffer() : blob;
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
await workbook.xlsx.load(buf);
|
||||
await failDetailDecorator(workbook, { businessName });
|
||||
@@ -77,6 +133,31 @@ const decorateFailExcel = async (blob, businessName, failDetailDecorator) => {
|
||||
return new Blob([out], { type: 'application/vnd.ms-excel' });
|
||||
};
|
||||
|
||||
/** 通知上传组件成功:只传业务响应体,避免其误调 axios 响应上的 .text() */
|
||||
const notifyUploadSuccess = (option, res) => {
|
||||
if (typeof option?.onSuccess !== 'function') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const body = isBusinessJson(res?.data) ? res.data : { code: 200, success: true };
|
||||
option.onSuccess(body);
|
||||
} catch (callbackError) {
|
||||
console.warn('upload onSuccess callback failed', callbackError);
|
||||
}
|
||||
};
|
||||
|
||||
/** 通知上传组件失败 */
|
||||
const notifyUploadError = (option, error) => {
|
||||
if (typeof option?.onError !== 'function') {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
option.onError(error instanceof Error ? error : new Error(String(error?.message || error || '导入失败')));
|
||||
} catch (callbackError) {
|
||||
console.warn('upload onError callback failed', callbackError);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 打开导入弹窗
|
||||
* @param {Object} vm 组件实例
|
||||
@@ -108,9 +189,7 @@ export const handleImportExcel = async (vm, option, column, businessName, onSucc
|
||||
const fileName = file && file.name ? file.name.toLowerCase() : '';
|
||||
if (!excelPattern.test(fileName)) {
|
||||
vm.$message.error('请上传 .xls,.xlsx 标准格式文件');
|
||||
if (typeof option.onError === 'function') {
|
||||
option.onError(new Error('请上传 .xls,.xlsx 标准格式文件'));
|
||||
}
|
||||
notifyUploadError(option, new Error('请上传 .xls,.xlsx 标准格式文件'));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -130,12 +209,11 @@ export const handleImportExcel = async (vm, option, column, businessName, onSucc
|
||||
);
|
||||
vm.$message.warning('部分数据导入失败,已下载失败明细');
|
||||
} else {
|
||||
const result = await parseBlobJson(res.data);
|
||||
if (result.code !== 200) {
|
||||
// 成功体常被 axios 拦截器提前解析成对象;优先走业务 JSON,避免再调 Blob.text
|
||||
const result = isBusinessJson(res?.data) ? res.data : await parseBlobJson(res?.data);
|
||||
if (Number(result.code) !== 200) {
|
||||
vm.$message.error(result.msg || '导入失败');
|
||||
if (typeof option.onError === 'function') {
|
||||
option.onError(new Error(result.msg || '导入失败'));
|
||||
}
|
||||
notifyUploadError(option, new Error(result.msg || '导入失败'));
|
||||
return;
|
||||
}
|
||||
vm.$message.success('导入完成');
|
||||
@@ -149,18 +227,17 @@ export const handleImportExcel = async (vm, option, column, businessName, onSucc
|
||||
} else if (typeof vm.initTree === 'function') {
|
||||
vm.initTree();
|
||||
}
|
||||
if (typeof option.onSuccess === 'function') {
|
||||
option.onSuccess(res);
|
||||
}
|
||||
// 上传组件 onSuccess 约定接收「响应体」,不是完整 axios 响应。
|
||||
// 若传入 axios 响应对象,部分环境下会按 Fetch Response 调用 .text(),
|
||||
// 从而在导入已成功后仍弹出「e.text is not a function」。
|
||||
notifyUploadSuccess(option, res);
|
||||
} catch (error) {
|
||||
// 拦截器已提示过的错误(如后端 400 返回的业务提示)不再重复弹一次,
|
||||
// 只保留一次清晰的中文提示。
|
||||
if (!error?._notified) {
|
||||
vm.$message.error(await resolveErrorMessage(error));
|
||||
}
|
||||
if (typeof option.onError === 'function') {
|
||||
option.onError(error);
|
||||
}
|
||||
notifyUploadError(option, error);
|
||||
} finally {
|
||||
loading.close();
|
||||
NProgress.done();
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { getList as getMeasurementUnitList } from '@/api/base/measurement-unit';
|
||||
|
||||
/**
|
||||
* 加载启用状态的计量单位选项,展示/取值均为「计量单位」字段(unitName)。
|
||||
* @returns {Promise<Array<{ label: string, value: string, dimension: string, id: string|number }>>}
|
||||
*/
|
||||
export const loadMeasurementUnitOptions = () => {
|
||||
return getMeasurementUnitList(1, 9999, { status: 1 }).then(res => {
|
||||
const data = res?.data?.data || res?.data || {};
|
||||
const records = Array.isArray(data) ? data : data.records || [];
|
||||
const names = new Set();
|
||||
return records
|
||||
.filter(item => item.status === undefined || item.status === null || Number(item.status) === 1)
|
||||
.map(item => {
|
||||
const name = String(item.unitName || '').trim();
|
||||
if (!name || names.has(name)) return null;
|
||||
names.add(name);
|
||||
return {
|
||||
id: item.id,
|
||||
label: name,
|
||||
value: name,
|
||||
dimension: String(item.dimension || '').trim(),
|
||||
};
|
||||
})
|
||||
.filter(Boolean);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* 行政区划展示格式化(仅展示层,不改动后端存储值)。
|
||||
*
|
||||
* 需求:省 / 市 / 区县之间要有空格隔开,避免「上海市浦东新区」「广西壮族自治区南宁市邕宁区」挤成一坨。
|
||||
* 与全站既有规则保持一致(公路地址按「市 区县」展示,省/自治区不重复展示):
|
||||
* 上海市浦东新区 -> 上海市 浦东新区
|
||||
* 广西壮族自治区南宁市邕宁区 -> 南宁市 邕宁区
|
||||
* 梅州市梅县区 -> 梅州市 梅县区
|
||||
*
|
||||
* 非纯行政区划串(站点名「南宁站」「广州南站」、含街道门牌的详细地址等)原样返回,不做任何改动。
|
||||
*/
|
||||
|
||||
// 行政区划后缀:长后缀在前,避免「自治区」被截成「区」、「自治州」被截成「州」
|
||||
const REGION_SUFFIXES = [
|
||||
'特别行政区',
|
||||
'自治区',
|
||||
'自治州',
|
||||
'自治县',
|
||||
'自治旗',
|
||||
'开发区',
|
||||
'新区',
|
||||
'林区',
|
||||
'矿区',
|
||||
'地区',
|
||||
'省',
|
||||
'市',
|
||||
'州',
|
||||
'盟',
|
||||
'区',
|
||||
'县',
|
||||
'旗',
|
||||
];
|
||||
|
||||
// 省级区划:展示时不在区划链首重复(「广西壮族自治区南宁市邕宁区」-> 「南宁市 邕宁区」)
|
||||
const PROVINCE_SUFFIX = /(?:省|自治区|特别行政区)$/;
|
||||
|
||||
/**
|
||||
* 从文本头部匹配第一个行政区划片段。
|
||||
* 特例:「梅州市」州后紧跟市,并入同一片段;「梅县区」县/旗后紧跟区,并入同一片段。
|
||||
* @param {string} text 已去除空白的文本
|
||||
* @returns {string} 片段,未匹配到返回 ''
|
||||
*/
|
||||
function matchRegionToken(text) {
|
||||
for (let end = 0; end < text.length; end += 1) {
|
||||
const prefix = text.slice(0, end + 1);
|
||||
const suffix = REGION_SUFFIXES.find(item => prefix.endsWith(item));
|
||||
if (!suffix) continue;
|
||||
const next = text[end + 1] || '';
|
||||
if ((suffix === '州' || suffix === '盟') && next === '市') continue;
|
||||
if ((suffix === '县' || suffix === '旗') && next === '区') return text.slice(0, end + 2);
|
||||
return prefix;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* 按行政区划后缀把文本切成区划片段。
|
||||
* @param {string} value 原值
|
||||
* @returns {string[]|null} 整串都是行政区划时返回片段数组,否则返回 null
|
||||
*/
|
||||
export function splitRegionTokens(value) {
|
||||
const text = String(value ?? '').replace(/\s+/g, '');
|
||||
if (!text) return null;
|
||||
const tokens = [];
|
||||
let rest = text;
|
||||
while (rest) {
|
||||
const token = matchRegionToken(rest);
|
||||
if (!token) return null;
|
||||
tokens.push(token);
|
||||
rest = rest.slice(token.length);
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/**
|
||||
* 行政区划串按「市 区县」展示,省/自治区不重复展示。
|
||||
* @param {string} value 原值
|
||||
* @returns {string} 含空格的展示值;非纯行政区划串原样返回
|
||||
*/
|
||||
export function formatRegionAddress(value) {
|
||||
const text = String(value ?? '').trim();
|
||||
if (!text) return '';
|
||||
const tokens = splitRegionTokens(text);
|
||||
if (!tokens || !tokens.length) return text;
|
||||
const display = PROVINCE_SUFFIX.test(tokens[0]) ? tokens.slice(1) : tokens;
|
||||
return (display.length ? display : tokens).join(' ');
|
||||
}
|
||||
|
||||
export default formatRegionAddress;
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 路线变更记录内容格式化
|
||||
*
|
||||
* 存储格式(单行):
|
||||
* YD-20260904-0022:发货地 A → B;到货地 C → D;YD-20260904-0025:发货地 E → F;到货地 G → H
|
||||
*
|
||||
* 展示格式(变更前 / 变更后分行):
|
||||
* YD-20260904-0022:发货地 A →
|
||||
* B
|
||||
* 到货地 C →
|
||||
* D
|
||||
*
|
||||
* 说明:仅用于展示层,不改变已存储的 content 文本(历史数据同样适用)。
|
||||
*/
|
||||
export const formatRouteChangeContent = (content, emptyText = '-') => {
|
||||
if (content === undefined || content === null) return emptyText;
|
||||
const text = String(content).trim();
|
||||
if (!text) return emptyText;
|
||||
|
||||
return text
|
||||
.replace(/\r\n?/g, '\n')
|
||||
// 多条记录之间换行
|
||||
.replace(/[ \t]*[;;][ \t]*/g, '\n')
|
||||
// 变更前地址 / 变更后地址分行(箭头保留在上一行行尾)
|
||||
.replace(/[ \t]*[-—]+>[ \t]*|[ \t]*→[ \t]*/g, ' →\n')
|
||||
.replace(/\n{2,}/g, '\n')
|
||||
.replace(/[ \t]+\n/g, '\n')
|
||||
.trim();
|
||||
};
|
||||
Reference in New Issue
Block a user