feat: 优化分类页内容管理
This commit is contained in:
@@ -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) =>
|
||||
formatWorksheet(raw as unknown as Record<string, unknown>),
|
||||
);
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user