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

@ -10,14 +10,22 @@
</template> </template>
<script> <script>
import Spinner from "./components/Spinner"; import Spinner from "./components/Spinner";
export default { import {mapState} from "vuex";
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,11 +47,17 @@
// //
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) {
this.transitionName = 'app-slide-no'; this.transitionName = 'app-slide-no';
return; return;
@ -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;
@ -64,27 +79,22 @@
if (ToIndex && ToIndex < FromIndex) { if (ToIndex && ToIndex < FromIndex) {
isBack = true; //退 isBack = true; //退
this.sessionStorage(true, ToIndex); this.sessionStorage(true, ToIndex);
}else{ } else {
isBack = false; // isBack = false; //
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,12 +103,13 @@
} }
} }
}, },
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__'] || '{}');
if (path === true) { if (path === true) {
let items = {}; let items = {};
for(let i in history){ for (let i in history) {
if (history.hasOwnProperty(i)) { if (history.hasOwnProperty(i)) {
if (parseInt(history[i]) <= num) { if (parseInt(history[i]) <= num) {
items[i] = history[i]; items[i] = history[i];
@ -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);
}, },
@ -144,9 +159,9 @@
if (button === null) { if (button === null) {
return; return;
} }
row.find("input.ivu-input").keydown(function(e) { row.find("input.ivu-input").keydown(function (e) {
if (e.keyCode == 13) { if (e.keyCode == 13) {
if (!button.hasClass("ivu-btn-loading") ) { if (!button.hasClass("ivu-btn-loading")) {
button.click(); button.click();
} }
} }
@ -156,8 +171,21 @@
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>
<style lang="scss" scoped> <style lang="scss" scoped>