feat:完成首页、分类页内容管理功能开发
This commit is contained in:
@@ -3,11 +3,11 @@ const cloud = require('wx-server-sdk');
|
||||
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
|
||||
|
||||
const VALID_STATUS = new Set(['draft', 'active', 'hidden']);
|
||||
const STATUS_ORDER = { draft: 0, hidden: 1, active: 2 };
|
||||
|
||||
exports.main = async (event) => {
|
||||
try {
|
||||
const db = cloud.database();
|
||||
const _ = db.command;
|
||||
const collection = db.collection('worksheets');
|
||||
|
||||
const category = String(event.category || '').trim();
|
||||
@@ -26,6 +26,13 @@ exports.main = async (event) => {
|
||||
.limit(100)
|
||||
.get();
|
||||
|
||||
// Sort by status order: draft → hidden → active
|
||||
data.sort((a, b) => {
|
||||
const orderA = STATUS_ORDER[a.status] ?? 99;
|
||||
const orderB = STATUS_ORDER[b.status] ?? 99;
|
||||
return orderA - orderB;
|
||||
});
|
||||
|
||||
// Compute stats for the category (all statuses)
|
||||
let allData = data;
|
||||
if (status) {
|
||||
|
||||
Reference in New Issue
Block a user