(编辑:jimmy 日期: 2024/11/19 浏览:2)
相关依赖
里面使用了vuex vue vue-route storeJs
storeJs 用来持久化vuex状态
展示
介绍说明
没有使用electron内置的-webkit-app-region: drag
因为使用他那个有很多问题
比如事件无法使用 右键无法使用 以及不能使用手型等!
安装
安装的时候没有截图 所以就参考下我其他的文章吧
storeJs 安装
npm install storejs
准备写代码
配置路由文件
export default new Router({ routes: [ {path: '/', name: 'home', component: ()=> import('@/view//home')}, {path: '/suspension', name: 'suspension', component: ()=> import('@/view/components/suspension')} ] })
写悬浮窗页面
页面路径 /src/renderer/view/components/suspension.vue
<template> <div id="suspension"> <div class="logo"></div> <div class="content_body"> <div class="upload">拖拽上传</div> </div> </div> </template> <script> export default { name: "suspension", mounted() { let win = this.$electron.remote.getCurrentWindow(); let biasX = 0; let biasY = 0; let that = this; document.addEventListener('mousedown', function (e) { switch (e.button) { case 0: biasX = e.x; biasY = e.y; document.addEventListener('mousemove', moveEvent); break; case 2: that.$electron.ipcRenderer.send('createSuspensionMenu'); break; } }); document.addEventListener('mouseup', function () { biasX = 0; biasY = 0; document.removeEventListener('mousemove', moveEvent) }); function moveEvent(e) { win.setPosition(e.screenX - biasX, e.screenY - biasY) } } } </script> <style> * { padding: 0; margin: 0; } .upload { height: 25px; line-height: 25px; font-size: 12px; text-align: center; color: #74A1FA; } .logo { width: 40px; background: #5B9BFE url("../../assets/img/logo@2x.png") no-repeat 2px 3px; background-size: 80%; } .content_body { background-color: #EEF4FE; width: 100%; } #suspension { -webkit-user-select: none; cursor: pointer; overflow: hidden; } #suspension { cursor: pointer !important; height: 25px; border-radius: 4px; display: flex; border: 1px solid #3388FE; } </style>
主进程创建悬浮窗页面代码
路径: /src/main/window.js
import {BrowserWindow, ipcMain, screen, Menu, shell, app, webContents} from 'electron' var win = null; const window = BrowserWindow.fromWebContents(webContents.getFocusedWebContents()); const winURL = process.env.NODE_ENV === 'development' "htmlcode">import storejs from 'storejs' const state = { show: storejs.get('showSuspension') }; const actions = { showSuspension: function ({state, commit}) { let status = true; storejs.set('showSuspension', status); state.show = status; }, hideSuspension: function ({state, commit}) { let status = false; storejs.set('showSuspension', status); state.show = status; }, }; export default ({ state, actions });遗留问题
github地址
使用electron制作百度网盘客户端: https://github.com/lihaotian0607/baidupan
使用electron制作百度网盘悬浮窗: https://github.com/lihaotian0607/electron-suspension
目前这个开源代码中没有悬浮窗 有时间了会加上去!!!