mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-11-12 20:08:59 +08:00
feat(gift-card): 新增提货卡类型支持
- 列表页拆分为提货卡和现金卡两个独立创建入口 - 创建页支持提货卡兑换方式配置(任选一种/全部兑换/任选N种) - 集成 SKU 商品选择器,支持最多50个商品兑换配置 - 批次凭证页增加"已提货"状态标签及提货卡面额展示适配 - 批次凭证页新增导出卡密功能 - 重构表单布局为响应式 grid 并优化有效期选项交互样式
This commit is contained in:
44
manager/src/utils/specs.js
Normal file
44
manager/src/utils/specs.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 商品规格展示:兼容简要规格、键值 JSON 和旧数组结构,过滤图片数据,不展示原始 JSON。
|
||||
* @author Bulbasaur
|
||||
* @since 2026-11-06
|
||||
*/
|
||||
|
||||
/** 将规格中的简单值转为文字,图片对象等复杂数据不参与规格展示。 */
|
||||
function specValueText(value) {
|
||||
if (typeof value === "string") return value.trim();
|
||||
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
||||
if (typeof value === "boolean") return String(value);
|
||||
if (Array.isArray(value)) return value.filter(item => !item || typeof item !== "object").map(specValueText).filter(Boolean).join("、");
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成可读的 SKU 规格,优先复用接口已有的 simpleSpecs;无有效规格时显示默认规格。
|
||||
* @param {string|object|Array|null} specs SKU 原始规格
|
||||
* @param {string|null} simpleSpecs 接口提供的简要规格
|
||||
* @returns {string} 排除 images 后的规格值,以斜线分隔
|
||||
*/
|
||||
export function formatSkuSpecs(specs, simpleSpecs) {
|
||||
if (typeof simpleSpecs === "string" && simpleSpecs.trim()) return simpleSpecs.trim();
|
||||
let parsed = specs;
|
||||
if (typeof parsed === "string") {
|
||||
const text = parsed.trim();
|
||||
if (!text) return "默认规格";
|
||||
try {
|
||||
parsed = JSON.parse(text);
|
||||
} catch {
|
||||
return /^[\[{]/.test(text) ? "默认规格" : text;
|
||||
}
|
||||
}
|
||||
let values;
|
||||
if (Array.isArray(parsed)) {
|
||||
values = parsed.filter(item => item && typeof item === "object" && item.specName !== "images")
|
||||
.map(item => specValueText(item.specValue));
|
||||
} else if (parsed && typeof parsed === "object") {
|
||||
values = Object.entries(parsed).filter(([name]) => name !== "images").map(([, value]) => specValueText(value));
|
||||
} else {
|
||||
values = [specValueText(parsed)];
|
||||
}
|
||||
return values.filter(Boolean).join(" / ") || "默认规格";
|
||||
}
|
||||
Reference in New Issue
Block a user