import { essayProjection } from '@project/utils/projection'; export default OakComponent({ entity: 'essay', isList: true, projection: essayProjection, sorters: [ { // 先按置顶排序 sorter: { $attr: { isTop: 1, }, $direction: 'desc', }, }, { // 再按创建时间排序 sorter: { $attr: { $$createAt$$: 1, }, $direction: 'desc', }, }, ], // 只能看到已经发布的 filters: [ { filter: { iState: 'published', }, }, { // 如果存在categoryId,则按照categoryId过滤 filter() { if (!this.props.categoryId) { return {}; } return { category: { id: this.props.categoryId, }, }; }, }, ], listeners: { searchParam(prev, next) { // 如果searchParam变化,则重新获取数据 if (prev.searchParam !== next.searchParam) { this.addNamedFilter({ // 如果存在searchParam,则按照searchParam过滤 filter() { if (!next.searchParam.searchText) { return {}; } switch (next.searchParam.searchType) { case 'title': return { title: { $includes: next.searchParam.searchText, }, }; case 'content': return { $text: { $search: next.searchParam.searchText, }, }; default: return {}; } }, '#name': 'searchParam', }, true); } }, }, formData({ data }) { return { list: data.map((item) => { const fileIndex = item?.extraFile$entity?.findIndex( (item) => item.tag1 === 'cover' ); if (fileIndex !== undefined && fileIndex > -1) { const url = this.features.extraFile.getUrl( item!.extraFile$entity![fileIndex] ); return { ...item, // 获取封面的url地址 cover: url, }; } return { ...item, cover: '', }; }), }; }, });