125 lines
3.7 KiB
JavaScript
125 lines
3.7 KiB
JavaScript
import dayjs from "dayjs";
|
|
import copy from 'copy-to-clipboard';
|
|
export default OakComponent({
|
|
entity: 'article',
|
|
isList: true,
|
|
projection: {
|
|
id: 1,
|
|
name: 1,
|
|
articleMenuId: 1,
|
|
$$updateAt$$: 1,
|
|
},
|
|
sorters: [
|
|
{
|
|
sorter: {
|
|
$attr: {
|
|
$$createAt$$: 1,
|
|
},
|
|
$direction: 'asc',
|
|
},
|
|
},
|
|
],
|
|
filters: [
|
|
{
|
|
filter() {
|
|
const { articleMenuId } = this.props;
|
|
return {
|
|
articleMenuId,
|
|
};
|
|
}
|
|
}
|
|
],
|
|
formData({ data, }) {
|
|
return {
|
|
articles: data?.map((ele) => {
|
|
return {
|
|
...ele,
|
|
updateAtStr: ele.$$updateAt$$ ? dayjs(ele.$$updateAt$$).format('YYYY-MM-DD HH:mm:ss') : '--',
|
|
};
|
|
}),
|
|
};
|
|
},
|
|
properties: {
|
|
entityId: '',
|
|
articleMenuId: '',
|
|
generateUrl: ((mode, type, id) => { }),
|
|
empty: undefined,
|
|
menuCheck: (isArticle) => undefined,
|
|
},
|
|
// data: {
|
|
// unsub: undefined as undefined | (() => void),
|
|
// },
|
|
// listeners: {
|
|
// async entityId(prev, next) {
|
|
// if (prev.entityId !== next.entityId) {
|
|
// if (prev.entityId) {
|
|
// const { unsub } = this.state;
|
|
// console.log('listener unsub');
|
|
// unsub && unsub();
|
|
// }
|
|
// if (next.entityId) {
|
|
// const unsub = await this.subDataEvents([`${DATA_SUBSCRIBER_KEYS.articleCreate}-${next.entityId}`]);
|
|
// console.log('listener sub');
|
|
// this.setState({
|
|
// unsub,
|
|
// })
|
|
// }
|
|
// }
|
|
// }
|
|
// },
|
|
// lifetimes: {
|
|
// async ready() {
|
|
// const { entityId, } = this.props;
|
|
// if (entityId) {
|
|
// const unsub = await this.subDataEvents([`${DATA_SUBSCRIBER_KEYS.articleCreate}-${entityId}`]);
|
|
// console.log('ready sub');
|
|
// this.setState({
|
|
// unsub,
|
|
// })
|
|
// }
|
|
// },
|
|
// detached() {
|
|
// const { unsub } = this.state;
|
|
// console.log('detached unsub')
|
|
// unsub && unsub();
|
|
// },
|
|
// },
|
|
methods: {
|
|
goDetail(articleId) {
|
|
const { generateUrl } = this.props;
|
|
const url = generateUrl ? generateUrl('article', 'detail', articleId) : '';
|
|
window.open(url, '_blank');
|
|
},
|
|
onCopy(articleId) {
|
|
const { generateUrl } = this.props;
|
|
const url = generateUrl ? generateUrl('article', 'copy', articleId) : '';
|
|
copy(url);
|
|
this.setMessage({
|
|
type: 'success',
|
|
content: this.t('success.copy'),
|
|
});
|
|
},
|
|
onEditor(articleId) {
|
|
const { generateUrl } = this.props;
|
|
const url = generateUrl ? generateUrl('article', 'editor', articleId) : '';
|
|
window.open(url, '_blank');
|
|
},
|
|
afterDelete() {
|
|
const { articleMenuId, menuCheck } = this.props;
|
|
if (articleMenuId && menuCheck) {
|
|
const [menu] = this.features.cache.get('articleMenu', {
|
|
data: {
|
|
id: 1,
|
|
isArticle: 1,
|
|
},
|
|
filter: {
|
|
id: articleMenuId,
|
|
}
|
|
});
|
|
const { isArticle } = menu;
|
|
menuCheck(!!isArticle);
|
|
}
|
|
}
|
|
}
|
|
});
|