diff --git a/src/main/index.js b/src/main/index.js index 719e6d7..f177584 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,4 +1,4 @@ -import { app, BrowserWindow, Menu } from 'electron' +import { app, BrowserWindow, Menu, ipcMain } from 'electron' import '../renderer/store' /** @@ -10,11 +10,9 @@ if (process.env.NODE_ENV !== 'development') { } let mainWindow -const winURL = process.env.NODE_ENV === 'development' - ? `http://localhost:9080` - : `file://${__dirname}/index.html` +const winURL = process.env.NODE_ENV === 'development' ? `http://localhost:9080` : `file://${__dirname}/index.html` -function createWindow () { +function createWindow() { /** * Initial window options */ @@ -30,11 +28,19 @@ function createWindow () { contextIsolation: false } }) - require("@electron/remote/main").initialize(); - require("@electron/remote/main").enable(mainWindow.webContents); + require('@electron/remote/main').initialize() + require('@electron/remote/main').enable(mainWindow.webContents) // 禁用默认菜单 // Menu.setApplicationMenu(null); // mainWindow.maximize() + // 设置快捷键 + const menuTemplate = [{ label: '复制', role: 'copy' }, { label: '粘贴', role: 'paste' }, { type: 'separator' }, { label: '全选', role: 'selectall' }] + + const menu = Menu.buildFromTemplate(menuTemplate) + + ipcMain.on('show-context-menu', () => { + menu.popup(BrowserWindow.getFocusedWindow()) + }) mainWindow.show() mainWindow.loadURL(winURL) mainWindow.on('closed', () => { diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 5811fa5..3c5fd7d 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -9,6 +9,11 @@ const dayjs = require('dayjs') export default { name: 'App', + data() { + return { + errors: [] + } + }, mounted() { let that = this if (that.$store.getters.token) { @@ -21,41 +26,59 @@ export default { let that = this const currentTime = dayjs().format('HH:mm:ss'); if (val.message) { - that.$message({ - message: val.message, - type: val.type, - }) + if (that.errors.indexOf(val.message) === -1) { + that.errors.push(val.message) + that.$message({ + message: val.message, + type: val.type, + onClose() { + that.errors.splice(that.errors.indexOf(val.message), 1) + } + }) + } } if (val.notify) { - that.$notify({ - title: '温馨提示:' + currentTime, - message: val.notify, - type: val.type, - duration: 0 - }) + if (that.errors.indexOf(val.notify) === -1) { + that.errors.push(val.notify) + that.$notify({ + title: '温馨提示:' + currentTime, + message: val.notify, + type: val.type, + duration: 0, + onClose() { + that.errors.splice(that.errors.indexOf(val.notify), 1) + } + }) + } } if (val.confirm) { - that.$notify({ - title: '温馨提示:' + currentTime, - duration: 0, - dangerouslyUseHTMLString: true, - message: `