feat: 优化名片详情加载逻辑,处理未登录和卡片不存在的情况,新增公开页跳转功能
This commit is contained in:
@@ -174,15 +174,19 @@ export default {
|
|||||||
data: { card_id: this.cardId },
|
data: { card_id: this.cardId },
|
||||||
success: res => {
|
success: res => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
const data = res.data || {};
|
||||||
if (res.code == 0) {
|
if (res.code == 0) {
|
||||||
const data = res.data || {};
|
|
||||||
this.relation = data.relation || null;
|
this.relation = data.relation || null;
|
||||||
this.source = data.source || null;
|
this.source = data.source || null;
|
||||||
this.shareList = data.share_list || [];
|
this.shareList = data.share_list || [];
|
||||||
|
// 公开页/二维码地址由后端统一拼装返回, 前端不自行拼接
|
||||||
|
this.shareUrl = data.wap_url || '';
|
||||||
|
this.qrUrl = data.qr_url || '';
|
||||||
} else {
|
} else {
|
||||||
// 后端对"不存在"与"非本人名下"同一报错口径,不区分展示
|
// 未登录 / 卡片不存在 / 非本人名下(详情接口按归属校验, 同事打开
|
||||||
this.errorMsg = res.message || '卡片不存在或已被删除';
|
// 别人分享的链接会命中) —— 后端在报错 data 里同样返回公开页地址,
|
||||||
this.relation = null;
|
// 据此匿名落到公开名片页(可看、可提交交换/留资), 不出现死路
|
||||||
|
this.fallbackToPublicPage(data.wap_url || '');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
fail: () => {
|
fail: () => {
|
||||||
@@ -192,6 +196,23 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
fallbackToPublicPage(wapUrl) {
|
||||||
|
// 公开页地址完全由后端 detail 接口返回(成功/报错路径都带), 前端零拼装
|
||||||
|
if (!wapUrl) {
|
||||||
|
this.isLoading = false;
|
||||||
|
this.errorMsg = this.errorMsg || '卡片不存在或已被删除';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// #ifdef H5
|
||||||
|
window.location.href = wapUrl;
|
||||||
|
// #endif
|
||||||
|
// #ifndef H5
|
||||||
|
// 小程序/鸿蒙/APP: 复用 share.vue 中转页(web-view 加载 wap 页)
|
||||||
|
uni.redirectTo({
|
||||||
|
url: '/pages_tool/card/share?url=' + encodeURIComponent(wapUrl)
|
||||||
|
});
|
||||||
|
// #endif
|
||||||
|
},
|
||||||
callPhone(mobile) {
|
callPhone(mobile) {
|
||||||
if (!mobile) return;
|
if (!mobile) return;
|
||||||
uni.makePhoneCall({ phoneNumber: mobile });
|
uni.makePhoneCall({ phoneNumber: mobile });
|
||||||
@@ -206,18 +227,13 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/* ---------- 分享 ---------- */
|
/* ---------- 分享 ---------- */
|
||||||
siteId() {
|
|
||||||
return uni.getStorageSync('uniacid') || this.$config.uniacid || 0;
|
|
||||||
},
|
|
||||||
openShare() {
|
openShare() {
|
||||||
if (!this.relation) return;
|
if (!this.relation) return;
|
||||||
const sid = this.siteId();
|
// 链接/二维码地址已在 loadDetail 时由后端返回(wap_url/qr_url), 这里只做兜底校验
|
||||||
const rid = this.relation.id;
|
if (!this.shareUrl || !this.qrUrl) {
|
||||||
const base = this.$config.baseUrl || '';
|
uni.showToast({ title: '分享链接未返回,请稍后重试', icon: 'none' });
|
||||||
// wap 公开名片页(客户视角, 无需登录)
|
return;
|
||||||
this.shareUrl = base + '/card/wap/index/detail?site_id=' + sid + '&id=' + rid;
|
}
|
||||||
// 二维码由后端同源生成(项目内置 extend\QRcode), 与链接一一对应
|
|
||||||
this.qrUrl = base + '/card/wap/index/qr?site_id=' + sid + '&id=' + rid;
|
|
||||||
this.showShare = true;
|
this.showShare = true;
|
||||||
},
|
},
|
||||||
closeShare() {
|
closeShare() {
|
||||||
|
|||||||
Reference in New Issue
Block a user