Electron38-Wechat電腦端聊天|vite7+electron38仿微信桌面端聊天系統(tǒng)
最新研發(fā)Electron38+Vite7+Pinia3客戶端仿微信聊天系統(tǒng)ElectronWinChat。
electron38-vue3-wechat基于vite7.1+electron38+pinia3+element-plus跨平臺(tái)仿微信/QQ電腦端聊天Exe程序。封裝electron多窗口管理、自定義系統(tǒng)導(dǎo)航欄。實(shí)現(xiàn)聊天、通訊錄、收藏、朋友圈/短視頻、我的等模塊。

Electron38-Vue3OS客戶端OS系統(tǒng)|vite7+electron38+arco桌面os后臺(tái)管理
electron38-admin桌面端后臺(tái)|Electron38+Vue3+ElementPlus管理系統(tǒng)
使用技術(shù)
- 編輯器:VScode
- 技術(shù)框架:Electron38.0.0+Vite7.1.2+Vue3.5.18+vue-router4.5.1
- UI組件庫(kù):element-plus^2.11.2
- 狀態(tài)管理:pinia^3.0.3
- 存儲(chǔ)服務(wù):pinia-plugin-persistedstate^4.5.0
- 打包構(gòu)建:electron-builder^24.13.3
- electron結(jié)合vite插件:vite-plugin-electron^0.29.0


項(xiàng)目結(jié)構(gòu)框架
vue3-electronchat桌面端聊天項(xiàng)目采用最新版 vite7+electron38 搭建項(xiàng)目模板。

Electron38-ViteChat聊天項(xiàng)目已經(jīng)更新到我的原創(chuàng)作品集,感謝支持!

通用布局模板
項(xiàng)目整體分為左側(cè)菜單欄+側(cè)邊欄+右側(cè)內(nèi)容區(qū)(自定義導(dǎo)航條)等模塊。


<template> <template v-if="!route?.meta?.isNewWin"> <div class="vu__container flexbox flex-alignc flex-justifyc" :style="{'--themeSkin': appstate.config.skin}" > <div class="vu__layout flexbox flex-col"> <div class="vu__layout-body flex1 flexbox" @contextmenu.prevent> <!-- 菜單欄 --> <slot v-if="!route?.meta?.hideMenuBar" name="menubar"> <MenuBar /> </slot> <!-- 側(cè)邊欄 --> <div v-if="route?.meta?.showSideBar" class="vu__layout-sidebar flexbox"> <aside class="vu__layout-sidebar__body flexbox flex-col"> <slot name="sidebar"> <SideBar /> </slot> </aside> </div> <!-- 主內(nèi)容區(qū) --> <div class="vu__layout-main flex1 flexbox flex-col"> <ToolBar v-if="!route?.meta?.hideToolBar" /> <router-view v-slot="{ Component, route }"> <keep-alive> <component :is="Component" :key="route.path" /> </keep-alive> </router-view> </div> </div> </div> </div> </template> <template v-else> <WinLayout /> </template> </template>




























Electron主進(jìn)程/預(yù)加載文件配置

/** * electron主進(jìn)程配置 * @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}) // 系統(tǒng)托盤管理 win.trayManager() // 監(jiān)聽(tīng)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預(yù)加載文件配置 * @author andy */ import { contextBridge, ipcRenderer } from 'electron' contextBridge.exposeInMainWorld( 'electron', { // 通過(guò) channel 向主進(jìn)程發(fā)送異步消息。主進(jìn)程使用 ipcMain.on() 監(jiān)聽(tīng) channel send: (channel, args) => { ipcRenderer.send(channel, args) }, // 通過(guò) channel 向主進(jìn)程發(fā)送消息,并異步等待結(jié)果。主進(jìn)程應(yīng)該使用 ipcMain.handle() 監(jiān)聽(tīng) channel invoke: (channel, args) => { return new Promise(resolve => ipcRenderer.invoke(channel, args).then(data => resolve(data)).catch(e => console.log(e))) }, // 監(jiān)聽(tīng) channel 事件 on: (channel, func) => { console.log('receive event') ipcRenderer.on(channel, (event, ...args) => func(event, ...args)) }, // 一次性監(jiān)聽(tīng)事件 once: (channel, func) => { ipcRenderer.once(channel, (event, ...args) => func(event, ...args)) }, setTitle: (title) => ipcRenderer.send('win-setTitle', title) } )
Electron+Vue3自定義系統(tǒng)無(wú)邊框拖拽窗口|導(dǎo)航欄





項(xiàng)目自定義無(wú)邊框iframe:false窗口拖拽導(dǎo)航欄。

<script setup> import { ref } from 'vue' import { isTrue } from '@/utils' import { winSet } from '@/windows/actions' import Winbtns from './btns.vue' const props = defineProps({ // 標(biāo)題 title: {type: String, default: ''}, // 標(biāo)題顏色 color: String, // 背景色 background: String, // 標(biāo)題是否居中 center: {type: [Boolean, String], default: false}, // 是否固定 fixed: {type: [Boolean, String], default: false}, // 背景是否鏤空 transparent: {type: [Boolean, String], default: false}, // 層級(jí) zIndex: {type: [Number, String], default: 2024}, /* 控制Winbtn參數(shù) */ // 窗口是否可最小化 minimizable: {type: [Boolean, String], default: true}, // 窗口是否可最大化 maximizable: {type: [Boolean, String], default: true}, // 窗口是否可關(guān)閉 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"> <!-- 左側(cè)區(qū)域 --> <div class="ev__winbar-left"><slot name="left" /></div> <!-- 標(biāo)題 --> <div class="ev__winbar-title" :class="{'center': center}"> <slot name="title">{{title}}</slot> </div> <!-- 右側(cè)附加區(qū)域 --> <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+Vite7封裝新開(kāi)多窗口

項(xiàng)目支持同時(shí)打開(kāi)多個(gè)窗口,調(diào)用封裝函數(shù)即可快速創(chuàng)建一個(gè)新窗口。
/** * 創(chuàng)建新窗口 * @param {object} args 窗口配置參數(shù) {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 }) } // 關(guān)于窗口 export function aboutWindow() { winCreate({ url: '/win/about', title: '關(guān)于', width: 375, height: 300, minWidth: 375, minHeight: 300, maximizable: false, alwaysOnTop: true, }) } // 設(shè)置窗口 export function settingWindow() { winCreate({ url: '/win/setting', title: '設(shè)置', width: 550, height: 470, resizable: false, maximizable: false, }) }
窗口參數(shù)配置
// 自定義窗口參數(shù) const windowOptions = { // 窗口唯一標(biāo)識(shí)id id: null, // 窗口標(biāo)題 title: 'Electron-ViteChat', // 窗口路由地址 url: '', // 窗口數(shù)據(jù)傳參 data: null, // 是否是主窗口(為true則會(huì)關(guān)閉所有窗口并創(chuàng)建一個(gè)新窗口) isMajor: false, // 是否支持多開(kāi)窗口(為true則支持創(chuàng)建多個(gè)窗口) isMultiple: false, // 窗口是否最大化 maximize: false, } // 系統(tǒng)窗口參數(shù)(與electron的new BrowserWindow()參數(shù)一致) const windowBaseOptions = { // 窗口圖標(biāo) icon: join(__root, 'resources/shortcut.ico'), // 是否自動(dòng)隱藏菜單欄(按下Alt鍵顯示) autoHideMenuBar: true, // 窗口標(biāo)題欄樣式 titleBarStyle: 'hidden', // 窗口背景色 backgroundColor: '#fff', // 寬度 width: 840, // 高度 height: 610, // 最小寬度 minWidth: '', // 最小高度 minHeight: '', // 窗口x坐標(biāo) x: '', // 窗口y坐標(biāo) y: '', // 是否可縮放 resizable: true, // 是否可最小化 minimizable: true, // 是否可最大化 maximizable: true, // 是否可關(guān)閉 closable: true, // 父窗口 parent: null, // 是否模態(tài)窗口 modal: false, // 窗口是否置頂 alwaysOnTop: false, // 是否顯示窗口邊框(要?jiǎng)?chuàng)建無(wú)邊框窗口,將frame參數(shù)設(shè)置為false) frame: false, // 是否透明窗口(僅frame: false有效) transparent: false, // 創(chuàng)建時(shí)是否顯示窗口 show: false, }
Electron自定義系統(tǒng)托盤|消息提醒

/** * 系統(tǒng)托盤圖標(biāo)管理 */ trayManager() { if(this.tray) return const trayMenu = Menu.buildFromTemplate([ { label: '打開(kāi)主界面', icon: join(__root, 'resources/tray-win.png'), click: () => { this.winMain.restore() this.winMain.show() } }, { label: '設(shè)置', icon: join(__root, 'resources/tray-setting.png'), click: () => this.sendByMainWin('win-ipcdata', {type: 'WINIPC_SETTINGWIN', value: null}) }, { label: '鎖定系統(tǒng)', click: () => null, }, { label: '關(guān)閉托盤閃爍', click: () => this.trayFlash(false) }, { label: '關(guān)于', 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: ['取消', '最小化托盤', '確認(rèn)退出'], 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('鼠標(biāo)劃入', position) if(!this.hasFlash) return this.sendByMainWin('win-ipcdata', {type: 'WINIPC_MESSAGEWIN', value: position}) // 簡(jiǎn)略消息通知 /* this.tray.displayBalloon({ iconType: 'none', title: 'Electron38研發(fā)組', content: 'Electron38+Vite7仿微信客戶端聊天。' }) */ }) this.tray.on('mouse-leave', (event, position) => { // console.log('鼠標(biāo)離開(kāi)') }) }
開(kāi)啟/關(guān)閉托盤圖標(biāo)閃爍
// 開(kāi)啟/關(guān)閉托盤閃爍 trayFlash(bool) { let flag = false if(bool) { if(this.trayTimer) return this.trayTimer = setInterval(() => { this.tray.setImage(flag ? this.trayIcon : this.trayEmpty) flag = !flag }, 500) }else { if(this.trayTimer) { clearInterval(this.trayTimer) this.trayTimer = null } this.tray.setImage(this.trayIcon) } }

托盤圖標(biāo)鼠標(biāo)劃入消息提醒彈窗。
this.tray.on('mouse-enter', (event, position) => { // console.log('鼠標(biāo)劃入', position) if(!this.hasFlash) return this.sendByMainWin('win-ipcdata', {type: 'WINIPC_MESSAGEWIN', value: position}) // 簡(jiǎn)略消息通知 /* this.tray.displayBalloon({ iconType: 'none', title: 'Electron38研發(fā)組', content: 'Electron38+Vite7仿微信客戶端聊天。' }) */ })
// 托盤新消息提醒窗口 export function messageWindow(position) { winCreate({ url: '/win/msgbox', title: '設(shè)置', width: 250, height: 120, resizable: false, movable: false, fullscreenable: false, alwaysOnTop: true, skipTaskbar: true, x: position?.x - 125, y: position?.y - 120 - 10, show: true, }) }
綜上就是vite7+electron38搭建仿微信客戶端聊天應(yīng)用的一些知識(shí)分享,希望對(duì)大家有點(diǎn)幫助~
vite7-webos網(wǎng)頁(yè)版os管理|Vue3+Vite7+ArcoDesign搭建pc端os后臺(tái)系統(tǒng)
Vite7網(wǎng)頁(yè)版聊天|Vue3.5+Pinia3+ElementPlus仿微信網(wǎng)頁(yè)端web聊天系統(tǒng)
最后附上幾個(gè)最新實(shí)戰(zhàn)項(xiàng)目
uniapp-vue3-os手機(jī)oa系統(tǒng)|uni-app+vue3跨三端os后臺(tái)管理模板
最新版uni-app+vue3+uv-ui跨三端仿微信app聊天應(yīng)用【h5+小程序+app端】
最新版uniapp+vue3+uv-ui跨三端短視頻+直播+聊天【H5+小程序+App端】
Flutter3-MacOS桌面OS系統(tǒng)|flutter3.32+window_manager客戶端OS模板
最新研發(fā)flutter3.27+bitsdojo_window+getx客戶端仿微信聊天Exe應(yīng)用
flutter3-deepseek流式AI模板|Flutter3.27+Dio+DeepSeeek聊天ai助手
Uniapp-DeepSeek跨三端AI助手|uniapp+vue3+deepseek-v3流式ai聊天模板
vue3-webseek網(wǎng)頁(yè)版AI問(wèn)答|Vite6+DeepSeek+Arco流式ai聊天打字效果
flutter3-dymall仿抖音直播商城|Flutter3.27短視頻+直播+聊天App實(shí)例
Tauri2.0-Vue3OS桌面端os平臺(tái)|tauri2+vite6+arco電腦版OS管理系統(tǒng)
tauri2.0-admin桌面端后臺(tái)系統(tǒng)|Tauri2+Vite5+ElementPlus管理后臺(tái)EXE程序


浙公網(wǎng)安備 33010602011771號(hào)