123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>Electron测试</title>
- <style>
- body { font-family: Arial, sans-serif; padding: 20px; }
- button { padding: 10px 15px; margin-top: 20px; cursor: pointer; }
- #electron-info { margin-top: 20px; padding: 10px; background: #f0f0f0; }
- </style>
- </head>
- <body>
- <h1>Electron测试页面</h1>
- <p>如果您看到这个页面,说明Electron可以正常加载HTML。</p>
- <div id="electron-info"></div>
-
- <button id="loadApp">加载Vue应用</button>
- <button id="debugInfo">显示调试信息</button>
-
- <div id="debug-output" style="margin-top: 20px; white-space: pre; background: #eee; padding: 10px; display: none;"></div>
-
- <div style="margin-top: 20px;">
- <h3>直接访问路由</h3>
- <button id="loadReport">加载报表页面</button>
- <button id="loadTest">加载测试页面</button>
- </div>
-
- <div style="margin-top: 20px;">
- <h3>启动选项</h3>
- <label>
- <input type="checkbox" id="defaultLoad" checked>
- 下次启动时直接加载报表页面
- </label>
- <button id="saveSettings" style="margin-left: 10px;">保存设置</button>
- <div id="settingsStatus" style="margin-top: 5px; color: green;"></div>
- </div>
-
- <script>
- // 显示Electron版本信息
- document.getElementById('electron-info').textContent =
- window.electronAPI ? `Electron版本: ${window.electronAPI.versions.electron}` : '未检测到Electron API';
-
- // 加载Vue应用按钮
- document.getElementById('loadApp').addEventListener('click', function() {
- if (window.electronAPI && window.electronAPI.loadApp) {
- window.electronAPI.loadApp();
- } else {
- alert('无法加载应用,electronAPI未定义');
- }
- });
-
- // 显示调试信息按钮
- document.getElementById('debugInfo').addEventListener('click', function() {
- const debugOutput = document.getElementById('debug-output');
- debugOutput.style.display = debugOutput.style.display === 'none' ? 'block' : 'none';
-
- if (debugOutput.style.display === 'block') {
- let info = '';
- // 收集环境信息
- info += `User Agent: ${navigator.userAgent}\n`;
- info += `Platform: ${navigator.platform}\n`;
- info += `Screen: ${window.screen.width}x${window.screen.height}\n`;
-
- if (window.electronAPI) {
- info += `Electron: ${window.electronAPI.versions.electron}\n`;
- info += `Chrome: ${window.electronAPI.versions.chrome}\n`;
- info += `Node: ${window.electronAPI.versions.node}\n`;
- }
-
- debugOutput.textContent = info;
- }
- });
-
- // 添加直接访问路由的按钮事件
- document.getElementById('loadReport').addEventListener('click', function() {
- if (window.electronAPI && window.electronAPI.loadApp) {
- window.electronAPI.loadApp('/report');
- }
- });
-
- document.getElementById('loadTest').addEventListener('click', function() {
- if (window.electronAPI && window.electronAPI.loadApp) {
- window.electronAPI.loadApp('/test');
- }
- });
-
- // 添加保存设置的功能
- document.getElementById('saveSettings').addEventListener('click', function() {
- const defaultLoad = document.getElementById('defaultLoad').checked;
- const statusEl = document.getElementById('settingsStatus');
-
- if (window.electronAPI && window.electronAPI.saveSettings) {
- window.electronAPI.saveSettings({ defaultLoad: defaultLoad });
- statusEl.textContent = '设置已保存: ' + (defaultLoad ? '直接加载报表页面' : '显示测试页面');
- statusEl.style.display = 'block';
-
- // 3秒后隐藏状态信息
- setTimeout(() => {
- statusEl.style.display = 'none';
- }, 3000);
- } else {
- alert('无法保存设置,electronAPI未定义');
- }
- });
-
- // 在页面加载时获取当前设置
- window.addEventListener('DOMContentLoaded', async function() {
- if (window.electronAPI && window.electronAPI.getSettings) {
- try {
- const settings = await window.electronAPI.getSettings();
- console.log('当前设置:', settings);
-
- // 更新复选框状态
- if (settings && typeof settings.defaultLoad === 'boolean') {
- document.getElementById('defaultLoad').checked = settings.defaultLoad;
- }
- } catch (err) {
- console.error('获取设置失败:', err);
- }
- }
- });
- </script>
- </body>
- </html>
|