From 21b3247547ac4526b7db28b4068c8e01d52e564f Mon Sep 17 00:00:00 2001 From: jing <1683105490@qq.com> Date: Sat, 17 Oct 2026 17:02:22 +0800 Subject: [PATCH] =?UTF-8?q?chore=EF=BC=9A=20=E5=BE=AE=E4=BF=A1=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E6=AD=A3=E5=B8=B8=E5=90=8D=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages_tool/card/list.vue | 51 +++++++++++++++++++++++++++++++-------- pages_tool/card/style.vue | 38 ++++++++++++++++++++++++----- 2 files changed, 73 insertions(+), 16 deletions(-) diff --git a/pages_tool/card/list.vue b/pages_tool/card/list.vue index aa08294..92b40ae 100644 --- a/pages_tool/card/list.vue +++ b/pages_tool/card/list.vue @@ -30,8 +30,8 @@ - + {{ avatarText(item.name) }} @@ -49,10 +49,10 @@ - {{ item.is_favorite == 1 ? '★' : '☆' }} + {{ item.is_favorite == 1 ? '★' : '☆' }} 完成 + :data-index="index" @tap.stop="markDone">完成 › @@ -92,9 +92,9 @@ 还没有名片 提交信息,申请商家为您建卡 - - {{ applying ? '提交中…' : '提交申请' }} @@ -269,7 +269,8 @@ export default { this.refresh(); }, // 标记跟进完成(2.11.3): followDone, 成功后该卡从待跟进消失 - markDone(item) { + markDone(payload) { + const item = this.resolveItem(payload); const cardId = this.cardIdOf(item); if (!cardId) return; uni.showLoading({ title: '标记中…' }); @@ -300,6 +301,14 @@ export default { }); }, // 提交建卡申请(2.11.15) + // 模板内联箭头函数(`@input="e => x = e.detail.value"`)在 H5 能跑, + // 但小程序端编译不进 wxml, 输入会失效, 统一收成方法 + onApplyNameInput(e) { + this.applyName = (e && e.detail && e.detail.value) || ''; + }, + onApplyMobileInput(e) { + this.applyMobile = (e && e.detail && e.detail.value) || ''; + }, submitApply() { const name = (this.applyName || '').trim(); const mobile = (this.applyMobile || '').trim(); @@ -329,7 +338,8 @@ export default { * 切换收藏(双向 toggle): 直接调, 用返回的 is_favorite 回填。 * 乐观更新 + 失败回滚; 仅看收藏模式下取消收藏则从列表移除该行。 */ - toggleFavorite(item) { + toggleFavorite(payload) { + const item = this.resolveItem(payload); if (!item) return; const cardId = this.cardIdOf(item); if (!cardId) { @@ -417,7 +427,28 @@ export default { const raw = item.card_id || item.cardId; return raw ? String(raw) : ''; }, - goDetail(item) { + /** + * 取事件对应的行数据。 + * + * 为什么需要: 列表内联事件传对象(`@tap="goDetail(item)"`)在 H5 由 Vue 直接求值没问题, + * 但小程序端要经 data-event-opts 索引回填, 实测会拿到 undefined(点击后提示"缺少编号", + * console 打印 可用字段: undefined), 导致小程序点不进详情。 + * 现在模板统一改成 `:data-index="index"` + 不传参, 这里从 dataset 取索引回表拿行。 + * 兼容三种入参: 数字索引 / 事件对象 / 行对象本身。 + */ + resolveItem(payload) { + if (payload == null) return null; + if (typeof payload === 'number') return this.list[payload] || null; + const ds = payload.currentTarget && payload.currentTarget.dataset; + if (ds) { + const i = Number(ds.index); + if (!isNaN(i) && this.list[i]) return this.list[i]; + } + // 兜底: 已经是行对象(旧写法/内部调用) + return payload.card_id || payload.cardId || payload.name ? payload : null; + }, + goDetail(payload) { + const item = this.resolveItem(payload); const cardId = this.cardIdOf(item); if (!cardId) { // 之前这里是静默 return: 命中时点名片毫无反应, 用户只会认为"点不进去" diff --git a/pages_tool/card/style.vue b/pages_tool/card/style.vue index 2c050fc..5b1bf5a 100644 --- a/pages_tool/card/style.vue +++ b/pages_tool/card/style.vue @@ -38,14 +38,15 @@ + :class="{ active: p.key === selectedKey }" :style="cellActiveStyle(p)" + @tap="selectPreset(p.key)"> 画布式 - - - + + + @@ -249,11 +250,36 @@ export default { } }, methods: { + /** + * 预设缩略图的配色。 + * + * 为什么不用 CSS 变量: 微信小程序的渲染层不支持在内联 style 里定义自定义属性 + * (`style="--card-bg:#fff"`), 整条 style 会被丢弃 → var(--card-bg) 全部回落默认值, + * 表现就是「小程序端样式缩略图全是白底黑条灰线, 没有颜色」(H5 正常)。 + * 这里改为直接输出具体属性 + 具体色值, 三端一致。 + */ + cellDs(p) { + return normalizeDesign(p && p.design); + }, cellVars(p) { - return designVarsFor(normalizeDesign(p.design)); + const s = this.cellDs(p); + return { backgroundColor: s.bgColor, borderRadius: s.cardRadius + 'px' }; }, cellHeader(p) { - return { background: headerBgFor(normalizeDesign(p.design)) }; + const s = this.cellDs(p); + // 纯色代替渐变: 小尺寸缩略图看不出渐变, 但能保证各端一定渲染 + return { backgroundColor: s.themeColor }; + }, + cellText(p) { + return { backgroundColor: this.cellDs(p).textColor }; + }, + cellSoft(p) { + return { backgroundColor: this.cellDs(p).textSoft }; + }, + // 选中描边也要给具体色值(CSS 里的 var(--card-theme) 在小程序端同样失效) + cellActiveStyle(p) { + if (p.key !== this.selectedKey) return null; + return { borderColor: this.cellDs(p).themeColor }; }, onLoad(options) { this.cardId = decodeURIComponent(options.card_id || '');