|
15 | 15 | <el-tab-pane label="Skills 市场" name="skill" /> |
16 | 16 | <el-tab-pane label="报表市场" name="report" /> |
17 | 17 | </el-tabs> |
18 | | - <el-input v-model="keyword" placeholder="搜索名称/描述" size="small" style="width:220px;margin-bottom:12px" clearable /> |
| 18 | + <div style="display:flex;gap:16px;align-items:center;margin-bottom:12px"> |
| 19 | + <el-input v-model="keyword" placeholder="搜索名称/描述" size="small" style="width:220px" clearable /> |
| 20 | + <el-checkbox v-model="onlyFavorite" size="small" @change="loadData">⭐ 只看收藏</el-checkbox> |
| 21 | + </div> |
19 | 22 | <el-table :data="filteredList" v-loading="loading"> |
20 | 23 | <el-table-column label="名称" width="240" show-overflow-tooltip> |
21 | 24 | <template #default="{ row }"><span style="margin-right:4px">{{ row.icon || '📦' }}</span>{{ row.itemName }}</template> |
|
26 | 29 | <el-table-column prop="updatedAt" label="更新日期" width="110" /> |
27 | 30 | <el-table-column prop="description" label="描述" min-width="220" show-overflow-tooltip /> |
28 | 31 | <el-table-column prop="downloadCount" label="下载" width="70" align="center" /> |
| 32 | + <el-table-column label="收藏" width="70" align="center"> |
| 33 | + <template #default="{ row }"> |
| 34 | + <el-button size="small" link :loading="favoritingId === row.id" @click="toggleFavorite(row)"> |
| 35 | + <span :style="`font-size:16px;color:${row.favorited ? '#f7ba2a' : '#c0c4cc'}`">{{ row.favorited ? '★' : '☆' }}</span> |
| 36 | + </el-button> |
| 37 | + </template> |
| 38 | + </el-table-column> |
29 | 39 | <el-table-column label="操作" width="140" fixed="right"> |
30 | 40 | <template #default="{ row }"> |
31 | 41 | <el-button size="small" type="primary" link :loading="importingId === row.id" @click="doImport(row)">直接应用</el-button> |
@@ -87,8 +97,10 @@ import request from '../../utils/request' |
87 | 97 | const loading = ref(false) |
88 | 98 | const activeTab = ref('api') |
89 | 99 | const keyword = ref('') |
| 100 | +const onlyFavorite = ref(false) |
90 | 101 | const tableData = ref<any[]>([]) |
91 | 102 | const importingId = ref<number | null>(null) |
| 103 | +const favoritingId = ref<number | null>(null) |
92 | 104 |
|
93 | 105 | // ====== 发现官方市场 ====== |
94 | 106 | const discoverVisible = ref(false) |
@@ -116,11 +128,25 @@ onMounted(loadData) |
116 | 128 | async function loadData() { |
117 | 129 | loading.value = true |
118 | 130 | try { |
119 | | - const res: any = await request.get('/market/list', { params: { type: activeTab.value } }) |
| 131 | + const res: any = await request.get('/market/list', { params: { type: activeTab.value, favorite: onlyFavorite.value ? 1 : 0 } }) |
120 | 132 | tableData.value = res.data || [] |
121 | 133 | } finally { loading.value = false } |
122 | 134 | } |
123 | 135 |
|
| 136 | +async function toggleFavorite(row: any) { |
| 137 | + favoritingId.value = row.id |
| 138 | + try { |
| 139 | + const res: any = await request.post(row.favorited ? `/market/unfavorite/${row.id}` : `/market/favorite/${row.id}`) |
| 140 | + row.favorited = res.data |
| 141 | + if (onlyFavorite.value && !row.favorited) { |
| 142 | + tableData.value = tableData.value.filter((r: any) => r.id !== row.id) |
| 143 | + } |
| 144 | + ElMessage.success(row.favorited ? '已收藏' : '已取消收藏') |
| 145 | + } catch (e: any) { |
| 146 | + ElMessage.error(e?.message || '操作失败') |
| 147 | + } finally { favoritingId.value = null } |
| 148 | +} |
| 149 | +
|
124 | 150 | async function doImport(row: any) { |
125 | 151 | importingId.value = row.id |
126 | 152 | try { |
|
0 commit comments