diff --git a/src/pages/projectSelect/index.vue b/src/pages/projectSelect/index.vue index f5b1ee0..92a1c4c 100644 --- a/src/pages/projectSelect/index.vue +++ b/src/pages/projectSelect/index.vue @@ -1,7 +1,7 @@ @@ -15,6 +15,7 @@ import { useGeomagnetism } from '@/hooks/useGeomagnetism'; const baiduMap = ref(null) const projectList = ref([]) const webViewUrl = ref('') +const webViewKey = ref(0) // 用于强制重新渲染 web-view const memberStore = useMemberStore() // 获取项目列表信息 @@ -24,26 +25,127 @@ const getProjectList = async () => { } const handleWebViewMessage = (event) => { - getProjectModelListApi({ projectId: event.detail.data[0].projectInfo.proId }).then((res) => { - if (res?.data?.length > 0) { - const ctx = uni.requireNativePlugin('bonus-textodule') - ctx.openNativePage( - { - modelInfoList: res.data, - projectId: event.detail.data[0].projectInfo.proId, - token: memberStore.token, - }, - (result) => {}, - ) - } else { - uni.$u.toast('该工程暂无模型数据') + console.log('=== 收到 web-view 消息 ==='); + console.log('完整事件对象:', event); + console.log('event.detail:', event.detail); + console.log('event.detail.data:', event.detail.data); + console.log('event.detail.data 类型:', Array.isArray(event.detail.data) ? '数组' : typeof event.detail.data); + + // 尝试多种数据格式 + let action, projectInfo; + + // 格式1: event.detail.data 是对象 + if (event.detail && event.detail.data) { + if (event.detail.data.action) { + action = event.detail.data.action; + projectInfo = event.detail.data.projectInfo; + console.log('使用对象格式解析'); } - }) + // 格式2: event.detail.data 是数组 + else if (Array.isArray(event.detail.data) && event.detail.data.length > 0) { + action = event.detail.data[0]?.action; + projectInfo = event.detail.data[0]?.projectInfo; + console.log('使用数组格式解析'); + } + } + + // 格式3: 直接访问 event.detail + if (!action && event.detail) { + if (event.detail.action) { + action = event.detail.action; + projectInfo = event.detail.projectInfo; + console.log('使用直接格式解析'); + } + } + + console.log('解析后的 action:', action); + console.log('解析后的 projectInfo:', projectInfo); + + if (!action) { + console.warn('无法解析 action,消息格式可能不正确'); + console.warn('请检查 event.detail 的结构'); + return; + } + + if (action === 'modelPreview') { + console.log('收到模型预览请求,projectId:', projectInfo?.proId); + // 模型预览逻辑 + getProjectModelListApi({ projectId: projectInfo.proId }).then((res) => { + console.log('获取模型列表成功:', res); + if (res?.data?.length > 0) { + // 使用 URL 参数方式传递数据(最可靠的方式) + const modelListJson = JSON.stringify(res.data); + const clickedProjectJson = JSON.stringify(projectInfo); + + // 重新构建项目信息 + const allProjectInfo = rebuildProjectInfo(); + + // 构建新的 URL + const projectInfoParam = encodeURIComponent(JSON.stringify(allProjectInfo)); + const modelListParam = encodeURIComponent(modelListJson); + const clickedProjectParam = encodeURIComponent(clickedProjectJson); + const timestamp = Date.now(); + + const newUrl = `/static/map.html?projectInfo=${projectInfoParam}&modelList=${modelListParam}&clickedProject=${clickedProjectParam}&action=showPreview&t=${timestamp}`; + + console.log('准备更新 webViewUrl,URL 长度:', newUrl.length); + + // 强制重新渲染 web-view + webViewKey.value += 1; + // 先清空,再设置新值,确保触发更新 + webViewUrl.value = ''; + + setTimeout(() => { + webViewUrl.value = newUrl; + console.log('webViewUrl 已更新'); + }, 100); + } else { + console.warn('该工程暂无模型数据'); + uni.$u.toast('该工程暂无模型数据'); + } + }).catch((err) => { + console.error('获取模型列表失败:', err); + uni.$u.toast('获取模型列表失败'); + }); + } else if (action === 'navigateToProject') { + // 原来的勘察逻辑 + getProjectModelListApi({ projectId: projectInfo.proId }).then((res) => { + if (res?.data?.length > 0) { + const ctx = uni.requireNativePlugin('bonus-textodule') + ctx.openNativePage( + { + modelInfoList: res.data, + projectId: projectInfo.proId, + token: memberStore.token, + }, + (result) => {}, + ) + } else { + uni.$u.toast('该工程暂无模型数据') + } + }) + } } // 计算磁偏角 const { calculate } = useGeomagnetism(); +// 重新构建项目信息的辅助函数 +const rebuildProjectInfo = () => { + return projectList.value.map((item) => { + const res = calculate(item.latitude, item.longitude); + const declVal = res?.declinationFormatted || (res?.declination !== undefined ? `${res.declination.toFixed(2)}°` : '0° 0\''); + return { + lat: item.latitude, + declination: declVal, + lng: item.longitude, + proName: item.proName, + chargePerson: item.chargePerson, + location: item.location, + proId: item.proId, + }; + }); +}; onLoad(() => { getProjectList().then(() => { diff --git a/src/static/map.html b/src/static/map.html index 8d5459d..7131578 100644 --- a/src/static/map.html +++ b/src/static/map.html @@ -14,6 +14,7 @@ #map-container { width: 100vw; height: 100vh; + position: relative; } /** 去除百度地图的水印和logo */ @@ -21,71 +22,300 @@ .anchorBL { display: none; } + + /* 模型预览面板 */ + .model-preview-panel { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 1000; + display: flex; + background: rgba(0, 0, 0, 0.3); + } + + .model-preview-tree { + width: 300px; + height: 100%; + background: #fff; + border-right: 1px solid #e0e0e0; + overflow-y: auto; + padding: 20px; + } + + .tree-title { + font-size: 18px; + font-weight: bold; + color: #333; + margin-bottom: 20px; + padding-bottom: 10px; + border-bottom: 2px solid #002db6; + } + + .tree-node { + margin-bottom: 8px; + } + + .tree-node-item { + display: flex; + align-items: center; + padding: 8px 12px; + cursor: pointer; + border-radius: 4px; + transition: background-color 0.2s; + } + + .tree-node-item:hover { + background-color: #f5f5f5; + } + + .tree-node-checkbox { + width: 18px; + height: 18px; + margin-right: 8px; + cursor: pointer; + } + + .tree-node-label { + flex: 1; + font-size: 14px; + color: #333; + user-select: none; + } + + .model-preview-close { + position: absolute; + top: 20px; + right: 20px; + width: 40px; + height: 40px; + background: #fff; + border: 1px solid #ddd; + border-radius: 50%; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15); + transition: all 0.2s; + z-index: 1001; + } + + .model-preview-close:hover { + background: #f5f5f5; + transform: scale(1.1); + } + + .model-preview-close::before, + .model-preview-close::after { + content: ''; + position: absolute; + width: 2px; + height: 20px; + background: #666; + transform: rotate(45deg); + } + + .model-preview-close::after { + transform: rotate(-45deg); + } + + /* 点击菜单样式 */ + .action-menu { + background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%); + border-radius: 16px; + box-shadow: 0 8px 32px rgba(0, 45, 182, 0.12), + 0 4px 16px rgba(0, 0, 0, 0.08), + 0 2px 8px rgba(0, 0, 0, 0.04); + width: 100%; + height: 100%; + overflow: hidden; + border: 1px solid rgba(0, 45, 182, 0.08); + backdrop-filter: blur(10px); + padding: 0; + display: flex; + flex-direction: column; + justify-content: stretch; + align-items: stretch; + box-sizing: border-box; + } + + .action-menu-item { + padding: 0 20px; + margin: 0; + cursor: pointer; + font-size: 15px; + color: #1a1a1a; + border-radius: 0; + transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); + display: flex; + align-items: center; + justify-content: flex-start; + position: relative; + font-weight: 500; + letter-spacing: 0.2px; + flex: 1; + box-sizing: border-box; + text-align: left; + border-bottom: 1px solid rgba(0, 45, 182, 0.06); + } + + .action-menu-item:first-child { + border-radius: 16px 16px 0 0; + } + + .action-menu-item:last-child { + border-bottom: none; + border-radius: 0 0 16px 16px; + } + + .action-menu-item::before { + content: ''; + position: absolute; + left: 0; + top: 50%; + transform: translateY(-50%); + width: 3px; + height: 0; + background: linear-gradient(180deg, #002db6 0%, #0056e6 100%); + border-radius: 0 2px 2px 0; + opacity: 0; + transition: all 0.25s ease; + } + + .action-menu-item:hover { + background: linear-gradient(135deg, #f0f4ff 0%, #e6edff 100%); + color: #002db6; + padding-left: 24px; + transform: translateX(2px); + box-shadow: inset 0 0 0 1px rgba(0, 45, 182, 0.1); + } + + .action-menu-item:hover::before { + opacity: 1; + height: 60%; + } + + .action-menu-item span { + display: inline-flex; + align-items: center; + justify-content: center; + font-size: 20px; + margin-right: 12px; + width: 24px; + height: 24px; + flex-shrink: 0; + transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1); + } + + .action-menu-item:hover span { + transform: scale(1.15) rotate(5deg); + }
+ + \ No newline at end of file