2026最新款Electron 41+Vite 8+ElementPlus仿微信客户端聊天Exe

0 阅读4分钟

重构完成!🎉 Electron 41 + Vite 8 + Vue3 + Pinia4 仿微信桌面端,HMR 快到飞起~

360截图20261104125043928.png

p1.gif

使用技术

  • 跨平台框架:Electron41.2.0
  • 前端技术框架:vite^8.3.5+vue^3.5.44+vue-router^5.4.0
  • 组件库:element-plus^2.14.7
  • 状态管理:pinia^4.1.0
  • 本地存储:pinia-plugin-persistedstate^4.7.1
  • 样式处理:sass^1.107.1
  • 打包管理:electron-builder^

360截图20261104120714110.png

p2.gif

p9.gif

项目目录结构

electron-vitechat使用最新跨平台框架Electron41集成Vite8搭建项目。

360截图20261104113551571.png

Electron41+Vite8+Vue3+ElementPlus仿微信客户端聊天系统

p3.gif

p5.gif

p6.gif

ElectronChat实现类似微信QQ登录/主窗口切换,主题壁纸、自定义最大化/最小化/关闭操作按钮,新窗口打开朋友圈/短视频。深度封装 Electron 多开窗口管理。

001360截图20261104132307605.png

012360截图20261104142857622.png

聊天面板布局

360截图20261104113551573.png

7a38d1a01768cfa947aa85f425926a64_1289798-20250913073839199-108741287.png

<script setup>
  import { useRoute } from 'vue-router'
  import { appState } from '@/pinia/modules/app'

  import MenuBar from './components/menubar/index.vue'
  import SideBar from './components/sidebar/index.vue'
  import ToolBar from './components/toolbar.vue'

  const route = useRoute()
  const appstate = appState()
</script>

<template>
  <div
    class="vu__container flex-c"
    :style="{'--themeSkin': appstate.config.skin, '--themeColor': appstate.config.skin ? '#fff' : '#191919'}"
  >
    <div class="vu__layout flexbox flex-col">
      <div class="vu__layout-body flex1 flexbox" @contextmenu.prevent>
        <!-- 菜单栏 -->
        <slot name="menubar">
          <MenuBar />
        </slot>

        <!-- 侧边栏 -->
        <slot name="sidebar">
          <SideBar />
        </slot>
        
        <!-- 主内容区 -->
        <div class="vu__layout-main flex1 flexbox flex-col">
          <ToolBar />
          <router-view v-slot="{ Component, route }">
            <keep-alive>
              <component :is="Component" :key="route.path" />
            </keep-alive>
          </router-view>
        </div>
      </div>
    </div>
  </div>
</template>

001360截图20261104132307602.png

002360截图20261104132452077.png

002360截图20261104132729853.png

003360截图20261104133115470.png

004360截图20261104133530668.png

004360截图20261104133939132.png

005360截图20261104134153732.png

005360截图20261104134247148.png

005360截图20261104134426163.png

005360截图20261104134610867.png

006360截图20261104134738189.png

electron进程配置

9e53ed11bf315826920c3c1a37274824_1289798-20250913074947075-1129199514.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()
})

01560fda56ec642a3c7ad1a08e293a0f_1289798-20261104175435261-1714192699.png

p9-1.gif

p9-2.gif

electron+vue3自定义无边框拖拽窗口导航

774e3cb8a5218d2af27a40eb1f5207d5_1289798-20261104180044177-1546639336.png

b8d120de5aaa892caed299d7768734ba_1289798-20250913080042252-589917298.png

<script setup>
  import { ref } from 'vue'
  import { isTrue } from '@/utils'

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

  import Winbtns from './btns.vue'

  const props = defineProps({
    // 标题
    title: {type: String, default: ''},
    // 标题颜色
    color: String,
    // 背景色
    background: String,
    // 标题是否居中
    center: {type: [Boolean, String], default: false},
    // 是否固定
    fixed: {type: [Boolean, String], default: false},
    // 背景是否镂空
    transparent: {type: [Boolean, String], default: false},
    // 层级
    zIndex: {type: [Number, String], default: 2024},

    /* 控制Winbtn参数 */
    // 窗口是否可最小化
    minimizable: {type: [Boolean, String], default: true},
    // 窗口是否可最大化
    maximizable: {type: [Boolean, String], default: true},
    // 窗口是否可关闭
    closable: {type: [Boolean, String], default: true},
  })
</script>

<template>
  <div class="ev__winbar" :class="{'fixed': fixed || transparent, 'transparent': transparent}">
    <div class="ev__winbar-wrap flexbox flex-alignc vu__drag">
      <div class="ev__winbar-body flex1 flexbox flex-alignc">
        <!-- 左侧区域 -->
        <div class="ev__winbar-left"><slot name="left" /></div>
        <!-- 标题 -->
        <div class="ev__winbar-title" :class="{'center': center}">
          <slot name="title">{{title}}</slot>
        </div>
        <!-- 右侧附加区域 -->
        <div class="ev__winbar-extra vu__undrag"><slot name="extra" /></div>
      </div>
      <Winbtns :color="color" :minimizable="minimizable" :maximizable="maximizable" :closable="closable" :zIndex="zIndex" />
    </div>
  </div>
</template>

360截图20261104131713472.png

electron封装多开窗口

360截图20261104120159706.png

/**
 * 创建新窗口
 * @param {object} args 窗口配置参数 {url: '/about', width: 500, height: 300, ...}
 */
export function winCreate(args) {
  window.electron.send('win-create', args)
}

通过如下方式快速创建一个新窗口。

// 登录窗口
export function loginWindow() {
  winCreate({
    url: '/login',
    title: '登录',
    width: 320,
    height: 380,
    isMajor: true,
    resizable: false,
    maximizable: false,
    alwaysOnTop: true
  })
}

// 关于窗口
export function aboutWindow() {
  winCreate({
    url: '/win/about',
    title: '关于',
    width: 375,
    height: 300,
    minWidth: 375,
    minHeight: 300,
    maximizable: false,
    alwaysOnTop: true,
  })
}

// 设置窗口
export function settingWindow() {
  winCreate({
    url: '/win/setting',
    title: '设置',
    width: 550,
    height: 470,
    resizable: false,
    maximizable: false,
  })
}

electron自定义仿微信/QQ托盘消息

p10.gif

/** 
 * 系统托盘图标管理
 */
trayManager() {
  if(this.tray) return
  const trayMenu = Menu.buildFromTemplate([
    {
      label: '打开主界面',
      icon: join(__root, 'resources/tray-win.png'),
      click: () => {
        this.winMain.restore()
        this.winMain.show()
      }
    },
    {
      label: '设置',
      icon: join(__root, 'resources/tray-setting.png'),
      click: () => this.sendByMainWin('win-ipcdata', {type: 'WINIPC_SETTINGWIN', value: null})
    },
    {
      label: '锁定系统',
      click: () => null,
    },
    {
      label: '关闭托盘闪烁',
      click: () => this.trayFlash(false)
    },
    {
      label: '关于',
      click: () => this.sendByMainWin('win-ipcdata', {type: 'WINIPC_ABOUTWIN', value: null})
    },
    {
      label: '退出聊天室',
      icon: join(__root, 'resources/tray-exit.png'),
      click: () => {
        dialog.showMessageBox(this.winMain, {
          title: '提示',
          message: '确定要退出聊天程序吗?',
          buttons: ['取消', '最小化托盘', '确认退出'],
          type: 'error',
          noLink: false,
          cancelId: 0,
        }).then(res => {
          // console.log(res)
          const index = res.response
          if(index == 0) {
            console.log('用户取消操作')
          }else if(index == 1) {
            console.log('最小化到托盘')
            this.winMain.hide()
          }else if(index == 2) {
            console.log('退出程序')
            this.sendByMainWin('win-ipcdata', {type: 'WINIPC_LOGOUT', value: null})
            app.quit()
          }
        })
      }
    }
  ])
  this.tray = new Tray(this.trayIcon)
  this.tray.setContextMenu(trayMenu)
  this.tray.setToolTip(app.name)
  this.tray.on('double-click', () => {
    console.log('tray double clicked!')
    this.winMain.restore()
    this.winMain.show()
  })
  this.tray.on('mouse-enter', (event, position) => {
    // console.log('鼠标划入', position)
    if(!this.hasFlash) return
    this.sendByMainWin('win-ipcdata', {type: 'WINIPC_MESSAGEWIN', value: position})
    // 简略消息通知
    /* this.tray.displayBalloon({
      iconType: 'none',
      title: 'Electron38研发组',
      content: 'Electron38+Vite7仿微信客户端聊天。'
    }) */
  })
  this.tray.on('mouse-leave', (event, position) => {
    // console.log('鼠标离开')
  })
}

Tauri2.12+Vite8+Vue3+ArcoDesign重写桌面OS系统

最新版Tauri 2.12+Vite8+Vue3+Element Plus重构桌面端后台管理系统

tauri2.12+vite8+vue3+pinia4+elementPlus仿微信/QQ聊天软件

最新版Flutter3.41+Dart3.11仿写抖音APP直播+短视频+聊天应用程序

Electron38-Wechat电脑端聊天|vite7+electron38仿微信桌面端聊天系统

Electron38-Vue3OS客户端OS系统|vite7+electron38+arco桌面os后台管理

electron38-admin桌面端后台|Electron38+Vue3+ElementPlus管理系统

vite8-webos网页版os管理|Vue3+Vite8.0+ArcoDesign搭建pc端os桌面系统

Vite8+DeepSeek-V4.1网页版AI助手|vue3+arco手搓web版ai流式问答系统

uniapp+deepseek-v4.1-flash+vue3跨端流式ai应用【h5+小程序+app端】

最新版uni-app+vue3+uv-ui跨三端仿微信app聊天应用【h5+小程序+app端】

Flutter3-MacOS桌面OS系统|flutter3.41+window_manager客户端OS模板

最新版Flutter3.41+Dart3.11跨平台仿微信app聊天界面|朋友圈

最新版uni-app+vue3+uv-ui跨端仿携程酒店预订模板【H5+小程序+App端】