添加测试信息

This commit is contained in:
yuding
2025-12-04 18:41:11 +08:00
parent 8a727c4485
commit 244891ceec
28 changed files with 41330 additions and 0 deletions

6
demo-vue/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
node_modules/
dist/
dist-ssr/
*.local
.DS_Store

91
demo-vue/README.md Normal file
View File

@@ -0,0 +1,91 @@
# BIM Engine SDK Vue3 Demo
这是一个使用 Vue3 + TypeScript 的演示项目,用于验证 BIM Engine SDK 在 Vue 环境下的兼容性。
## 前置要求
1. 确保父项目已经构建完成:
```bash
cd ..
npm run build
```
2. 安装依赖:
```bash
npm install
```
3. 复制 SDK 文件到 public 目录:
```bash
npm run copy-sdk
```
或者手动复制:
```bash
mkdir -p public/lib
cp ../dist/bim-engine-sdk.umd.js public/lib/
cp ../dist/bim-engine-sdk.umd.js.map public/lib/
```
## 运行
### 开发模式
```bash
npm run dev
```
服务器会在 `http://localhost:8081` 启动,并自动打开浏览器。
### 构建
```bash
npm run build
```
构建后的文件会在 `dist` 目录中。
### 预览构建结果
```bash
npm run preview
```
## 项目结构
```
demo-vue/
├── src/
│ ├── App.vue # 主组件(包含所有功能)
│ ├── main.ts # Vue3 入口文件
│ ├── style.css # 全局样式
│ └── vite-env.d.ts # TypeScript 类型声明
├── public/
│ ├── lib/ # SDK 文件目录
│ │ └── bim-engine-sdk.umd.js
│ └── model/ # 3D 模型文件
│ └── gujianzhu.glb
├── index.html # HTML 入口
├── package.json # 项目配置
├── vite.config.ts # Vite 配置
├── tsconfig.json # TypeScript 配置
└── README.md # 说明文档
```
## 使用说明
1. 点击 "初始化引擎" 按钮初始化 3D 引擎
2. 点击 "加载模型" 按钮加载 3D 模型
3. 其他功能按钮可以测试 SDK 的各种功能
## 技术栈
- Vue 3.4+ (Composition API)
- TypeScript 5.9+
- Vite 7.2+
## 注意事项
- 确保父项目的 `dist` 目录中有构建好的 SDK 文件
- 模型文件路径是相对于 `public` 目录的
- 使用 HTTP 服务器运行(不能直接打开 HTML 文件)以避免 CORS 问题

16
demo-vue/index.html Normal file
View File

@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BIM Engine SDK Vue3 Demo</title>
<!-- 从 public/lib 目录加载 SDK 文件 -->
<script src="/lib/bim-engine-sdk.umd.js"></script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>

1455
demo-vue/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

22
demo-vue/package.json Normal file
View File

@@ -0,0 +1,22 @@
{
"name": "bim-engine-demo-vue",
"version": "1.0.0",
"description": "BIM Engine SDK Vue3 Demo",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc && vite build",
"preview": "vite preview",
"copy-sdk": "mkdir -p public/lib && cp ../dist/bim-engine-sdk.umd.js public/lib/ && cp ../dist/bim-engine-sdk.umd.js.map public/lib/ 2>/dev/null || true"
},
"dependencies": {
"vue": "^3.4.21"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.4",
"typescript": "^5.9.3",
"vite": "^6.0.0",
"vue-tsc": "^2.0.6"
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

396
demo-vue/src/App.vue Normal file
View File

@@ -0,0 +1,396 @@
<template>
<div class="app-container">
<!-- 左侧控制面板 -->
<aside class="sidebar">
<h1>BIM SDK Demo (Vue3)</h1>
<!-- 1. 语言设置 -->
<div class="control-group">
<h2>🌍 语言 (Language)</h2>
<div class="btn-container">
<button class="primary" @click="setLang('zh-CN')">中文</button>
<button class="primary" @click="setLang('en-US')">English</button>
</div>
</div>
<!-- 2. 弹窗测试 -->
<div class="control-group">
<h2>🪟 弹窗 (Dialog)</h2>
<div class="btn-container">
<button @click="openTestDialog">测试弹窗</button>
<button @click="openInfoDialog">信息弹窗</button>
<button @click="openRedDialog">警告弹窗</button>
</div>
</div>
<!-- 3. 工具栏操作 -->
<div class="control-group">
<h2>🛠 工具栏 (Toolbar)</h2>
<div class="btn-container">
<button @click="toggleToolbar">显隐工具栏</button>
<button @click="toggleLabel">显隐标签</button>
<button @click="toggleLocationBtn">显隐定位按钮</button>
</div>
<div class="btn-container" style="margin-top: 8px;">
<button @click="addCustomGroup">加组</button>
<button @click="addCustomButton">加按钮</button>
</div>
</div>
<!-- 4. 样式主题 -->
<div class="control-group">
<h2>🎨 样式 (Theme)</h2>
<div class="btn-container">
<button @click="setTheme('dark')">深色 (Dark)</button>
<button @click="setTheme('light')">浅色 (Light)</button>
<button @click="setCustomTheme">自定义 (Red)</button>
</div>
</div>
<!-- 5. 3D 引擎 -->
<div class="control-group">
<h2>🎮 3D 引擎 (Engine)</h2>
<div class="btn-container">
<button class="primary" @click="initEngine">初始化引擎</button>
<button class="primary" @click="loadModel">加载模型</button>
</div>
<div style="margin-top: 10px; font-size: 0.85rem; color: #666;">
<div>状态: <span :style="{ color: engineStatusColor }">{{ engineStatus }}</span></div>
</div>
</div>
</aside>
<!-- 右侧主区域 -->
<main class="main-content">
<div ref="appContainer" id="app-container"></div>
</main>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue';
// 响应式状态
const appContainer = ref<HTMLElement | null>(null);
const engine = ref<any>(null);
const isToolbarVisible = ref(true);
const isLabelVisible = ref(true);
const isLocationVisible = ref(true);
const customGroupAdded = ref(false);
const engineStatus = ref('未初始化');
const engineStatusColor = ref('#666');
// 初始化引擎
onMounted(() => {
if (window.LyzBimEngineSDK) {
const Engine = window.LyzBimEngineSDK.BimEngine;
try {
if (appContainer.value) {
engine.value = new Engine(appContainer.value, { locale: 'zh-CN' });
initEngine();
console.log('Engine initialized:', engine.value);
}
} catch (err) {
console.error('Init failed:', err);
}
} else {
console.error('SDK not found');
}
});
// 清理资源
onUnmounted(() => {
if (engine.value) {
engine.value.destroy();
}
});
// 更新引擎状态
const updateEngineStatus = (status: string) => {
engineStatus.value = status;
if (status === '已初始化') {
engineStatusColor.value = '#28a745';
} else if (status === '初始化失败' || status === '初始化错误') {
engineStatusColor.value = '#dc3545';
} else {
engineStatusColor.value = '#666';
}
};
// --- 语言设置 ---
const setLang = (lang: 'zh-CN' | 'en-US') => {
if (engine.value) {
engine.value.setLocale(lang);
}
};
// --- 弹窗测试 ---
const openTestDialog = () => {
if (!engine.value || !engine.value.dialog) return;
engine.value.dialog.create({
title: 'dialog.testTitle',
width: 350,
height: 200,
position: 'center',
draggable: true,
resizable: true
});
};
const openInfoDialog = () => {
if (!engine.value || !engine.value.dialog) return;
engine.value.dialog.showInfoDialog();
};
const openRedDialog = () => {
if (!engine.value || !engine.value.dialog) return;
engine.value.dialog.create({
title: 'Alert',
content: '<div style="color: #ffcccc;">Critical Warning!</div>',
width: 300,
height: 150,
backgroundColor: 'rgba(100, 0, 0, 0.95)',
headerBackgroundColor: '#cc0000',
titleColor: '#ffffff',
borderColor: '#ff6666',
position: { x: 50, y: 50 }
});
};
// --- 工具栏操作 ---
const toggleToolbar = () => {
if (!engine.value || !engine.value.toolbar) return;
isToolbarVisible.value = !isToolbarVisible.value;
engine.value.toolbar.setVisible(isToolbarVisible.value);
};
const toggleLabel = () => {
if (!engine.value || !engine.value.toolbar) return;
isLabelVisible.value = !isLabelVisible.value;
engine.value.toolbar.setShowLabel(isLabelVisible.value);
};
const toggleLocationBtn = () => {
if (!engine.value || !engine.value.toolbar) return;
isLocationVisible.value = !isLocationVisible.value;
engine.value.toolbar.setButtonVisibility('location', isLocationVisible.value);
};
const addCustomGroup = () => {
if (!engine.value || !engine.value.toolbar) return;
if (customGroupAdded.value) {
alert('已添加过');
return;
}
engine.value.toolbar.addGroup('custom-group', 'group-1');
customGroupAdded.value = true;
};
const addCustomButton = () => {
if (!engine.value || !engine.value.toolbar) return;
if (!customGroupAdded.value) {
alert('Please add custom group first / 请先添加自定义组');
return;
}
const btnId = 'custom-btn-' + Date.now();
engine.value.toolbar.addButton({
id: btnId,
groupId: 'custom-group',
type: 'button',
label: 'New',
icon: '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"></circle><path d="M8 14s1.5 2 4 2 4-2 4-2"></path><line x1="9" y1="9" x2="9.01" y2="9"></line><line x1="15" y1="9" x2="15.01" y2="9"></line></svg>',
onClick: (btn: any) => {
alert('Clicked: ' + btn.label);
}
});
};
// --- 主题操作 ---
const setTheme = (themeName: 'dark' | 'light') => {
if (engine.value) {
engine.value.setTheme(themeName);
}
};
const setCustomTheme = () => {
if (!engine.value) return;
// 定义一个红色主题
engine.value.setCustomTheme({
name: 'red-alert',
primary: '#d32f2f',
primaryHover: '#b71c1c',
background: '#ffebee', // 浅红背景
panelBackground: 'rgba(255, 255, 255, 0.9)',
textPrimary: '#b71c1c',
textSecondary: '#e57373',
border: '#ffcdd2',
icon: '#d32f2f',
iconActive: '#b71c1c',
componentBackground: 'rgba(255, 205, 210, 0.3)',
componentHover: 'rgba(255, 205, 210, 0.8)',
componentActive: '#e57373'
});
};
// --- 3D 引擎操作 ---
/**
* 初始化 3D 引擎
*/
const initEngine = () => {
if (!engine.value || !engine.value.engine) {
alert('引擎未创建,请先等待页面加载完成');
return;
}
if (engine.value.engine.isInitialized()) {
alert('3D 引擎已经初始化过了');
updateEngineStatus('已初始化');
return;
}
try {
// 初始化引擎,使用默认配置
const success = engine.value.initEngine({
backgroundColor: 0x333333, // 深色背景
version: 'v1', // WebGL 版本
showStats: true, // 显示性能统计
showViewCube: true // 显示视图立方体
});
if (success) {
updateEngineStatus('已初始化');
console.log('✅ 3D 引擎初始化成功');
} else {
updateEngineStatus('初始化失败');
console.error('❌ 3D 引擎初始化失败');
}
} catch (error: any) {
updateEngineStatus('初始化错误');
console.error('❌ 3D 引擎初始化错误:', error);
}
};
/**
* 加载 3D 模型
*/
const loadModel = () => {
if (!engine.value || !engine.value.engine) {
alert('引擎未创建,请先等待页面加载完成');
return;
}
if (!engine.value.engine.isInitialized()) {
alert('请先初始化 3D 引擎!');
return;
}
try {
// 加载模型文件(从 model 目录)
const modelUrl = '/model/gujianzhu.glb';
engine.value.engine.loadModel(modelUrl, {
position: [0, 0, 0], // 初始位置
rotation: [0, 0, 0], // 初始旋转
scale: [1, 1, 1] // 初始缩放
});
console.log('✅ 模型加载请求已发送:', modelUrl);
} catch (error: any) {
console.error('❌ 模型加载错误:', error);
}
};
</script>
<style scoped>
.app-container {
width: 100%;
height: 100%;
display: flex;
overflow: hidden;
}
/* 左侧侧边栏:控制面板 */
.sidebar {
width: 320px;
background: white;
border-right: 1px solid #e0e0e0;
padding: 20px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 20px;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
z-index: 10;
}
.sidebar h1 {
font-size: 1.4rem;
color: #333;
margin-bottom: 10px;
}
.control-group {
background: #f9f9f9;
padding: 15px;
border-radius: 8px;
border: 1px solid #eee;
}
.control-group h2 {
font-size: 1rem;
color: #555;
margin-bottom: 10px;
padding-bottom: 5px;
border-bottom: 2px solid #e0e0e0;
}
.btn-container {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
button {
padding: 6px 12px;
font-size: 0.9rem;
border: 1px solid #ddd;
background: #fff;
border-radius: 4px;
cursor: pointer;
transition: all 0.2s;
flex: 1 1 auto;
}
button:hover {
background: #f0f0f0;
border-color: #ccc;
}
button.primary {
background: #0078d4;
color: white;
border-color: #0063b1;
}
button.primary:hover {
background: #0063b1;
}
/* 右侧主内容区:引擎展示 */
.main-content {
flex: 1;
position: relative;
background: #eef2f5;
display: flex;
justify-content: center;
align-items: center;
}
#app-container {
width: 100%;
height: 100%;
background: #fff;
position: relative;
}
</style>

6
demo-vue/src/main.ts Normal file
View File

@@ -0,0 +1,6 @@
import { createApp } from 'vue';
import App from './App.vue';
import './style.css';
createApp(App).mount('#app');

20
demo-vue/src/style.css Normal file
View File

@@ -0,0 +1,20 @@
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f5f5f5;
height: 100vh;
display: flex;
overflow: hidden;
}
#app {
width: 100%;
height: 100%;
display: flex;
}

19
demo-vue/src/vite-env.d.ts vendored Normal file
View File

@@ -0,0 +1,19 @@
/// <reference types="vite/client" />
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
// 声明全局 SDK 类型
declare global {
interface Window {
LyzBimEngineSDK: {
BimEngine: any;
};
}
}
export {}

32
demo-vue/tsconfig.json Normal file
View File

@@ -0,0 +1,32 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
/* Path alias */
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}

View File

@@ -0,0 +1,11 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}

17
demo-vue/vite.config.ts Normal file
View File

@@ -0,0 +1,17 @@
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
export default defineConfig({
plugins: [vue()],
server: {
port: 8081,
open: true
},
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
}
});