perf: 客户端新窗口打开文件

This commit is contained in:
kuaifan 2021-12-25 16:20:55 +08:00
parent ffe62b8f8e
commit a32c0b028b
3 changed files with 92 additions and 9 deletions

73
electron/main.js vendored
View File

@ -4,6 +4,7 @@ const XLSX = require('xlsx');
const {app, BrowserWindow, ipcMain, dialog} = require('electron') const {app, BrowserWindow, ipcMain, dialog} = require('electron')
let mainWindow = null, let mainWindow = null,
subWindow = [],
willQuitApp = false, willQuitApp = false,
inheritClose = false, inheritClose = false,
devloadCachePath = path.resolve(__dirname, ".devload"), devloadCachePath = path.resolve(__dirname, ".devload"),
@ -30,10 +31,22 @@ function runNum(str, fixed) {
return _s; return _s;
} }
function randomString(len) {
len = len || 32;
let $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678oOLl9gqVvUuI1';
let maxPos = $chars.length;
let pwd = '';
for (let i = 0; i < len; i++) {
pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
}
return pwd;
}
function createWindow() { function createWindow() {
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
width: 1280, width: 1280,
height: 800, height: 800,
center: true,
webPreferences: { webPreferences: {
preload: path.join(__dirname, 'preload.js'), preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true, nodeIntegration: true,
@ -63,6 +76,60 @@ function createWindow() {
}) })
} }
function createRouter(arg) {
if (!arg) {
return;
}
if (typeof arg !== "object") {
arg = {
path: arg,
config: {},
}
}
let name = arg.name || "auto_" + randomString(6);
let item = subWindow.find(item => item.name == name);
let browser = item ? item.browser : null;
if (browser) {
browser.focus();
if (arg.force === false) {
return;
}
} else {
browser = new BrowserWindow(Object.assign({
width: 1280,
height: 800,
center: true,
parent: mainWindow,
webPreferences: {
preload: path.join(__dirname, 'preload.js'),
nodeIntegration: true,
contextIsolation: false
}
}, arg.config || {}))
browser.on('close', function () {
let index = subWindow.findIndex(item => item.name == name);
if (index > -1) {
subWindow.splice(index, 1)
}
})
subWindow.push({ name, browser })
}
if (devloadUrl) {
browser.loadURL(devloadUrl + '#' + (arg.hash || arg.path)).then(r => {
})
} else {
browser.loadFile('./public/index.html', {
hash: arg.hash || arg.path
}).then(r => {
})
}
}
app.whenReady().then(() => { app.whenReady().then(() => {
createWindow() createWindow()
@ -83,6 +150,10 @@ ipcMain.on('inheritClose', () => {
inheritClose = true inheritClose = true
}) })
ipcMain.on('windowRouter', (event, arg) => {
createRouter(arg)
})
ipcMain.on('windowHidden', () => { ipcMain.on('windowHidden', () => {
app.hide(); app.hide();
}) })
@ -101,7 +172,7 @@ ipcMain.on('windowMax', function () {
ipcMain.on('setDockBadge', (event, arg) => { ipcMain.on('setDockBadge', (event, arg) => {
if(process.platform !== 'darwin'){ if(process.platform !== 'darwin'){
console.log('Mac only'); // Mac only
return; return;
} }
if (runNum(arg) > 0) { if (runNum(arg) > 0) {

View File

@ -54,12 +54,19 @@
"mac": { "mac": {
"icon": "../resources/assets/statics/public/images/logo-app.png", "icon": "../resources/assets/statics/public/images/logo-app.png",
"target": "dmg", "target": "dmg",
"publish": ["github"] "publish": [
"github"
]
}, },
"win": { "win": {
"icon": "../resources/assets/statics/public/images/logo-app.ico", "icon": "../resources/assets/statics/public/images/logo-app.ico",
"target": ["tar.gz", "nsis"], "target": [
"publish": ["github"] "tar.gz",
"nsis"
],
"publish": [
"github"
]
}, },
"nsis": { "nsis": {
"oneClick": false, "oneClick": false,

View File

@ -654,11 +654,16 @@ export default {
}, },
openSingle(item) { openSingle(item) {
let url = $A.originUrl("index.html#/single/file/" + item.id), this.$electron.ipcRenderer.send('windowRouter', {
name = 'file-' + item.id, name: 'file-' + item.id,
width = Math.min(window.screen.availWidth, 1280), path: "/single/file/" + item.id,
height = Math.min(window.screen.availHeight, 800); force: false, //
window.open(url, name, 'height=' + height + ',innerHeight=' + height + ',width=' + width + ',innerWidth=' + width); config: {
parent: null,
width: Math.min(window.screen.availWidth, 1280),
height: Math.min(window.screen.availHeight, 800),
}
});
}, },
clickRow(row) { clickRow(row) {