feat: 优化分类页内容管理

This commit is contained in:
R524809
2026-06-15 15:39:46 +08:00
parent 25a37fc5e2
commit 11469f7dca
5 changed files with 47 additions and 11 deletions
+3
View File
@@ -19,6 +19,7 @@ exports.main = async (event) => {
const category = String(event.category || '').trim();
const status = String(event.status || '').trim();
const rawStats = event.rawStats === true;
// Build query condition
const where = {};
@@ -61,7 +62,9 @@ exports.main = async (event) => {
else if (item.status === 'hidden') stats.hidden++;
}
if (!rawStats) {
mergeSeedStats(data);
}
return {
success: true,
+1
View File
@@ -241,6 +241,7 @@ Page({
if (!result.success) throw new Error(result.message || '查询失败');
const rows = result.data || [];
console.log('rows', rows);
_categoryData = buildCategoryDataFromCloud(rows);
debugLogWorksheetStatsAfterCategoryLoad({ kind: 'cloud', rows });
} catch {
@@ -235,9 +235,13 @@ page {
.ws-card__sort {
flex: 1;
min-width: 0;
margin-left: 16rpx;
font-size: 22rpx;
color: @text-gray;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
// ── Build Button ──
@@ -13,6 +13,8 @@ type WorksheetItem = {
tagsText: string;
status: 'draft' | 'active' | 'hidden';
sortOrder: number;
downloads: number;
likes: number;
updatedAt: string;
// display helpers
ageBand: string;
@@ -48,9 +50,24 @@ const STATUS_CONFIG: Record<
string,
{ text: string; action: string; target: string; actionType: string }
> = {
draft: { text: '草稿', action: '激活', target: 'active', actionType: 'green' },
active: { text: '线上', action: '下架', target: 'hidden', actionType: 'default' },
hidden: { text: '已隐藏', action: '恢复', target: 'draft', actionType: 'primary' },
draft: {
text: '草稿',
action: '激活',
target: 'active',
actionType: 'green',
},
active: {
text: '线上',
action: '下架',
target: 'hidden',
actionType: 'default',
},
hidden: {
text: '已隐藏',
action: '恢复',
target: 'draft',
actionType: 'primary',
},
};
function formatWorksheet(raw: Record<string, unknown>): WorksheetItem {
@@ -70,9 +87,13 @@ function formatWorksheet(raw: Record<string, unknown>): WorksheetItem {
ageMax,
difficulty,
tags: Array.isArray(raw.tags) ? raw.tags.map(String) : [],
tagsText: Array.isArray(raw.tags) ? raw.tags.map(String).join('、') : '',
tagsText: Array.isArray(raw.tags)
? raw.tags.map(String).join('、')
: '',
status: status as WorksheetItem['status'],
sortOrder: Number(raw.sortOrder) || 0,
downloads: Number(raw.downloads) || 0,
likes: Number(raw.likes) || 0,
updatedAt: raw.updatedAt ? String(raw.updatedAt) : '',
ageBand: `${ageMin}-${ageMax}`,
difficultyLabel: DIFFICULTY_LABELS[difficulty] || '基础',
@@ -120,16 +141,21 @@ Page({
try {
const result = await callCloudFunction<WorksheetItem[]>(
'worksheetsQuery',
{ category: this.data.activeCategoryId },
{
category: this.data.activeCategoryId,
rawStats: true,
},
);
if (!result.success) {
throw new Error(result.message || '查询失败');
}
const worksheets = (result.data || []).map((raw) =>
const worksheets = (result.data || [])
.map((raw) =>
formatWorksheet(raw as unknown as Record<string, unknown>),
);
)
.sort((a, b) => b.downloads - a.downloads);
this.setData({
loading: false,
@@ -191,8 +217,7 @@ Page({
await this.loadWorksheets();
} catch (error) {
wx.showToast({
title:
error instanceof Error ? error.message : '操作失败',
title: error instanceof Error ? error.message : '操作失败',
icon: 'none',
});
} finally {
@@ -77,6 +77,9 @@
<text>{{item.statusText}}</text>
</view>
<text class="ws-card__sort">排序 {{item.sortOrder}}</text>
<text class="ws-card__sort"
>下载 {{item.downloads}} · 喜欢 {{item.likes}}</text
>
<toy-button
type="{{item.actionType}}"
size="small"