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,154 +10,182 @@
</template> </template>
<script> <script>
import Spinner from "./components/Spinner"; import Spinner from "./components/Spinner";
export default { import {mapState} from "vuex";
components: {Spinner},
data () { export default {
return { components: {Spinner},
transitionName: null,
data() {
return {
transitionName: null,
}
},
created() {
this.electronEvents();
},
mounted() {
let hash = window.location.hash;
if (hash.indexOf("#") === 0) {
hash = hash.substr(1);
if (hash) {
this.$nextTick(() => {
hash = $A.removeURLParameter(hash, 'token');
this.goForward({path: hash});
});
} }
}, }
mounted() { this.sessionStorage('/', 1);
let hash = window.location.hash; let pathname = window.location.pathname;
if (hash.indexOf("#") === 0) { if (pathname && this.sessionStorage(pathname) === 0) {
hash = hash.substr(1); this.sessionStorage(pathname, this.sessionStorage('::count') + 1);
if (hash) { }
this.$nextTick(() => { //
hash = $A.removeURLParameter(hash, 'token'); setInterval(this.searchEnter, 1000);
this.goForward({path: hash}); //
}); window.addEventListener('resize', this.windowMax768Listener);
} },
beforeDestroy() {
window.removeEventListener('resize', this.windowMax768Listener);
},
computed: {
...mapState(['taskId']),
},
watch: {
'$route'(To, From) {
if (this.transitionName === null) {
this.transitionName = 'app-slide-no';
return;
} }
this.sessionStorage('/', 1); if (typeof To.name === 'undefined' || typeof From.name === 'undefined') {
let pathname = window.location.pathname; return;
if (pathname && this.sessionStorage(pathname) === 0) { }
this.sessionStorage(pathname, this.sessionStorage('::count') + 1); this.slideType(To, From);
}
},
methods: {
slideType(To, From) {
let isBack = this.$router.isBack;
this.$router.isBack = false;
//
let ToIndex = this.sessionStorage(To.path);
let FromIndex = this.sessionStorage(From.path);
if (ToIndex && ToIndex < FromIndex) {
isBack = true; //退
this.sessionStorage(true, ToIndex);
} else {
isBack = false; //
this.sessionStorage(To.path, this.sessionStorage('::count') + 1);
} }
// //
setInterval(this.searchEnter, 1000); if (To.meta.slide === false || From.meta.slide === false) {
// //
window.addEventListener('resize', this.windowMax768Listener); this.transitionName = 'app-slide-no'
}, } else if (To.meta.slide === 'up' || From.meta.slide === 'up' || To.meta.slide === 'down' || From.meta.slide === 'down') {
beforeDestroy() { //
window.removeEventListener('resize', this.windowMax768Listener); if (isBack) {
}, this.transitionName = 'app-slide-down'
watch: { } else {
'$route' (To, From) { this.transitionName = 'app-slide-up'
if (this.transitionName === null) {
this.transitionName = 'app-slide-no';
return;
} }
if (typeof To.name === 'undefined' || typeof From.name === 'undefined') { } else {
return; //
if (isBack) {
this.transitionName = 'app-slide-right'
} else {
this.transitionName = 'app-slide-left'
} }
this.slideType(To, From);
} }
}, },
methods: {
slideType(To, From) { sessionStorage(path, num) {
let isBack = this.$router.isBack; let conut = 0;
this.$router.isBack = false; let history = JSON.parse(window.sessionStorage['__history__'] || '{}');
// if (path === true) {
let ToIndex = this.sessionStorage(To.path); let items = {};
let FromIndex = this.sessionStorage(From.path); for (let i in history) {
if (ToIndex && ToIndex < FromIndex) { if (history.hasOwnProperty(i)) {
isBack = true; //退 if (parseInt(history[i]) <= num) {
this.sessionStorage(true, ToIndex); items[i] = history[i];
}else{ conut++;
isBack = false; //
this.sessionStorage(To.path, this.sessionStorage('::count') + 1);
}
//
if (To.meta.slide === false || From.meta.slide === false)
{
//
this.transitionName = 'app-slide-no'
}
else if (To.meta.slide === 'up' || From.meta.slide === 'up' || To.meta.slide === 'down' || From.meta.slide === 'down')
{
//
if (isBack) {
this.transitionName = 'app-slide-down'
} else {
this.transitionName = 'app-slide-up'
}
}
else
{
//
if (isBack) {
this.transitionName = 'app-slide-right'
} else {
this.transitionName = 'app-slide-left'
}
}
},
sessionStorage(path, num) {
let conut = 0;
let history = JSON.parse(window.sessionStorage['__history__'] || '{}');
if (path === true) {
let items = {};
for(let i in history){
if (history.hasOwnProperty(i)) {
if (parseInt(history[i]) <= num) {
items[i] = history[i];
conut++;
}
} }
} }
history = items;
history['::count'] = Math.max(num, conut);
window.sessionStorage['__history__'] = JSON.stringify(history);
return history;
} }
if (typeof num === 'undefined') { history = items;
return parseInt(history[path] || 0);
}
if (path === "/") num = 1;
history[path] = num;
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);
}, return history;
}
if (typeof num === 'undefined') {
return parseInt(history[path] || 0);
}
if (path === "/") num = 1;
history[path] = num;
for (let key in history) {
if (history.hasOwnProperty(key) && key !== '::count') {
conut++;
}
}
history['::count'] = Math.max(num, conut);
window.sessionStorage['__history__'] = JSON.stringify(history);
},
searchEnter() { searchEnter() {
let row = $A(".sreachBox"); let row = $A(".sreachBox");
if (row.length === 0) { if (row.length === 0) {
return; return;
}
if (row.attr("data-enter-init") === "init") {
return;
}
row.attr("data-enter-init", "init");
//
let buttons = row.find("button[type='button']");
let button = null;
if (buttons.length === 0) {
return;
}
buttons.each((index, item) => {
if ($A(item).text().indexOf("搜索")) {
button = $A(item);
} }
if (row.attr("data-enter-init") === "init") { });
return; if (button === null) {
} return;
row.attr("data-enter-init", "init"); }
// row.find("input.ivu-input").keydown(function (e) {
let buttons = row.find("button[type='button']"); if (e.keyCode == 13) {
let button = null; if (!button.hasClass("ivu-btn-loading")) {
if (buttons.length === 0) { button.click();
return;
}
buttons.each((index, item) => {
if ($A(item).text().indexOf("搜索")) {
button = $A(item);
} }
});
if (button === null) {
return;
} }
row.find("input.ivu-input").keydown(function(e) { });
if (e.keyCode == 13) { },
if (!button.hasClass("ivu-btn-loading") ) {
button.click();
}
}
});
},
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>