"use server"; import { getCollection } from "../mongodb"; export type SearchTypeItem = { name: string; key: string; includes: string[]; priority: number; } export type SearchWayItemType = { label: string; value: string; fullName: string; key: string; } export async function getSearchTypeList({ page = 1, pageSize = 9999 }: { page?: number; pageSize?: number; }) { const collection = await getCollection('search-type'); const startIndex = (page - 1) * pageSize; const pipeline = [ { $sort: { priority: 1 } }, { $skip: startIndex }, { $limit: pageSize }, { $addFields: { _id: { $toString: "$_id" } } } ]; const cursor = collection.aggregate(pipeline); const list = await cursor.toArray(); // 计算总数量 const total = (await collection.find({}).toArray()).length return { total, list } } export async function getSearchWayList({ page = 1, pageSize = 9999 }: { page?: number; pageSize?: number; }) { const collection = await getCollection('search'); const startIndex = (page - 1) * pageSize; const pipeline = [ { $sort: { priority: 1 } }, { $skip: startIndex }, { $limit: pageSize }, { $addFields: { _id: { $toString: "$_id" } } } ]; const cursor = collection.aggregate(pipeline); const list = await cursor.toArray(); // 计算总数量 const total = (await collection.find({}).toArray()).length return { total, list } } export async function addSearchType(searchTypeItem: SearchTypeItem) { const collection = await getCollection('search-type') collection.insertOne(searchTypeItem) } export async function addSearchWay(searchItem: SearchWayItemType) { const collection = await getCollection('search') collection.insertOne(searchItem) }