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

View File

@ -58,7 +58,7 @@
"stylus-loader": "^6.2.0",
"tinymce": "^5.10.2",
"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-clipboard2": "^0.3.3",
"vue-emoji-picker": "^1.0.3",

View File

@ -10,154 +10,182 @@
</template>
<script>
import Spinner from "./components/Spinner";
export default {
components: {Spinner},
data () {
return {
transitionName: null,
import Spinner from "./components/Spinner";
import {mapState} from "vuex";
export default {
components: {Spinner},
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() {
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});
});
}
}
this.sessionStorage('/', 1);
let pathname = window.location.pathname;
if (pathname && this.sessionStorage(pathname) === 0) {
this.sessionStorage(pathname, this.sessionStorage('::count') + 1);
}
//
setInterval(this.searchEnter, 1000);
//
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);
let pathname = window.location.pathname;
if (pathname && this.sessionStorage(pathname) === 0) {
this.sessionStorage(pathname, this.sessionStorage('::count') + 1);
if (typeof To.name === 'undefined' || typeof From.name === 'undefined') {
return;
}
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);
//
window.addEventListener('resize', this.windowMax768Listener);
},
beforeDestroy() {
window.removeEventListener('resize', this.windowMax768Listener);
},
watch: {
'$route' (To, From) {
if (this.transitionName === null) {
this.transitionName = 'app-slide-no';
return;
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'
}
if (typeof To.name === 'undefined' || typeof From.name === 'undefined') {
return;
} else {
//
if (isBack) {
this.transitionName = 'app-slide-right'
} else {
this.transitionName = 'app-slide-left'
}
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);
}
//
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++;
}
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') {
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 = items;
history['::count'] = Math.max(num, conut);
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() {
let row = $A(".sreachBox");
if (row.length === 0) {
return;
searchEnter() {
let row = $A(".sreachBox");
if (row.length === 0) {
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;
}
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 (button === null) {
return;
}
row.find("input.ivu-input").keydown(function (e) {
if (e.keyCode == 13) {
if (!button.hasClass("ivu-btn-loading")) {
button.click();
}
});
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() {
this.$store.state.windowMax768 = window.innerWidth <= 768
},
windowMax768Listener() {
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>
<style lang="scss" scoped>