134 lines
4.2 KiB
JavaScript
134 lines
4.2 KiB
JavaScript
import { generateNewIdAsync } from "oak-domain/lib/utils/uuid";
|
||
export default OakComponent({
|
||
entity: 'articleMenu',
|
||
isList: false,
|
||
projection: {
|
||
id: 1,
|
||
name: 1,
|
||
entity: 1,
|
||
entityId: 1,
|
||
parentId: 1,
|
||
isArticle: 1,
|
||
extraFile$entity: {
|
||
$entity: 'extraFile',
|
||
data: {
|
||
id: 1,
|
||
tag1: 1,
|
||
origin: 1,
|
||
bucket: 1,
|
||
objectId: 1,
|
||
filename: 1,
|
||
extra1: 1,
|
||
extension: 1,
|
||
type: 1,
|
||
entity: 1,
|
||
},
|
||
filter: {
|
||
tag1: {
|
||
$in: ['logo'],
|
||
},
|
||
},
|
||
},
|
||
articleMenu$parent: {
|
||
$entity: 'articleMenu',
|
||
data: {
|
||
id: 1,
|
||
},
|
||
},
|
||
article$articleMenu: {
|
||
$entity: 'article',
|
||
data: {
|
||
id: 1,
|
||
name: 1,
|
||
},
|
||
},
|
||
},
|
||
properties: {
|
||
onRemove: () => undefined,
|
||
onUpdateName: async (name) => undefined,
|
||
onChildEditArticleChange: (data) => undefined,
|
||
show: 'edit', // edit为编辑,doc为查看,preview为预览
|
||
getBreadcrumbItemsByParent: (breadcrumbItems) => undefined,
|
||
breadItems: [],
|
||
drawerOpen: false,
|
||
changeDrawerOpen: (open) => undefined,
|
||
selectedArticleId: '',
|
||
openArray: [],
|
||
getTopInfo: (data) => undefined,
|
||
articleId: '',
|
||
articleMenuId: '',
|
||
getSideInfo: (data) => undefined,
|
||
currentArticle: '',
|
||
setCurrentArticle: (id) => undefined,
|
||
onMenuViewById: (articleMenuId) => undefined,
|
||
setCopyArticleUrl: (id) => '',
|
||
origin: null, // cos origin默认由系统决定
|
||
},
|
||
formData({ data: row }) {
|
||
const { articleMenu$parent, article$articleMenu } = row || {};
|
||
const allowCreateSubMenu = article$articleMenu && article$articleMenu.length === 0; //目录下无文章则允许创建子目录
|
||
const allowCreateSubArticle = articleMenu$parent && articleMenu$parent.length === 0; //目录下无子目录则允许创建文章
|
||
const allowRemove = allowCreateSubMenu && allowCreateSubArticle; //目录下无子目录且无文章则允许删除
|
||
const logoExtraFile = row?.extraFile$entity?.find((ele) => ele.tag1 === 'logo');
|
||
const logo = this.features.extraFile.getUrl(logoExtraFile);
|
||
return {
|
||
row,
|
||
allowCreateSubMenu,
|
||
allowCreateSubArticle,
|
||
allowRemove,
|
||
logo,
|
||
article$articleMenu,
|
||
};
|
||
},
|
||
data: {
|
||
editArticleId: '',
|
||
},
|
||
methods: {
|
||
async createSubArticle(name) {
|
||
const id = await generateNewIdAsync();
|
||
this.setState({
|
||
editArticleId: '',
|
||
});
|
||
this.update({
|
||
article$articleMenu: [{
|
||
id,
|
||
action: 'create',
|
||
data: {
|
||
id,
|
||
name,
|
||
content: '',
|
||
}
|
||
}]
|
||
});
|
||
await this.execute();
|
||
this.setState({
|
||
editArticleId: id
|
||
});
|
||
},
|
||
async createSubArticleMenu(name) {
|
||
const { row } = this.state;
|
||
this.update({
|
||
articleMenu$parent: [
|
||
{
|
||
id: await generateNewIdAsync(),
|
||
action: 'create',
|
||
data: {
|
||
id: await generateNewIdAsync(),
|
||
name,
|
||
entity: row.entity,
|
||
entityId: row.entityId,
|
||
isArticle: false,
|
||
isLeaf: false,
|
||
},
|
||
}
|
||
]
|
||
});
|
||
await this.execute();
|
||
},
|
||
gotoDoc(articleMenuId) {
|
||
const { onMenuViewById } = this.props;
|
||
onMenuViewById && onMenuViewById(articleMenuId);
|
||
}
|
||
}
|
||
});
|