{"repo": "adachissss/ecological-environment-data-space", "files": {"public/receiver/index.js": {"ee121648c0a86c43d21f273b21df7b9492756ddc": {"t": 1785768939.3012965, "n": 31833, "h": "7c3901c66d38b85e", "c": "// 配置\n// 优先使用 config.js 的配置,否则使用当前域名\nconst API_BASE_URL = (typeof API_BASE !== 'undefined' ? API_BASE : window.location.origin);\nlet currentTab = \"animal\";\nlet currentPage = 1;\nconst pageLimit = 10;\nlet totalPages = 1;\n\n// 页面加载时初始化\ndocument.addEventListener(\"DOMContentLoaded\", () => {\n checkAuth();\n loadUserInfo();\n loadAllCounts(); // 加载所有资产统计\n loadAssets(currentTab);\n});\n\n// 检查登录状态\nfunction checkAuth() {\n const token = localStorage.getItem(\"token\");\n if (!token) {\n alert(\"请先登录\");\n window.location.href = \"../login.html\";\n return;\n }\n}\n\n// 获取 token\nfunction getToken() {\n return localStorage.getItem(\"token\");\n}\n\n// 加载用户信息\nasync function loadUserInfo() {\n try {\n const userId = localStorage.getItem(\"userId\");\n if (userId) {\n document.getElementById(\"username\").textContent = userId;\n }\n } catch (error) {\n console.error(\"加载用户信息失败:\", error);\n }\n}\n\n// 退出登录\nfunction logout() {\n localStorage.removeItem(\"token\");\n localStorage.removeItem(\"userId\");\n localStorage.removeItem(\"institution\");\n window.location.href = \"../login.html\";\n}\n\n// 加载所有资产类型的统计数字\nasync function loadAllCounts() {\n const types = ['animal', 'lake', 'air', 'plant'];\n \n for (const type of types) {\n try {\n const response = await fetch(`${API_BASE_URL}/org2/assets?type=${type}&page=1&limit=1`, {\n headers: {\n Authorization: `Bearer ${getToken()}`,\n },\n });\n\n if (response.ok) {\n const result = await response.json();\n if (result.success && result.data) {\n document.getElementById(`${type}-count`).textContent = result.data.total;\n }\n }\n } catch (error) {\n console.error(`加载${type}统计失败:`, error);\n document.getElementById(`${type}-count`).textContent = '0';\n }\n }\n}\n\n// 切换标签\nfunction switchTab(tab) {\n currentTab = tab;\n currentPage = 1;\n\n // 更新按钮状态\n const buttons = document.querySelectorAll(\".tab-btn\");\n buttons.forEach((btn) => {\n btn.classList.remove(\"active\");\n // 简单的匹配逻辑\n if (btn.textContent.toLowerCase().includes(tab.replace('-verify',''))) {\n btn.classList.add(\"active\");\n } else if (tab === 'permissions' && btn.textContent.includes('申请')) {\n btn.classList.add(\"active\");\n } else if (tab === 'hash-verify' && btn.textContent.includes('验证')) {\n btn.classList.add(\"active\");\n }\n });\n\n // 加载对应数据\n if (tab === 'permissions') {\n loadMyPermissions();\n } else if (tab === 'hash-verify') {\n loadHashVerifyTool();\n } else {\n loadAssets(tab);\n }\n}\n\n// 加载资产数据\nasync function loadAssets(type) {\n const tableContent = document.getElementById(\"table-content\");\n tableContent.innerHTML = `\n
正在加载数据...
\n❌ 加载失败: ${error.message}
\n \n暂无数据 / No Data Available
\n| ID | \nBusiness ID | \nName | \n ${type === 'animal' || type === 'plant' ? 'Species | ' : ''}\nPermission | \nAction | \n
|---|---|---|---|---|---|
| ${asset.globalId} | \n${asset.businessId} | \n${asset.name} | \n ${type === 'animal' || type === 'plant' ? `${asset.species || '-'} | ` : ''}\n${permissionBadge} | \n\n \n | \n
加载中...
加载中...
加载失败: ${error.message}
\n `;\n }\n}\n\n// 渲染权限状态\nfunction renderPermissionStatus(asset, type) {\n const section = document.getElementById(\"permission-status-section\");\n \n if (asset.permissionStatus === null || asset.permissionStatus === undefined) {\n // 未申请\n section.innerHTML = `\n您还未申请访问该资产的权限 / No access permission
\n \n `;\n } else if (asset.permissionStatus === 0) {\n // 审核中\n section.innerHTML = `\n⏳ 权限申请审核中 / Audit Pending...
\n `;\n } else if (asset.permissionStatus === 1) {\n // 已通过\n section.innerHTML = `\n✅ 权限审核已通过 / Access Granted
\n \n `;\n } else if (asset.permissionStatus === 2) {\n // 已驳回\n section.innerHTML = `\n❌ 权限申请已被驳回 / Request Rejected
\n `;\n }\n}\n\n// 申请权限\nasync function applyPermission(globalId, type) {\n if (!confirm('Confirm to apply for access?')) {\n return;\n }\n\n try {\n const response = await fetch(`${API_BASE_URL}/org2/permission/apply`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${getToken()}`,\n },\n body: JSON.stringify({ globalId })\n });\n\n const result = await response.json();\n\n if (result.success) {\n alert('✅ ' + result.message);\n // 重新加载详情\n viewAssetDetail(type, globalId);\n } else {\n alert('❌ ' + result.message);\n }\n } catch (error) {\n console.error(\"申请权限失败:\", error);\n alert('申请失败: ' + error.message);\n }\n}\n\n// ==================== AI 功能模块 ====================\n// 保持逻辑不变,仅修改生成的HTML样式以适应黑白灰主题\n\nlet currentChainData = []; \nlet currentAssetType = '';\nlet currentBusinessId = '';\nlet conversationHistory = []; \n\n// 修改原有的 loadChainData 函数\nwindow.loadChainData = async function(type, businessId, assetName) {\n const section = document.getElementById(\"chain-data-section\");\n const content = document.getElementById(\"chain-data-content\");\n \n section.style.display = \"block\";\n content.innerHTML = `\nLoading Blockchain Data...
\n暂无链上数据 / No Data on Chain
`;\n return;\n }\n\n // 渲染链上数据\n let dataHTML = `${JSON.stringify(item, null, 2)}\n ${result.message}
`;\n }\n } catch (error) {\n console.error(\"加载链上数据失败:\", error);\n content.innerHTML = `加载失败: ${error.message}
`;\n }\n};\n\n// 显示 AI 功能按钮(样式已修改为适应新主题)\nfunction showAIFeatures() {\n const section = document.getElementById(\"chain-data-section\");\n const existingAI = document.getElementById('ai-features-container');\n if (existingAI) existingAI.remove();\n \n const aiContainer = document.createElement('div');\n aiContainer.id = 'ai-features-container';\n // 内联样式被移除,转而在 CSS 中定义 #ai-features-container\n aiContainer.innerHTML = `\nFeel free to ask questions about the data.
\nFeel free to ask questions about the data.
\nLoading Permissions...
❌ Failed: ${error.message}
No Applications Found
| App ID | \nType | \nBusiness ID | \nName | \nStatus | \nAction | \n
|---|---|---|---|---|---|
| ${perm.id} | \n${perm.assetType} | \n${perm.businessId} | \n${perm.name} | \n${permissionBadge} | \n\n \n | \n
Upload the JSON file to verify its SHA-256 hash against the certificate.
\n \nClick or Drag JSON file here
\n \nPaste certificate hash below:
\n \n \n \nHashes match perfectly. Data is intact.
\nHash mismatch. Data might be modified.
\n