feat:开发分类页内容管理

This commit is contained in:
R524809
2026-04-29 18:17:48 +08:00
parent 2cb9ec55d6
commit fa39938e5a
12 changed files with 853 additions and 0 deletions
@@ -0,0 +1,43 @@
const cloud = require('wx-server-sdk');
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
const VALID_STATUS = new Set(['draft', 'active', 'hidden']);
exports.main = async (event) => {
try {
const db = cloud.database();
const collection = db.collection('worksheets');
const id = String(event.id || '').trim();
const status = String(event.status || '').trim();
if (!id) throw new Error('worksheet id 不能为空');
if (!VALID_STATUS.has(status)) throw new Error('状态不合法');
// Check worksheet exists
try {
await collection.doc(id).get();
} catch {
throw new Error('worksheet 不存在');
}
await collection.doc(id).update({
data: {
status,
updatedAt: db.serverDate(),
},
});
return {
success: true,
data: { _id: id, status },
};
} catch (error) {
return {
success: false,
message:
error instanceof Error ? error.message : '更新状态失败',
};
}
};