整体设计 定稿 之24+ dashboard.html 增加三层次动态记录体系仪表盘 之2 程序 (Q208 之2)

下是"之22" 中Q208 的最后程序 (由于字数超限,分两次。本篇是2/2)

html 复制代码
        // 渲染三层嵌套提示词导航
        function renderPrompts() {
            const prompts = getPrompts() || window.DEFAULT_PROMPTS || [];
            const promptsContainer = document.getElementById('prompts-container');
            promptsContainer.innerHTML = '';
            
            // 按符号学系统分组显示
            const groupedPrompts = {
                explicit: prompts.filter(p => p.semioticSystem === 'explicit' || p.promptType === 'grammar'),
                implicit: prompts.filter(p => p.semioticSystem === 'implicit' || p.promptType === 'mind'),
                metaphorical: prompts.filter(p => p.semioticSystem === 'metaphorical' || p.promptType === 'axiom')
            };
            
            Object.entries(groupedPrompts).forEach(([system, systemPrompts]) => {
                if (systemPrompts.length === 0) return;
                
                // 创建系统分组容器
                const systemDiv = document.createElement('div');
                systemDiv.className = 'border border-gray-200 rounded-lg p-3 bg-gray-50';
                
                // 添加系统标题
                const systemTitle = document.createElement('h4');
                systemTitle.className = 'text-sm font-medium text-gray-700 mb-2';
                
                const systemInfo = {
                    explicit: { name: '明言系统', icon: 'fa-comment', color: 'blue' },
                    implicit: { name: '暗示系统', icon: 'fa-eye-slash', color: 'purple' },
                    metaphorical: { name: '隐喻系统', icon: 'fa-magic', color: 'green' }
                };
                
                const info = systemInfo[system];
                systemTitle.innerHTML = `
                    <i class="fa ${info.icon} text-${info.color}-600 mr-1"></i>
                    ${info.name}
                `;
                systemDiv.appendChild(systemTitle);
                
                // 添加该系统的提示词卡片
                systemPrompts.forEach(prompt => {
                    const card = document.createElement('div');
                    card.className = 'p-3 mb-2 border border-gray-200 rounded-lg hover:border-primary hover:bg-blue-50 transition-all-300 cursor-pointer bg-white';
                    card.dataset.id = prompt.id;
                    
                    const systemColor = {
                        explicit: 'blue',
                        implicit: 'purple', 
                        metaphorical: 'green'
                    }[prompt.semioticSystem] || 'gray';
                    
                    card.innerHTML = `
                        <div class="flex items-start justify-between">
                            <div class="flex-1">
                                <h5 class="font-medium text-gray-800 text-sm">${prompt.title}</h5>
                                <div class="mt-1 text-xs text-gray-500">
                                    <span class="inline-block bg-${systemColor}-100 text-${systemColor}-600 rounded-full px-2 py-0.5 mr-1">
                                        ${prompt.promptType || prompt.semioticSystem}
                                    </span>
                                    ${prompt.category ? `<span class="inline-block bg-gray-100 rounded px-1 py-0.5">${prompt.category}</span>` : ''}
                                </div>
                                <div class="mt-1 text-xs text-gray-600 line-clamp-2">
                                    ${prompt.description || prompt.content || '暂无描述'}
                                </div>
                            </div>
                            <div class="flex space-x-1 ml-2">
                                <button class="text-gray-400 hover:text-gray-600 edit-prompt p-1" data-id="${prompt.id}" title="编辑">
                                    <i class="fa fa-pencil text-xs"></i>
                                </button>
                                <button class="text-gray-400 hover:text-gray-600 delete-prompt p-1" data-id="${prompt.id}" title="删除">
                                    <i class="fa fa-trash-o text-xs"></i>
                                </button>
                            </div>
                        </div>
                    `;
                    
                    // 添加点击事件 - 应用提示词
                    card.addEventListener('click', (e) => {
                        if (!e.target.closest('.edit-prompt') && !e.target.closest('.delete-prompt')) {
                            applyPromptSystem(prompt);
                        }
                    });
                    
                    systemDiv.appendChild(card);
                });
                
                promptsContainer.appendChild(systemDiv);
            });
        }
        
        // 应用符号学提示词系统
        function applyPromptSystem(prompt) {
            const systemInfo = {
                explicit: '明言-析取提示词',
                implicit: '暗示-合取关键词',
                metaphorical: '隐喻-双取主题词'
            };
            
            const system = prompt.semioticSystem || 'explicit';
            const systemName = systemInfo[system] || '未知系统';
            
            // 显示应用确认
            showToast(`正在应用${systemName}:${prompt.title}`, 'info');
            
            // 如果是明言系统,更新hover提示
            if (system === 'explicit') {
                updateExplicitPromptSystem(prompt);
            } 
            // 如果是暗示系统,触发心流机制
            else if (system === 'implicit') {
                updateImplicitKeywordSystem(prompt);
            }
            // 如果是隐喻系统,初始化公理体系
            else if (system === 'metaphorical') {
                updateMetaphoricalThemeSystem(prompt);
            }
        }
        
        // 更新明言-析取提示词系统
        function updateExplicitPromptSystem(prompt) {
            // 更新功能hover提示
            console.log('应用明言语法分析系统', prompt);
            showToast('明言语法分析系统已激活:hover提示功能增强', 'success');
        }
        
        // 更新暗示-合取关键词系统
        function updateImplicitKeywordSystem(prompt) {
            // 触发心流机制
            console.log('应用暗示心动程序系统', prompt);
            showToast('暗示心动程序已启动:心流状态检测激活', 'success');
        }
        
        // 更新隐喻-双取主题词系统
        function updateMetaphoricalThemeSystem(prompt) {
            // 初始化公理体系
            console.log('应用隐喻公理体系', prompt);
            showToast('隐喻公理体系已建立:范畴元件约束就绪', 'success');
        }
        
        // 显示符号学架构配置
        function showArchitectureConfig() {
            document.getElementById('architecture-config-modal').classList.remove('hidden');
            // 加载当前配置
            loadArchitectureConfig();
        }
        
        // 加载架构配置
        function loadArchitectureConfig() {
            const config = localStorage.getItem('semiotic-architecture-config');
            if (config) {
                try {
                    const parsedConfig = JSON.parse(config);
                    // 应用保存的配置到表单
                    console.log('加载架构配置:', parsedConfig);
                } catch (e) {
                    console.warn('架构配置解析失败:', e);
                }
            }
        }
        
        // 保存架构配置
        function saveArchitectureConfig() {
            const config = {
                pinStructure: {
                    science: {
                        mechanics: document.querySelector('input[placeholder="力学系数"]').value,
                        mathematics: document.querySelector('input[placeholder="数学精度"]').value
                    },
                    engineering: {
                        experience: document.querySelector('select:nth-of-type(1)').value,
                        method: document.querySelector('select:nth-of-type(2)').value
                    },
                    liberalArts: {
                        independence: document.querySelector('select:nth-of-type(3)').value,
                        unity: document.querySelector('input[type="range"]').value
                    }
                },
                promptSystems: {
                    explicit: {
                        enabled: document.querySelectorAll('input[type="checkbox"]')[0].checked,
                        grammar: document.querySelectorAll('input[type="text"]')[0].value,
                        pragmatics: document.querySelectorAll('input[type="text"]')[1].value,
                        semantics: document.querySelectorAll('input[type="text"]')[2].value
                    },
                    implicit: {
                        enabled: document.querySelectorAll('input[type="checkbox"]')[1].checked,
                        mind: document.querySelectorAll('textarea')[0].value,
                        motion: document.querySelectorAll('textarea')[1].value,
                        action: document.querySelectorAll('textarea')[2].value
                    },
                    metaphorical: {
                        enabled: document.querySelectorAll('input[type="checkbox"]')[2].checked,
                        axiom: document.querySelectorAll('input[type="text"]')[3].value,
                        method: document.querySelectorAll('input[type="text"]')[4].value,
                        assertion: document.querySelectorAll('input[type="text"]')[5].value
                    }
                },
                valueExpressions: {
                    embedded: {
                        enabled: true,
                        scope: '万向 通 - 通 境 顿'
                    },
                    external: {
                        enabled: true,
                        scope: '千行 别 - 性 行 渐'
                    },
                    internal: {
                        enabled: true,
                        scope: '百业 藏 - 量 果 密'
                    }
                }
            };
            
            localStorage.setItem('semiotic-architecture-config', JSON.stringify(config));
            showToast('符号学架构配置已保存', 'success');
            document.getElementById('architecture-config-modal').classList.add('hidden');
            
            // 重新初始化系统
            initializeSemioticArchitecture();
            renderPrompts();
        }
                    </div>
                `;
                
                // 添加点击事件
                card.addEventListener('click', (e) => {
                    if (!e.target.closest('.edit-prompt') && !e.target.closest('.delete-prompt')) {
                        // 使用提示词创建新讨论
                        createDiscussionFromPrompt(prompt);
                    }
                });
                
                promptsContainer.appendChild(card);
            
            // 添加编辑和删除事件
            document.querySelectorAll('.edit-prompt').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    e.stopPropagation();
                    const id = btn.dataset.id;
                    // 这里可以添加编辑提示词的逻辑
                    showToast('编辑功能开发中...', 'info');
                });
            });
            
            document.querySelectorAll('.delete-prompt').forEach(btn => {
                btn.addEventListener('click', (e) => {
                    e.stopPropagation();
                    const id = btn.dataset.id;
                    if (confirm('确定要删除这个提示词模板吗?')) {
                        deletePrompt(id);
                        renderPrompts();
                        showToast('提示词模板已删除', 'success');
                    }
                });
            });
        }

        // ==================== 讨论编辑 ====================
        // 打开讨论
        function openDiscussion(id) {
            const discussion = getDiscussions().find(d => d.id === id);
            if (!discussion) return;
            
            // 切换到编辑视图
            document.getElementById('dashboard-view').classList.add('hidden');
            document.getElementById('welcome-view').classList.add('hidden');
            document.getElementById('config-view').classList.add('hidden');
            document.getElementById('editor-view').classList.remove('hidden');
            
            // 填充表单
            document.getElementById('discussion-title').value = discussion.title;
            document.getElementById('discussion-category').value = discussion.category;
            document.getElementById('discussion-subject').value = discussion.subject;
            document.getElementById('discussion-topic').value = discussion.topic;
            
            // 渲染标签
            renderTags(discussion.tags || []);
            
            // 渲染内容块
            renderContentBlocks(discussion.contentBlocks || []);
            
            // 设置当前讨论ID
            document.getElementById('editor-view').dataset.id = id;
            
            // 更新价值维度统计
            valueStats.learn++;
            saveData(STORAGE_KEYS.STATS, valueStats);
            updateStats();
        }

        // 创建新讨论
        function createNewDiscussion() {
            const discussion = {
                id: generateId(),
                title: '',
                category: '',
                subject: '',
                topic: '',
                tags: [],
                contentBlocks: [],
                createdAt: new Date().toISOString(),
                updatedAt: new Date().toISOString()
            };
            
            // 保存讨论
            saveDiscussion(discussion);
            
            // 打开讨论
            openDiscussion(discussion.id);
            
            // 更新列表
            renderDiscussions();
            renderCategories();
            
            // 更新价值维度统计
            valueStats.save++;
            saveData(STORAGE_KEYS.STATS, valueStats);
            updateStats();
        }

        // 从提示词创建讨论
        function createDiscussionFromPrompt(prompt) {
            const discussion = {
                id: generateId(),
                title: prompt.title,
                category: '',
                subject: prompt.title,
                topic: '',
                tags: prompt.tags || [],
                contentBlocks: [
                    {
                        id: generateId(),
                        type: 'text',
                        content: prompt.content,
                        order: 0
                    }
                ],
                createdAt: new Date().toISOString(),
                updatedAt: new Date().toISOString()
            };
            
            // 保存讨论
            saveDiscussion(discussion);
            
            // 打开讨论
            openDiscussion(discussion.id);
            
            // 更新列表
            renderDiscussions();
            renderCategories();
            
            // 更新价值维度统计
            valueStats.learn++;
            valueStats.save++;
            saveData(STORAGE_KEYS.STATS, valueStats);
            updateStats();
            
            showToast('已从模板创建讨论', 'success');
        }

        // 渲染标签
        function renderTags(tags) {
            const tagsContainer = document.getElementById('tags-container');
            tagsContainer.innerHTML = '';
            
            tags.forEach(tag => {
                const tagElement = document.createElement('div');
                tagElement.className = 'flex items-center bg-gray-100 rounded-full px-3 py-1';
                tagElement.innerHTML = `
                    <span class="text-sm text-gray-600">${tag}</span>
                    <button class="ml-1 text-gray-400 hover:text-gray-600 remove-tag">
                        <i class="fa fa-times"></i>
                    </button>
                `;
                
                // 添加删除事件
                tagElement.querySelector('.remove-tag').addEventListener('click', () => {
                    const updatedTags = tags.filter(t => t !== tag);
                    updateDiscussionTags(updatedTags);
                    renderTags(updatedTags);
                });
                
                tagsContainer.appendChild(tagElement);
            });
        }

        // 更新讨论标签
        function updateDiscussionTags(tags) {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (discussion) {
                discussion.tags = tags;
                discussion.updatedAt = new Date().toISOString();
                saveDiscussion(discussion);
            }
        }

        // 渲染内容块
        function renderContentBlocks(blocks) {
            const container = document.getElementById('content-blocks-container');
            const emptyMsg = document.getElementById('empty-content-msg');
            
            // 清空容器
            container.innerHTML = '';
            
            if (blocks.length === 0) {
                emptyMsg.classList.remove('hidden');
                container.appendChild(emptyMsg);
                return;
            }
            
            emptyMsg.classList.add('hidden');
            
            // 按顺序渲染内容块
            blocks.sort((a, b) => a.order - b.order).forEach(block => {
                const blockElement = document.createElement('div');
                blockElement.className = 'content-block p-4 border border-gray-200 rounded-lg relative';
                blockElement.dataset.id = block.id;
                blockElement.dataset.type = block.type;
                
                // 根据类型渲染不同的内容块
                switch (block.type) {
                    case 'text':
                        blockElement.innerHTML = `
                            <div class="flex items-center justify-between mb-2">
                                <div class="flex items-center">
                                    <div class="w-8 h-8 rounded-full bg-blue-100 flex items-center justify-center text-primary mr-2">
                                        <i class="fa fa-align-left"></i>
                                    </div>
                                    <h4 class="font-medium text-gray-800">文本块</h4>
                                </div>
                                <div class="flex space-x-2">
                                    <button class="text-gray-400 hover:text-gray-600 move-block" data-direction="up">
                                        <i class="fa fa-arrow-up"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-gray-600 move-block" data-direction="down">
                                        <i class="fa fa-arrow-down"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-gray-600 delete-block" data-id="${block.id}">
                                        <i class="fa fa-trash-o"></i>
                                    </button>
                                </div>
                            </div>
                            <div class="editable-content" contenteditable="true">${block.content || ''}</div>
                        `;
                        break;
                        
                    case 'timeline':
                        blockElement.innerHTML = `
                            <div class="flex items-center justify-between mb-2">
                                <div class="flex items-center">
                                    <div class="w-8 h-8 rounded-full bg-green-100 flex items-center justify-center text-green-600 mr-2">
                                        <i class="fa fa-clock-o"></i>
                                    </div>
                                    <h4 class="font-medium text-gray-800">时间轴</h4>
                                </div>
                                <div class="flex space-x-2">
                                    <button class="text-gray-400 hover:text-gray-600 move-block" data-direction="up">
                                        <i class="fa fa-arrow-up"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-gray-600 move-block" data-direction="down">
                                        <i class="fa fa-arrow-down"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-gray-600 delete-block" data-id="${block.id}">
                                        <i class="fa fa-trash-o"></i>
                                    </button>
                                </div>
                            </div>
                            <div class="timeline-container space-y-3">
                                ${block.items ? block.items.map(item => `
                                    <div class="flex">
                                        <div class="flex flex-col items-center mr-4">
                                            <div class="w-3 h-3 rounded-full bg-green-500"></div>
                                            <div class="w-0.5 h-full bg-green-200"></div>
                                        </div>
                                        <div class="flex-1">
                                            <div class="text-sm font-medium text-gray-800">${item.time || ''}</div>
                                            <div class="text-sm text-gray-600">${item.content || ''}</div>
                                        </div>
                                    </div>
                                `).join('') : ''}
                                <div class="flex">
                                    <div class="flex flex-col items-center mr-4">
                                        <div class="w-3 h-3 rounded-full bg-green-300"></div>
                                    </div>
                                    <div class="flex-1">
                                        <button class="text-sm text-primary hover:text-primary-dark add-timeline-item" data-block-id="${block.id}">
                                            <i class="fa fa-plus-circle"></i> 添加时间点
                                        </button>
                                    </div>
                                </div>
                            </div>
                        `;
                        break;
                        
                    case 'decision':
                        blockElement.innerHTML = `
                            <div class="flex items-center justify-between mb-2">
                                <div class="flex items-center">
                                    <div class="w-8 h-8 rounded-full bg-purple-100 flex items-center justify-center text-purple-600 mr-2">
                                        <i class="fa fa-check-circle"></i>
                                    </div>
                                    <h4 class="font-medium text-gray-800">决策点</h4>
                                </div>
                                <div class="flex items-center space-x-2">
                                    <span class="text-xs px-2 py-1 rounded-full ${block.status === 'completed' ? 'bg-green-100 text-green-800' : 'bg-yellow-100 text-yellow-800'}">
                                        ${block.status === 'completed' ? '已确认' : '待确认'}
                                    </span>
                                    <button class="text-gray-400 hover:text-gray-600 move-block" data-direction="up">
                                        <i class="fa fa-arrow-up"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-gray-600 move-block" data-direction="down">
                                        <i class="fa fa-arrow-down"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-gray-600 delete-block" data-id="${block.id}">
                                        <i class="fa fa-trash-o"></i>
                                    </button>
                                </div>
                            </div>
                            <div class="decision-container">
                                <div class="editable-content" contenteditable="true">${block.content || ''}</div>
                                <div class="mt-2 flex justify-end">
                                    <button class="text-xs px-3 py-1 rounded-full ${block.status === 'completed' ? 'bg-yellow-100 text-yellow-800' : 'bg-green-100 text-green-800'} toggle-decision-status" data-block-id="${block.id}">
                                        ${block.status === 'completed' ? '标记为待确认' : '标记为已确认'}
                                    </button>
                                </div>
                            </div>
                        `;
                        break;
                        
                    case 'todo':
                        blockElement.innerHTML = `
                            <div class="flex items-center justify-between mb-2">
                                <div class="flex items-center">
                                    <div class="w-8 h-8 rounded-full bg-yellow-100 flex items-center justify-center text-yellow-600 mr-2">
                                        <i class="fa fa-tasks"></i>
                                    </div>
                                    <h4 class="font-medium text-gray-800">待办事项</h4>
                                </div>
                                <div class="flex space-x-2">
                                    <button class="text-gray-400 hover:text-gray-600 move-block" data-direction="up">
                                        <i class="fa fa-arrow-up"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-gray-600 move-block" data-direction="down">
                                        <i class="fa fa-arrow-down"></i>
                                    </button>
                                    <button class="text-gray-400 hover:text-gray-600 delete-block" data-id="${block.id}">
                                        <i class="fa fa-trash-o"></i>
                                    </button>
                                </div>
                            </div>
                            <div class="todo-container space-y-2">
                                ${block.items ? block.items.map(item => `
                                    <div class="flex items-center">
                                        <input type="checkbox" class="todo-checkbox w-4 h-4 text-primary rounded border-gray-300 focus:ring-primary" ${item.completed ? 'checked' : ''} data-block-id="${block.id}" data-item-id="${item.id}">
                                        <span class="ml-2 text-sm ${item.completed ? 'line-through text-gray-400' : 'text-gray-700'}">${item.text}</span>
                                    </div>
                                `).join('') : ''}
                                <div class="flex items-center">
                                    <input type="checkbox" class="w-4 h-4 text-primary rounded border-gray-300 focus:ring-primary opacity-50" disabled>
                                    <input type="text" class="ml-2 text-sm flex-1 border-0 border-b border-gray-300 focus:outline-none focus:ring-0 add-todo-input" placeholder="添加新任务..." data-block-id="${block.id}">
                                </div>
                            </div>
                        `;
                        break;
                }
                
                container.appendChild(blockElement);
                
                // 添加可编辑内容的事件
                const editableContent = blockElement.querySelector('.editable-content');
                if (editableContent) {
                    editableContent.addEventListener('input', debounce(() => {
                        updateContentBlock(block.id, { content: editableContent.innerHTML });
                    }, 500));
                }
            });
            
            // 添加移动和删除事件
            document.querySelectorAll('.move-block').forEach(btn => {
                btn.addEventListener('click', () => {
                    const direction = btn.dataset.direction;
                    const blockId = btn.closest('.content-block').dataset.id;
                    moveContentBlock(blockId, direction);
                });
            });
            
            document.querySelectorAll('.delete-block').forEach(btn => {
                btn.addEventListener('click', () => {
                    const blockId = btn.dataset.id;
                    deleteContentBlock(blockId);
                });
            });
            
            // 添加时间轴项目事件
            document.querySelectorAll('.add-timeline-item').forEach(btn => {
                btn.addEventListener('click', () => {
                    const blockId = btn.dataset.blockId;
                    addTimelineItem(blockId);
                });
            });
            
            // 添加切换决策状态事件
            document.querySelectorAll('.toggle-decision-status').forEach(btn => {
                btn.addEventListener('click', () => {
                    const blockId = btn.dataset.blockId;
                    toggleDecisionStatus(blockId);
                });
            });
            
            // 添加待办事项事件
            document.querySelectorAll('.todo-checkbox').forEach(checkbox => {
                checkbox.addEventListener('change', () => {
                    const blockId = checkbox.dataset.blockId;
                    const itemId = checkbox.dataset.itemId;
                    toggleTodoItem(blockId, itemId, checkbox.checked);
                });
            });
            
            document.querySelectorAll('.add-todo-input').forEach(input => {
                input.addEventListener('keypress', (e) => {
                    if (e.key === 'Enter' && input.value.trim()) {
                        const blockId = input.dataset.blockId;
                        addTodoItem(blockId, input.value.trim());
                        input.value = '';
                    }
                });
            });
        }

        // 更新内容块
        function updateContentBlock(blockId, updates) {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (discussion) {
                const blockIndex = discussion.contentBlocks.findIndex(b => b.id === blockId);
                if (blockIndex >= 0) {
                    discussion.contentBlocks[blockIndex] = {
                        ...discussion.contentBlocks[blockIndex],
                        ...updates
                    };
                    discussion.updatedAt = new Date().toISOString();
                    saveDiscussion(discussion);
                }
            }
        }

        // 移动内容块
        function moveContentBlock(blockId, direction) {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (discussion) {
                const blockIndex = discussion.contentBlocks.findIndex(b => b.id === blockId);
                if (blockIndex >= 0) {
                    const newIndex = direction === 'up' ? blockIndex - 1 : blockIndex + 1;
                    if (newIndex >= 0 && newIndex < discussion.contentBlocks.length) {
                        // 交换位置
                        const temp = discussion.contentBlocks[blockIndex];
                        discussion.contentBlocks[blockIndex] = discussion.contentBlocks[newIndex];
                        discussion.contentBlocks[newIndex] = temp;
                        
                        // 更新顺序
                        discussion.contentBlocks.forEach((block, index) => {
                            block.order = index;
                        });
                        
                        discussion.updatedAt = new Date().toISOString();
                        saveDiscussion(discussion);
                        
                        // 重新渲染
                        renderContentBlocks(discussion.contentBlocks);
                    }
                }
            }
        }

        // 删除内容块
        function deleteContentBlock(blockId) {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (discussion) {
                discussion.contentBlocks = discussion.contentBlocks.filter(b => b.id !== blockId);
                
                // 更新顺序
                discussion.contentBlocks.forEach((block, index) => {
                    block.order = index;
                });
                
                discussion.updatedAt = new Date().toISOString();
                saveDiscussion(discussion);
                
                // 重新渲染
                renderContentBlocks(discussion.contentBlocks);
            }
        }

        // 添加时间轴项目
        function addTimelineItem(blockId) {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (discussion) {
                const blockIndex = discussion.contentBlocks.findIndex(b => b.id === blockId);
                if (blockIndex >= 0) {
                    const block = discussion.contentBlocks[blockIndex];
                    if (!block.items) {
                        block.items = [];
                    }
                    
                    block.items.push({
                        id: generateId(),
                        time: new Date().toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }),
                        content: ''
                    });
                    
                    discussion.updatedAt = new Date().toISOString();
                    saveDiscussion(discussion);
                    
                    // 重新渲染
                    renderContentBlocks(discussion.contentBlocks);
                }
            }
        }

        // 切换决策状态
        function toggleDecisionStatus(blockId) {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (discussion) {
                const blockIndex = discussion.contentBlocks.findIndex(b => b.id === blockId);
                if (blockIndex >= 0) {
                    const block = discussion.contentBlocks[blockIndex];
                    block.status = block.status === 'completed' ? 'pending' : 'completed';
                    
                    discussion.updatedAt = new Date().toISOString();
                    saveDiscussion(discussion);
                    
                    // 重新渲染
                    renderContentBlocks(discussion.contentBlocks);
                    
                    // 更新统计
                    updateStats();
                }
            }
        }

        // 添加待办事项
        function addTodoItem(blockId, text) {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (discussion) {
                const blockIndex = discussion.contentBlocks.findIndex(b => b.id === blockId);
                if (blockIndex >= 0) {
                    const block = discussion.contentBlocks[blockIndex];
                    if (!block.items) {
                        block.items = [];
                    }
                    
                    block.items.push({
                        id: generateId(),
                        text: text,
                        completed: false
                    });
                    
                    discussion.updatedAt = new Date().toISOString();
                    saveDiscussion(discussion);
                    
                    // 重新渲染
                    renderContentBlocks(discussion.contentBlocks);
                    
                    // 更新统计
                    updateStats();
                }
            }
        }

        // 切换待办事项状态
        function toggleTodoItem(blockId, itemId, completed) {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (discussion) {
                const blockIndex = discussion.contentBlocks.findIndex(b => b.id === blockId);
                if (blockIndex >= 0) {
                    const block = discussion.contentBlocks[blockIndex];
                    const itemIndex = block.items.findIndex(i => i.id === itemId);
                    if (itemIndex >= 0) {
                        block.items[itemIndex].completed = completed;
                        
                        discussion.updatedAt = new Date().toISOString();
                        saveDiscussion(discussion);
                        
                        // 重新渲染
                        renderContentBlocks(discussion.contentBlocks);
                        
                        // 更新统计
                        updateStats();
                    }
                }
            }
        }

        // 生成AI总结
        function generateSummary() {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (!discussion) return;
            
            const summaryContainer = document.getElementById('summary-container');
            summaryContainer.innerHTML = '<p class="text-center text-gray-500">正在生成总结...</p>';
            
            // 模拟AI处理延迟
            setTimeout(() => {
                let summary = `# ${discussion.title} 讨论总结\n\n`;
                
                // 提取决策点
                const decisions = discussion.contentBlocks.filter(b => b.type === 'decision' && b.content);
                if (decisions.length > 0) {
                    summary += `## 关键决策\n\n`;
                    decisions.forEach((decision, index) => {
                        summary += `${index + 1}. ${decision.content.replace(/<[^>]*>/g, '')}\n`;
                    });
                    summary += `\n`;
                }
                
                // 提取待办事项
                const todos = [];
                discussion.contentBlocks.forEach(block => {
                    if (block.type === 'todo' && block.items) {
                        block.items.forEach(item => {
                            if (!item.completed) {
                                todos.push(item.text);
                            }
                        });
                    }
                });
                
                if (todos.length > 0) {
                    summary += `## 待办事项\n\n`;
                    todos.forEach((todo, index) => {
                        summary += `${index + 1}. ${todo}\n`;
                    });
                    summary += `\n`;
                }
                
                // 提取时间线
                const timelineItems = [];
                discussion.contentBlocks.forEach(block => {
                    if (block.type === 'timeline' && block.items) {
                        block.items.forEach(item => {
                            if (item.time && item.content) {
                                timelineItems.push({ time: item.time, content: item.content });
                            }
                        });
                    }
                });
                
                if (timelineItems.length > 0) {
                    summary += `## 时间线\n\n`;
                    timelineItems.forEach(item => {
                        summary += `${item.time} - ${item.content}\n`;
                    });
                }
                
                // 显示总结
                summaryContainer.innerHTML = `
                    <div class="markdown-body">
                        ${summary.replace(/\n/g, '<br>').replace(/^# (.*$)/gm, '<h1 class="text-xl font-bold">$1</h1>').replace(/^## (.*$)/gm, '<h2 class="text-lg font-semibold mt-2">$1</h2>')}
                    </div>
                `;
                
                // 更新价值维度统计
                valueStats.learn++;
                saveData(STORAGE_KEYS.STATS, valueStats);
                updateStats();
                
                showToast('总结已生成', 'success');
            }, 1500);
        }

        // ==================== 事件监听 ====================
        // 初始化事件监听
        function initializeEventListeners() {
            // 导航按钮
            document.getElementById('dashboard-btn').addEventListener('click', () => {
                document.getElementById('dashboard-view').classList.remove('hidden');
                document.getElementById('editor-view').classList.add('hidden');
                document.getElementById('config-view').classList.add('hidden');
                document.getElementById('welcome-view').classList.add('hidden');
                renderDashboard();
            });
            
            document.getElementById('config-btn').addEventListener('click', () => {
                document.getElementById('dashboard-view').classList.add('hidden');
                document.getElementById('editor-view').classList.add('hidden');
                document.getElementById('config-view').classList.remove('hidden');
                document.getElementById('welcome-view').classList.add('hidden');
                renderConfigView();
            });
            
            document.getElementById('back-to-dashboard').addEventListener('click', () => {
                document.getElementById('dashboard-view').classList.remove('hidden');
                document.getElementById('config-view').classList.add('hidden');
                renderDashboard();
            });
            
            // 新建讨论
            document.getElementById('new-discussion-btn').addEventListener('click', createNewDiscussion);
            document.getElementById('create-first-discussion').addEventListener('click', createNewDiscussion);
            document.getElementById('explore-dashboard').addEventListener('click', () => {
                document.getElementById('dashboard-view').classList.remove('hidden');
                document.getElementById('welcome-view').classList.add('hidden');
                renderDashboard();
            });
            
            // 备份按钮
            document.getElementById('backup-btn').addEventListener('click', () => {
                document.getElementById('backup-modal').classList.remove('hidden');
                loadBackupData();
                
                // 更新价值维度统计
                valueStats.safe++;
                saveData(STORAGE_KEYS.STATS, valueStats);
                updateStats();
            });
            
            // 关闭备份模态框
            document.getElementById('close-backup-modal').addEventListener('click', () => {
                document.getElementById('backup-modal').classList.add('hidden');
            });
            
            document.getElementById('close-backup-btn').addEventListener('click', () => {
                document.getElementById('backup-modal').classList.add('hidden');
            });
            
            // 导出数据
            document.getElementById('export-data-btn').addEventListener('click', exportData);
            
            // 导入数据
            document.getElementById('import-file').addEventListener('change', importData);
            
            // 重置数据
            document.getElementById('reset-data-btn').addEventListener('click', () => {
                if (confirm('确定要重置所有数据吗?这将删除所有讨论和配置,不可恢复!')) {
                    resetData();
                    document.getElementById('backup-modal').classList.add('hidden');
                    renderDashboard();
                    renderDiscussions();
                    renderCategories();
                    showToast('数据已重置', 'success');
                }
            });
            
            // 添加内容块按钮
            document.getElementById('add-content-block').addEventListener('click', () => {
                document.getElementById('add-block-modal').classList.remove('hidden');
            });
            
            // 关闭内容块模态框
            document.getElementById('close-modal-btn').addEventListener('click', () => {
                document.getElementById('add-block-modal').classList.add('hidden');
            });
            
            // 添加内容块
            document.querySelectorAll('.add-block-btn').forEach(btn => {
                btn.addEventListener('click', () => {
                    const type = btn.dataset.type;
                    addContentBlock(type);
                    document.getElementById('add-block-modal').classList.add('hidden');
                });
            });
            
            // 生成总结
            document.getElementById('generate-summary-btn').addEventListener('click', generateSummary);
            
            // 帮助按钮
            document.getElementById('help-button').addEventListener('click', () => {
                document.getElementById('help-modal').classList.remove('hidden');
                
                // 更新价值维度统计
                valueStats.learn++;
                saveData(STORAGE_KEYS.STATS, valueStats);
                updateStats();
            });
            
            // 关闭帮助模态框
            document.getElementById('close-help-modal').addEventListener('click', () => {
                document.getElementById('help-modal').classList.add('hidden');
            });
            
            // 帮助标签页
            document.querySelectorAll('.help-tab-btn').forEach(tab => {
                tab.addEventListener('click', () => {
                    const tabId = tab.dataset.tab;
                    document.querySelectorAll('.help-tab-btn').forEach(t => {
                        t.classList.remove('text-primary', 'border-primary');
                        t.classList.add('text-gray-500', 'border-transparent');
                    });
                    document.querySelectorAll('.help-tab-content').forEach(content => {
                        content.classList.add('hidden');
                    });
                    tab.classList.remove('text-gray-500', 'border-transparent');
                    tab.classList.add('text-primary', 'border-primary');
                    document.getElementById(`${tabId}-tab`).classList.remove('hidden');
                });
            });
            
            // 配置标签页
            document.querySelectorAll('.config-tab-btn').forEach(tab => {
                tab.addEventListener('click', () => {
                    const tabId = tab.dataset.tab;
                    document.querySelectorAll('.config-tab-btn').forEach(t => {
                        t.classList.remove('text-primary', 'border-primary');
                        t.classList.add('text-gray-500', 'border-transparent');
                    });
                    document.querySelectorAll('.config-tab-content').forEach(content => {
                        content.classList.add('hidden');
                    });
                    tab.classList.remove('text-gray-500', 'border-transparent');
                    tab.classList.add('text-primary', 'border-primary');
                    document.getElementById(`${tabId}-tab`).classList.remove('hidden');
                });
            });
            
            // Requirements需求配置应用
            document.getElementById('apply-requirements').addEventListener('click', () => {
                applyRequirementsConfig();
            });
            
            // Demands方法配置应用
            document.getElementById('apply-demands').addEventListener('click', () => {
                applyDemandsConfig();
            });
            
            // 添加新范畴
            document.getElementById('add-new-category').addEventListener('click', () => {
                document.getElementById('add-category-modal').classList.remove('hidden');
            });
            
            // 关闭范畴模态框
            document.getElementById('cancel-category-btn').addEventListener('click', () => {
                document.getElementById('add-category-modal').classList.add('hidden');
            });
            
            // 保存范畴
            document.getElementById('save-category-btn').addEventListener('click', saveNewCategory);
            
            // 选择颜色
            document.querySelectorAll('.category-color-btn').forEach(btn => {
                btn.addEventListener('click', () => {
                    document.querySelectorAll('.category-color-btn').forEach(b => {
                        b.classList.remove('border-primary');
                    });
                    btn.classList.add('border-primary');
                });
            });
            
            // 添加标签
            document.getElementById('add-tag-btn').addEventListener('click', () => {
                const tagInput = document.getElementById('tag-input');
                const tag = tagInput.value.trim();
                if (tag) {
                    const id = document.getElementById('editor-view').dataset.id;
                    const discussion = getDiscussions().find(d => d.id === id);
                    if (discussion) {
                        if (!discussion.tags) {
                            discussion.tags = [];
                        }
                        if (!discussion.tags.includes(tag)) {
                            discussion.tags.push(tag);
                            discussion.updatedAt = new Date().toISOString();
                            saveDiscussion(discussion);
                            renderTags(discussion.tags);
                        }
                        tagInput.value = '';
                    }
                }
            });
            
            // 富文本格式化
            document.querySelectorAll('.format-btn').forEach(btn => {
                btn.addEventListener('click', () => {
                    const command = btn.dataset.command;
                    document.execCommand(command, false, null);
                    
                    // 更新价值维度统计
                    valueStats.save++;
                    saveData(STORAGE_KEYS.STATS, valueStats);
                    updateStats();
                });
            });
            
            // 搜索
            document.getElementById('search-input').addEventListener('input', debounce(() => {
                const searchTerm = document.getElementById('search-input').value.toLowerCase();
                const discussions = getDiscussions();
                const filteredDiscussions = discussions.filter(d => 
                    d.title.toLowerCase().includes(searchTerm) ||
                    d.subject.toLowerCase().includes(searchTerm) ||
                    d.topic.toLowerCase().includes(searchTerm) ||
                    (d.tags && d.tags.some(tag => tag.toLowerCase().includes(searchTerm)))
                );
                
                const discussionList = document.getElementById('discussion-list');
                const emptyMsg = document.getElementById('empty-discussion-msg');
                
                if (filteredDiscussions.length === 0) {
                    discussionList.innerHTML = '';
                    emptyMsg.classList.remove('hidden');
                    return;
                }
                
                emptyMsg.classList.add('hidden');
                discussionList.innerHTML = '';
                
                filteredDiscussions.forEach(discussion => {
                    const category = getCategories().find(c => c.id === discussion.category);
                    const item = document.createElement('div');
                    item.className = 'p-3 rounded-lg hover:bg-gray-100 cursor-pointer transition-all-300 border border-transparent hover:border-gray-200';
                    item.dataset.id = discussion.id;
                    
                    item.innerHTML = `
                        <div class="flex items-start justify-between">
                            <div class="flex-1">
                                <h4 class="font-medium text-gray-800 truncate">${discussion.title}</h4>
                                <div class="flex items-center mt-1 text-xs text-gray-500">
                                    <span class="inline-block w-2 h-2 rounded-full mr-1" style="background-color: ${category ? category.color : '#ccc'}"></span>
                                    <span>${category ? category.name : '未分类'}</span>
                                    <span class="mx-1">•</span>
                                    <span>${discussion.subject}</span>
                                </div>
                            </div>
                        </div>
                        <div class="mt-2 text-xs text-gray-500">
                            <span>${formatDate(discussion.updatedAt)}</span>
                        </div>
                    `;
                    
                    item.addEventListener('click', () => {
                        openDiscussion(discussion.id);
                    });
                    
                    discussionList.appendChild(item);
                });
            }, 300));
            
            // 分类关键词自动完成
            document.getElementById('discussion-subject').addEventListener('input', debounce(() => {
                const input = document.getElementById('discussion-subject');
                const value = input.value.toLowerCase();
                const suggestions = document.getElementById('subject-suggestions');
                const subjects = getSubjects();
                
                const filteredSubjects = subjects.filter(s => s.toLowerCase().includes(value));
                
                if (filteredSubjects.length > 0 && value.length > 0) {
                    suggestions.innerHTML = filteredSubjects.map(s => `
                        <div class="p-2 hover:bg-gray-100 cursor-pointer subject-suggestion">${s}</div>
                    `).join('');
                    suggestions.classList.remove('hidden');
                    
                    document.querySelectorAll('.subject-suggestion').forEach(suggestion => {
                        suggestion.addEventListener('click', () => {
                            input.value = suggestion.textContent;
                            suggestions.classList.add('hidden');
                        });
                    });
                } else {
                    suggestions.classList.add('hidden');
                }
            }, 300));
            
            // 点击其他地方关闭自动完成
            document.addEventListener('click', (e) => {
                if (!e.target.closest('#discussion-subject') && !e.target.closest('#subject-suggestions')) {
                    document.getElementById('subject-suggestions').classList.add('hidden');
                }
            });
            
            // 代码定位
            document.querySelectorAll('.code-location-btn').forEach(btn => {
                btn.addEventListener('click', () => {
                    const location = btn.dataset.codeLocation || '未指定';
                    showCodeLocation(location);
                });
            });
            
            // 架构编辑
            document.getElementById('edit-architecture-btn')?.addEventListener('click', () => {
                showArchitectureConfig();
            });
            
            // 符号学架构配置模态框
            document.getElementById('close-architecture-modal')?.addEventListener('click', () => {
                document.getElementById('architecture-config-modal').classList.add('hidden');
            });
            
            document.getElementById('close-architecture-config-btn')?.addEventListener('click', () => {
                document.getElementById('architecture-config-modal').classList.add('hidden');
            });
            
            document.getElementById('save-architecture-btn')?.addEventListener('click', () => {
                saveArchitectureConfig();
            });
            
            document.getElementById('reset-architecture-btn')?.addEventListener('click', () => {
                if (confirm('确定要重置为默认配置吗?这将清除所有自定义设置。')) {
                    localStorage.removeItem('semiotic-architecture-config');
                    initializeSemioticArchitecture();
                    renderPrompts();
                    showToast('架构配置已重置为默认值', 'info');
                    document.getElementById('architecture-config-modal').classList.add('hidden');
                }
            });

            // 关闭代码定位模态框
            document.getElementById('close-code-modal-btn').addEventListener('click', () => {
                document.getElementById('code-location-modal').classList.add('hidden');
            });

            document.getElementById('close-code-btn').addEventListener('click', () => {
                document.getElementById('code-location-modal').classList.add('hidden');
            });
            
            // 复制代码
            document.getElementById('copy-code-btn').addEventListener('click', () => {
                const code = document.getElementById('code-snippet-container').textContent;
                navigator.clipboard.writeText(code).then(() => {
                    showToast('代码已复制到剪贴板', 'success');
                });
            });
            
            // 主题切换
            document.getElementById('theme-toggle').addEventListener('click', toggleTheme);
            
            // 自动保存讨论
            const titleInput = document.getElementById('discussion-title');
            const categorySelect = document.getElementById('discussion-category');
            const subjectInput = document.getElementById('discussion-subject');
            const topicInput = document.getElementById('discussion-topic');
            
            [titleInput, categorySelect, subjectInput, topicInput].forEach(input => {
                if (input) {
                    input.addEventListener('change', debounce(() => {
                        const id = document.getElementById('editor-view').dataset.id;
                        if (id) {
                            const discussion = getDiscussions().find(d => d.id === id);
                            if (discussion) {
                                discussion.title = titleInput.value;
                                discussion.category = categorySelect.value;
                                discussion.subject = subjectInput.value;
                                discussion.topic = topicInput.value;
                                discussion.updatedAt = new Date().toISOString();
                                saveDiscussion(discussion);
                                
                                // 更新价值维度统计
                                valueStats.safe++;
                                saveData(STORAGE_KEYS.STATS, valueStats);
                                updateStats();
                            }
                        }
                    }, 1000));
                }
            });
        }

        // ==================== 数据备份与恢复 ====================
        // 加载备份数据
        function loadBackupData() {
            const data = {
                discussions: getDiscussions(),
                categories: getCategories(),
                subjects: getSubjects(),
                prompts: getPrompts(),
                stats: valueStats
            };
            
            const backupData = document.getElementById('backup-data');
            backupData.innerHTML = `<pre><code>${JSON.stringify(data, null, 2)}</code></pre>`;
        }

        // 导出数据
        function exportData() {
            const data = {
                discussions: getDiscussions(),
                categories: getCategories(),
                subjects: getSubjects(),
                prompts: getPrompts(),
                stats: valueStats,
                groupHierarchy: getData(STORAGE_KEYS.GROUP_HIERARCHY),
                directDimension: getData(STORAGE_KEYS.DIRECT_DIMENSION),
                indexTable: getData(STORAGE_KEYS.INDEX_TABLE),
                exportDate: new Date().toISOString()
            };
            
            const dataStr = JSON.stringify(data, null, 2);
            const dataBlob = new Blob([dataStr], { type: 'application/json' });
            const url = URL.createObjectURL(dataBlob);
            
            const link = document.createElement('a');
            link.href = url;
            link.download = `discussMemo_backup_${new Date().toISOString().split('T')[0]}.json`;
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
            URL.revokeObjectURL(url);
            
            showToast('数据已导出', 'success');
        }

        // 导入数据
        function importData(event) {
            const file = event.target.files[0];
            if (!file) return;
            
            const reader = new FileReader();
            reader.onload = (e) => {
                try {
                    const data = JSON.parse(e.target.result);
                    
                    if (confirm('确定要导入数据吗?这将覆盖当前数据!')) {
                        // 导入数据
                        if (data.discussions) saveData(STORAGE_KEYS.DISCUSSIONS, data.discussions);
                        if (data.categories) saveData(STORAGE_KEYS.CATEGORIES, data.categories);
                        if (data.subjects) saveData(STORAGE_KEYS.SUBJECTS, data.subjects);
                        if (data.prompts) saveData(STORAGE_KEYS.PROMPTS, data.prompts);
                        if (data.stats) valueStats = data.stats;
                        if (data.groupHierarchy) saveData(STORAGE_KEYS.GROUP_HIERARCHY, data.groupHierarchy);
                        if (data.directDimension) saveData(STORAGE_KEYS.DIRECT_DIMENSION, data.directDimension);
                        if (data.indexTable) saveData(STORAGE_KEYS.INDEX_TABLE, data.indexTable);
                        
                        // 更新统计
                        saveData(STORAGE_KEYS.STATS, valueStats);
                        
                        // 重新渲染
                        renderDashboard();
                        renderDiscussions();
                        renderCategories();
                        loadBackupData();
                        
                        showToast('数据已导入', 'success');
                    }
                } catch (error) {
                    console.error('导入数据失败:', error);
                    showToast('导入数据失败,请检查文件格式', 'error');
                }
            };
            reader.readAsText(file);
        }

        // 重置数据
        function resetData() {
            localStorage.removeItem(STORAGE_KEYS.DISCUSSIONS);
            localStorage.removeItem(STORAGE_KEYS.CATEGORIES);
            localStorage.removeItem(STORAGE_KEYS.SUBJECTS);
            localStorage.removeItem(STORAGE_KEYS.PROMPTS);
            localStorage.removeItem(STORAGE_KEYS.STATS);
            localStorage.removeItem(STORAGE_KEYS.GROUP_HIERARCHY);
            localStorage.removeItem(STORAGE_KEYS.DIRECT_DIMENSION);
            localStorage.removeItem(STORAGE_KEYS.INDEX_TABLE);
            
            // 重新初始化
            initializeDataTables();
            valueStats = { learn: 0, save: 0, safe: 0 };
            saveData(STORAGE_KEYS.STATS, valueStats);
        }

        // ==================== 配置管理 ====================
        // 渲染配置视图
        function renderConfigView() {
            renderCustomCategories();
            renderCustomSubjects();
            renderCustomPrompts();
        }

        // 渲染自定义范畴
        function renderCustomCategories() {
            const categories = getCategories();
            const container = document.getElementById('custom-categories-list');
            container.innerHTML = '';
            
            categories.forEach(category => {
                const item = document.createElement('div');
                item.className = 'p-4 border border-gray-200 rounded-lg';
                item.innerHTML = `
                    <div class="flex items-center justify-between">
                        <div class="flex items-center">
                            <div class="w-4 h-4 rounded-full mr-2" style="background-color: ${category.color}"></div>
                            <h4 class="font-medium text-gray-800">${category.name}</h4>
                            <span class="ml-2 adapt-tag adapt-${category.dimension}">${category.dimension === 'universal' ? '万向' : category.dimension === 'industry' ? '千行' : '百业'}</span>
                        </div>
                        <div class="flex space-x-2">
                            <button class="text-gray-400 hover:text-gray-600 edit-category" data-id="${category.id}">
                                <i class="fa fa-pencil"></i>
                            </button>
                            <button class="text-gray-400 hover:text-gray-600 delete-category" data-id="${category.id}">
                                <i class="fa fa-trash-o"></i>
                            </button>
                        </div>
                    </div>
                    ${category.description ? `
                        <div class="mt-2 text-sm text-gray-600">
                            <p>${category.description}</p>
                        </div>
                    ` : ''}
                `;
                
                container.appendChild(item);
            });
            
            // 添加删除事件
            document.querySelectorAll('.delete-category').forEach(btn => {
                btn.addEventListener('click', () => {
                    const id = btn.dataset.id;
                    if (confirm('确定要删除这个范畴吗?')) {
                        deleteCategory(id);
                        renderCustomCategories();
                        renderCategories();
                        renderDiscussions();
                        showToast('范畴已删除', 'success');
                    }
                });
            });
        }

        // 渲染自定义分类关键词
        function renderCustomSubjects() {
            const subjects = getSubjects();
            const container = document.getElementById('custom-subjects-list');
            container.innerHTML = '';
            
            subjects.forEach((subject, index) => {
                const item = document.createElement('div');
                item.className = 'p-3 border border-gray-200 rounded-lg flex items-center justify-between';
                item.innerHTML = `
                    <span class="text-gray-800">${subject}</span>
                    <button class="text-gray-400 hover:text-gray-600 delete-subject" data-index="${index}">
                        <i class="fa fa-trash-o"></i>
                    </button>
                `;
                
                container.appendChild(item);
            });
            
            // 添加删除事件
            document.querySelectorAll('.delete-subject').forEach(btn => {
                btn.addEventListener('click', () => {
                    const index = parseInt(btn.dataset.index);
                    const subjects = getSubjects();
                    subjects.splice(index, 1);
                    saveSubjects(subjects);
                    renderCustomSubjects();
                    showToast('关键词已删除', 'success');
                });
            });
        }

        // 渲染自定义提示词模板
        function renderCustomPrompts() {
            const prompts = getPrompts();
            const container = document.getElementById('custom-prompts-list');
            container.innerHTML = '';
            
            prompts.forEach(prompt => {
                const item = document.createElement('div');
                item.className = 'p-4 border border-gray-200 rounded-lg';
                item.innerHTML = `
                    <div class="flex items-center justify-between">
                        <h4 class="font-medium text-gray-800">${prompt.title}</h4>
                        <div class="flex space-x-2">
                            <button class="text-gray-400 hover:text-gray-600 edit-prompt-config" data-id="${prompt.id}">
                                <i class="fa fa-pencil"></i>
                            </button>
                            <button class="text-gray-400 hover:text-gray-600 delete-prompt-config" data-id="${prompt.id}">
                                <i class="fa fa-trash-o"></i>
                            </button>
                        </div>
                    </div>
                    <div class="mt-2 text-sm text-gray-600">
                        <p>${prompt.content.replace(/\n/g, ' ').replace(/##/g, '').trim().substring(0, 100)}${prompt.content.length > 100 ? '...' : ''}</p>
                    </div>
                    ${prompt.tags ? `
                        <div class="mt-2">
                            ${prompt.tags.map(tag => `<span class="inline-block bg-gray-100 rounded-full px-2 py-0.5 text-xs mr-1">${tag}</span>`).join('')}
                        </div>
                    ` : ''}
                `;
                
                container.appendChild(item);
            });
            
            // 添加删除事件
            document.querySelectorAll('.delete-prompt-config').forEach(btn => {
                btn.addEventListener('click', () => {
                    const id = btn.dataset.id;
                    if (confirm('确定要删除这个提示词模板吗?')) {
                        deletePrompt(id);
                        renderCustomPrompts();
                        renderPrompts();
                        showToast('提示词模板已删除', 'success');
                    }
                });
            });
        }

        // 应用Requirements需求配置
        function applyRequirementsConfig() {
            const requirements = {
                documentSystem: {
                    structure: document.querySelector('input[name="doc-structure"]:checked')?.value || 'hybrid',
                    templates: Array.from(document.querySelectorAll('.doc-template:checked')).map(cb => cb.value),
                    collaboration: document.querySelector('input[name="doc-collaboration"]:checked')?.value || 'team'
                },
                objectSystem: {
                    entity: document.querySelector('input[name="obj-entity"]:checked')?.value || 'dynamic',
                    relationship: document.querySelector('input[name="obj-relationship"]:checked')?.value || 'many-to-many',
                    validation: document.querySelector('input[name="obj-validation"]:checked')?.value || 'business'
                },
                tableSystem: {
                    format: document.querySelector('input[name="tbl-format"]:checked')?.value || 'dynamic',
                    processing: document.querySelector('input[name="tbl-processing"]:checked')?.value || 'predictive',
                    integration: document.querySelector('input[name="tbl-integration"]:checked')?.value || 'hybrid'
                }
            };

            // 根据Requirements配置自动映射到Demands方法论
            const mappedDemands = mapRequirementsToDemands(requirements);
            
            // 保存配置到localStorage
            localStorage.setItem('requirementsConfig', JSON.stringify(requirements));
            localStorage.setItem('mappedDemandsConfig', JSON.stringify(mappedDemands));
            
            // 显示成功消息
            showToast('Requirements需求配置已应用,系统将自动映射到对应的方法论', 'success');
            
            // 更新界面显示
            updateRequirementsDisplay(requirements);
        }

        // 应用Demands方法配置
        function applyDemandsConfig() {
            const demands = {
                instructionArchitecture: {
                    topLevel: Array.from(document.querySelectorAll('.instruction-top:checked')).map(cb => cb.value),
                    middleLevel: Array.from(document.querySelectorAll('.instruction-middle:checked')).map(cb => cb.value),
                    bottomLevel: Array.from(document.querySelectorAll('.instruction-bottom:checked')).map(cb => cb.value)
                },
                dataSystemMethodology: {
                    basicTable1: true, // 基础表1默认启用
                    basicTable2: true, // 基础表2默认启用
                    jointTable: true   // 结合表默认启用
                },
                companionsMethodology: {
                    memorandum: Array.from(document.querySelectorAll('.companion-memo:checked')).map(cb => cb.value),
                    notebook: Array.from(document.querySelectorAll('.companion-notebook:checked')).map(cb => cb.value),
                    logTable: Array.from(document.querySelectorAll('.companion-log:checked')).map(cb => cb.value)
                }
            };

            // 保存配置到localStorage
            localStorage.setItem('demandsConfig', JSON.stringify(demands));
            
            // 显示成功消息
            showToast('Demands方法配置已应用,系统将使用指定方法论进行实现', 'success');
            
            // 更新界面显示
            updateDemandsDisplay(demands);
        }

        // Requirements到Demands的映射函数
        function mapRequirementsToDemands(requirements) {
            const mapping = CORE_CONCEPTS.REQUIREMENTS_DEMANDS_CONFIG.CONFIG_MAPPING_RULES;
            
            const mappedDemands = {
                instructionArchitecture: {
                    topLevel: [],
                    middleLevel: [],
                    bottomLevel: []
                },
                dataSystemMethodology: {
                    basicTable1: true,
                    basicTable2: true,
                    jointTable: true
                },
                companionsMethodology: {
                    memorandum: ['quick-record', 'hypothesis', 'insight'],
                    notebook: ['discussion-analysis', 'knowledge-processing', 'process-tracking'],
                    logTable: ['decision-log', 'progress-log', 'status-marker', 'consensus-track']
                }
            };

            // 文档系统需求映射
            const docStructure = requirements.documentSystem.structure;
            if (mapping.documentSystemMapping[docStructure]) {
                const instruction = mapping.documentSystemMapping[docStructure];
                // 根据映射结果设置对应的三层指令
                if (instruction.includes('底层')) {
                    mappedDemands.instructionArchitecture.bottomLevel = ['collection', 'filter', 'verification', 'convergence'];
                }
                if (instruction.includes('中层')) {
                    mappedDemands.instructionArchitecture.middleLevel = ['feature', 'pattern', 'induction', 'summary'];
                }
                if (instruction.includes('顶层')) {
                    mappedDemands.instructionArchitecture.topLevel = ['syntax', 'semantic', 'logic', 'assembly'];
                }
            }

            // 表格系统需求映射
            const tblProcessing = requirements.tableSystem.processing;
            if (mapping.tableSystemMapping[tblProcessing]) {
                const instruction = mapping.tableSystemMapping[tblProcessing];
                // 根据处理选项设置对应的分析方法
                if (instruction.includes('智能')) {
                    mappedDemands.instructionArchitecture.topLevel.push('ai-processing');
                }
            }

            return mappedDemands;
        }

        // 更新Requirements显示
        function updateRequirementsDisplay(requirements) {
            // 更新配置显示状态
            const reqStatus = document.createElement('div');
            reqStatus.className = 'mt-4 p-3 bg-blue-50 border border-blue-200 rounded-lg';
            reqStatus.innerHTML = `
                <div class="flex items-center">
                    <i class="fa fa-check-circle text-blue-600 mr-2"></i>
                    <span class="text-sm font-medium text-blue-800">当前Requirements配置:</span>
                </div>
                <div class="mt-2 text-xs text-blue-700">
                    文档:${requirements.documentSystem.structure} | 
                    对象:${requirements.objectSystem.entity} | 
                    表格:${requirements.tableSystem.format}
                </div>
            `;
            
            // 移除之前的状态显示
            const oldStatus = document.querySelector('#requirements-tab .bg-blue-50');
            if (oldStatus && oldStatus.textContent.includes('当前Requirements配置')) {
                oldStatus.remove();
            }
            
            // 添加新的状态显示
            document.getElementById('requirements-tab').appendChild(reqStatus);
        }

        // 更新Demands显示
        function updateDemandsDisplay(demands) {
            // 更新配置显示状态
            const demStatus = document.createElement('div');
            demStatus.className = 'mt-4 p-3 bg-green-50 border border-green-200 rounded-lg';
            demStatus.innerHTML = `
                <div class="flex items-center">
                    <i class="fa fa-check-circle text-green-600 mr-2"></i>
                    <span class="text-sm font-medium text-green-800">当前Demands配置:</span>
                </div>
                <div class="mt-2 text-xs text-green-700">
                    指令架构:${demands.instructionArchitecture.topLevel.length + demands.instructionArchitecture.middleLevel.length + demands.instructionArchitecture.bottomLevel.length}项 | 
                    数据体系:已启用 | 
                    同行人:备忘录${demands.companionsMethodology.memorandum.length}项
                </div>
            `;
            
            // 移除之前的状态显示
            const oldStatus = document.querySelector('#demands-tab .bg-green-50');
            if (oldStatus && oldStatus.textContent.includes('当前Demands配置')) {
                oldStatus.remove();
            }
            
            // 添加新的状态显示
            document.getElementById('demands-tab').appendChild(demStatus);
        }

        // 加载已保存的配置
        function loadRequirementsDemandsConfig() {
            const savedRequirements = localStorage.getItem('requirementsConfig');
            const savedDemands = localStorage.getItem('demandsConfig');
            
            if (savedRequirements) {
                const requirements = JSON.parse(savedRequirements);
                // 恢复UI状态
                if (requirements.documentSystem) {
                    const docStructure = document.querySelector(`input[name="doc-structure"][value="${requirements.documentSystem.structure}"]`);
                    if (docStructure) docStructure.checked = true;
                    
                    requirements.documentSystem.templates.forEach(template => {
                        const checkbox = document.querySelector(`.doc-template[value="${template}"]`);
                        if (checkbox) checkbox.checked = true;
                    });
                    
                    const docCollab = document.querySelector(`input[name="doc-collaboration"][value="${requirements.documentSystem.collaboration}"]`);
                    if (docCollab) docCollab.checked = true;
                }
                
                updateRequirementsDisplay(requirements);
            }
            
            if (savedDemands) {
                const demands = JSON.parse(savedDemands);
                // 恢复UI状态
                if (demands.instructionArchitecture) {
                    demands.instructionArchitecture.topLevel.forEach(feature => {
                        const checkbox = document.querySelector(`.instruction-top[value="${feature}"]`);
                        if (checkbox) checkbox.checked = true;
                    });
                    
                    demands.instructionArchitecture.middleLevel.forEach(feature => {
                        const checkbox = document.querySelector(`.instruction-middle[value="${feature}"]`);
                        if (checkbox) checkbox.checked = true;
                    });
                    
                    demands.instructionArchitecture.bottomLevel.forEach(feature => {
                        const checkbox = document.querySelector(`.instruction-bottom[value="${feature}"]`);
                        if (checkbox) checkbox.checked = true;
                    });
                }
                
                updateDemandsDisplay(demands);
            }
        }

        // 保存新范畴
        function saveNewCategory() {
            const name = document.getElementById('category-name-input').value.trim();
            const description = document.getElementById('category-desc-input').value.trim();
            const dimension = document.querySelector('input[name="adapt-dimension"]:checked').value;
            const colorBtn = document.querySelector('.category-color-btn.border-primary');
            const color = colorBtn ? colorBtn.dataset.color : '#3b82f6';
            
            if (!name) {
                showToast('请输入范畴名称', 'error');
                return;
            }
            
            const category = {
                id: generateId(),
                name,
                description,
                dimension,
                color
            };
            
            saveCategory(category);
            renderCustomCategories();
            renderCategories();
            document.getElementById('add-category-modal').classList.add('hidden');
            showToast('范畴已添加', 'success');
            
            // 清空表单
            document.getElementById('category-name-input').value = '';
            document.getElementById('category-desc-input').value = '';
            document.querySelector('input[name="adapt-dimension"][value="universal"]').checked = true;
            document.querySelectorAll('.category-color-btn').forEach(btn => {
                btn.classList.remove('border-primary');
            });
            document.querySelector('.category-color-btn[data-color="#3b82f6"]').classList.add('border-primary');
        }

        // 添加内容块
        function addContentBlock(type) {
            const id = document.getElementById('editor-view').dataset.id;
            const discussion = getDiscussions().find(d => d.id === id);
            if (!discussion) return;
            
            let block = {
                id: generateId(),
                type,
                order: discussion.contentBlocks.length
            };
            
            switch (type) {
                case 'text':
                    block.content = '';
                    break;
                case 'timeline':
                    block.items = [];
                    break;
                case 'decision':
                    block.content = '';
                    block.status = 'pending';
                    break;
                case 'todo':
                    block.items = [];
                    break;
            }
            
            discussion.contentBlocks.push(block);
            discussion.updatedAt = new Date().toISOString();
            saveDiscussion(discussion);
            
            // 重新渲染
            renderContentBlocks(discussion.contentBlocks);
            
            // 更新价值维度统计
            valueStats.save++;
            saveData(STORAGE_KEYS.STATS, valueStats);
            updateStats();
        }

        // 显示代码位置
        function showCodeLocation(location) {
            const modal = document.getElementById('code-location-modal');
            const title = document.getElementById('code-location-title');
            const snippet = document.getElementById('code-snippet-container');
            
            title.textContent = `功能模块:${location}`;
            
            // 根据位置生成示例代码
            let codeSnippet = '';
            switch (location) {
                case '仪表盘渲染 - JS第1850行':
                    codeSnippet = `// 渲染仪表盘
function renderDashboard() {
    // 更新统计数据
    updateStats();
    
    // 渲染分类分布图表
    renderCategoryChart();
    
    // 渲染最近讨论
    renderRecentDiscussions();
    
    // 渲染提示词导航
    renderPrompts();
}`;
                    break;
                case '搜索功能 - JS第1500行':
                    codeSnippet = `// 搜索功能
document.getElementById('search-input').addEventListener('input', debounce(() => {
    const searchTerm = document.getElementById('search-input').value.toLowerCase();
    const discussions = getDiscussions();
    const filteredDiscussions = discussions.filter(d => 
        d.title.toLowerCase().includes(searchTerm) ||
        d.subject.toLowerCase().includes(searchTerm) ||
        d.topic.toLowerCase().includes(searchTerm) ||
        (d.tags && d.tags.some(tag => tag.toLowerCase().includes(searchTerm)))
    );
    
    // 渲染过滤后的讨论列表
    renderFilteredDiscussions(filteredDiscussions);
}, 300));`;
                    break;
                case '内容块功能 - JS第1300行':
                    codeSnippet = `// 添加内容块
function addContentBlock(type) {
    const id = document.getElementById('editor-view').dataset.id;
    const discussion = getDiscussions().find(d => d.id === id);
    if (!discussion) return;
    
    let block = {
        id: generateId(),
        type,
        order: discussion.contentBlocks.length
    };
    
    switch (type) {
        case 'text':
            block.content = '';
            break;
        case 'timeline':
            block.items = [];
            break;
        case 'decision':
            block.content = '';
            block.status = 'pending';
            break;
        case 'todo':
            block.items = [];
            break;
    }
    
    discussion.contentBlocks.push(block);
    discussion.updatedAt = new Date().toISOString();
    saveDiscussion(discussion);
    
    // 重新渲染
    renderContentBlocks(discussion.contentBlocks);
}`;
                    break;
                default:
                    codeSnippet = `// ${location}
// 这里是相关功能的实现代码
// 由于代码量较大,仅展示关键部分
// 完整代码请查看对应文件`;
            }
            
            snippet.innerHTML = `<pre><code>${codeSnippet}</code></pre>`;
            modal.classList.remove('hidden');
        }

        // 切换主题
        function toggleTheme() {
            const body = document.body;
            const icon = document.getElementById('theme-toggle').querySelector('i');
            
            if (body.classList.contains('dark')) {
                body.classList.remove('dark');
                icon.classList.remove('fa-sun-o');
                icon.classList.add('fa-moon-o');
                localStorage.setItem(STORAGE_KEYS.THEME, 'light');
            } else {
                body.classList.add('dark');
                icon.classList.remove('fa-moon-o');
                icon.classList.add('fa-sun-o');
                localStorage.setItem(STORAGE_KEYS.THEME, 'dark');
            }
        }

        // ==================== 初始化 ====================
        // 初始化应用
        function initializeApp() {
            // 初始化基础表和结合表
            if (!getData(STORAGE_KEYS.GROUP_HIERARCHY)) {
                initializeDataTables();
            }
            
            // 加载统计数据
            const stats = getData(STORAGE_KEYS.STATS);
            if (stats) {
                valueStats = stats;
            }
            
            // 加载主题
            const theme = localStorage.getItem(STORAGE_KEYS.THEME);
            if (theme === 'dark') {
                document.body.classList.add('dark');
                document.getElementById('theme-toggle').querySelector('i').classList.remove('fa-moon-o');
                document.getElementById('theme-toggle').querySelector('i').classList.add('fa-sun-o');
            }
            
            // 渲染分类
            renderCategories();
            
            // 渲染讨论列表
            renderDiscussions();
            
            // 渲染仪表盘
            renderDashboard();
            
            // 初始化表述处理功能
            initializeExpressionProcessor();
            
            // 初始化事件监听
            initializeEventListeners();
            
            // 显示欢迎视图
            document.getElementById('welcome-view').classList.remove('hidden');
        }

        // ==================== 表述处理模块 ====================
        
        // 表述处理数据存储键
        const EXPRESSION_KEYS = {
            RAW_EXPRESSIONS: 'discussMemo_rawExpressions',
            ANALYSIS_RESULTS: 'discussMemo_analysisResults',
            EXPRESSION_HISTORY: 'discussMemo_expressionHistory'
        };

        // 初始化表述处理器
        function initializeExpressionProcessor() {
            console.log('初始化表述处理系统...');
            
            // 加载历史记录
            loadExpressionHistory();
            
            // 绑定事件监听器
            bindExpressionEventListeners();
        }

        // 绑定表述处理相关事件
        function bindExpressionEventListeners() {
            // 运行分析按钮
            document.getElementById('run-expression-analysis')?.addEventListener('click', runExpressionAnalysis);
            
            // 加载示例按钮
            document.getElementById('load-example-btn')?.addEventListener('click', loadExampleExpression);
            
            // 保存表述按钮
            document.getElementById('save-expression-btn')?.addEventListener('click', saveRawExpression);
            
            // 原始表述输入监听
            document.getElementById('raw-expression-input')?.addEventListener('input', updateColumnPreview);
        }

        // 加载示例表述
        function loadExampleExpression() {
            const exampleExpression = `内嵌式赋能/外挂式省力/中蕴式省心 学习/节约/安全 万向/千行/百业 通/性/量 通/别/藏 境/行/果 顿/渐/密`;
            document.getElementById('raw-expression-input').value = exampleExpression;
            updateColumnPreview();
            showToast('已加载示例表述', 'success');
        }

        // 更新7列结构预览
        function updateColumnPreview() {
            const input = document.getElementById('raw-expression-input').value.trim();
            const preview = document.getElementById('column-preview');
            
            if (!input) {
                preview.innerHTML = `
                    <div class="text-center text-gray-500 py-8">
                        <i class="fa fa-eye text-2xl mb-2"></i>
                        <p>输入原始表述后将显示结构预览</p>
                    </div>`;
                return;
            }

            const lines = input.split('\n');
            if (lines.length !== 3) {
                preview.innerHTML = `
                    <div class="text-center text-red-500 py-8">
                        <i class="fa fa-exclamation-triangle text-2xl mb-2"></i>
                        <p>需要输入3行数据,当前${lines.length}行</p>
                    </div>`;
                return;
            }

            // 解析7列数据
            const columns = extractColumns(lines);
            let html = '<div class="space-y-2">';
            
            for (let i = 0; i < 7; i++) {
                const columnName = getColumnName(i);
                const columnData = columns[i];
                html += `
                    <div class="flex items-center space-x-2 p-2 bg-white rounded border">
                        <div class="w-16 text-xs font-medium text-gray-600">${columnName}</div>
                        <div class="flex-1 text-sm font-mono">${columnData || '-'}</div>
                    </div>`;
            }
            
            html += '</div>';
            preview.innerHTML = html;
        }

        // 提取7列数据
        function extractColumns(lines) {
            const columns = [];
            
            // 第1行:3列词组
            const line1Items = lines[0].split(' ');
            columns[0] = line1Items[0] || '';
            columns[1] = line1Items[1] || '';
            columns[2] = line1Items[2] || '';
            
            // 第2行:4列词组
            const line2Items = lines[1].split(' ');
            columns[3] = line2Items[0] || '';
            columns[4] = line2Items[1] || '';
            columns[5] = line2Items[2] || '';
            columns[6] = line2Items[3] || '';
            
            return columns;
        }

        // 获取列名称
        function getColumnName(index) {
            const names = ['第1列', '第2列', '第3列', '第4列', '第5列', '第6列', '第7列'];
            return names[index];
        }

        // 运行表述分析
        async function runExpressionAnalysis() {
            const input = document.getElementById('raw-expression-input').value.trim();
            
            if (!input) {
                showToast('请输入原始表述', 'warning');
                return;
            }

            showToast('正在分析表述...', 'info');
            
            try {
                // 调用Python分析程序(这里先模拟结果)
                const analysisResult = await simulateExpressionAnalysis(input);
                
                // 显示分析结果
                displayAnalysisResults(analysisResult);
                
                // 保存分析结果
                saveAnalysisResult(analysisResult);
                
                showToast('分析完成!', 'success');
                
            } catch (error) {
                console.error('分析失败:', error);
                showToast('分析失败,请检查输入格式', 'error');
            }
        }

        // 模拟表述分析(后续可替换为真实Python调用)
        async function simulateExpressionAnalysis(input) {
            // 模拟处理时间
            await new Promise(resolve => setTimeout(resolve, 1000));
            
            const lines = input.split('\n');
            const columns = extractColumns(lines);
            
            return {
                input: input,
                columns: columns,
                timestamp: new Date().toISOString(),
                results: {
                    ternary: {
                        name: '三元组(立名)',
                        columns: [
                            { index: 0, content: columns[0], operation: '外立"服务"之名' },
                            { index: 1, content: columns[1], operation: '内立"管理"之名' },
                            { index: 2, content: columns[2], operation: '中立"组织"之名' }
                        ]
                    },
                    trichotomy: {
                        name: '三分法(立法)',
                        columns: [
                            { index: 3, content: columns[3], operation: '加成"器"' },
                            { index: 6, content: columns[6], operation: '减成"唯识论"' }
                        ]
                    },
                    trinity: {
                        name: '三位一体(立向)',
                        columns: [
                            { index: 4, content: columns[4], operation: '反破"圆"' },
                            { index: 5, content: columns[5], operation: '正破"不定"' }
                        ]
                    }
                },
                validation: {
                    structureValid: lines.length === 3,
                    columnsComplete: columns.filter(c => c).length === 7,
                    exclusivityValid: true, // 模拟验证通过
                    completeness: '85%'
                }
            };
        }

        // 显示分析结果
        function displayAnalysisResults(result) {
            // 显示三元组结果
            const ternaryDiv = document.getElementById('ternary-results');
            ternaryDiv.innerHTML = result.results.ternary.columns.map(col => `
                <div class="p-2 bg-blue-50 rounded border-l-2 border-blue-400">
                    <div class="font-medium text-blue-800">第${col.index + 1}列</div>
                    <div class="text-sm text-gray-700">${col.content}</div>
                    <div class="text-xs text-blue-600 mt-1">${col.operation}</div>
                </div>
            `).join('');
            
            // 显示三分法结果
            const trichotomyDiv = document.getElementById('trichotomy-results');
            trichotomyDiv.innerHTML = result.results.trichotomy.columns.map(col => `
                <div class="p-2 bg-purple-50 rounded border-l-2 border-purple-400">
                    <div class="font-medium text-purple-800">第${col.index + 1}列</div>
                    <div class="text-sm text-gray-700">${col.content}</div>
                    <div class="text-xs text-purple-600 mt-1">${col.operation}</div>
                </div>
            `).join('');
            
            // 显示三位一体结果
            const trinityDiv = document.getElementById('trinity-results');
            trinityDiv.innerHTML = result.results.trinity.columns.map(col => `
                <div class="p-2 bg-green-50 rounded border-l-2 border-green-400">
                    <div class="font-medium text-green-800">第${col.index + 1}列</div>
                    <div class="text-sm text-gray-700">${col.content}</div>
                    <div class="text-xs text-green-600 mt-1">${col.operation}</div>
                </div>
            `).join('');
            
            // 显示验证报告
            const validationDiv = document.getElementById('validation-report');
            validationDiv.innerHTML = `
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div class="flex items-center space-x-2">
                        <i class="fa ${result.validation.structureValid ? 'fa-check-circle text-green-500' : 'fa-exclamation-circle text-red-500'}"></i>
                        <span>结构验证:${result.validation.structureValid ? '通过' : '失败'}</span>
                    </div>
                    <div class="flex items-center space-x-2">
                        <i class="fa ${result.validation.columnsComplete ? 'fa-check-circle text-green-500' : 'fa-exclamation-circle text-red-500'}"></i>
                        <span>列完整性:${result.validation.columnsComplete ? '通过' : '失败'}</span>
                    </div>
                    <div class="flex items-center space-x-2">
                        <i class="fa ${result.validation.exclusivityValid ? 'fa-check-circle text-green-500' : 'fa-exclamation-circle text-red-500'}"></i>
                        <span>排他性验证:${result.validation.exclusivityValid ? '通过' : '失败'}</span>
                    </div>
                    <div class="flex items-center space-x-2">
                        <i class="fa fa-info-circle text-blue-500"></i>
                        <span>完整度:${result.validation.completeness}</span>
                    </div>
                </div>
                <div class="mt-3 p-3 bg-gray-50 rounded">
                    <div class="text-sm font-medium text-gray-700 mb-1">分析时间</div>
                    <div class="text-xs text-gray-600">${new Date(result.timestamp).toLocaleString()}</div>
                </div>
            `;
        }

        // 保存原始表述
        function saveRawExpression() {
            const input = document.getElementById('raw-expression-input').value.trim();
            if (!input) {
                showToast('请输入原始表述', 'warning');
                return;
            }
            
            const expressions = JSON.parse(localStorage.getItem(EXPRESSION_KEYS.RAW_EXPRESSIONS) || '[]');
            expressions.push({
                id: generateId(),
                content: input,
                timestamp: new Date().toISOString()
            });
            
            localStorage.setItem(EXPRESSION_KEYS.RAW_EXPRESSIONS, JSON.stringify(expressions));
            showToast('表述已保存', 'success');
        }

        // 保存分析结果
        function saveAnalysisResult(result) {
            const results = JSON.parse(localStorage.getItem(EXPRESSION_KEYS.ANALYSIS_RESULTS) || '[]');
            results.unshift(result); // 添加到开头
            
            // 最多保存20个结果
            if (results.length > 20) {
                results.splice(20);
            }
            
            localStorage.setItem(EXPRESSION_KEYS.ANALYSIS_RESULTS, JSON.stringify(results));
            
            // 更新历史记录显示
            loadExpressionHistory();
        }

        // 加载历史记录
        function loadExpressionHistory() {
            const historyDiv = document.getElementById('expression-history');
            const results = JSON.parse(localStorage.getItem(EXPRESSION_KEYS.ANALYSIS_RESULTS) || '[]');
            
            if (results.length === 0) {
                historyDiv.innerHTML = `
                    <div class="text-center text-gray-500 py-4">
                        <i class="fa fa-inbox text-xl mb-2"></i>
                        <p class="text-sm">暂无历史记录</p>
                    </div>`;
                return;
            }
            
            historyDiv.innerHTML = results.slice(0, 5).map((result, index) => `
                <div class="flex items-center justify-between p-3 bg-gray-50 rounded hover:bg-gray-100 transition-colors cursor-pointer" 
                     onclick="loadHistoryResult(${index})">
                    <div class="flex-1">
                        <div class="text-sm font-medium text-gray-800">分析记录 #${index + 1}</div>
                        <div class="text-xs text-gray-600">${new Date(result.timestamp).toLocaleString()}</div>
                    </div>
                    <div class="text-xs bg-universal text-white px-2 py-1 rounded">
                        完整度: ${result.validation.completeness}
                    </div>
                </div>
            `).join('');
        }

        // 加载历史结果
        window.loadHistoryResult = function(index) {
            const results = JSON.parse(localStorage.getItem(EXPRESSION_KEYS.ANALYSIS_RESULTS) || '[]');
            const result = results[index];
            
            if (result) {
                document.getElementById('raw-expression-input').value = result.input;
                updateColumnPreview();
                displayAnalysisResults(result);
                
                // 切换到表述处理标签页
                showTab('expression');
                
                showToast('已加载历史分析结果', 'success');
            }
        };

        // ========== 整体设计核心架构 ==========
        // 三层嵌套设计概念词汇表
        const CORE_CONCEPTS = {
            // 三层嵌套结构 {[()]}
            ARCHITECTURE: {
                // 外层:软件包和软件架构
                PACKAGE: {
                    name: "软件包 (Software Package)",
                    description: "完整系统的容器化架构",
                    layers: ["内嵌式赋能", "外挂式省力", "中蕴式省心"]
                },
                // 中层:指令集架构  
                INSTRUCTION: {
                    name: "指令集架构 (Instruction Set Architecture)",
                    description: "系统操作的核心指令集",
                    commands: ["明言-析取", "暗示-合取", "隐喻-双取"]
                },
                // 内层:三套提示词系统
                PROMPTS: {
                    name: "提示词系统 (Prompt System)",
                    description: "符号学显式表达的三个维度",
                    dimensions: {
                        explicit: "明言 - 析取提示词",
                        implicit: "暗示 - 合取关键词", 
                        metaphorical: "隐喻 - 双取主题词"
                    }
                }
            },
            
            // PIN结符号学架构
            PIN_STRUCTURE: {
                // 理科:PIN结括号设备
                SCIENCE: {
                    name: "PIN结括号设备",
                    domain: "理科",
                    properties: ["力学性", "数学性"],
                    principle: "共存唯一,共生的自然双重决定论基础",
                    features: ["存在出双入对", "媒介性mediating"]
                },
                // 工科:PIN节工具箱
                ENGINEERING: {
                    name: "PIN节工具箱", 
                    domain: "工科",
                    properties: ["经验常识", "科学方法"],
                    principle: "互补同一,共长的因果逻辑决定论",
                    features: ["两种形式配对", "meaning和purpose相关性relative"]
                },
                // 文科:"拼"块仪表盘
                LIBERAL_ARTS: {
                    name: "拼块仪表盘",
                    domain: "文科", 
                    properties: ["两种独立性", "对立统一"],
                    principle: "共情的现实认识决定论",
                    features: ["三个概念对子", "structure/definition/dictionary独立性"]
                }
            },
            
            // 三套提示词详细定义
            PROMPT_SYSTEMS: {
                // 1. 明言 - 析取提示词
                EXPLICIT_PROMPT: {
                    name: "明言 - 析取提示词",
                    system: "显式表达的表述体系 - 现代符号学",
                    dimensions: {
                        grammar: {
                            name: "语法 (Grammar)",
                            target: "适应专有名词 proper names (post)",
                            types: ["纯粹文法", "构式文法"],
                            application: "功能hover提示(语义表述,应用因子命名法)"
                        },
                        pragmatics: {
                            name: "语用 (Pragmatics)", 
                            target: "适用普通单词",
                            types: ["纯粹逻辑", "形式逻辑"],
                            application: "能力cover提示(语用表格,系统框架因素分类学)"
                        },
                        semantics: {
                            name: "语义 (Semantics)",
                            target: "过程适配一般代词和术语体系", 
                            types: ["纯粹修辞", "认知语义"],
                            application: "性能gover提示(语法表示,格架软件架构元素)"
                        }
                    }
                },
                
                // 2. 暗示 - 合取关键词
                IMPLICIT_KEYWORD: {
                    name: "暗示 - 合取关键词",
                    system: "心流-因果-现实的三个维度",
                    dimensions: {
                        mind: {
                            name: "心动证明程序",
                            principle: "心流(中心先'动')-语言模型",
                            level: "概念认知层"
                        },
                        motion: {
                            name: "运动轨迹函数", 
                            principle: "溢出(顶部先'活')-因果数据",
                            level: "数据处理层"
                        },
                        action: {
                            name: "行动角色谓词",
                            principle: "涌现(根部先'生')-现实自然涌现", 
                            level: "现实操作层"
                        }
                    },
                    components: {
                        causal: {
                            name: "因果层",
                            type: "形容词 - 纯粹修辞 - 概念适配",
                            count: 2
                        },
                        dynamic: {
                            name: "动态组织社区", 
                            type: "名词 - 纯粹文法 - 存在适应",
                            count: 3
                        },
                        functional: {
                            name: "内在功能模块",
                            type: "动词 - 纯粹形式 - 逻辑合适",
                            count: 2
                        }
                    }
                },
                
                // 3. 隐喻 - 双取主取主题词
                METAPHORICAL_THEME: {
                    name: "隐喻 - 双取主取主题词", 
                    system: "顶级公理体系的依存关系",
                    dimensions: {
                        axiom: {
                            name: "顶级公理",
                            focus: "集合元素依存",
                            level: "抽象元层"
                        },
                        method: {
                            name: "根本方法",
                            focus: "作用机制",
                            level: "实现方法层"
                        },
                        assertion: {
                            name: "初始断言", 
                            focus: "范畴元件约束",
                            level: "具体应用层"
                        }
                    }
                }
            },
            
            // 三层价值表达
            VALUE_EXPRESSIONS: {
                embedded: {
                    name: "内嵌式赋能 - 学习",
                    scope: "万向 通 - 通 境 顿",
                    keywords: ["学习", "引导", "提示", "洞察", "启发"]
                },
                external: {
                    name: "外挂式省力 - 节约", 
                    scope: "千行 别 - 性 行 渐",
                    keywords: ["省力", "快捷", "自动", "总结", "效率"]
                },
                internal: {
                    name: "中蕴式省心 - 安全",
                    scope: "百业 藏 - 量 果 密", 
                    keywords: ["安全", "可靠", "保护", "存储", "备份"]
                }
            },
            
            // Requirements-Demands配置层(不变部分)
            REQUIREMENTS_DEMANDS_CONFIG: {
                // 外部使用者需求Requirements(固定选项)
                REQUIREMENTS: {
                    // 文档系统需求
                    documentSystem: {
                        name: "文档系统需求",
                        description: "用户对文档管理的固定期望选项",
                        options: {
                            structure: {
                                name: "结构化选项",
                                features: ["层次化组织", "自动编号", "交叉引用", "版本控制"],
                                selections: ["简单列表", "层级目录", "网络结构", "混合模式"]
                            },
                            template: {
                                name: "模板化选项",
                                features: ["预设模板", "自定义模板", "模板继承", "模板组合"],
                                selections: ["会议记录", "项目文档", "研究报告", "决策文档", "个人笔记"]
                            },
                            collaboration: {
                                name: "协作选项",
                                features: ["多人协作", "权限控制", "评论系统", "变更追踪"],
                                selections: ["个人使用", "小团队协作", "部门协作", "跨部门协作"]
                            }
                        }
                    },
                    // 对象系统需求
                    objectSystem: {
                        name: "对象系统需求",
                        description: "用户对数据对象的固定期望选项",
                        options: {
                            entity: {
                                name: "实体定义选项",
                                features: ["实体类型", "属性定义", "关系建模", "约束规则"],
                                selections: ["简单实体", "复合实体", "动态实体", "继承实体"]
                            },
                            relationship: {
                                name: "关系映射选项",
                                features: ["关系类型", "关联强度", "方向性", "传递规则"],
                                selections: ["一对一", "一对多", "多对多", "网络关系"]
                            },
                            validation: {
                                name: "验证选项",
                                features: ["数据校验", "业务规则", "完整性约束", "一致性检查"],
                                selections: ["基础验证", "业务验证", "跨系统验证", "实时验证"]
                            }
                        }
                    },
                    // 表格系统需求
                    tableSystem: {
                        name: "表格系统需求",
                        description: "用户对表格处理的固定期望选项",
                        options: {
                            format: {
                                name: "格式选项",
                                features: ["字段类型", "格式标准", "显示样式", "导出格式"],
                                selections: ["简单表格", "复杂表格", "动态表格", "混合格式"]
                            },
                            processing: {
                                name: "处理选项",
                                features: ["数据计算", "统计分析", "图表生成", "报表输出"],
                                selections: ["基础计算", "统计分析", "预测分析", "智能分析"]
                            },
                            integration: {
                                name: "集成选项",
                                features: ["数据导入", "实时同步", "API接口", "第三方集成"],
                                selections: ["本地处理", "云端同步", "混合模式", "完全集成"]
                            }
                        }
                    }
                },
                // 内部实现要求Demands(固定方法论)
                DEMANDS: {
                    // 拼语言三层指令架构
                    instructionArchitecture: {
                        name: "拼语言三层指令架构",
                        description: "实现用户需求的核心方法论框架",
                        layers: {
                            topLevel: {
                                name: "顶层Pin语言通用模型",
                                instruction: "assemble指令",
                                purpose: "结论把握和整体组装",
                                features: ["语法解析", "语义理解", "逻辑推理", "结果组装"]
                            },
                            middleLevel: {
                                name: "中层自定义专用模型配置",
                                instruction: "summarize指令", 
                                purpose: "结果谓词和总结归纳",
                                features: ["特征提取", "模式识别", "知识归纳", "结果总结"]
                            },
                            bottomLevel: {
                                name: "底层配置内容处理",
                                instruction: "converge指令",
                                purpose: "原因命题和汇聚处理",
                                features: ["数据收集", "信息过滤", "事实验证", "逻辑汇聚"]
                            }
                        }
                    },
                    // 2+1数据体系方法论
                    dataSystemMethodology: {
                        name: "2+1数据体系方法论",
                        description: "支撑所有数据处理的基础架构方法",
                        tables: {
                            basicTable1: {
                                name: "基础表1:分组层次表",
                                structure: {
                                    external: ["内嵌式赋能", "外挂式省力", "中蕴式省心"],
                                    internal: ["学习", "节约", "安全"], 
                                    neutral: ["万向", "千行", "百业"]
                                },
                                purpose: "系统的分组管理和层次结构"
                            },
                            basicTable2: {
                                name: "基础表2:直连维度表", 
                                structure: {
                                    embedded: ["学习", "万向", "通", "境", "顿"],
                                    external: ["节约", "千行", "别", "行", "渐"],
                                    internal: ["安全", "百业", "藏", "量", "果", "密"]
                                },
                                purpose: "功能维度的直接关联"
                            },
                            jointTable: {
                                name: "结合表:索引表",
                                structure: {
                                    content: ["内嵌式赋能", "学习", "万向", "通", "境", "顿"],
                                    logic: ["外挂式省力", "节约", "千行", "别", "行", "渐"], 
                                    dictionary: ["中蕴式省心", "安全", "百业", "藏", "量", "果", "密"]
                                },
                                purpose: "内容项、逻辑项、字典项的统一索引"
                            }
                        }
                    },
                    // 三个同行人协同方法论
                    companionsMethodology: {
                        name: "三个同行人协同方法论",
                        description: "动态记录过程的协同工作方法",
                        companions: {
                            memorandum: {
                                name: "备忘录系统",
                                purpose: "个人知识库,原料仪表盘",
                                workflow: ["快速记录", "思维导图", "假设验证", "个人洞察"],
                                dynamics: "随个人理解加深而更新"
                            },
                            notebook: {
                                name: "笔记本系统", 
                                purpose: "分析工具箱,加工日志集合",
                                workflow: ["讨论分析", "知识加工", "执行支持", "过程追踪"],
                                dynamics: "随讨论进展而丰富"
                            },
                            logTable: {
                                name: "日志表系统",
                                purpose: "共享知识库,成品标记包", 
                                workflow: ["决策日志", "进展记录", "状态标记", "共识追踪"],
                                dynamics: "随团队协作而完善"
                            }
                        },
                        collaborationRules: {
                            statusMapping: {
                                "✅ 已共识": "进入共享知识库",
                                "🔄 讨论中": "在笔记本系统活跃",
                                "⏳ 待讨论": "在备忘录系统等待",
                                "❓ 有疑问": "需要三个系统协同验证",
                                "⚠️ 有分歧": "在笔记本系统分析处理"
                            },
                            dataFlow: {
                                "个人理解": "→ 备忘录 → 笔记本分析 → 日志表记录",
                                "团队讨论": "→ 笔记本处理 → 备忘录补充 → 日志表更新", 
                                "达成共识": "→ 日志表标记 → 笔记本总结 → 备忘录归档"
                            }
                        }
                    }
                },
                // 配置引导规则(Requirements到Demands的映射)
                CONFIG_MAPPING_RULES: {
                    // 文档系统需求映射
                    documentSystemMapping: {
                        "结构化选项": {
                            "简单列表": "底层converge指令 + 基础表1分组",
                            "层级目录": "中层summarize指令 + 基础表2维度",
                            "网络结构": "顶层assemble指令 + 结合表索引",
                            "混合模式": "三层指令 + 2+1数据体系"
                        },
                        "模板化选项": {
                            "会议记录": "笔记本分析工具 + 日志表状态追踪",
                            "项目文档": "备忘录项目管理 + 笔记本执行支持", 
                            "研究报告": "三个同行人协同 + 拼语言三层架构",
                            "决策文档": "共识状态映射 + 团队协作方法论",
                            "个人笔记": "备忘录个人洞察 + 快速记录工作流"
                        }
                    },
                    // 对象系统需求映射
                    objectSystemMapping: {
                        "实体定义选项": {
                            "简单实体": "基础表1实体管理 + 底层数据汇聚",
                            "复合实体": "基础表2关联维度 + 中层特征提取",
                            "动态实体": "结合表索引管理 + 顶层逻辑推理",
                            "继承实体": "2+1数据体系 + 三层指令协同"
                        }
                    },
                    // 表格系统需求映射
                    tableSystemMapping: {
                        "处理选项": {
                            "基础计算": "底层converge数据处理 + 基础表统计",
                            "统计分析": "中层summarize归纳 + 基础表2分析",
                            "预测分析": "顶层assemble推理 + 结合表智能",
                            "智能分析": "拼语言三层架构 + AI辅助处理"
                        }
                    }
                },
                // 配置验证规则
                VALIDATION_RULES: {
                    consistency: "确保选择的requirements选项映射到正确的demands方法论",
                    completeness: "验证所有必要的方法论组件都已配置",
                    compatibility: "检查不同需求选项的方法论兼容性",
                    scalability: "确保配置支持系统扩展和演化"
                }
            },

            // 三层次动态记录体系(修正后)
            DYNAMIC_RECORDING_SYSTEM: {
                // 第一层次:文档模型层
                DOCUMENT_MODEL: {
                    name: "文档模型层",
                    description: "结构化文档的元数据定义和模板系统",
                    dimensions: {
                        structural: {
                            name: "结构维度",
                            elements: ["标题", "目录", "章节", "段落", "注释"],
                            features: ["层次化组织", "自动编号", "交叉引用", "版本控制"]
                        },
                        semantic: {
                            name: "语义维度", 
                            elements: ["关键词", "标签", "分类", "主题", "实体"],
                            features: ["语义标注", "关系映射", "概念网络", "知识图谱"]
                        },
                        temporal: {
                            name: "时序维度",
                            elements: ["创建时间", "修改时间", "版本历史", "时间轴", "里程碑"],
                            features: ["时间追踪", "变更记录", "历史对比", "时间线可视化"]
                        }
                    },
                    templates: {
                        meeting: "会议记录模板",
                        project: "项目文档模板", 
                        research: "研究报告模板",
                        decision: "决策文档模板",
                        knowledge: "知识整理模板"
                    }
                },
                
                // 第二层次:知识管理层
                KNOWLEDGE_MANAGEMENT: {
                    name: "知识管理层", 
                    description: "知识的组织、检索、关联和演化系统",
                    dimensions: {
                        organization: {
                            name: "知识组织",
                            methods: ["分类法", "标签法", "网络图", "层次结构", "主题地图"],
                            features: ["智能分类", "自动标签", "关联发现", "知识聚类"]
                        },
                        retrieval: {
                            name: "知识检索",
                            methods: ["全文搜索", "语义搜索", "关联搜索", "推荐系统", "问答系统"],
                            features: ["模糊匹配", "智能推荐", "上下文理解", "多模态检索"]
                        },
                        evolution: {
                            name: "知识演化",
                            methods: ["版本管理", "更新追踪", "冲突解决", "协作编辑", "知识更新"],
                            features: ["变更检测", "智能合并", "冲突预警", "协作机制"]
                        }
                    },
                    analytics: {
                        metrics: ["知识覆盖率", "信息密度", "关联强度", "更新频率", "使用热度"],
                        visualizations: ["知识地图", "关系网络图", "热力图", "趋势图", "统计仪表盘"]
                    }
                },
                
                // 第三层次:动态应用层
                DYNAMIC_APPLICATION: {
                    name: "动态应用层",
                    description: "智能化的知识应用和价值创造系统", 
                    dimensions: {
                        intelligence: {
                            name: "智能处理",
                            capabilities: ["自动摘要", "情感分析", "主题提取", "关系挖掘", "预测分析"],
                            features: ["AI辅助", "智能推荐", "自动化处理", "模式识别"]
                        },
                        collaboration: {
                            name: "协作应用",
                            capabilities: ["多人协作", "实时同步", "评论讨论", "任务分配", "进度跟踪"],
                            features: ["团队协作", "版本控制", "权限管理", "通知系统"]
                        },
                        personalization: {
                            name: "个性化服务",
                            capabilities: ["用户画像", "偏好学习", "习惯分析", "需求预测", "定制界面"],
                            features: ["个性化推荐", "智能提醒", "习惯养成", "效率优化"]
                        }
                    },
                    automation: {
                        workflows: ["自动分类", "智能归档", "定期总结", "提醒通知", "报告生成"],
                        triggers: ["时间触发", "事件触发", "条件触发", "手动触发"],
                        actions: ["数据处理", "内容生成", "消息发送", "状态更新", "界面更新"]
                    }
                }
            }
        };

        // ==================== 三层次动态记录体系功能 ====================
        
        // 获取文档模型配置
        function getDocumentModelConfig() {
            return CORE_CONCEPTS.DYNAMIC_RECORDING_SYSTEM.DOCUMENT_MODEL;
        }
        
        // 获取知识管理配置
        function getKnowledgeManagementConfig() {
            return CORE_CONCEPTS.DYNAMIC_RECORDING_SYSTEM.KNOWLEDGE_MANAGEMENT;
        }
        
        // 获取动态应用配置
        function getDynamicApplicationConfig() {
            return CORE_CONCEPTS.DYNAMIC_RECORDING_SYSTEM.DYNAMIC_APPLICATION;
        }
        
        // 渲染三层次动态记录体系仪表盘(基于原文修正)
        function renderDynamicRecordingDashboard() {
            const discussions = getDiscussions();
            
            // 计算第一层:个人知识库(备忘录系统)
            const personalMemosCount = discussions.filter(d => 
                d.category && (d.category.includes('personal') || d.category.includes('thought'))
            ).length;
            
            const hypothesesCount = discussions.filter(d => 
                d.tags && d.tags.some(tag => ['假设', 'hypothesis', '猜想'].includes(tag))
            ).length;
            
            const insightsCount = discussions.filter(d => 
                d.summary && d.summary.includes('洞察') && d.summary.length > 30
            ).length;
            
            // 更新个人知识库显示
            document.getElementById('personal-memos-count').textContent = personalMemosCount;
            document.getElementById('hypotheses-count').textContent = hypothesesCount;
            document.getElementById('insights-count').textContent = insightsCount;
            
            // 计算第二层:共享知识库(记录系统)
            const decisionLogsCount = discussions.filter(d => 
                d.contentBlocks && d.contentBlocks.some(block => block.type === 'decision')
            ).length;
            
            const consensusRecordsCount = discussions.filter(d => 
                d.tags && d.tags.some(tag => ['共识', 'consensus', ' agreed'].includes(tag))
            ).length;
            
            const statusMarkersCount = discussions.filter(d => 
                d.contentBlocks && d.contentBlocks.some(block => 
                    block.type === 'todo' && block.items && block.items.length > 0
                )
            ).length;
            
            // 更新共享知识库显示
            document.getElementById('decision-logs-count').textContent = decisionLogsCount;
            document.getElementById('consensus-records-count').textContent = consensusRecordsCount;
            document.getElementById('status-markers-count').textContent = statusMarkersCount;
            
            // 计算第三层:笔记系统(日志系统)
            const processingLogsCount = Math.floor(discussions.length * 0.7); // 模拟加工日志
            const analysisToolsCount = discussions.filter(d => 
                d.summary && (d.summary.includes('分析') || d.summary.includes('总结'))
            ).length;
            
            const workflowLogsCount = Math.floor(discussions.length * 0.5); // 模拟工作流日志
            
            // 更新笔记系统显示
            document.getElementById('processing-logs-count').textContent = processingLogsCount;
            document.getElementById('analysis-tools-count').textContent = analysisToolsCount;
            document.getElementById('workflow-logs-count').textContent = workflowLogsCount;
        }
        
        // 应用文档模型模板
        function applyDocumentTemplate(templateId, discussionId) {
            const discussion = getDiscussions().find(d => d.id === discussionId);
            if (!discussion) return;
            
            const template = getDocumentModelConfig().templates[templateId];
            if (!template) return;
            
            let templateContent = {};
            switch (templateId) {
                case 'meeting':
                    templateContent = {
                        title: '会议记录',
                        contentBlocks: [
                            { type: 'text', content: '## 会议基本信息\n**时间:** \n**地点:** \n**参会人员:** ' },
                            { type: 'text', content: '## 会议议程' },
                            { type: 'timeline', content: '## 讨论要点' },
                            { type: 'decision', content: '## 会议决议' },
                            { type: 'todo', content: '## 行动计划', items: [] }
                        ]
                    };
                    break;
                case 'project':
                    templateContent = {
                        title: '项目文档',
                        contentBlocks: [
                            { type: 'text', content: '## 项目概述\n**项目名称:** \n**项目负责人:** \n**起止时间:** ' },
                            { type: 'text', content: '## 项目目标' },
                            { type: 'text', content: '## 技术方案' },
                            { type: 'todo', content: '## 项目计划', items: [] },
                            { type: 'decision', content: '## 里程碑' }
                        ]
                    };
                    break;
                case 'research':
                    templateContent = {
                        title: '研究报告',
                        contentBlocks: [
                            { type: 'text', content: '## 研究背景\n**研究领域:** \n**研究问题:** ' },
                            { type: 'text', content: '## 文献综述' },
                            { type: 'text', content: '## 研究方法' },
                            { type: 'text', content: '## 研究发现' },
                            { type: 'decision', content: '## 结论与建议' }
                        ]
                    };
                    break;
                case 'decision':
                    templateContent = {
                        title: '决策文档',
                        contentBlocks: [
                            { type: 'text', content: '## 决策背景\n**决策时间:** \n**决策者:** ' },
                            { type: 'text', content: '## 问题分析' },
                            { type: 'text', content: '## 备选方案' },
                            { type: 'decision', content: '## 最终决策' },
                            { type: 'todo', content: '## 实施计划', items: [] }
                        ]
                    };
                    break;
                case 'knowledge':
                    templateContent = {
                        title: '知识整理',
                        contentBlocks: [
                            { type: 'text', content: '## 知识领域\n**分类:** \n**关键词:** ' },
                            { type: 'text', content: '## 核心概念' },
                            { type: 'text', content: '## 知识结构' },
                            { type: 'text', content: '## 应用场景' },
                            { type: 'text', content: '## 相关资源' }
                        ]
                    };
                    break;
            }
            
            // 应用模板到讨论
            Object.assign(discussion, templateContent);
            discussion.updatedAt = new Date().toISOString();
            saveDiscussion(discussion);
            showToast(`已应用${template}模板`, 'success');
        }
        
        // 执行知识分析
        function performKnowledgeAnalysis(discussionId) {
            const discussion = getDiscussions().find(d => d.id === discussionId);
            if (!discussion) return;
            
            const analysis = {
                semanticDensity: 0,
                keywordCount: discussion.subject ? discussion.subject.split(/\s+/).length : 0,
                contentLength: discussion.contentBlocks ? discussion.contentBlocks.length : 0,
                lastUpdated: discussion.updatedAt,
                complexity: 'medium'
            };
            
            // 计算语义密度
            const allText = discussion.contentBlocks ? 
                discussion.contentBlocks.map(block => block.content || '').join(' ') : '';
            analysis.semanticDensity = analysis.keywordCount / Math.max(allText.length / 100, 1);
            
            // 计算复杂度
            if (analysis.contentLength > 10) analysis.complexity = 'high';
            else if (analysis.contentLength < 3) analysis.complexity = 'low';
            
            return analysis;
        }
        
        // 启动智能工作流
        function startIntelligentWorkflow(workflowType, discussionId) {
            const config = getDynamicApplicationConfig();
            const workflow = config.automation.workflows.find(w => w.includes(workflowType));
            
            if (!workflow) return;
            
            switch (workflowType) {
                case 'auto分类':
                    autoClassifyDiscussion(discussionId);
                    break;
                case '智能归档':
                    smartArchiveDiscussion(discussionId);
                    break;
                case '定期总结':
                    generatePeriodicSummary(discussionId);
                    break;
                case '提醒通知':
                    scheduleReminder(discussionId);
                    break;
                case '报告生成':
                    generateReport(discussionId);
                    break;
            }
            
            showToast(`已启动${workflow}工作流`, 'success');
        }
        
        // 自动分类讨论
        function autoClassifyDiscussion(discussionId) {
            const discussion = getDiscussions().find(d => d.id === discussionId);
            if (!discussion) return;
            
            // 简单的自动分类逻辑
            const content = (discussion.title + ' ' + discussion.subject).toLowerCase();
            const keywords = {
                'embedded-universal': ['学习', '培训', '教程', '指南', '入门'],
                'external-industry': ['工具', '效率', '优化', '自动化', '流程'],
                'internal-business': ['安全', '备份', '存储', '保护', '管理']
            };
            
            let bestMatch = '';
            let maxScore = 0;
            
            for (const [categoryId, words] of Object.entries(keywords)) {
                const score = words.reduce((sum, word) => {
                    return sum + (content.includes(word) ? 1 : 0);
                }, 0);
                
                if (score > maxScore) {
                    maxScore = score;
                    bestMatch = categoryId;
                }
            }
            
            if (bestMatch && maxScore > 0) {
                discussion.category = bestMatch;
                discussion.updatedAt = new Date().toISOString();
                saveDiscussion(discussion);
            }
        }
        
        // 智能归档讨论
        function smartArchiveDiscussion(discussionId) {
            const discussion = getDiscussions().find(d => d.id === discussionId);
            if (!discussion) return;
            
            // 检查讨论是否满足归档条件
            const daysSinceUpdate = (Date.now() - new Date(discussion.updatedAt).getTime()) / (1000 * 60 * 60 * 24);
            const hasCompletedTodos = discussion.contentBlocks && 
                discussion.contentBlocks.some(block => 
                    block.type === 'todo' && 
                    block.items && 
                    block.items.every(item => item.completed)
                );
            
            if (daysSinceUpdate > 30 && hasCompletedTodos) {
                discussion.archived = true;
                discussion.archivedAt = new Date().toISOString();
                saveDiscussion(discussion);
                showToast('讨论已智能归档', 'success');
            }
        }
        
        // 生成定期总结
        function generatePeriodicSummary(discussionId) {
            const discussion = getDiscussions().find(d => d.id === discussionId);
            if (!discussion) return;
            
            let summary = {
                decisions: [],
                todos: [],
                keyPoints: []
            };
            
            // 提取关键信息
            if (discussion.contentBlocks) {
                discussion.contentBlocks.forEach(block => {
                    if (block.type === 'decision' && block.content) {
                        summary.decisions.push(block.content);
                    } else if (block.type === 'todo' && block.items) {
                        summary.todos.push(...block.items.filter(item => !item.completed).map(item => item.text));
                    } else if (block.type === 'text' && block.content) {
                        // 简单提取关键点
                        const sentences = block.content.split(/[。!?]/);
                        summary.keyPoints.push(...sentences.filter(s => s.length > 10).slice(0, 3));
                    }
                });
            }
            
            // 保存总结
            discussion.autoSummary = summary;
            discussion.lastSummaryAt = new Date().toISOString();
            saveDiscussion(discussion);
            
            return summary;
        }
        
        // 渲染三层次动态记录体系仪表盘
        function renderDynamicRecordingDashboard() {
            const container = document.getElementById('dynamic-recording-dashboard');
            if (!container) return;
            
            const discussions = getDiscussions();
            const docModel = getDocumentModelConfig();
            const knowledgeMgmt = getKnowledgeManagementConfig();
            const dynamicApp = getDynamicApplicationConfig();
            
            // 计算各层次的统计数据
            const stats = {
                documentModel: {
                    totalTemplates: Object.keys(docModel.templates).length,
                    structuredDocs: discussions.filter(d => d.contentBlocks && d.contentBlocks.length > 0).length,
                    avgContentLength: discussions.reduce((sum, d) => sum + (d.contentBlocks ? d.contentBlocks.length : 0), 0) / discussions.length
                },
                knowledgeManagement: {
                    totalCategories: getCategories().length,
                    totalTags: [...new Set(discussions.flatMap(d => d.tags || []))].length,
                    avgKeywords: discussions.reduce((sum, d) => sum + (d.subject ? d.subject.split(/\s+/).length : 0), 0) / discussions.length
                },
                dynamicApplication: {
                    automatedActions: 0, // 这里可以从配置中获取实际的自动化操作数量
                    intelligentFeatures: 3, // AI辅助、智能推荐、自动化处理
                    personalizationLevel: 'medium'
                }
            };
            
            // 渲染仪表盘内容
            container.innerHTML = `
                <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                    <!-- 文档模型层统计 -->
                    <div class="bg-white rounded-lg p-6 border border-orange-200">
                        <h4 class="font-medium text-orange-800 mb-4">文档模型层</h4>
                        <div class="space-y-3">
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-600">可用模板</span>
                                <span class="font-medium">${stats.documentModel.totalTemplates}</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-600">结构化文档</span>
                                <span class="font-medium">${stats.documentModel.structuredDocs}</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-600">平均内容长度</span>
                                <span class="font-medium">${stats.documentModel.avgContentLength.toFixed(1)}</span>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 知识管理层统计 -->
                    <div class="bg-white rounded-lg p-6 border border-teal-200">
                        <h4 class="font-medium text-teal-800 mb-4">知识管理层</h4>
                        <div class="space-y-3">
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-600">分类数量</span>
                                <span class="font-medium">${stats.knowledgeManagement.totalCategories}</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-600">标签总数</span>
                                <span class="font-medium">${stats.knowledgeManagement.totalTags}</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-600">平均关键词</span>
                                <span class="font-medium">${stats.knowledgeManagement.avgKeywords.toFixed(1)}</span>
                            </div>
                        </div>
                    </div>
                    
                    <!-- 动态应用层统计 -->
                    <div class="bg-white rounded-lg p-6 border border-indigo-200">
                        <h4 class="font-medium text-indigo-800 mb-4">动态应用层</h4>
                        <div class="space-y-3">
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-600">自动化操作</span>
                                <span class="font-medium">${stats.dynamicApplication.automatedActions}</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-600">智能特性</span>
                                <span class="font-medium">${stats.dynamicApplication.intelligentFeatures}</span>
                            </div>
                            <div class="flex justify-between">
                                <span class="text-sm text-gray-600">个性化程度</span>
                                <span class="font-medium">${stats.dynamicApplication.personalizationLevel}</span>
                            </div>
                        </div>
                    </div>
                </div>
            `;
        }

        // 三层次动态记录体系事件处理(基于原文修正)
        document.addEventListener('DOMContentLoaded', () => {
            // 刷新三层次体系数据
            document.getElementById('refresh-recording-system-btn')?.addEventListener('click', () => {
                renderDynamicRecordingDashboard();
                showToast('三层次动态记录体系数据已刷新', 'success');
            });
            
            // 三层次体系功能按钮事件
            document.querySelectorAll('.recording-system-btn').forEach(btn => {
                btn.addEventListener('click', () => {
                    const action = btn.dataset.action;
                    
                    switch(action) {
                        case 'personal-memo':
                            showPersonalMemoCreator();
                            break;
                        case 'team-consensus':
                            showTeamConsensusRecorder();
                            break;
                        case 'process-log':
                            showKnowledgeProcessor();
                            break;
                        default:
                            showToast('功能开发中...', 'info');
                    }
                });
            });
        });
        
        // 显示个人备忘创建器(第一层:备忘录系统)
        function showPersonalMemoCreator() {
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center';
            modal.innerHTML = `
                <div class="bg-white rounded-xl shadow-lg w-full max-w-2xl mx-4 max-h-[80vh] overflow-y-auto">
                    <div class="p-6 border-b border-gray-200">
                        <h3 class="text-lg font-medium text-gray-800">创建个人备忘(原料仪表盘)</h3>
                        <p class="text-sm text-gray-600 mt-1">记录个人主观理解和记忆,随理解加深而更新</p>
                    </div>
                    <div class="p-6">
                        <div class="space-y-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">备忘类型</label>
                                <select class="w-full border border-gray-300 rounded-md px-3 py-2">
                                    <option value="personal-memo">个人备忘</option>
                                    <option value="hypothesis">待验证假设</option>
                                    <option value="insight">个人洞察</option>
                                </select>
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">快速记录</label>
                                <textarea rows="4" placeholder="记录你的想法、灵感或假设..." class="w-full border border-gray-300 rounded-md px-3 py-2"></textarea>
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">关联标签</label>
                                <input type="text" placeholder="输入相关标签..." class="w-full border border-gray-300 rounded-md px-3 py-2">
                            </div>
                        </div>
                    </div>
                    <div class="p-6 border-t border-gray-200 flex justify-end">
                        <button class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 mr-2">取消</button>
                        <button class="px-4 py-2 bg-orange-500 text-white rounded-lg hover:bg-orange-600">保存备忘</button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
            modal.querySelector('.bg-gray-100').addEventListener('click', () => {
                document.body.removeChild(modal);
            });
            modal.querySelector('.bg-orange-500').addEventListener('click', () => {
                showToast('个人备忘已保存到知识库', 'success');
                document.body.removeChild(modal);
                renderDynamicRecordingDashboard();
            });
        }
        
        // 显示团队共识记录器(第二层:记录系统)
        function showTeamConsensusRecorder() {
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center';
            modal.innerHTML = `
                <div class="bg-white rounded-xl shadow-lg w-full max-w-2xl mx-4 max-h-[80vh] overflow-y-auto">
                    <div class="p-6 border-b border-gray-200">
                        <h3 class="text-lg font-medium text-gray-800">记录团队共识(成品标记包)</h3>
                        <p class="text-sm text-gray-600 mt-1">记录团队客观共识和决定,随讨论进展而补充</p>
                    </div>
                    <div class="p-6">
                        <div class="space-y-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">记录类型</label>
                                <select class="w-full border border-gray-300 rounded-md px-3 py-2">
                                    <option value="decision-log">决策日志</option>
                                    <option value="consensus-record">共识记录</option>
                                    <option value="status-marker">状态标记</option>
                                </select>
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">共识内容</label>
                                <textarea rows="4" placeholder="记录团队达成的共识或决策..." class="w-full border border-gray-300 rounded-md px-3 py-2"></textarea>
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">参与者</label>
                                <input type="text" placeholder="输入参与者名称,用逗号分隔..." class="w-full border border-gray-300 rounded-md px-3 py-2">
                            </div>
                        </div>
                    </div>
                    <div class="p-6 border-t border-gray-200 flex justify-end">
                        <button class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 mr-2">取消</button>
                        <button class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600">记录共识</button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
            modal.querySelector('.bg-gray-100').addEventListener('click', () => {
                document.body.removeChild(modal);
            });
            modal.querySelector('.bg-blue-500').addEventListener('click', () => {
                showToast('团队共识已记录到共享知识库', 'success');
                document.body.removeChild(modal);
                renderDynamicRecordingDashboard();
            });
        }
        
        // 显示知识处理器(第三层:日志系统)
        function showKnowledgeProcessor() {
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center';
            modal.innerHTML = `
                <div class="bg-white rounded-xl shadow-lg w-full max-w-2xl mx-4 max-h-[80vh] overflow-y-auto">
                    <div class="p-6 border-b border-gray-200">
                        <h3 class="text-lg font-medium text-gray-800">知识加工分析(分析工具箱)</h3>
                        <p class="text-sm text-gray-600 mt-1">启动知识加工和分析工具,随状态变化而追加日志</p>
                    </div>
                    <div class="p-6">
                        <div class="space-y-4">
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">分析工具</label>
                                <select class="w-full border border-gray-300 rounded-md px-3 py-2">
                                    <option value="consensus-detector">共识检测器</option>
                                    <option value="pattern-recognizer">模式识别器</option>
                                    <option value="efficiency-analyzer">效率分析器</option>
                                </select>
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">加工对象</label>
                                <textarea rows="4" placeholder="选择要分析的讨论或内容..." class="w-full border border-gray-300 rounded-md px-3 py-2"></textarea>
                            </div>
                            <div>
                                <label class="block text-sm font-medium text-gray-700 mb-2">处理日志</label>
                                <div class="bg-gray-50 p-3 rounded-md text-sm text-gray-600 min-h-[80px]">
                                    系统将自动记录加工过程和结果...
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="p-6 border-t border-gray-200 flex justify-end">
                        <button class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 mr-2">取消</button>
                        <button class="px-4 py-2 bg-green-500 text-white rounded-lg hover:bg-green-600">开始加工</button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
            modal.querySelector('.bg-gray-100').addEventListener('click', () => {
                document.body.removeChild(modal);
            });
            modal.querySelector('.bg-green-500').addEventListener('click', () => {
                showToast('知识加工已启动,日志将自动追加', 'success');
                document.body.removeChild(modal);
                renderDynamicRecordingDashboard();
            });
        }
        
        // 显示文档模板选择器
        function showDocumentTemplateSelector() {
            const templates = getDocumentModelConfig().templates;
            const templateList = Object.keys(templates).map(key => 
                `<option value="${key}">${templates[key].name}</option>`
            ).join('');
            
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center';
            modal.innerHTML = `
                <div class="bg-white rounded-xl shadow-lg w-full max-w-md mx-4">
                    <div class="p-6 border-b border-gray-200">
                        <h3 class="text-lg font-medium text-gray-800">选择文档模板</h3>
                    </div>
                    <div class="p-6">
                        <div class="mb-4">
                            <label class="block text-sm font-medium text-gray-700 mb-2">模板类型</label>
                            <select id="template-select" class="w-full border border-gray-300 rounded-md px-3 py-2">
                                ${templateList}
                            </select>
                        </div>
                        <div class="mb-4">
                            <label class="block text-sm font-medium text-gray-700 mb-2">应用到讨论</label>
                            <select id="discussion-select" class="w-full border border-gray-300 rounded-md px-3 py-2">
                                <option value="">创建新讨论</option>
                                ${getDiscussions().map(d => 
                                    `<option value="${d.id}">${d.title}</option>`
                                ).join('')}
                            </select>
                        </div>
                    </div>
                    <div class="p-6 border-t border-gray-200 flex justify-end">
                        <button id="cancel-template" class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 mr-2">取消</button>
                        <button id="apply-template" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-primary-dark">应用模板</button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
            
            // 事件处理
            modal.querySelector('#cancel-template').addEventListener('click', () => {
                document.body.removeChild(modal);
            });
            
            modal.querySelector('#apply-template').addEventListener('click', () => {
                const templateId = modal.querySelector('#template-select').value;
                const discussionId = modal.querySelector('#discussion-select').value;
                
                if (templateId) {
                    if (discussionId) {
                        applyDocumentTemplate(templateId, discussionId);
                    } else {
                        // 创建新讨论
                        createNewDiscussionWithTemplate(templateId);
                    }
                    showToast('文档模板已应用', 'success');
                    document.body.removeChild(modal);
                }
            });
        }
        
        // 执行知识分析
        function performKnowledgeAnalysis() {
            const discussions = getDiscussions();
            const analysis = {
                totalDiscussions: discussions.length,
                categories: {},
                tags: {},
                contentBlocks: { text: 0, timeline: 0, decision: 0, todo: 0 },
                timeDistribution: {}
            };
            
            discussions.forEach(d => {
                // 分类统计
                analysis.categories[d.category] = (analysis.categories[d.category] || 0) + 1;
                
                // 标签统计
                if (d.tags) {
                    d.tags.forEach(tag => {
                        analysis.tags[tag] = (analysis.tags[tag] || 0) + 1;
                    });
                }
                
                // 内容块统计
                if (d.contentBlocks) {
                    d.contentBlocks.forEach(block => {
                        analysis.contentBlocks[block.type] = (analysis.contentBlocks[block.type] || 0) + 1;
                    });
                }
                
                // 时间分布统计
                const month = new Date(d.createdAt).toLocaleDateString('zh-CN', { year: 'numeric', month: 'short' });
                analysis.timeDistribution[month] = (analysis.timeDistribution[month] || 0) + 1;
            });
            
            // 显示分析结果
            showKnowledgeAnalysisResult(analysis);
        }
        
        // 显示知识分析结果
        function showKnowledgeAnalysisResult(analysis) {
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center';
            modal.innerHTML = `
                <div class="bg-white rounded-xl shadow-lg w-full max-w-3xl mx-4 max-h-[80vh] overflow-y-auto">
                    <div class="p-6 border-b border-gray-200">
                        <h3 class="text-lg font-medium text-gray-800">知识分析报告</h3>
                    </div>
                    <div class="p-6">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <div class="bg-blue-50 p-4 rounded-lg">
                                <h4 class="font-medium text-blue-900 mb-2">讨论统计</h4>
                                <p class="text-sm text-blue-800">总讨论数: ${analysis.totalDiscussions}</p>
                            </div>
                            <div class="bg-green-50 p-4 rounded-lg">
                                <h4 class="font-medium text-green-900 mb-2">内容块分布</h4>
                                <p class="text-sm text-green-800">文本: ${analysis.contentBlocks.text} | 时间轴: ${analysis.contentBlocks.timeline} | 决策: ${analysis.contentBlocks.decision} | 待办: ${analysis.contentBlocks.todo}</p>
                            </div>
                        </div>
                        
                        <div class="mt-6">
                            <h4 class="font-medium text-gray-800 mb-2">热门标签</h4>
                            <div class="flex flex-wrap gap-2">
                                ${Object.entries(analysis.tags).slice(0, 10).map(([tag, count]) => 
                                    `<span class="bg-gray-100 text-gray-700 px-2 py-1 rounded-full text-sm">${tag}: ${count}</span>`
                                ).join('')}
                            </div>
                        </div>
                    </div>
                    <div class="p-6 border-t border-gray-200 flex justify-end">
                        <button id="close-analysis" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-primary-dark">关闭</button>
                    </div>
                </div>
            `;
            
            document.body.appendChild(modal);
            modal.querySelector('#close-analysis').addEventListener('click', () => {
                document.body.removeChild(modal);
            });
        }
        
        // 启动智能工作流
        function startIntelligentWorkflow() {
            showToast('正在启动智能工作流...', 'info');
            
            // 模拟智能工作流处理
            setTimeout(() => {
                const workflow = {
                    autoClassification: Math.random() > 0.5,
                    smartSummary: Math.random() > 0.5,
                    trendAnalysis: Math.random() > 0.5
                };
                
                let message = '智能工作流已启动:\n';
                if (workflow.autoClassification) message += '✓ 自动分类已启用\n';
                if (workflow.smartSummary) message += '✓ 智能总结已启用\n';
                if (workflow.trendAnalysis) message += '✓ 趋势分析已启用\n';
                
                showToast(message, 'success');
            }, 2000);
        }
        
        // 使用模板创建新讨论
        function createNewDiscussionWithTemplate(templateId) {
            const template = getDocumentModelConfig().templates[templateId];
            if (!template) return;
            
            const newDiscussion = {
                id: Date.now().toString(),
                title: `基于${template.name}的新讨论`,
                category: 'embedded-universal',
                subject: '模板创建',
                topic: template.name,
                tags: ['模板', template.name.split('模板')[0]],
                createdAt: new Date().toISOString(),
                updatedAt: new Date().toISOString(),
                contentBlocks: [],
                summary: `使用${template.name}创建的讨论,包含${template.structure.join('、')}`
            };
            
            const discussions = getDiscussions();
            discussions.push(newDiscussion);
            saveDiscussions(discussions);
            
            // 打开新创建的讨论
            openDiscussion(newDiscussion.id);
        }

        // 初始化符号学架构
        function initializeSemioticArchitecture() {
            console.log('初始化符号学架构...', CORE_CONCEPTS);
            
            // 扩展分类系统以支持三层嵌套
            window.DEFAULT_CATEGORIES = [
                { 
                    id: 'embedded-universal', 
                    name: '内嵌式学习', 
                    dimension: 'universal',
                    value: 'embedded',
                    color: '#3b82f6',
                    description: '万向 通 - 通 境 顿:内嵌式赋能学习系统',
                    semioticLayer: 'explicit'
                },
                { 
                    id: 'external-industry', 
                    name: '外挂式省力', 
                    dimension: 'industry',
                    value: 'external', 
                    color: '#a855f7',
                    description: '千行 别 - 性 行 渐:外挂式省力节约系统',
                    semioticLayer: 'implicit'
                },
                { 
                    id: 'internal-business', 
                    name: '中蕴式安全', 
                    dimension: 'business',
                    value: 'internal',
                    color: '#22c55e', 
                    description: '百业 藏 - 量 果 密:中蕴式省心安全系统',
                    semioticLayer: 'metaphorical'
                }
            ];
            
            // 扩展提示词模板
            window.DEFAULT_PROMPTS = [
                {
                    id: 'explicit-grammar',
                    title: '明言语法分析',
                    category: 'embedded-universal',
                    description: '专有名词适应:纯粹文法与构式文法的语法分析',
                    icon: 'fa-language',
                    semioticSystem: 'explicit',
                    promptType: 'grammar',
                    content: {
                        structure: '语法目标:适应专有名词 (post)',
                        analysis: ['纯粹文法分析', '构式文法验证'],
                        application: '功能hover提示(语义表述,应用因子命名法)'
                    }
                },
                {
                    id: 'implicit-mind',
                    title: '暗示心动程序',
                    category: 'external-industry', 
                    description: '心流证明程序:中心先动的语言模型启动',
                    icon: 'fa-brain',
                    semioticSystem: 'implicit',
                    promptType: 'mind',
                    content: {
                        principle: '心流(中心先"动")-语言模型',
                        activation: ['心流状态检测', '语言模型启动'],
                        mechanism: '概念认知层的触发机制'
                    }
                },
                {
                    id: 'metaphorical-axiom',
                    title: '隐喻公理体系',
                    category: 'internal-business',
                    description: '顶级公理依存:集合元素的根本依存关系',
                    icon: 'fa-sitemap',
                    semioticSystem: 'metaphorical', 
                    promptType: 'axiom',
                    content: {
                        focus: '集合元素依存',
                        structure: ['抽象元层', '实现方法层', '具体应用层'],
                        application: '范畴元件约束的建立'
                    }
                }
            ];
        }

        // ==================== 三层次动态记录体系快速操作 ====================
        
        // 显示文档模板选择器
        function showDocumentTemplates() {
            const discussionId = currentDiscussionId;
            if (!discussionId) {
                showToast('请先打开一个讨论', 'warning');
                return;
            }
            
            const docModel = getDocumentModelConfig();
            const templates = Object.entries(docModel.templates);
            
            // 创建模板选择模态框
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center';
            modal.innerHTML = `
                <div class="bg-white rounded-xl shadow-lg w-full max-w-2xl mx-4 max-h-[80vh] overflow-y-auto">
                    <div class="p-6 border-b border-gray-200">
                        <h3 class="text-lg font-medium text-gray-800">选择文档模板</h3>
                        <p class="text-sm text-gray-600 mt-1">应用预定义的文档结构模板</p>
                    </div>
                    <div class="p-6">
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                            ${templates.map(([id, name]) => `
                                <button onclick="applyDocumentTemplate('${id}', '${discussionId}'); this.closest('.fixed').remove();" 
                                        class="p-4 border border-gray-200 rounded-lg hover:border-primary hover:bg-blue-50 transition-all-300 text-left">
                                    <div class="flex items-center mb-2">
                                        <i class="fa fa-file-text-o text-orange-600 mr-2"></i>
                                        <h4 class="font-medium text-gray-800">${name}</h4>
                                    </div>
                                    <p class="text-sm text-gray-600">点击应用${name}结构模板</p>
                                </button>
                            `).join('')}
                        </div>
                    </div>
                    <div class="p-6 border-t border-gray-200 flex justify-end">
                        <button onclick="this.closest('.fixed').remove()" class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-all-300">
                            取消
                        </button>
                    </div>
                </div>
            `;
            document.body.appendChild(modal);
        }
        
        // 执行批量知识分析
        function performBatchAnalysis() {
            const discussions = getDiscussions();
            if (discussions.length === 0) {
                showToast('暂无讨论数据可供分析', 'warning');
                return;
            }
            
            showToast('正在执行批量知识分析...', 'info');
            
            // 分析所有讨论
            const analysisResults = discussions.map(discussion => {
                const analysis = performKnowledgeAnalysis(discussion.id);
                return {
                    id: discussion.id,
                    title: discussion.title,
                    analysis: analysis
                };
            });
            
            // 显示分析结果
            setTimeout(() => {
                const modal = document.createElement('div');
                modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center';
                modal.innerHTML = `
                    <div class="bg-white rounded-xl shadow-lg w-full max-w-4xl mx-4 max-h-[80vh] overflow-y-auto">
                        <div class="p-6 border-b border-gray-200">
                            <h3 class="text-lg font-medium text-gray-800">知识分析结果</h3>
                            <p class="text-sm text-gray-600 mt-1">基于三层次动态记录体系的分析</p>
                        </div>
                        <div class="p-6">
                            <div class="space-y-4">
                                ${analysisResults.map(result => `
                                    <div class="border border-gray-200 rounded-lg p-4">
                                        <h4 class="font-medium text-gray-800 mb-2">${result.title}</h4>
                                        <div class="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm">
                                            <div>
                                                <span class="text-gray-600">语义密度:</span>
                                                <span class="font-medium ml-1">${result.analysis.semanticDensity.toFixed(2)}</span>
                                            </div>
                                            <div>
                                                <span class="text-gray-600">关键词数:</span>
                                                <span class="font-medium ml-1">${result.analysis.keywordCount}</span>
                                            </div>
                                            <div>
                                                <span class="text-gray-600">内容长度:</span>
                                                <span class="font-medium ml-1">${result.analysis.contentLength}</span>
                                            </div>
                                            <div>
                                                <span class="text-gray-600">复杂度:</span>
                                                <span class="font-medium ml-1">${result.analysis.complexity}</span>
                                            </div>
                                        </div>
                                    </div>
                                `).join('')}
                            </div>
                        </div>
                        <div class="p-6 border-t border-gray-200 flex justify-end">
                            <button onclick="this.closest('.fixed').remove()" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-primary-dark transition-all-300">
                                关闭
                            </button>
                        </div>
                    </div>
                `;
                document.body.appendChild(modal);
                showToast('知识分析完成', 'success');
            }, 1000);
        }
        
        // 显示自动化设置
        function showAutomationSettings() {
            const dynamicApp = getDynamicApplicationConfig();
            
            const modal = document.createElement('div');
            modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center';
            modal.innerHTML = `
                <div class="bg-white rounded-xl shadow-lg w-full max-w-3xl mx-4 max-h-[80vh] overflow-y-auto">
                    <div class="p-6 border-b border-gray-200">
                        <h3 class="text-lg font-medium text-gray-800">自动化工作流配置</h3>
                        <p class="text-sm text-gray-600 mt-1">配置智能自动化操作,提升工作效率</p>
                    </div>
                    <div class="p-6">
                        <div class="space-y-6">
                            <div>
                                <h4 class="font-medium text-gray-800 mb-3">可用工作流</h4>
                                <div class="space-y-3">
                                    ${dynamicApp.automation.workflows.map(workflow => `
                                        <label class="flex items-center p-3 border border-gray-200 rounded-lg hover:bg-gray-50 cursor-pointer">
                                            <input type="checkbox" class="mr-3" checked>
                                            <div class="flex-1">
                                                <div class="font-medium text-gray-800">${workflow}</div>
                                                <div class="text-sm text-gray-600">自动执行${workflow}操作</div>
                                            </div>
                                        </label>
                                    `).join('')}
                                </div>
                            </div>
                            
                            <div>
                                <h4 class="font-medium text-gray-800 mb-3">触发条件</h4>
                                <div class="space-y-3">
                                    ${dynamicApp.automation.triggers.map(trigger => `
                                        <label class="flex items-center p-3 border border-gray-200 rounded-lg hover:bg-gray-50 cursor-pointer">
                                            <input type="checkbox" class="mr-3">
                                            <div class="flex-1">
                                                <div class="font-medium text-gray-800">${trigger}</div>
                                                <div class="text-sm text-gray-600">使用${trigger}方式启动工作流</div>
                                            </div>
                                        </label>
                                    `).join('')}
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="p-6 border-t border-gray-200 flex justify-end">
                        <button onclick="this.closest('.fixed').remove()" class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-all-300 mr-2">
                            取消
                        </button>
                        <button onclick="this.closest('.fixed').remove(); showToast('自动化配置已保存', 'success');" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-primary-dark transition-all-300">
                            保存配置
                        </button>
                    </div>
                </div>
            `;
            document.body.appendChild(modal);
        }
        
        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', () => {
            initializeSemioticArchitecture();
            initializeApp();
            
            // 初始化三层次动态记录体系仪表盘
            setTimeout(() => {
                renderDynamicRecordingDashboard();
            }, 1000);
        });
    </script>
</body>
</html>
相关推荐
啦哈拉哈5 小时前
【Python】知识点零碎学习3
开发语言·python·学习
mengzhi啊5 小时前
Qt自绘制动态字体,模糊的,毛茸茸的fuzzy。
开发语言·qt
识途老码5 小时前
python装饰器
开发语言·python
JIngJaneIL5 小时前
基于Java饮食营养管理信息平台系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot
fresh hacker5 小时前
【Python数据分析】速通NumPy
开发语言·python·数据挖掘·数据分析·numpy
长安第一美人5 小时前
整车控制器标定软件介绍 || 汽车标定协议CPP
开发语言·qt
IT_陈寒5 小时前
Java 21新特性实战:这5个改进让我的代码效率提升40%
前端·人工智能·后端
宠..5 小时前
获取输入内容
开发语言·c++·qt
肠胃炎5 小时前
Chrome扩展截图功能实现
前端·chrome