经过半个月爆肝实战开发,原创新作electron31+vue3
跨平台桌面权限管理系统正式完结啦~
electron31-viteadmin内置4种通用布局模板,支持i18n国际化、动态路由权限。
vite5-electron-admin整合vitejs+electron
跨平台技术。实现常用的表格、表单、图表、列表、编辑器等业务场景。
使用vite.js
搭建项目模板,整合最新跨平台技术electronjs
。
/**
* 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()
})
import { createApp } from 'vue'
import './style.scss'
import App from './App.vue'
import { launchApp } from '@/windows/actions'
// 引入路由和状态配置
import Router from './router'
import Pinia from './pinia'
// 引入插件配置
import Plugins from './plugins'
launchApp().then(config => {
if(config) {
console.log('窗口参数:', config)
console.log('窗口id:', config?.id)
// 全局存储窗口配置
window.config = config
}
// 初始化app应用实例
createApp(App)
.use(Router)
.use(Pinia)
.use(Plugins)
.mount('#app')
})
提供了4种通用布局模板。
/**
* 通用布局模板
* @author Andy
*/
<script setup>
import { appState } from '@/pinia/modules/app'
// 引入布局模板
import Classic from './template/classic/index.vue'
import Columns from './template/columns/index.vue'
import Vertical from './template/vertical/index.vue'
import Horizontal from './template/horizontal/index.vue'
const appstate = appState()
const LayoutMap = {
'classic': Classic,
'columns': Columns,
'vertical': Vertical,
'horizontal': Horizontal
}
</script>
<template>
<div class="vuadmin__container" :style="{'--themeSkin': appstate.config.skin}">
<component :is="LayoutMap[appstate.config.layout]" />
</div>
</template>
<Menus :rootRouteEnable="false" />
<Menus rootRouteEnable :dark="true" />
<Menus mode="horizontal" :dark="true" />
调用非常简单。
<script setup>
import { ref, computed } from 'vue'
import { isObject, isArray, isImg } from '@/utils'
import { appState } from '@/pinia/modules/app'
import { useRoutes } from '@/hooks/useRoutes'
const props = defineProps({
// 菜单模式(vertical|horizontal)
mode: { type: String, default: 'vertical' },
// 是否开启一级路由菜单
rootRouteEnable: { type: Boolean, default: true },
// 是否暗黑模式
dark: { type: Boolean }
})
import Submenu from './submenu.vue'
// 引入主路由表
import routes from '@/router/modules/main.js'
const appstate = appState()
const { route, getActiveRoute, getCurrentRootRoute, getTreeRoutes } = useRoutes()
const activeRoute = computed(() => getActiveRoute(route))
const rootRoute = computed(() => getCurrentRootRoute(route))
const treeRoutes = computed(() => getTreeRoutes(routes))
const filterRoutes = computed(() => {
if(props.rootRouteEnable) {
return treeRoutes.value
}
// 过滤一级路由菜单
return treeRoutes.value.find(item => item.path === rootRoute.value && item.children)?.children
})
</script>
<template>
<div class="vu__menubar" :class="{'is-dark': dark, 'is-collapsed': mode == 'vertical' && appstate.config.collapsed}">
<el-menu class="vu__menus" :default-active="activeRoute" :mode="mode" :collapse="appstate.config.collapsed">
<Submenu
v-for="route in filterRoutes"
:key="route.path"
:item="route"
:rootRoute="rootRoute"
:rootRouteEnable="rootRouteEnable"
/>
</el-menu>
</div>
</template>
/**
* 国际化配置
* @author YXY
*/
import { createI18n } from 'vue-i18n'
import { appState } from '@/pinia/modules/app'
// 引入语言配置
import enUS from './en-US'
import zhCN from './zh-CN'
import zhTW from './zh-TW'
// 默认语言
export const langVal = 'zh-CN'
export default async (app) => {
const appstate = appState()
const lang = appstate.lang || langVal
appstate.setLang(lang)
const i18n = createI18n({
legacy: false,
locale: lang,
messages: {
'en': enUS,
'zh-CN': zhCN,
'zh-TW': zhTW
}
})
app.use(i18n)
}
/**
* 动态图表Hook
*/
import { onMounted, onBeforeUnmount, ref } from 'vue'
import * as echarts from 'echarts'
import elementResizeDetectorMaker from 'element-resize-detector'
export function useEcharts(el, options) {
let chartEl
let chartRef = ref(null)
let erd = elementResizeDetectorMaker()
const resizeHandle = () => {
chartEl && chartEl.resize()
}
onMounted(() => {
if(el?.value) {
chartEl = echarts.init(el.value)
chartEl.setOption(options)
chartRef.value = chartEl
}
erd.listenTo(el.value, resizeHandle)
})
onBeforeUnmount(() => {
chartEl.dispose()
erd.removeListener(el.value, resizeHandle)
})
return chartRef
}
以上就是electron31+vue3开发桌面端后台管理系统的一些分享,希望对大家有所帮助。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。