diff --git a/pages_tool/card/list.vue b/pages_tool/card/list.vue
index 1d94d4c..82fc54d 100644
--- a/pages_tool/card/list.vue
+++ b/pages_tool/card/list.vue
@@ -12,6 +12,14 @@
认领
+
+
+
+ {{ onlyFav ? '★' : '☆' }}
+ {{ onlyFav ? '仅看收藏' : '全部名片' }}
+
+
+
📱 {{ item.mobile }}
+
+ {{ item.is_favorite == 1 ? '★' : '☆' }}
›
@@ -53,6 +64,7 @@ export default {
pageCount: 1,
count: 0,
keyword: '',
+ onlyFav: false,
isLoading: false,
emptyText: '暂无名片,可点击右上角「新建」或「认领」添加'
};
@@ -82,18 +94,65 @@ export default {
this.keyword = '';
this.refresh();
},
+ // 仅看收藏筛选开关(列表筛选, favorite=1; 可与 keyword 叠加)
+ toggleFavFilter() {
+ this.onlyFav = !this.onlyFav;
+ this.refresh();
+ },
+ /**
+ * 切换收藏(双向 toggle): 直接调, 用返回的 is_favorite 回填。
+ * 乐观更新 + 失败回滚; 仅看收藏模式下取消收藏则从列表移除该行。
+ */
+ toggleFavorite(item) {
+ if (!item) return;
+ const cardId = this.cardIdOf(item);
+ if (!cardId) {
+ uni.showToast({ title: '该名片缺少编号,无法收藏', icon: 'none' });
+ return;
+ }
+ const prev = item.is_favorite == 1 ? 1 : 0;
+ // 乐观翻转
+ this.$set(item, 'is_favorite', prev ? 0 : 1);
+ this.$cardApi.cardToggleFavorite({
+ data: { card_id: cardId },
+ success: res => {
+ if (res.code == 0) {
+ const d = res.data || {};
+ const next = d.is_favorite == 1 ? 1 : 0;
+ this.$set(item, 'is_favorite', next);
+ // 仅看收藏模式下取消收藏 → 从列表移除
+ if (this.onlyFav && next === 0) {
+ const idx = this.list.indexOf(item);
+ if (idx >= 0) this.list.splice(idx, 1);
+ }
+ } else {
+ // 「名片不存在」/「非自己名下卡」等拒绝场景: 回滚 + 直接 toast message
+ this.$set(item, 'is_favorite', prev);
+ if (res.message) uni.showToast({ title: res.message, icon: 'none' });
+ }
+ },
+ fail: () => {
+ this.$set(item, 'is_favorite', prev);
+ uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' });
+ }
+ });
+ },
refresh(done) {
this.page = 1;
this.loadPage(1, done);
},
loadPage(pageNo, done) {
this.isLoading = true;
+ // 列表筛选: favorite=1 只返回星标卡(后端 2.9.12); 不传/非1 返回全部。
+ // 与现有 page/keyword 一并放 body(TP6 param() 合并 query+body, 等效 ?favorite=1)。
+ const reqData = {
+ page: pageNo,
+ page_size: this.pageSize,
+ keyword: this.keyword.trim()
+ };
+ if (this.onlyFav) reqData.favorite = 1;
this.$cardApi.cardLists({
- data: {
- page: pageNo,
- page_size: this.pageSize,
- keyword: this.keyword.trim()
- },
+ data: reqData,
success: res => {
if (res.code == 0) {
const data = res.data || {};
@@ -259,6 +318,40 @@ export default {
}
}
+/* 筛选条: 仅看收藏 */
+.filter-row {
+ display: flex;
+ margin-bottom: 20rpx;
+}
+
+.fav-filter {
+ display: inline-flex;
+ align-items: center;
+ height: 60rpx;
+ padding: 0 28rpx;
+ border-radius: 30rpx;
+ background-color: #ffffff;
+ color: #666;
+ font-size: 26rpx;
+ border: 1rpx solid #e5e5e5;
+
+ .fav-filter-icon {
+ margin-right: 8rpx;
+ font-size: 30rpx;
+ color: #ccc;
+ }
+
+ &.active {
+ background-color: #fff6e0;
+ border-color: #f5b301;
+ color: #c8860a;
+
+ .fav-filter-icon {
+ color: #f5b301;
+ }
+ }
+}
+
.card-list {
.card-item {
display: flex;
@@ -315,6 +408,20 @@ export default {
font-size: 40rpx;
margin-left: 16rpx;
}
+
+ /* 收藏星标: 空心=未收藏(灰), 实心=已收藏(金) */
+ .card-fav {
+ flex-shrink: 0;
+ font-size: 44rpx;
+ line-height: 1;
+ color: #ccc;
+ margin-left: 16rpx;
+ padding: 4rpx;
+
+ &.is-fav {
+ color: #f5b301;
+ }
+ }
}
}