chore:“发送名片”按钮功能正常

This commit is contained in:
2026-10-22 09:53:27 +08:00
parent 6f9ac29aa6
commit b294fc3640
4 changed files with 132 additions and 15 deletions

View File

@@ -114,6 +114,19 @@ export function themeGradient(card, angle) {
: 'linear-gradient(' + deg + 'deg, ' + theme + ' 20%, ' + theme + ' 100%)';
}
/** 颜色压暗(ratio 0~1): 用于「渐变圆角」在名片仅单主题色时生成可见明暗渐变终止色。
* 纯函数, 非法输入原样返回(不影响既有主题色渲染) */
export function darkenColor(hex, ratio) {
const r = ratio < 0 ? 0 : (ratio > 1 ? 1 : ratio);
const h = String(hex || '').replace('#', '');
if (!/^[0-9a-fA-F]{6}$/.test(h)) return hex;
const n = parseInt(h, 16);
const cr = Math.max(0, Math.round(((n >> 16) & 0xff) * (1 - r)));
const cg = Math.max(0, Math.round(((n >> 8) & 0xff) * (1 - r)));
const cb = Math.max(0, Math.round((n & 0xff) * (1 - r)));
return '#' + ((1 << 24) + (cr << 16) + (cg << 8) + cb).toString(16).slice(1);
}
/** 安全数字(配置字段) */
export function num(v, dft) {
const n = Number(v);
@@ -160,9 +173,17 @@ export function rowActOf(row) {
/** 二维码位置(四档): rows 资料行下方(默认) / head 头部右侧 / corner 右上角浮层 / bottom 主按钮上方 */
export const QR_POSITIONS = ['rows', 'head', 'corner', 'bottom'];
/** 位置档位中文别名(面板下拉若直接存中文档名, 归一化时兼容) */
const QR_POSITION_ALIAS = {
'资料行下方': 'rows',
'头部右侧': 'head',
'右上角浮层': 'corner',
'主按钮上方': 'bottom',
};
export function normalizeQrPosition(v) {
const s = String(v || '').trim();
return QR_POSITIONS.indexOf(s) >= 0 ? s : 'rows';
if (QR_POSITIONS.indexOf(s) >= 0) return s;
return QR_POSITION_ALIAS[s] || 'rows';
}
/** 各档位的二维码边长(rpx): 头部右侧紧凑, 浮层带衬底, 行下/底部大图便于扫 */
export const QR_SIZES = { rows: 180, head: 120, corner: 120, bottom: 180 };
@@ -173,9 +194,17 @@ export const QR_SIZES = { rows: 180, head: 120, corner: 120, bottom: 180 };
* 多彩体现在装饰层(主题色/渐变), 码本身保持黑白 —— 可扫性优先
*/
export const QR_STYLES = ['plain', 'card', 'theme', 'gradient'];
/** 外观档位中文别名(面板下拉若直接存中文档名, 归一化时兼容) */
const QR_STYLE_ALIAS = {
'原图': 'plain',
'白卡描边': 'card',
'主题色衬底': 'theme',
'渐变圆角': 'gradient',
};
export function normalizeQrStyle(v) {
const s = String(v || '').trim();
return QR_STYLES.indexOf(s) >= 0 ? s : 'card';
if (QR_STYLES.indexOf(s) >= 0) return s;
return QR_STYLE_ALIAS[s] || 'card';
}
/** 二维码边长: 自定义 > 0 时用自定义(px), 否则按档位自动(rpx) */