2025全新原创研发vite7.1+electron38+vue3 setup+element-plus
仿微信电脑端聊天Exe。
electron-vite-wechat使用最新版跨平台框架Electron38
整合Vite7
搭建项目。
electron38-wechat包含了聊天、通讯录、收藏、朋友圈、短视频、我的等模块。
electron38封装多窗口管理器。
最新版跨平台框架electron38
结合vite7
构建项目框架。
import { createApp } from 'vue'
import './style.scss'
import App from './App.vue'
// 引入element-plus组件库
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 引入路由/状态管理
import Router from './router'
import Pinia from './pinia'
import { launchApp } from '@/windows/actions'
launchApp().then(config => {
if(config) {
// 全局存储窗口配置
window.config = config
}
// 创建app应用实例
createApp(App)
.use(ElementPlus)
.use(Router)
.use(Pinia)
.mount('#app')
})
<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>
<!-- 侧边栏 -->
<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>
<!-- 主内容区 -->
<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主进程配置
* @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()
})
preload.js配置
/**
* 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))
},
setTitle: (title) => ipcRenderer.send('win-setTitle', title)
}
)
<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>
/**
* 系统托盘图标管理
*/
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('鼠标离开')
})
}
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仿微信客户端聊天。'
}) */
})
托盘消息提醒弹窗
// 托盘新消息提醒窗口
export function messageWindow(position) {
winCreate({
url: '/win/msgbox',
title: '设置',
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,
})
}
最新原创uniapp-vue3-osadmin手机版后台管理系统
最新原创flutter3.27+bitsdojo_window客户端聊天Exe
基于uni-app+vue3实战短视频+聊天+直播app商城
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。