Commit d5ef1775 by liimin

refactor(Express): 重构物流状态判断逻辑并优化代码结构

- 新增状态判断规则配置(STATUS_RULES)集中管理状态判断逻辑
- 将状态判断和轨迹过滤拆分为独立方法(_determineStatusByContent和_shouldShowTrack)
- 增加输入参数校验和错误处理
- 优化轨迹数据处理流程,提高代码可读性
- 移除无用注释代码,保持代码整洁

fix(TimeLine): 调整时间轴节点点尺寸为22rpx
1 parent 58dcd44b
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
/* 时间轴节点点 */ /* 时间轴节点点 */
.timeline-node__dot { .timeline-node__dot {
width: 20rpx; width: 22rpx;
height: 20rpx; height: 22rpx;
background-color: #e8e8ea; background-color: #e8e8ea;
border-radius: 50%; border-radius: 50%;
z-index: 1; z-index: 1;
......
...@@ -5,6 +5,41 @@ const LOGISTICS_STATUS = { ...@@ -5,6 +5,41 @@ const LOGISTICS_STATUS = {
1003: "已签收", 1003: "已签收",
1004: "拒收", 1004: "拒收",
}; };
// 状态判断规则配置
const STATUS_RULES = [
{
keywords: ["已签收", "签收人"],
status: 1003,
statusDesc: "已签收",
},
{
keywords: ["拒收", "退回"],
status: 1004,
statusDesc: "拒收",
},
{
keywords: ["派件", "驿站", "暂存"],
status: 1002,
statusDesc: "运输中",
},
{
keywords: ["转运中心", "发往", "到达"],
status: 1002,
statusDesc: "运输中",
},
{
keywords: ["已收件", "揽收"],
status: 1001,
statusDesc: "已揽件",
},
{
keywords: ["已发往"],
status: 1001,
statusDesc: "已揽件",
},
];
Component({ Component({
properties: { properties: {
expressInfo: { expressInfo: {
...@@ -19,127 +54,128 @@ Component({ ...@@ -19,127 +54,128 @@ Component({
type: Boolean, type: Boolean,
value: false, value: false,
}, },
// height: {
// type: String,
// value: '256rpx'
// }
}, },
data: { data: {
logisticsData: {}, logisticsData: {},
// timelineData: [
// {
// time: "2021-02-02 10:30:30",
// tips: ["这是主要内容部分"],
// title: "已发货",
// type: 'active',// 高亮显示
// },
// {
// time: "2021-02-02 10:30:30",
// tips: ["这是主要内容部分"],
// title:'运输中',
// type: 'small',// 小点显示
// },
// {
// time: "2021-02-02 10:30:30",
// tips: ["这是主要内容部分11111111111",
// "这是主要内容部分11111111111",
// "这是主要内容部分11111111111"
// ],
// title:'运输中',
// type: 'normal',
// },
// {
// title:'收货地址',
// tips: ["这是主要内容部分"],
// type: 'special' // 地址节点,使用专门的样式
// }
// ],
}, },
methods: { methods: {
/**
* 根据内容判断物流状态
* @param {string} content - 物流轨迹内容
* @returns {Object} 包含status和statusDesc的对象
*/
_determineStatusByContent(content) {
if (!content || typeof content !== "string") {
return { status: 1000, statusDesc: "待揽件" };
}
for (const rule of STATUS_RULES) {
if (rule.keywords.some((keyword) => content.includes(keyword))) {
return {
status: rule.status,
statusDesc: rule.statusDesc,
};
}
}
return { status: 1000, statusDesc: "待揽件" };
},
/**
* 根据物流状态过滤轨迹
* @param {number} trackStatus - 轨迹状态
* @param {number} logisticsStatus - 整体物流状态
* @returns {boolean} 是否显示该轨迹
*/
_shouldShowTrack(trackStatus, logisticsStatus) {
const statusThresholds = {
1000: 1000, // 待揽件 - 只显示收件相关记录
1001: 1001, // 已揽件 - 显示揽件和发往记录
1002: 1002, // 运输中 - 显示所有运输中的记录
1003: 1003, // 已签收 - 显示所有记录
1004: 1004, // 拒收 - 显示所有记录
};
const threshold = statusThresholds[logisticsStatus];
return threshold !== undefined ? trackStatus <= threshold : true;
},
/**
* 处理物流轨迹数据
* @param {Array} shipmentTrack - 原始轨迹数据
* @param {number} logisticsStatus - 物流状态
* @returns {Array} 处理后的轨迹数据
*/
processShipmentTrack(shipmentTrack, logisticsStatus) { processShipmentTrack(shipmentTrack, logisticsStatus) {
if (!shipmentTrack || !shipmentTrack.length) return; if (!Array.isArray(shipmentTrack) || shipmentTrack.length === 0) {
if (!this.data.showAll) { return [];
shipmentTrack = shipmentTrack.slice(0, 2);
} }
return shipmentTrack
// 根据showAll决定显示数量
const tracksToProcess = this.data.showAll
? shipmentTrack
: shipmentTrack.slice(0, 2);
return tracksToProcess
.map((track, index) => { .map((track, index) => {
let status = 1000; const { content = "", operateTime = "" } = track;
let statusDesc = "待揽件";
const content = track.content;
const operateTime = track.operateTime;
const isLast = index === 0; const isLast = index === 0;
// 根据内容判断状态 // 根据内容判断状态
if (content.includes("已签收") || content.includes("签收人")) { const { status, statusDesc: initialStatusDesc } =
status = 1003; this._determineStatusByContent(content);
statusDesc = "已签收";
} else if (content.includes("拒收") || content.includes("退回")) {
status = 1004;
statusDesc = "拒收";
} else if (
content.includes("派件") ||
content.includes("驿站") ||
content.includes("暂存")
) {
status = 1002;
statusDesc = "运输中";
} else if (
content.includes("转运中心") ||
content.includes("发往") ||
content.includes("到达")
) {
status = 1002;
statusDesc = "运输中";
} else if (content.includes("已收件") || content.includes("揽收")) {
status = 1001;
statusDesc = "已揽件";
} else if (content.includes("已发往")) {
status = 1001;
statusDesc = "已揽件";
}
// 根据整体物流状态进行最终调整 // 根据整体物流状态进行最终调整
let finalStatusDesc = initialStatusDesc;
if (logisticsStatus < status) { if (logisticsStatus < status) {
// 如果整体状态低于当前轨迹状态,说明该轨迹尚未完成 finalStatusDesc = `${LOGISTICS_STATUS[logisticsStatus]}(进行中)`;
statusDesc = LOGISTICS_STATUS[logisticsStatus] + "(进行中)";
} }
return { return {
...track, ...track,
type: isLast ? "active" : "small", content,
operateTime,
type: isLast ? "active" : "",
status, status,
statusDesc, statusDesc: finalStatusDesc,
}; };
}) })
.filter((track) => { .filter((track) =>
// 根据整体物流状态过滤轨迹 this._shouldShowTrack(track.status, logisticsStatus)
switch (logisticsStatus) { );
case 1000: // 待揽件 - 只显示收件相关记录
return track.status === 1000;
case 1001: // 已揽件 - 显示揽件和发往记录
return track.status <= 1001;
case 1002: // 运输中 - 显示所有运输中的记录
return track.status <= 1002;
case 1003: // 已签收 - 显示所有记录
return track.status <= 1003;
case 1004: // 拒收 - 显示所有记录
return track.status <= 1004;
default:
return true;
}
});
}, },
/**
* 处理快递信息
* @param {Object} expressInfo - 快递信息对象
*/
processExpressInfo(expressInfo) { processExpressInfo(expressInfo) {
if (!expressInfo || typeof expressInfo !== "object") {
console.warn("Express组件: expressInfo参数无效");
return;
}
const { logisticsStatus, shipmentTrack, ...rest } = expressInfo; const { logisticsStatus, shipmentTrack, ...rest } = expressInfo;
// 验证必要字段
if (typeof logisticsStatus !== "number") {
console.warn("Express组件: logisticsStatus字段无效");
return;
}
const processedTrack = this.processShipmentTrack( const processedTrack = this.processShipmentTrack(
shipmentTrack, shipmentTrack,
logisticsStatus logisticsStatus
); );
const logisticsData = { const logisticsData = {
...rest, ...rest,
logisticsStatus, logisticsStatus,
logisticsStatusDesc: LOGISTICS_STATUS[logisticsStatus], logisticsStatusDesc: LOGISTICS_STATUS[logisticsStatus] || "未知状态",
shipmentTrack: processedTrack, shipmentTrack: processedTrack,
}; };
this.setData({ this.setData({
logisticsData, logisticsData,
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!