feat: 客户端快捷键关闭窗口先关网页内的弹窗

This commit is contained in:
kuaifan 2021-12-23 19:35:35 +08:00
parent 26e7d562aa
commit 544496a09b
3 changed files with 178 additions and 133 deletions

25
electron/main.js vendored
View File

@ -3,6 +3,7 @@ const path = require('path')
const XLSX = require('xlsx'); const XLSX = require('xlsx');
const {app, BrowserWindow, ipcMain, dialog} = require('electron') const {app, BrowserWindow, ipcMain, dialog} = require('electron')
let mainWindow = null;
let willQuitApp = false, let willQuitApp = false,
devloadCachePath = path.resolve(__dirname, ".devload"), devloadCachePath = path.resolve(__dirname, ".devload"),
devloadUrl = ""; devloadUrl = "";
@ -29,7 +30,7 @@ function runNum(str, fixed) {
} }
function createWindow() { function createWindow() {
const mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 1280, width: 1280,
height: 800, height: 800,
webPreferences: { webPreferences: {
@ -52,7 +53,7 @@ function createWindow() {
mainWindow.on('close', function (e) { mainWindow.on('close', function (e) {
if (!willQuitApp) { if (!willQuitApp) {
e.preventDefault(); e.preventDefault();
app.hide(); mainWindow.webContents.send("windowClose", {})
} }
}) })
} }
@ -71,7 +72,7 @@ app.on('window-all-closed', function () {
app.on('before-quit', () => { app.on('before-quit', () => {
willQuitApp = true willQuitApp = true
}); })
ipcMain.on('setDockBadge', (event, arg) => { ipcMain.on('setDockBadge', (event, arg) => {
if (runNum(arg) > 0) { if (runNum(arg) > 0) {
@ -79,6 +80,22 @@ ipcMain.on('setDockBadge', (event, arg) => {
} else { } else {
app.dock.setBadge("") app.dock.setBadge("")
} }
})
ipcMain.on('windowMax', function () {
if (mainWindow.isMaximized()) {
mainWindow.restore();
} else {
mainWindow.maximize();
}
})
ipcMain.on('windowHidden', () => {
app.hide();
})
ipcMain.on('windowClose', () => {
mainWindow.close()
}); });
ipcMain.on('saveSheet', (event, data, filename, opts) => { ipcMain.on('saveSheet', (event, data, filename, opts) => {
@ -93,4 +110,4 @@ ipcMain.on('saveSheet', (event, data, filename, opts) => {
}).then(o => { }).then(o => {
XLSX.writeFile(data, o.filePath, opts); XLSX.writeFile(data, o.filePath, opts);
}); });
}); })

View File

@ -58,7 +58,7 @@
"stylus-loader": "^6.2.0", "stylus-loader": "^6.2.0",
"tinymce": "^5.10.2", "tinymce": "^5.10.2",
"tui-calendar-hi": "^1.15.1-1", "tui-calendar-hi": "^1.15.1-1",
"view-design-hi": "^4.7.0-1", "view-design-hi": "^4.7.0-2",
"vue": "^2.6.14", "vue": "^2.6.14",
"vue-clipboard2": "^0.3.3", "vue-clipboard2": "^0.3.3",
"vue-emoji-picker": "^1.0.3", "vue-emoji-picker": "^1.0.3",

View File

@ -11,13 +11,21 @@
<script> <script>
import Spinner from "./components/Spinner"; import Spinner from "./components/Spinner";
import {mapState} from "vuex";
export default { export default {
components: {Spinner}, components: {Spinner},
data() { data() {
return { return {
transitionName: null, transitionName: null,
} }
}, },
created() {
this.electronEvents();
},
mounted() { mounted() {
let hash = window.location.hash; let hash = window.location.hash;
if (hash.indexOf("#") === 0) { if (hash.indexOf("#") === 0) {
@ -39,9 +47,15 @@
// //
window.addEventListener('resize', this.windowMax768Listener); window.addEventListener('resize', this.windowMax768Listener);
}, },
beforeDestroy() { beforeDestroy() {
window.removeEventListener('resize', this.windowMax768Listener); window.removeEventListener('resize', this.windowMax768Listener);
}, },
computed: {
...mapState(['taskId']),
},
watch: { watch: {
'$route'(To, From) { '$route'(To, From) {
if (this.transitionName === null) { if (this.transitionName === null) {
@ -54,6 +68,7 @@
this.slideType(To, From); this.slideType(To, From);
} }
}, },
methods: { methods: {
slideType(To, From) { slideType(To, From) {
let isBack = this.$router.isBack; let isBack = this.$router.isBack;
@ -69,22 +84,17 @@
this.sessionStorage(To.path, this.sessionStorage('::count') + 1); this.sessionStorage(To.path, this.sessionStorage('::count') + 1);
} }
// //
if (To.meta.slide === false || From.meta.slide === false) if (To.meta.slide === false || From.meta.slide === false) {
{
// //
this.transitionName = 'app-slide-no' this.transitionName = 'app-slide-no'
} } else if (To.meta.slide === 'up' || From.meta.slide === 'up' || To.meta.slide === 'down' || From.meta.slide === 'down') {
else if (To.meta.slide === 'up' || From.meta.slide === 'up' || To.meta.slide === 'down' || From.meta.slide === 'down')
{
// //
if (isBack) { if (isBack) {
this.transitionName = 'app-slide-down' this.transitionName = 'app-slide-down'
} else { } else {
this.transitionName = 'app-slide-up' this.transitionName = 'app-slide-up'
} }
} } else {
else
{
// //
if (isBack) { if (isBack) {
this.transitionName = 'app-slide-right' this.transitionName = 'app-slide-right'
@ -93,6 +103,7 @@
} }
} }
}, },
sessionStorage(path, num) { sessionStorage(path, num) {
let conut = 0; let conut = 0;
let history = JSON.parse(window.sessionStorage['__history__'] || '{}'); let history = JSON.parse(window.sessionStorage['__history__'] || '{}');
@ -116,7 +127,11 @@
} }
if (path === "/") num = 1; if (path === "/") num = 1;
history[path] = num; history[path] = num;
for(let key in history){ if (history.hasOwnProperty(key) && key !== '::count') { conut++; } } for (let key in history) {
if (history.hasOwnProperty(key) && key !== '::count') {
conut++;
}
}
history['::count'] = Math.max(num, conut); history['::count'] = Math.max(num, conut);
window.sessionStorage['__history__'] = JSON.stringify(history); window.sessionStorage['__history__'] = JSON.stringify(history);
}, },
@ -156,6 +171,19 @@
windowMax768Listener() { windowMax768Listener() {
this.$store.state.windowMax768 = window.innerWidth <= 768 this.$store.state.windowMax768 = window.innerWidth <= 768
}, },
electronEvents() {
if (!this.isElectron) {
return;
}
const {ipcRenderer} = this.$electron;
ipcRenderer.on('windowClose', () => {
if (this.$Modal.removeLast()) {
return;
}
ipcRenderer.send('windowHidden');
})
}
} }
} }
</script> </script>