合并代码

This commit is contained in:
limengnan 2025-12-11 08:23:42 +08:00
commit 20ef65112d
8 changed files with 68 additions and 82 deletions

Binary file not shown.

View File

@ -2077,7 +2077,7 @@ def main():
"""主函数""" """主函数"""
# 解析命令行参数 # 解析命令行参数
parser = argparse.ArgumentParser(description='Body Balance Evaluation System Backend') parser = argparse.ArgumentParser(description='Body Balance Evaluation System Backend')
parser.add_argument('--host', default='0.0.0.0', help='Host address to bind to') parser.add_argument('--host', default='localhost', help='Host address to bind to')
parser.add_argument('--port', type=int, default=5000, help='Port number to bind to') parser.add_argument('--port', type=int, default=5000, help='Port number to bind to')
parser.add_argument('--debug', action='store_true', help='Enable debug mode') parser.add_argument('--debug', action='store_true', help='Enable debug mode')
args = parser.parse_args() args = parser.parse_args()

View File

@ -192,7 +192,8 @@ function createWindow() {
webPreferences: { webPreferences: {
nodeIntegration: false, nodeIntegration: false,
contextIsolation: true, contextIsolation: true,
sandbox: false, // 显式关闭沙盒,避免 preload 加载问题 // sandbox: false, // 显式关闭沙盒,避免 preload 加载问题
// backgroundThrottling: false,
preload: path.join(__dirname, 'preload.js') preload: path.join(__dirname, 'preload.js')
}, },
icon: path.join(__dirname, '../public/logo.png'), icon: path.join(__dirname, '../public/logo.png'),

View File

@ -2,5 +2,5 @@ const { contextBridge, ipcRenderer } = require('electron');
contextBridge.exposeInMainWorld('electronAPI', { contextBridge.exposeInMainWorld('electronAPI', {
generateReportPdf: (payload) => ipcRenderer.invoke('generate-report-pdf', payload), generateReportPdf: (payload) => ipcRenderer.invoke('generate-report-pdf', payload),
getBackendUrl: () => 'http://localhost:5000' getBackendUrl: () => process.env.BACKEND_URL || 'http://localhost:5000',
}); });

View File

@ -932,7 +932,7 @@ function connectWebSocket() {
// Socket.IO // Socket.IO
socket = io(BACKEND_URL, { socket = io(BACKEND_URL, {
transports: ['websocket', 'polling'], // 使polling transports: ['websocket'],
timeout: 10000, timeout: 10000,
forceNew: true, forceNew: true,
reconnection: true, reconnection: true,
@ -942,7 +942,7 @@ function connectWebSocket() {
// //
devicesSocket = io(BACKEND_URL + '/devices', { devicesSocket = io(BACKEND_URL + '/devices', {
transports: ['websocket', 'polling'], // 使polling transports: ['websocket'],
timeout: 10000, timeout: 10000,
forceNew: true forceNew: true
}) })
@ -995,9 +995,16 @@ function connectWebSocket() {
devicesSocket.on('connect', () => { devicesSocket.on('connect', () => {
console.log('🔗 设备命名空间连接成功') console.log('🔗 设备命名空间连接成功')
// const enabledCameras = (() => {
devicesSocket.emit('subscribe_device', { device_type: 'camera1' }) const list = []
devicesSocket.emit('subscribe_device', { device_type: 'camera2' }) const idx1 = String((cameraForm.value && cameraForm.value.camera1 && cameraForm.value.camera1.device_index) || '').trim()
const idx2 = String((cameraForm.value && cameraForm.value.camera2 && cameraForm.value.camera2.device_index) || '').trim()
if (idx1 !== '') list.push('camera1')
if (idx2 !== '') list.push('camera2')
if (list.length === 0) list.push('camera1')
return list
})()
enabledCameras.forEach(t => devicesSocket.emit('subscribe_device', { device_type: t }))
devicesSocket.emit('subscribe_device', { device_type: 'femtobolt' }) devicesSocket.emit('subscribe_device', { device_type: 'femtobolt' })
devicesSocket.emit('subscribe_device', { device_type: 'imu' }) devicesSocket.emit('subscribe_device', { device_type: 'imu' })
devicesSocket.emit('subscribe_device', { device_type: 'pressure' }) devicesSocket.emit('subscribe_device', { device_type: 'pressure' })
@ -1033,9 +1040,9 @@ function connectWebSocket() {
frameCount++ frameCount++
// camera1 / camera2 // camera1 / camera2
const devId = (data && data.device_id) ? String(data.device_id).toLowerCase() : '' const devId = (data && data.device_id) ? String(data.device_id).toLowerCase() : ''
if (!tempInfo.value.camera_frames) { if (!tempInfo.value.camera_frames) {
tempInfo.value.camera_frames = {} tempInfo.value.camera_frames = {}
} }
if (devId === 'camera1') { if (devId === 'camera1') {
tempInfo.value.camera_frames['camera1'] = data tempInfo.value.camera_frames['camera1'] = data
tempInfo.value.camera1_frame = data tempInfo.value.camera1_frame = data
@ -1080,15 +1087,15 @@ function connectWebSocket() {
const { device_type, status } = data const { device_type, status } = data
const statusText = status ? '已连接' : '未连接' const statusText = status ? '已连接' : '未连接'
switch (device_type) { switch (device_type) {
case 'camera1': case 'camera1':
camera1Status.value = statusText camera1Status.value = statusText
console.log(`📷 相机1状态: ${statusText}`) console.log(`📷 相机1状态: ${statusText}`)
break break
case 'camera2': case 'camera2':
camera2Status.value = statusText camera2Status.value = statusText
console.log(`📷 相机2状态: ${statusText}`) console.log(`📷 相机2状态: ${statusText}`)
break break
case 'femtobolt': case 'femtobolt':
femtoboltStatus.value = statusText femtoboltStatus.value = statusText
console.log(`🔍 深度相机状态: ${statusText}`) console.log(`🔍 深度相机状态: ${statusText}`)

View File

@ -41,9 +41,9 @@ function initThreeJS() {
camera.lookAt(0, 0, 0); camera.lookAt(0, 0, 0);
// //
renderer = new THREE.WebGLRenderer({ antialias: true,alpha: true }); renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false, powerPreference: 'high-performance' });
scene.background = null; // scene.background = null; //
renderer.setClearColor(0x000000, 0); // 0 renderer.setClearColor(0x000000, 0.02);
renderer.setSize(containermodel.offsetWidth, containermodel.offsetHeight); renderer.setSize(containermodel.offsetWidth, containermodel.offsetHeight);
renderer.shadowMap.enabled = true; renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap; renderer.shadowMap.type = THREE.PCFSoftShadowMap;

View File

@ -20,7 +20,7 @@
import { patientAPI, detectionAPI,historyAPI,getBackendUrl } from '@/services/api.js' import { patientAPI, detectionAPI,historyAPI,getBackendUrl } from '@/services/api.js'
import { ref, onMounted } from 'vue' import { ref, onMounted } from 'vue'
import * as pdfjsLib from 'pdfjs-dist' // import * as pdfjsLib from 'pdfjs-dist'
const emit = defineEmits([ 'closeViewPDF' ]); const emit = defineEmits([ 'closeViewPDF' ]);
const props = defineProps({ const props = defineProps({
pdfUrl: { pdfUrl: {
@ -32,7 +32,7 @@ const props = defineProps({
const pdfUrl = ref(props.pdfUrl) const pdfUrl = ref(props.pdfUrl)
const pdfContainer = ref(null) // canvas const pdfContainer = ref(null) // canvas
// worker // worker
pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.js' // pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.js'
const BACKEND_URL = getBackendUrl() const BACKEND_URL = getBackendUrl()
const pdfCanvas = ref(null) const pdfCanvas = ref(null)
function handleCancel(){ function handleCancel(){
@ -66,64 +66,42 @@ const pdfCanvas = ref(null)
// console.error('Error rendering PDF:', error) // console.error('Error rendering PDF:', error)
// } // }
// } // }
const renderPDF = async (url) => { // const renderPDF = async (url) => {
try { // try {
// 1 PDF // const pdfjsLib = await import('pdfjs-dist/legacy/build/pdf')
const loadingTask = pdfjsLib.getDocument(url) // if (pdfjsLib && pdfjsLib.GlobalWorkerOptions) {
const pdf = await loadingTask.promise // pdfjsLib.GlobalWorkerOptions.workerSrc = 'https://cdn.jsdelivr.net/npm/pdfjs-dist@3.11.174/build/pdf.worker.min.js'
console.log(`PDF loaded: ${pdf.numPages} pages`) // }
// const loadingTask = pdfjsLib.getDocument(url)
// 2 // const pdf = await loadingTask.promise
if (pdfContainer.value) { // if (pdfContainer.value) {
pdfContainer.value.innerHTML = '' // pdfContainer.value.innerHTML = ''
} // }
// const scale = 1.5
const scale = 1.5 // DPR // const pagePromises = []
const pagePromises = [] // for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) {
// pagePromises.push(renderPage(pdf, pageNum, scale))
// 3 // }
for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) { // await Promise.all(pagePromises)
pagePromises.push(renderPage(pdf, pageNum, scale)) // } catch (error) {
} // console.error('Error rendering PDF:', error)
// }
// 4 // }
await Promise.all(pagePromises)
console.log('✅ All PDF pages rendered successfully')
} catch (error) {
console.error('❌ Error rendering PDF:', error)
}
}
// renderPage 便 // renderPage 便
const renderPage = async (pdf, pageNum, scale) => { // const renderPage = async (pdf, pageNum, scale) => {
const page = await pdf.getPage(pageNum) // const page = await pdf.getPage(pageNum)
// const viewport = page.getViewport({ scale })
// viewport // const canvas = document.createElement('canvas')
const viewport = page.getViewport({ scale }) // const context = canvas.getContext('2d')
// canvas.height = viewport.height
// canvas // canvas.width = viewport.width
const canvas = document.createElement('canvas') // if (pdfContainer.value) {
const context = canvas.getContext('2d') // pdfContainer.value.appendChild(canvas)
canvas.height = viewport.height // }
canvas.width = viewport.width // const renderContext = { canvasContext: context, viewport }
// await page.render(renderContext).promise
// }
//
const pageNumberDiv = document.createElement('div')
//
if (pdfContainer.value) {
pdfContainer.value.appendChild(canvas)
}
//
const renderContext = {
canvasContext: context,
viewport,
}
//
await page.render(renderContext).promise
}
onMounted(() => { onMounted(() => {
// PDF URL // PDF URL
// renderPDF(`${BACKEND_URL}/202512070001/20251209141628/report_142802459.pdf`) // // renderPDF(`${BACKEND_URL}/202512070001/20251209141628/report_142802459.pdf`) //

View File

@ -24,7 +24,7 @@ export default defineConfig({
}, },
server: { server: {
port: 3000, port: 3000,
host: '0.0.0.0', host: 'localhost',
// 开发服务器配置 // 开发服务器配置
cors: true, cors: true,
strictPort: false strictPort: false