Merge branch 'dev' of codeup.aliyun.com:61c14a7efa282c88e103c23f/oak-general-business into dev

This commit is contained in:
qsc 2023-07-11 10:10:16 +08:00
commit a7aa99e9f8
1 changed files with 120 additions and 107 deletions

View File

@ -29,7 +29,7 @@ export default OakComponent({
name: 1, name: 1,
content: 1, content: 1,
articleMenuId: 1, articleMenuId: 1,
} },
}, },
extraFile$entity: { extraFile$entity: {
$entity: 'extraFile', $entity: 'extraFile',
@ -59,8 +59,9 @@ export default OakComponent({
more: true, more: true,
}, },
isList: true, isList: true,
formData({ data: rows }) { formData({ data: rows, props }) {
const articleMenus: Partial<EntityDict['articleMenu']['Schema']>[] = this.getArticleMenus(); const articleMenus: Partial<EntityDict['articleMenu']['Schema']>[] =
this.getArticleMenus(props.articleMenuId);
const treeData = articleMenus?.map((articleMenu) => { const treeData = articleMenus?.map((articleMenu) => {
return { return {
@ -73,7 +74,10 @@ export default OakComponent({
) )
), ),
parentKey: articleMenu?.parentId, parentKey: articleMenu?.parentId,
children: this.buildTreeData(articleMenu.id, articleMenu.isArticle), children: this.buildTreeData(
articleMenu.id,
articleMenu.isArticle
),
}; };
}); });
return { return {
@ -81,7 +85,9 @@ export default OakComponent({
}; };
}, },
filters: [], filters: [],
lifetimes: { lifetimes: {},
properties: {
articleMenuId: '',
}, },
data: { data: {
selectedArticleId: '', selectedArticleId: '',
@ -89,12 +95,6 @@ export default OakComponent({
selectedKeys: [] as string[], selectedKeys: [] as string[],
treeData: [] as DataNode[], treeData: [] as DataNode[],
parentId: '', parentId: '',
articleMenuId: '',
id: '',
name: '',
isArticle: false,
isChildren: false,
logo: '',
breadcrumbItems: [] as { title: string }[], breadcrumbItems: [] as { title: string }[],
}, },
methods: { methods: {
@ -118,7 +118,7 @@ export default OakComponent({
name: 1, name: 1,
content: 1, content: 1,
articleMenuId: 1, articleMenuId: 1,
} },
}, },
extraFile$entity: { extraFile$entity: {
$entity: 'extraFile', $entity: 'extraFile',
@ -143,9 +143,11 @@ export default OakComponent({
}, },
}, },
filter: { filter: {
parentId: parentId ? parentId : { parentId: parentId
$exists: false ? parentId
} : {
$exists: false,
},
}, },
sorter: [ sorter: [
{ {
@ -156,66 +158,71 @@ export default OakComponent({
}, },
], ],
}); });
return articleMenus return articleMenus;
}, },
async loadArticleMenus(parentId?: string) { async loadArticleMenus(parentId?: string) {
const articleMenus = await this.features.cache.refresh('articleMenu', { const articleMenus = await this.features.cache.refresh(
data: { 'articleMenu',
id: 1, {
name: 1, data: {
isArticle: 1,
isLeaf: 1,
parent: {
id: 1, id: 1,
name: 1, name: 1,
isArticle: 1, isArticle: 1,
isLeaf: 1, isLeaf: 1,
}, parent: {
article$articleMenu: {
$entity: 'article',
data: {
id: 1, id: 1,
name: 1, name: 1,
content: 1, isArticle: 1,
articleMenuId: 1, isLeaf: 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,
entityId: 1,
}, },
filter: { article$articleMenu: {
tag1: { $entity: 'article',
$in: ['logo', 'introduce'], data: {
id: 1,
name: 1,
content: 1,
articleMenuId: 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,
entityId: 1,
},
filter: {
tag1: {
$in: ['logo', 'introduce'],
},
}, },
}, },
}, },
}, filter: {
filter: { parentId: parentId
parentId: parentId ? parentId : { ? parentId
$exists: false : {
} $exists: false,
}, },
sorter: [
{
$attr: {
$$createAt$$: 1,
},
$direction: 'asc',
}, },
], sorter: [
}); {
$attr: {
$$createAt$$: 1,
},
$direction: 'asc',
},
],
}
);
}, },
getArticles(articleMenuId: string) { getArticles(articleMenuId: string) {
const articleMenus = this.features.cache.get('article', { const articleMenus = this.features.cache.get('article', {
@ -226,7 +233,7 @@ export default OakComponent({
articleMenuId: 1, articleMenuId: 1,
}, },
filter: { filter: {
articleMenuId articleMenuId,
}, },
sorter: [ sorter: [
{ {
@ -237,7 +244,7 @@ export default OakComponent({
}, },
], ],
}); });
return articleMenus return articleMenus;
}, },
async loadArticles(articleMenuId?: string) { async loadArticles(articleMenuId?: string) {
@ -249,7 +256,7 @@ export default OakComponent({
articleMenuId: 1, articleMenuId: 1,
}, },
filter: { filter: {
articleMenuId articleMenuId,
}, },
sorter: [ sorter: [
{ {
@ -362,54 +369,55 @@ export default OakComponent({
return openKeys; return openKeys;
}, },
buildTreeData( buildTreeData(parentId: string, isArticle: boolean): DataNode[] {
parentId: string,
isArticle: boolean
): DataNode[] {
let children: DataNode[] = []; let children: DataNode[] = [];
if (isArticle) { if (isArticle) {
const articles: Partial<EntityDict['article']['Schema']>[] = this.getArticles(parentId!); const articles: Partial<EntityDict['article']['Schema']>[] =
children = articles?.map( this.getArticles(parentId!);
article => { children = articles?.map((article) => {
return { return {
label: article.name!, label: article.name!,
key: article.id!, key: article.id!,
type: 'article'!, type: 'article'!,
parentKey: article.articleMenuId!, parentKey: article.articleMenuId!,
} };
} });
) } else {
} const articleMenus: Partial<
else { EntityDict['articleMenu']['Schema']
const articleMenus: Partial<EntityDict['articleMenu']['Schema']>[] = this.getArticleMenus(parentId!); >[] = this.getArticleMenus(parentId!);
children = articleMenus?.map( children = articleMenus?.map((articleMenu) => {
articleMenu => { return {
return { label: articleMenu.name!,
label: articleMenu.name!, key: articleMenu.id?.toString()!,
key: articleMenu.id?.toString()!, isArticle: articleMenu.isArticle!,
isArticle: articleMenu.isArticle!, logo: this.features.extraFile.getUrl(
logo: this.features.extraFile.getUrl( articleMenu?.extraFile$entity?.find(
articleMenu?.extraFile$entity?.find( (ele) => ele.tag1 === 'logo'
(ele) => ele.tag1 === 'logo' )
) ),
), parentKey: articleMenu?.parentId!,
parentKey: articleMenu?.parentId!, children: this.buildTreeData(
children: this.buildTreeData(articleMenu.id, articleMenu.isArticle), articleMenu.id,
} articleMenu.isArticle
} ),
) };
});
} }
return children; return children;
}, },
findParentNodes(treeData:DataNode[], targetKey:string) { findParentNodes(treeData: DataNode[], targetKey: string) {
for (let i = 0; i < treeData.length; i++) { for (let i = 0; i < treeData.length; i++) {
const node = treeData[i]; const node = treeData[i];
if (node.key === targetKey) { if (node.key === targetKey) {
return [node]; return [node];
} }
if (node.children) { if (node.children) {
const parentNodes = this.findParentNodes(node.children, targetKey); const parentNodes = this.findParentNodes(
node.children,
targetKey
);
if (parentNodes.length > 0) { if (parentNodes.length > 0) {
return [node, ...parentNodes]; return [node, ...parentNodes];
} }
@ -421,12 +429,15 @@ export default OakComponent({
for (let i = 0; i < treeData.length; i++) { for (let i = 0; i < treeData.length; i++) {
const node = treeData[i]; const node = treeData[i];
if (node.type === 'article') { if (node.type === 'article') {
const parentNode = this.findParentNodes(this.state.treeData,node.key)[0]; const parentNode = this.findParentNodes(
this.state.treeData,
node.key
)[0];
return parentNode; return parentNode;
} }
if (node.children && node.children.length > 0) { if (node.children && node.children.length > 0) {
const childNode = this.findFirstArticle(node.children); const childNode = this.findFirstArticle(node.children);
if(childNode) { if (childNode) {
return childNode; return childNode;
} }
} }
@ -439,12 +450,15 @@ export default OakComponent({
) { ) {
if (selectedKeys.includes(articleId)) { if (selectedKeys.includes(articleId)) {
} else { } else {
const parentNodes = this.findParentNodes(this.state.treeData,articleId)?.map((ele: { label: any; }) => { const parentNodes = this.findParentNodes(
return {title: ele.label} this.state.treeData,
articleId
)?.map((ele: { label: any }) => {
return { title: ele.label };
}); });
this.setState({ this.setState({
breadcrumbItems: parentNodes, breadcrumbItems: parentNodes,
}) });
this.setState({ this.setState({
selectedKeys: [articleId], selectedKeys: [articleId],
selectedArticleId: articleId, selectedArticleId: articleId,
@ -453,6 +467,5 @@ export default OakComponent({
}); });
} }
}, },
}, },
}); });