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