头图

引言

半个月之前有分享一款electron31+vue3桌面端admin管理系统。今天再分享一款最新原创研发的Electron32+Vite5桌面版OS系统管理模板ElectronViteOS

运用技术

  • 编辑器:VScode
  • 技术框架:Vite^5.4.1+Vue^3.4.37+Vue-router^4.4.3
  • 跨平台框架:Electron^32.0.1
  • 组件库:@arco-design/web-vue^2.56.0
  • 状态插件:pinia^2.2.2
  • 拖拽插件:sortablejs^1.15.2
  • 图表组件:echarts^5.5.1
  • markdown编辑器:md-editor-v3^4.19.2
  • 模拟数据:mockjs^1.1.0
  • 打包构建:electron-builder^24.13.3
  • electron+vite插件:vite-plugin-electron^0.28.7

vite5-electronOS内置了macos+windows两种桌面风格模板。基于Electron32封装高性能多窗口管理,采用自研栅格化拖拽布局引擎

项目结构框架

electron-vue3os基于vite5.x整合最新跨平台技术electron32.x搭建项目模板。

目前electron32-vue3os项目已经同步到我的原创作品集,欢迎下载使用。
https://gf.bilibili.com/item/detail/1106958011

electron主进程配置

image.png

/**
 * electron主线程配置
 * @author andy
 */

import { app, BrowserWindow } from 'electron'

import { WindowManager } from '../src/windows/index.js'

// 忽略安全警告提示 Electron Security Warning (Insecure Content-Security-Policy)
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = true

const createWindow = () => {
  let win = new WindowManager()
  win.create({isMajor: true})
  // 系统托盘管理
  win.trayManager()
  // 监听ipcMain事件
  win.ipcManager()
}

app.whenReady().then(() => {
  createWindow()

  app.on('activate', () => {
    if(BrowserWindow.getAllWindows().length === 0) createWindow()
  })
})

app.on('window-all-closed', () => {
  if(process.platform !== 'darwin') app.quit()
})

main.js配置

import { createApp } from 'vue'
import './style.scss'
import App from './App.vue'

import { launchApp } from '@/windows/actions'

// 引入路由及状态管理
import Router from './router'
import Pinia from './pinia'

// 引入插件
import Plugins from './plugins'

launchApp().then(config => {
  if(config) {
    // 全局窗口配置
    window.config = config
  }

  // 初始化app实例
  createApp(App)
  .use(Router)
  .use(Pinia)
  .use(Plugins)
  .mount('#app')
})

vue3-electron-os桌面模板

e632010e2afbd7ca7a584e0f629f021e_1289798-20240904103339276-1644289602.png

<script setup>
  import { appState } from '@/pinia/modules/app'

  // 引入布局模板
  import MacosLayout from './template/macos.vue'
  import WindowsLayout from './template/windows.vue'

  const appstate = appState()

  const DeskLayout = {
    macos: MacosLayout,
    windows: WindowsLayout
  }
</script>

<template>
  <div class="vu__container" :style="{'--themeSkin': appstate.config.skin}">
    <component :is="DeskLayout[appstate.config.layout]" />
  </div>
</template>

736f79ba23c1e6545926ae1f09f9fe70_1289798-20240904104159042-1771832206.png

<script setup>
  import Wintool from '@/layouts/components/wintool/index.vue'
  import Desk from '@/layouts/components/mac/desk.vue'
  import Dock from '@/layouts/components/mac/dock.vue'
</script>

<template>
  <div class="vu__layout flexbox flex-col">
    <div class="vu__layout-header">
      <Wintool />
    </div>
    <div class="vu__layout-body flex1 flexbox">
      <Desk />
    </div>
    <div class="vu__layout-footer">
      <Dock />
    </div>
  </div>
</template>

vue3+electron实现栅格模板

0b5902729ac79c9277e933dd0311d179_1289798-20240904111140199-417397678.png

48b658acc05d236acc8611ffc84b3e07_1289798-20240904110945564-1083810895.png

桌面json配置参数

/**
  * label 图标标签
  * imgico 图标(本地或网络图片) 支持Arco Design内置图标或自定义iconfont字体图标
  * path 跳转路由地址
  * link 跳转外部链接
  * hideLabel 是否隐藏图标标签
  * background 自定义图标背景色
  * color 自定义图标颜色
  * size 栅格布局(16种) 1x1 1x2 1x3 1x4、2x1 2x2 2x3 2x4、3x1 3x2 3x3 3x4、4x1 4x2 4x3 4x4
  * onClick 点击图标回调函数
  * children 二级菜单配置  * isNewin 新窗口打开路由页面
  */

ae8f53b948884a8e604f379003c4a448_1289798-20240904112020699-1901923726.png

f5c9b4afdc8cda5b6438d917d004d772_1289798-20240904112048743-626676603.png

桌面菜单配置示例

const deskMenu = [
  {
    uid: 'd137f210-507e-7e8e-1950-9deefac27e48',
    list: [
      {imgico: markRaw(Today), size: '2x2'},
      {label: '日历', imgico: markRaw(Calendar3x3), size: '3x3'},
      {label: 'Electron32', imgico: '/electron.svg', link: 'https://www.electronjs.org/'},
      // ...
    ]
  },
  {
    uid: 'g270f210-207e-6e8e-2650-9deefac27e48',
    list: [
      {label: 'Appstore', imgico: '/static/mac/appstore.png'},
      // ...
    ]
  },
  {
    uid: 't165f210-607e-4e8e-9950-9deefac27e48',
    list: [
      {label: 'Vue.js', imgico: '/vue.svg', link: 'https://vuejs.org/',},
      {label: 'Vite.js官方文档', imgico: '/vite.svg', link: 'https://vitejs.dev/',},
      // ...
    ]
  },
  {
    uid: 'u327f210-207e-1e8e-9950-9deefac27e48',
    list: [
      {label: 'Electron32', imgico: '/electron.svg', link: 'https://www.electronjs.org/'},
      {label: '首页', imgico: markRaw(IconHome), path: '/home', color: '#fff', isNewin: true},
      {label: '工作台', imgico: 'elec-icon-dotchart', path: '/home/dashboard', color: '#fff'},
      // ...
      {
        label: '用户中心',
        children: [
          {label: '主页', imgico: '/static/svg/ucenter.svg', path: '/setting'},
          {label: '用户管理', imgico: markRaw(IconUserGroup), path: '/user', color: '#fff'},
          // ...
        ]
      },
      {
        label: '设置',
        children: [
          // ...
        ]
      },
      {
        label: '收藏网址',
        children: [
          {label: 'Electron32', imgico: '/electron.svg', link: 'https://www.electronjs.org/'},
          {label: 'Vite.js', imgico: '/vite.svg',},
          // ...
        ]
      },
      {
        label: '公众号', imgico: '/static/qrimg.png', color: '#07c160',
        onClick: () => {
          Modal.info({
            // ...
          })
        }
      },
    ]
  }
]

基于electron32+vue3实战桌面os系统就分享到这里,希望对大家有所帮助!

https://segmentfault.com/a/1190000045042968
https://segmentfault.com/a/1190000044899693
https://segmentfault.com/a/1190000044847552


xiaoyan2017
765 声望318 粉丝

web前端开发爱好者,专注于前端h5、jquery、vue、react、angular等技术研发实战项目案例。