最新版Electron41+Vite8+Vue3+ElementPlus重构客户端仿微信聊天Exe

2026/11原创重构electron41+vue3+pinia4仿微信/QQ桌面聊天应用程序。

🚀 真香!Electron 41.2 全新升级,Vite8 + Vue3 集成,Pinia4状态管理,ElementPlus组件库,跨平台搭建仿微信/QQ客户端聊天系统EXE。深度封装 Electron 多开窗口管理,涵盖聊天、通讯录、收藏夹、朋友圈/短视频及我的模块。

360截图20261104130430191

使用技术

  • 编辑器:VScode
  • 跨平台框架: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^26.18.0
  • vite集成electron插件:vite-plugin-electron^1.2.0

p9

p1

项目目录结构

vite-electron-wechat客户端聊天系统,使用最新跨平台框架 Electron41 集成 Vite8 搭建项目模板。

360截图20261104113551571

哔哩哔哩/微信扫码预览👇

image

p2

Electron-ViteChat聊天项目已经发布到我的原创作品集,欢迎下载使用!

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

electron集成vite搭建跨平台聊天项目

image

image

p4

electron-vue3-chat实现类似微信QQ登录/主窗口切换,支持主题壁纸、自定义最大化/最小化/关闭按钮,新窗口打开朋友圈/短视频。聊天模块支持新开窗口预览视频、拖拽图片到聊天区域。

001360截图20261104132307605

012360截图20261104142857622

聊天布局面板

360截图20261104113551573

image

<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截图20261104132236573

002360截图20261104132452077

360截图20261104114021766

360截图20261104114445289

360截图20261104115141074

360截图20261104115415307

360截图20261104125043928

electron主进程/预加载配置

image

/**
 * 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()
})
/**
 * electron预加载文件配置
 * @author andy
 */

import { contextBridge, ipcRenderer } from 'electron'

contextBridge.exposeInMainWorld(
  'electron',
  {
    // 通过 channel 向主进程发送异步消息。主进程使用 ipcMain.on() 监听 channel
    send: (channel, args) => {
      ipcRenderer.send(channel, args)
    },

    // 通过 channel 向主进程发送消息,并异步等待结果。主进程应该使用 ipcMain.handle() 监听 channel
    invoke: (channel, args) => {
      return new Promise(resolve => ipcRenderer.invoke(channel, args).then(data => resolve(data)).catch(e => console.log(e)))
    },

    // 监听 channel 事件
    on: (channel, func) => {
      console.log('receive event')
      ipcRenderer.on(channel, (event, ...args) => func(event, ...args))
    },

    // 一次性监听事件
    once: (channel, func) => {
      ipcRenderer.once(channel, (event, ...args) => func(event, ...args))
    }
  }
)

360截图20261104130813639

003360截图20261104132924381

003360截图20261104133115470

004360截图20261104133530668

004360截图20261104133939132

005360截图20261104134018893

005360截图20261104134247148

005360截图20261104134348244

005360截图20261104134426163

005360截图20261104134610867

006360截图20261104134738189

006360截图20261104134908708

009360截图20261104142002802

008360截图20261104135635572

008360截图20261104135504516

008360截图20261104135653996

008360截图20261104135817004

008360截图20261104135933628

008360截图20261104140810619

008360截图20261104141500324

008360截图20261104141602291

008360截图20261104141910211

electron+vue3封装无边框导航栏

image

image

<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>

electron+vue3封装多窗口管理

012360截图20261104143148903

/**
 * 创建新窗口
 * @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,
  })
}

窗口支持如下参数配置

// 自定义窗口参数
const windowOptions = {
  // 窗口唯一标识id
  id: null,
  // 窗口标题
  title: 'Electron-ViteChat',
  // 窗口路由地址
  url: '',
  // 窗口数据传参
  data: null,
  // 是否是主窗口(为true则会关闭所有窗口并创建一个新窗口)
  isMajor: false,
  // 是否支持多开窗口(为true则支持创建多个窗口)
  isMultiple: false,
  // 窗口是否最大化
  maximize: false,
}

// 系统窗口参数(与electron的new BrowserWindow()参数一致)
const windowBaseOptions = {
  // 窗口图标
  icon: join(__root, 'resources/shortcut.ico'),
  // 是否自动隐藏菜单栏(按下Alt键显示)
  autoHideMenuBar: true,
  // 窗口标题栏样式
  titleBarStyle: 'hidden',
  // 窗口背景色
  backgroundColor: '#fff',
  // 宽度
  width: 840,
  // 高度
  height: 610,
  // 最小宽度
  minWidth: '',
  // 最小高度
  minHeight: '',
  // 窗口x坐标
  x: '',
  // 窗口y坐标
  y: '',
  // 是否可缩放
  resizable: true,
  // 是否可最小化
  minimizable: true,
  // 是否可最大化
  maximizable: true,
  // 是否可关闭
  closable: true,
  // 父窗口
  parent: null,
  // 是否模态窗口
  modal: false,
  // 窗口是否置顶
  alwaysOnTop: false,
  // 是否显示窗口边框(要创建无边框窗口,将frame参数设置为false)
  frame: false,
  // 是否透明窗口(仅frame: false有效)
  transparent: false,
  // 创建时是否显示窗口
  show: false,
}

electron自定义托盘提醒消息

p10

/** 
 * 系统托盘图标管理
 */
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('鼠标离开')
  })
}

Electron + Vite8 +  Vue3 Setup实战打造高性能聊天系统就分享到这里了。感谢大家的阅读与支持!

最新进阶项目作品👇

a88e58ebeaaf5f5a09a52686a388ed71_1289798-20251223105825806-389288273

仅15MB!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端】

 

posted @ 2026-11-04 18:07  xiaoyan2017  阅读(79)  评论(0)    收藏  举报
友情链接: UP主小店B站