明树Git Lab

Commit 107054d7 authored by zhanghan's avatar zhanghan

项目档案库问题处理\

parent 89cfb09f
Pipeline #109491 passed with stage
in 21 seconds
......@@ -9,30 +9,32 @@ export default {
// 使用 nextTick 确保 DOM 完全渲染
setTimeout(() => {
// 获取所有 el-collapse-item 元素
const collapseItems = el.querySelectorAll('.el-collapse-item');
const collapseItems = el.querySelectorAll(".el-collapse-item");
const navItems = [];
collapseItems.forEach((item, index) => {
// 获取标题
const titleEl = item.querySelector('.el-collapse-item__header');
const title = titleEl ? titleEl.textContent.trim() : `项目${index + 1}`;
const titleEl = item.querySelector(".el-collapse-item__header");
const title = titleEl
? titleEl.textContent.trim()
: `项目${index + 1}`;
// 尝试从多个来源获取 name
let name = '';
let name = "";
// 1. 优先从已有的 id 属性获取
const existingId = item.getAttribute('id');
if (existingId && existingId.startsWith('collapse-')) {
name = existingId.replace('collapse-', '');
const existingId = item.getAttribute("id");
if (existingId && existingId.startsWith("collapse-")) {
name = existingId.replace("collapse-", "");
} else {
// 2. 尝试从 data-name 属性获取(Element Plus 可能会将 name 存储在这里)
const dataName = item.getAttribute('data-name');
const dataName = item.getAttribute("data-name");
if (dataName) {
name = dataName;
} else {
// 3. 尝试从 name 属性获取
const nameAttr = item.getAttribute('name');
const nameAttr = item.getAttribute("name");
if (nameAttr) {
name = nameAttr;
} else {
......@@ -42,33 +44,35 @@ export default {
}
// 设置 id
item.setAttribute('id', `collapse-${name}`);
item.setAttribute("id", `collapse-${name}`);
}
console.log('Navigation item:', {
console.log("Navigation item:", {
name,
title,
id: item.getAttribute('id'),
allAttrs: Array.from(item.attributes).map(attr => `${attr.name}="${attr.value}"`)
id: item.getAttribute("id"),
allAttrs: Array.from(item.attributes).map(
(attr) => `${attr.name}="${attr.value}"`,
),
});
navItems.push({
name,
label: title,
index
index,
});
});
console.log('All navigation items:', navItems);
console.log("All navigation items:", navItems);
// 更新绑定值
if (binding.value) {
if (typeof binding.value === 'function') {
if (typeof binding.value === "function") {
binding.value(navItems);
} else if (Array.isArray(binding.value)) {
// 先清空数组,再添加新元素
binding.value.length = 0;
navItems.forEach(navItem => {
navItems.forEach((navItem) => {
binding.value.push(navItem);
});
}
......@@ -82,8 +86,9 @@ export default {
// 使用 MutationObserver 监听 DOM 变化(处理动态内容)
const observer = new MutationObserver((mutations) => {
// 只在节点变化时更新,避免无限循环
const hasRelevantMutation = mutations.some(mutation =>
mutation.type === 'childList' && mutation.addedNodes.length > 0
const hasRelevantMutation = mutations.some(
(mutation) =>
mutation.type === "childList" && mutation.addedNodes.length > 0,
);
if (hasRelevantMutation) {
updateNavItems();
......@@ -92,7 +97,7 @@ export default {
observer.observe(el, {
childList: true,
subtree: false
subtree: false,
});
// 保存 observer 到元素上,方便后续清理
......@@ -105,7 +110,7 @@ export default {
el._collapseNavObserver.disconnect();
delete el._collapseNavObserver;
}
}
},
};
/**
......
......@@ -267,6 +267,15 @@ const handleSubItemClick = async (item) => {
::v-deep .add-project-back {
display: none;
}
::v-deep .navigation-wrapper {
display: none;
}
::v-deep .tab-content {
padding-top: 16px;
}
::v-deep .el-tabs__header {
padding: 8px 0 0 16px;
}
}
.main-tab-wrapper {
......@@ -459,7 +468,7 @@ const handleSubItemClick = async (item) => {
.detail-content {
flex: 1;
overflow-y: auto;
padding: 20px;
// padding: 20px;
min-height: 500px;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment