diff --git a/src/views/resource/catalogPerson/components/ShareDialog.vue b/src/views/resource/catalogPerson/components/ShareDialog.vue index 8eecbbc..4969648 100644 --- a/src/views/resource/catalogPerson/components/ShareDialog.vue +++ b/src/views/resource/catalogPerson/components/ShareDialog.vue @@ -39,23 +39,24 @@ const treeShareRules = ref({ /** 查询目录-同步教材列表 */ const getList = async () => { - loading.value = true; const res = await listCatalogTextbook(); const data = proxy?.handleTree(res.data, "catalogId", "parentId"); if (data) { treeData.value = data; - loading.value = false; } } const submitShareForm = () => { treeShareFormRef.value?.validate(async (valid: boolean) => { if (valid) { - treeShareDialog.visible = false; - loading.value = true; - const res = await share(treeShareForm.value) - proxy?.$modal.msgSuccess("分享成功") - await getList() - loading.value = false; + try { + loading.value = true; + const res = await share(treeShareForm.value) + proxy?.$modal.msgSuccess("分享成功") + await getList() + treeShareDialog.visible = false; + } finally { + loading.value = false; + } } }); } diff --git a/src/views/resourceMgt/catalogResourceMgt/index.vue b/src/views/resourceMgt/catalogResourceMgt/index.vue index 74d2da4..edd8cea 100644 --- a/src/views/resourceMgt/catalogResourceMgt/index.vue +++ b/src/views/resourceMgt/catalogResourceMgt/index.vue @@ -16,7 +16,8 @@
+ :default-expanded-keys="defaultExpandIds" node-key="catalogId" @node-click="handleNode" + @node-expand="handleNodeExpand" @node-collapse="handleNodeCollapse" />
@@ -103,18 +104,22 @@ --> - - 预览 + + 预览 - - 下载 + + 下载 - - 移动 + + 移动 - - 复制 + + 复制 { } const treeLoading = ref(false) + +// 记录当前展开的节点 +const defaultExpandIds = [] +// 树结点展开 +const handleNodeExpand = (data) => { + // 保存当前节点 + let flag = false + defaultExpandIds.some(item => { + if (item === data.catalogId) { + flag = true + return true + } + }) + if (!flag) { + // 不存在则存到数组里 + defaultExpandIds.push(data.catalogId) + } +} + +// 树节点关闭 +const handleNodeCollapse = (data) => { + // 删除当前关闭的节点 + defaultExpandIds.some((item, index) => { + if (item === data.catalogId) { + defaultExpandIds.splice(index, 1) + } + }) + // 这里主要针对多级树状结构,当关闭父节点时,递归删除父节点下的所有子节点 + removeChildrenIds(data) +} + +// 删除树子节点 +const removeChildrenIds = (data) => { + if (data.children) { + data.children.forEach(function (item) { + const index = defaultExpandIds.indexOf(item.catalogId) + if (index > 0) { + defaultExpandIds.splice(index, 1) + } + removeChildrenIds(item) + }) + } +} + /** 查询目录-同步教材列表 */ const getlistCatalogResource = async () => { treeLoading.value = true; const res = await listCatalogResource(); const data = proxy?.handleTree(res.data, "catalogId", "parentId"); if (data) { + defaultExpandIds.push(data[0].catalogId) treeData.value = data; treeLoading.value = false; } diff --git a/src/views/resourceMgt/catalogSchoolMgt/index.vue b/src/views/resourceMgt/catalogSchoolMgt/index.vue index e53375d..876e9e8 100644 --- a/src/views/resourceMgt/catalogSchoolMgt/index.vue +++ b/src/views/resourceMgt/catalogSchoolMgt/index.vue @@ -23,7 +23,8 @@
+ :expand-on-click-node="false" :default-expanded-keys="defaultExpandIds" node-key="catalogId" + @node-click="handleNode" @node-expand="handleNodeExpand" @node-collapse="handleNodeCollapse" />
@@ -110,18 +111,22 @@
--> - - 预览 + + 预览 - - 下载 + + 下载 - - 移动 + + 移动 - - 复制 + + 复制 { window.open(`${preViewUrl}?url=${encodeURIComponent(Base64.encode(fileRes.data))}`, '__blank') } +// 记录当前展开的节点 +const defaultExpandIds = [] +// 树结点展开 +const handleNodeExpand = (data) => { + // 保存当前节点 + let flag = false + defaultExpandIds.some(item => { + if (item === data.catalogId) { + flag = true + return true + } + }) + if (!flag) { + // 不存在则存到数组里 + defaultExpandIds.push(data.catalogId) + } +} + +// 树节点关闭 +const handleNodeCollapse = (data) => { + // 删除当前关闭的节点 + defaultExpandIds.some((item, index) => { + if (item === data.catalogId) { + defaultExpandIds.splice(index, 1) + } + }) + // 这里主要针对多级树状结构,当关闭父节点时,递归删除父节点下的所有子节点 + removeChildrenIds(data) +} + +// 删除树子节点 +const removeChildrenIds = (data) => { + if (data.children) { + data.children.forEach(function (item) { + const index = defaultExpandIds.indexOf(item.catalogId) + if (index > 0) { + defaultExpandIds.splice(index, 1) + } + removeChildrenIds(item) + }) + } +} const treeLoading = ref(false) /** 查询目录-同步教材列表 */ const getListCatalogTextbook = async () => { @@ -513,6 +560,7 @@ const getListCatalogTextbook = async () => { const res = await listCatalogTextbook(); const data = proxy?.handleTree(res.data, "catalogId", "parentId"); if (data) { + defaultExpandIds.push(data[0].catalogId) treeData.value = data; treeLoading.value = false; } diff --git a/src/views/resourceMgt/catalogTextbookMgt/index.vue b/src/views/resourceMgt/catalogTextbookMgt/index.vue index 3e28144..4f5b21e 100644 --- a/src/views/resourceMgt/catalogTextbookMgt/index.vue +++ b/src/views/resourceMgt/catalogTextbookMgt/index.vue @@ -23,7 +23,8 @@
+ :expand-on-click-node="false" :default-expanded-keys="defaultExpandIds" node-key="catalogId" + @node-click="handleNode" @node-expand="handleNodeExpand" @node-collapse="handleNodeCollapse" />
@@ -116,24 +117,29 @@
--> - - 预览 + + 预览 - - 下载 + + 下载 - - 移动 + + 移动 - - 复制 + + 复制 - - 定稿 + + 定稿 + 删除 @@ -529,12 +535,55 @@ const handlePreview = async (row: any) => { } const treeLoading = ref(false) +// 记录当前展开的节点 +const defaultExpandIds = [] +// 树结点展开 +const handleNodeExpand = (data) => { + // 保存当前节点 + let flag = false + defaultExpandIds.some(item => { + if (item === data.catalogId) { + flag = true + return true + } + }) + if (!flag) { + // 不存在则存到数组里 + defaultExpandIds.push(data.catalogId) + } +} + +// 树节点关闭 +const handleNodeCollapse = (data) => { + // 删除当前关闭的节点 + defaultExpandIds.some((item, index) => { + if (item === data.catalogId) { + defaultExpandIds.splice(index, 1) + } + }) + // 这里主要针对多级树状结构,当关闭父节点时,递归删除父节点下的所有子节点 + removeChildrenIds(data) +} + +// 删除树子节点 +const removeChildrenIds = (data) => { + if (data.children) { + data.children.forEach(function (item) { + const index = defaultExpandIds.indexOf(item.catalogId) + if (index > 0) { + defaultExpandIds.splice(index, 1) + } + removeChildrenIds(item) + }) + } +} /** 查询目录-同步教材列表 */ const getListCatalogTextbook = async () => { treeLoading.value = true; const res = await listCatalogTextbook(); const data = proxy?.handleTree(res.data, "catalogId", "parentId"); if (data) { + defaultExpandIds.push(data[0].catalogId) treeData.value = data; treeLoading.value = false; }