首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >2026重构版!Electron 41 + Vite8 + Pinia4 仿微信聊天客户端

2026重构版!Electron 41 + Vite8 + Pinia4 仿微信聊天客户端

原创
作者头像
andy2018
发布于 2026-11-05 11:05:08
发布于 2026-11-05 11:05:08
580
举报
文章被收录于专栏:h5h5

🎉 Electron 41 + Vite 8 + Vue3 + Element Plus 仿微信桌面端,快到飞起,内存仅占10M!

项目技术框架

  • 跨平台框架:electron41.2.0
  • 前端框架:vite^8.3.5+vue^3.5.44+vue-router^5.4.0
  • UI组件库: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

项目框架目录

electron+vue3聊天面板

代码语言:actionscript
复制
<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>

Electron入口配置

代码语言:actionscript
复制
/**
 * 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+Vue3封装无边框窗口导航栏

代码语言:actionscript
复制
<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多窗口调用

代码语言:actionscript
复制
// 登录窗口
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/微信托盘提醒

代码语言:actionscript
复制
/** 
 * 系统托盘图标管理
 */
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('鼠标离开')
  })
}

用 Electron41.2 + Vite 8 和 ElementPlus 重构你的桌面聊天应用,electron太香了!

仅15MB!Tauri 2.12 + Vite 8 + ElementPlus客户端Admin后台实战

全新升级!Tauri 2.12 + Vite 8 + ElementPlus 客户端聊天 架构实践

tauri2.9-vite7-vue3admin客户端后台系统管理Exe模板

electron38-vite7-vue3os电脑端os管理系统

最新版electron38-vite7-admin电脑端中后台管理系统

Electron38+Vite7+Pinia3+ElementPlus客户端聊天程序

最新款flutter3.41 & dart3.11仿写抖音app

升级款vite8+vue3.5+arcoDesign网页端webOS桌面框架

Electron-React19-WinChat聊天系统|react+electron客户端聊天程序Exe

React19+Arco+Zustand仿macOS风格webOS桌面系统

基于React19+Arco+Zustand5接入DeepSeek-V4网页版仿豆包/Kimi流式AI系统

Vite8.0+Vue3.5+Arco深度对接DeepSeek网页版AI智能助手

uni-app+mphtml快速集成DeepSeek-V4智能ai应用

2026原创自研React19+Vite8+ArcoDesign+Zustand中后台管理系统框架模板

自研Vite8+NaiveUI+Vue3+Echarts后台管理系统

全新研发Flutter3.41桌面版OS系统

Flutter3.41实战AI:从零到一构建app版流式ai系统

Electron41 + Vite8打造流式输出客户端AI助手

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

目录
  • 项目技术框架
  • 项目框架目录
  • electron+vue3聊天面板
  • Electron入口配置
  • Electron+Vue3封装无边框窗口导航栏
  • Electron多窗口调用
  • Electron自定义QQ/微信托盘提醒
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档