diff --git a/electron.vite.config.mjs b/electron.vite.config.mjs index af2f6ab..fcc5633 100644 --- a/electron.vite.config.mjs +++ b/electron.vite.config.mjs @@ -22,8 +22,8 @@ export default defineConfig({ server: { proxy: { '/dev-api': { - // target: 'http://27.128.240.72:7865', - target: 'http://192.168.2.52:7863', + target: 'http://27.128.240.72:7865', + // target: 'http://192.168.2.52:7863', changeOrigin: true, rewrite: (p) => p.replace(/^\/dev-api/, '') }, diff --git a/src/main/index.js b/src/main/index.js index 775c151..fca4014 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -3,8 +3,12 @@ import { join } from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' import icon from '../../resources/icon.png?asset' import File from './file' +import Tool from './tool' File({ app, shell, BrowserWindow, ipcMain }) +// zdg: 创建工具-如 悬浮球 +Tool(app, shell, BrowserWindow, ipcMain) + function createWindow() { // Create the browser window. const mainWindow = new BrowserWindow({ diff --git a/src/main/tool.js b/src/main/tool.js new file mode 100644 index 0000000..6343015 --- /dev/null +++ b/src/main/tool.js @@ -0,0 +1,43 @@ +/** + * @description: electron 封装的工具函数 + */ +// import { app, shell, BrowserWindow, ipcMain } from 'electron' +let electron = {} + +export default function(app, shell, BrowserWindow, ipcMain) { + electron = { app, shell, BrowserWindow, ipcMain } + // 创建工具-悬浮球 + ipcMain.on('create-tool-sphere', (e, data) => { + console.log('测试xxxx', data) + const res = createTools(...data) // 执行逻辑 + e.reply('create-tool-sphere-reply', {a: 1111}) // 返回结果 + }) +} +/** + * @description: 创建工具 + * @param {*} url 路由地址 + * @param {number} [width=800] 窗口宽度 + * @param {number} [height=600] 窗口高度 + * @param {{}} [option={}] 自定义选项 + * @author: zdg + * @date 2021-07-05 14:07:01 + */ +function createTools(url, width = 800, height = 600, option={}) { + if (!electron.BrowserWindow) return + const win = new electron.BrowserWindow({ + width, height, + type: 'toolbar', //创建的窗口类型为工具栏窗口 + frame: false, //要创建无边框窗口 + resizable: false, //禁止窗口大小缩放 + transparent: true, //设置透明 + alwaysOnTop: true, //窗口是否总是显示在其他窗口之前 + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + webSecurity: false + }, + ...option + }) + win.loadURL(url) + return win +} \ No newline at end of file diff --git a/src/renderer/src/router/index.js b/src/renderer/src/router/index.js index 0ae5748..ff9a6a0 100644 --- a/src/renderer/src/router/index.js +++ b/src/renderer/src/router/index.js @@ -1,6 +1,7 @@ import { createRouter, createWebHashHistory } from 'vue-router' import Layout from '../layout/index.vue' +import { toolRouters } from './tool' export const constantRoutes = [ { @@ -40,7 +41,7 @@ export const constantRoutes = [ } ] }, - + ...toolRouters ] const router = createRouter({ diff --git a/src/renderer/src/router/tool.js b/src/renderer/src/router/tool.js new file mode 100644 index 0000000..0ca7d23 --- /dev/null +++ b/src/renderer/src/router/tool.js @@ -0,0 +1,18 @@ +/** + * @description: 工具路由 + * @author: zdg + * @date 2021-07-05 14:07:01 + */ +export const toolRouters = [ + { + path: '/tool', + children: [ + { + path: '/sphere', + component: () => import('@/views/tool/sphere.vue'), + name: 'toolSphere', + meta: {title: '悬浮球'} + }, + ] + } +] \ No newline at end of file diff --git a/src/renderer/src/utils/tool.js b/src/renderer/src/utils/tool.js new file mode 100644 index 0000000..076c931 --- /dev/null +++ b/src/renderer/src/utils/tool.js @@ -0,0 +1,24 @@ +/** + * @description: electron 封装的工具函数 + */ +const { ipcRenderer } = window.electron || {} + +/** + * @form src/main/tool.js 来源 + * @description 创建工具 + * @param {*} key 消息头 + * create-tool-sphere 创建-悬浮球 | url:路由地址,width:窗口宽度,height:窗口高度,option:自定义选项 + * @param {*} data 参数 + */ +export function createTools(key, data) { + const msgKey = `create-tool-${key}` // 消息头 + const msgKeyRes = `${msgKey}-reply` // 消息头-返回结果 + return new Promise((resolve) => { + // 返回结果-监听 + ipcRenderer.once(msgKeyRes, async (e, res) => { + resolve(res) + }) + // 发送消息 + ipcRenderer.send(msgKey, data) + }) +} \ No newline at end of file diff --git a/src/renderer/src/views/resource/index.vue b/src/renderer/src/views/resource/index.vue index df5d5bf..7cbb3a2 100644 --- a/src/renderer/src/views/resource/index.vue +++ b/src/renderer/src/views/resource/index.vue @@ -19,13 +19,14 @@ \ No newline at end of file