new-demo/src/components/frontend/home/essays/index.ts

104 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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: '',
};
}),
};
},
});