feat: 添加自定义二维码图片及其优先级配置支持

This commit is contained in:
2026-10-27 11:57:11 +08:00
parent 30f7ec8631
commit 0a5794d260
5 changed files with 138 additions and 4 deletions

View File

@@ -147,7 +147,9 @@ export const CARD_FIELDS = [
'name', 'company', 'job_title', 'avatar',
'mobile', 'phone', 'email', 'website', 'wechat',
'country', 'province', 'city', 'address', 'postal_code',
'bio'
'bio',
// 2.20 名片级自定义二维码图片(空=用系统生成码)
'qr_image'
];
/** 人脉可更新白名单:与后端 Contact::EDITABLE_FIELDS 一致 */

View File

@@ -319,9 +319,38 @@ export default {
showQrBase() {
return flagOn(this.c.showQr, false) && !!this.qrSrc;
},
/** 二维码码源(2.18): 用户自定义图片(媒体库)优先, 空=名片自动生成的码 */
/**
* 二维码来源优先级模式(2.20.1, 由用户在 DIY 组件面板显式选择):
* card 名片级 > 组件级 > 系统码(默认)
* component 组件级 > 名片级 > 系统码
* system 仅系统生成码(忽略全部自定义图)
* 非法/缺失一律回落 'card' —— 与后端 CardQrSource::normalizePriority 同口径。
*/
qrPriority() {
const m = String(this.c.qrPriority || '').trim();
return ['card', 'component', 'system'].includes(m) ? m : 'card';
},
/**
* 二维码码源(2.20 三层来源 + 2.20.1 可选优先级, 与后端 CardQrSource::resolve 同口径):
* - 名片级 card.qr_image 每张名片各自一张(员工/企业都适用)
* - 组件级 c.qrImage 装修期统一指定
* - 系统码 card.qr_url 原有行为, 兜底
*/
qrSrc() {
const mode = this.qrPriority;
if (mode === 'system') {
return (this.card && this.card.qr_url) || '';
}
const own = String((this.card && this.card.qr_image) || '').trim();
const custom = String(this.c.qrImage || '').trim();
if (mode === 'component') {
// 组件级优先: 组件图 → 名片图 → 系统码
if (custom) return custom;
if (own) return own;
return (this.card && this.card.qr_url) || '';
}
// card(默认): 名片级 → 组件级 → 系统码
if (own) return own;
if (custom) return custom;
return (this.card && this.card.qr_url) || '';
},

View File

@@ -119,6 +119,8 @@ export default {
actsBlockPad: v.actsBlockPad,
actIcons: v.actIcons,
qrImage: v.qrImage,
// 2.20.1 二维码来源优先级(card/component/system; 缺省 card)
qrPriority: v.qrPriority,
// 2.19: 默认动作显隐/文案 + 自定义动作(基件 acts computed 合成)
actVis: v.actVis,
actDeleted: v.actDeleted,

View File

@@ -85,6 +85,8 @@ export default {
actsBlockPad: v.actsBlockPad,
actIcons: v.actIcons,
qrImage: v.qrImage,
// 2.20.1 二维码来源优先级(card/component/system; 缺省 card)
qrPriority: v.qrPriority,
// 2.19: 默认动作显隐/文案 + 自定义动作(基件 acts computed 合成)
actVis: v.actVis,
actDeleted: v.actDeleted,

View File

@@ -9,8 +9,21 @@
<image v-if="form.avatar" :src="$util.img(form.avatar)" class="avatar-img" mode="aspectFill" />
<text v-else class="avatar-plus">+</text>
</view>
<view class="avatar-tip">点击从相册选择</view>
<view class="avatar-tip">点击从相册选择</view>
</view>
<!-- 2.20 自定义二维码图片: 空=用系统按名片链接自动生成的码 -->
<view class="form-row">
<view class="row-label">二维码</view>
<view class="qr-box" @tap="chooseQrImage">
<image v-if="form.qr_image" :src="$util.img(form.qr_image)" class="qr-img" mode="aspectFit" />
<text v-else class="qr-plus">+</text>
</view>
<view class="qr-side">
<view class="avatar-tip">点击上传自定义二维码</view>
<view class="qr-tip">{{ form.qr_image ? '已自定义,将替换默认二维码' : '未设置时使用名片链接自动生成的码' }}</view>
<text v-if="form.qr_image" class="qr-clear" @tap.stop="clearQrImage">移除自定义二维码</text>
</view>
</view>
<view class="form-row">
<view class="row-label"><text class="req-star">*</text>姓名</view>
<input class="row-input" :value="form.name" placeholder="请输入姓名"
@@ -180,7 +193,9 @@ export default {
name: '', company: '', job_title: '', avatar: '',
mobile: '', phone: '', email: '', website: '', wechat: '',
country: '', province: '', city: '', address: '', postal_code: '',
bio: ''
bio: '',
// 2.20 自定义二维码图片(空=用系统自动生成的码)
qr_image: ''
},
mobiles: [],
socials: [],
@@ -227,6 +242,12 @@ export default {
this.form[k] = String(r[k]);
}
});
// 2.20 自定义二维码: 优先取后端归一化后的 qr_image(顶层),
// 回退 relation 原始值(归一化只影响站内相对路径补斜杠)
const qrNorm = res.data && res.data.qr_image;
this.form.qr_image = qrNorm !== undefined && qrNorm !== null
? String(qrNorm)
: String(r.qr_image || '');
// 富化字段: detail 由后端 CardRichFields 解码后挂在 relation 上
// (注意是 res.data.relation.mobiles_list, 不是 res.data.mobiles_list)
this.mobiles = (r.mobiles_list || []).map(v => String(v || ''));
@@ -284,6 +305,41 @@ export default {
});
},
/* ---------- 自定义二维码图片(2.20): 相册选择 → card 专用上传 → 回填路径 ---------- */
chooseQrImage() {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: res => {
const filePath = res.tempFilePaths && res.tempFilePaths[0];
if (!filePath) return;
uni.showLoading({ title: '上传中…', mask: true });
this.$api.upload({
url: '/card/api/card/uploadQrImage',
filePath: filePath,
fileType: 'image',
success: r => {
uni.hideLoading();
if (r && r.code == 0 && r.data && r.data.pic_path) {
this.form.qr_image = r.data.pic_path;
} else {
uni.showToast({ title: (r && r.message) || '上传失败', icon: 'none' });
}
},
fail: () => {
uni.hideLoading();
uni.showToast({ title: '上传失败', icon: 'none' });
}
});
}
});
},
/* 移除自定义二维码: 置空 = 提交时回落系统自动生成的码 */
clearQrImage() {
this.form.qr_image = '';
},
/* ---------- 附加手机号 ---------- */
onMobileInput(i, e) {
this.$set(this.mobiles, i, e.detail.value);
@@ -499,6 +555,49 @@ export default {
color: #999;
}
/* 自定义二维码行(2.20) */
.qr-box {
width: 108rpx;
height: 108rpx;
border-radius: 12rpx;
background-color: #f2f3f5;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
flex-shrink: 0;
.qr-img {
width: 100%;
height: 100%;
}
.qr-plus {
font-size: 44rpx;
color: #c0c4cc;
}
}
.qr-side {
flex: 1;
margin-left: 20rpx;
min-width: 0;
}
.qr-tip {
font-size: 22rpx;
color: #b0b4bc;
margin-top: 4rpx;
line-height: 1.5;
}
.qr-clear {
display: inline-block;
margin-top: 6rpx;
font-size: 24rpx;
color: var(--main-color, #0054a5);
}
/* 动态行(附加手机号/社交媒体/自定义字段) */
.dyn-row {
.row-label {