| <script setup lang="ts"> |
| import { ref, onMounted } from 'vue' |
| |
| const version = ref('Loading...') |
| const platform = ref('Loading...') |
| const message = ref('') |
| |
| onMounted(() => { |
| |
| window.ipcRenderer.on('main-process-message', (_event, value) => { |
| console.log(value) |
| }) |
| |
| |
| |
| window.ipcRenderer.invoke('get-system-info').then((info) => { |
| version.value = info.version |
| platform.value = info.platform |
| }) |
| }) |
| |
| const sendMessage = () => { |
| |
| window.ipcRenderer.send('message-from-renderer', 'Hello from Vue 3!') |
| message.value = 'Message sent to main process!' |
| setTimeout(() => { |
| message.value = '' |
| }, 3000) |
| } |
| |
| const openNewWindow = () => { |
| |
| window.ipcRenderer.send('open-new-window') |
| } |
| </script> |
| |
| <template> |
| <div class="container"> |
| <header> |
| <h1>Electron 跨平台应用 (Vue 3)</h1> |
| <p class="subtitle">高性能、安全、跨平台的桌面解决方案</p> |
| </header> |
| |
| <main> |
| <section class="info-card"> |
| <h2>系统信息</h2> |
| <div class="info-grid"> |
| <div class="info-item"> |
| <span class="label">Electron 版本:</span> |
| <span class="value">{{ version }}</span> |
| </div> |
| <div class="info-item"> |
| <span class="label">操作系统:</span> |
| <span class="value">{{ platform }}</span> |
| </div> |
| </div> |
| </section> |
| |
| <section class="actions"> |
| <h2>核心功能演示 (IPC)</h2> |
| <div class="button-group"> |
| <button @click="sendMessage" class="btn primary">发送 IPC 消息</button> |
| <button @click="openNewWindow" class="btn secondary">打开新窗口 (BrowserWindow)</button> |
| </div> |
| <p v-if="message" class="status-msg">{{ message }}</p> |
| </section> |
| |
| <section class="tech-stack"> |
| <h2>技术栈</h2> |
| <ul> |
| <li><strong>核心框架:</strong> Electron, Node.js, Vue 3, Chromium</li> |
| <li><strong>辅助工具:</strong> Electron Builder, Vite</li> |
| <li><strong>开发语言:</strong> TypeScript</li> |
| </ul> |
| </section> |
| </main> |
| |
| <footer> |
| <p>© 2024 Electron Cross-Platform Demo</p> |
| </footer> |
| </div> |
| </template> |
| |
| <style scoped> |
| :root { |
| --primary-color: #42b883; |
| --secondary-color: #35495e; |
| --text-color: #2c3e50; |
| --bg-color: #f8f9fa; |
| } |
| |
| .container { |
| max-width: 800px; |
| margin: 0 auto; |
| padding: 2rem; |
| font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; |
| color: var(--text-color); |
| } |
| |
| header { |
| text-align: center; |
| margin-bottom: 3rem; |
| } |
| |
| h1 { |
| font-size: 2.5rem; |
| color: var(--secondary-color); |
| margin-bottom: 0.5rem; |
| } |
| |
| .subtitle { |
| color: #666; |
| font-size: 1.1rem; |
| } |
| |
| main { |
| display: flex; |
| flex-direction: column; |
| gap: 2rem; |
| } |
| |
| .info-card, .actions, .tech-stack { |
| background: white; |
| padding: 1.5rem; |
| border-radius: 12px; |
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05); |
| } |
| |
| h2 { |
| margin-top: 0; |
| margin-bottom: 1rem; |
| font-size: 1.25rem; |
| border-bottom: 2px solid var(--primary-color); |
| padding-bottom: 0.5rem; |
| display: inline-block; |
| } |
| |
| .info-grid { |
| display: grid; |
| grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); |
| gap: 1rem; |
| } |
| |
| .info-item { |
| display: flex; |
| flex-direction: column; |
| } |
| |
| .label { |
| font-size: 0.9rem; |
| color: #888; |
| } |
| |
| .value { |
| font-weight: bold; |
| font-size: 1.1rem; |
| } |
| |
| .button-group { |
| display: flex; |
| gap: 1rem; |
| margin-top: 1rem; |
| } |
| |
| .btn { |
| padding: 0.75rem 1.5rem; |
| border: none; |
| border-radius: 6px; |
| cursor: pointer; |
| font-weight: 600; |
| transition: all 0.2s; |
| } |
| |
| .btn.primary { |
| background-color: var(--primary-color); |
| color: white; |
| } |
| |
| .btn.primary:hover { |
| background-color: #3aa876; |
| } |
| |
| .btn.secondary { |
| background-color: var(--secondary-color); |
| color: white; |
| } |
| |
| .btn.secondary:hover { |
| background-color: #2c3e50; |
| } |
| |
| .status-msg { |
| margin-top: 1rem; |
| color: var(--primary-color); |
| font-weight: 500; |
| } |
| |
| ul { |
| list-style-type: none; |
| padding: 0; |
| } |
| |
| li { |
| margin-bottom: 0.5rem; |
| } |
| |
| footer { |
| margin-top: 4rem; |
| text-align: center; |
| color: #888; |
| font-size: 0.9rem; |
| } |
| </style> |
| |