feat:登录的也是mock接口对接

This commit is contained in:
zoujing committed 2026-09-17 16:24:02 +08:00
1 parent d723eb1232
commit d759d48e79
37 files changed
+1791 -7498

No files matched your search

+24 -36
View File
@@ -15,16 +15,6 @@ export const clone = (val) => {
/** 去重 */
export const unique = (list) => list.filter((v, i, arr) => arr.indexOf(v) === i);
/**
* 条目图集:只读数据字段,禁止拼接路径。
* 主图 + 图集 URL 去重后返回。
*/
export const imageListOf = (item) => {
if (!item) return [];
const urls = [item.main_image_url, ...(item.gallery_urls || [])];
return unique(urls.filter((u) => typeof u === "string" && u.trim()));
};
/**
* 折扣率(前端计算,不落库)
* deal / original → 7.9 折;original 缺失或 ≥ 10 折时不展示
@@ -46,13 +36,31 @@ export const priceText = (val) => {
return Number.isInteger(n) ? String(n) : n.toFixed(2).replace(/0+$/, "").replace(/\.$/, "");
};
/** 手机号中间四位打码 */
/**
* 手机号中间四位打码
* 接口只回 `phone_masked`(形如 `+86138****8000`),先去掉 +86 国码;
* 已是脱敏串(位数不足 11)时原样返回,避免二次打码。
*/
export const maskPhone = (phone) => {
const p = String(phone || "").replace(/\D/g, "");
if (p.length < 7) return phone || "";
return `${p.slice(0, 3)}****${p.slice(-4)}`;
const raw = String(phone || "").trim();
if (!raw) return "";
const local = raw.replace(/^\+?86/, "");
const p = local.replace(/\D/g, "");
if (p.length >= 11) return `${p.slice(0, 3)}****${p.slice(-4)}`;
return local;
};
/** RFC3339(2026-09-11T00:00:00Z)→ 2026 年 9 月 11 日 */
export const cnDate = (str) => {
const m = String(str || "").match(/^(\d{4})-(\d{2})-(\d{2})/);
if (!m) return "";
return `${m[1]} 年 ${Number(m[2])} 月 ${Number(m[3])} 日`;
};
/** 幂等键(写操作 Idempotency-Key,≤128 字节) */
export const uid = () =>
`${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
/** 2026-09-12 / 2026-09-12T02:00:00Z → 2026.09.12(接口时间为 RFC3339 UTC,只取日期段) */
export const dotDate = (str) => String(str || "").slice(0, 10).replace(/-/g, ".");
@@ -67,34 +75,14 @@ export const dateRangeText = (from, to) => {
return sameMonth ? `${f} - ${t.slice(-5)}` : `${f} - ${t}`;
};
/** 距今天数(正数=还剩 N 天) */
export const daysFromNow = (dateStr) => {
if (!dateStr) return null;
const target = new Date(`${String(dateStr).replace(/\./g, "-")}T23:59:59`);
if (Number.isNaN(target.getTime())) return null;
return Math.ceil((target.getTime() - Date.now()) / 86400000);
};
/** 简易节流 */
export const throttle = (fn, wait = 500) => {
let last = 0;
return function (...args) {
const now = Date.now();
if (now - last < wait) return;
last = now;
return fn.apply(this, args);
};
};
export default {
clone,
unique,
imageListOf,
discountLabel,
priceText,
maskPhone,
cnDate,
uid,
dotDate,
dateRangeText,
daysFromNow,
throttle,
};