perf: 优化子窗口

This commit is contained in:
kuaifan 2024-03-05 19:29:27 +08:00 committed by Pang
parent c4430e1a6c
commit c96bad3cdf
18 changed files with 205 additions and 202 deletions

View File

@ -406,23 +406,6 @@ class IndexController extends InvokeController
abort(404); abort(404);
} }
/**
* 保存配置
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|string
*/
public function storage__synch()
{
$key = Request::input('key');
$value = Request::input('value');
if ($key) {
$value = [$key => $value];
}
if (!is_array($value)) {
$value = Base::json2array($value);
}
return view('storage', ['value' => Base::array2json($value)]);
}
/** /**
* 提取所有中文 * 提取所有中文
* @return array|string * @return array|string

View File

@ -15,9 +15,6 @@ class VerifyCsrfToken extends Middleware
// 接口部分 // 接口部分
'api/*', 'api/*',
// 保存配置
'storage/synch/',
// 发布桌面端 // 发布桌面端
'desktop/publish/', 'desktop/publish/',
]; ];

178
electron/electron.js vendored
View File

@ -26,8 +26,6 @@ let enablePlugins = false;
let mainWindow = null, let mainWindow = null,
mainTray = null, mainTray = null,
subWindow = [],
storageBrowser = null,
isReady = false, isReady = false,
willQuitApp = false, willQuitApp = false,
devloadUrl = "", devloadUrl = "",
@ -36,7 +34,8 @@ let mainWindow = null,
let screenshotObj = null, let screenshotObj = null,
screenshotKey = null; screenshotKey = null;
let webWindow = null, let childWindow = [],
webTabWindow = null,
webTabView = [], webTabView = [],
webTabHeight = 38; webTabHeight = 38;
@ -116,7 +115,7 @@ function createMainWindow() {
* 创建子窗口 * 创建子窗口
* @param args {path, hash, title, titleFixed, force, userAgent, config, webPreferences} * @param args {path, hash, title, titleFixed, force, userAgent, config, webPreferences}
*/ */
function createSubWindow(args) { function createChildWindow(args) {
if (!args) { if (!args) {
return; return;
} }
@ -126,7 +125,7 @@ function createSubWindow(args) {
} }
let name = args.name || "auto_" + utils.randomString(6); let name = args.name || "auto_" + utils.randomString(6);
let item = subWindow.find(item => item.name == name); let item = childWindow.find(item => item.name == name);
let browser = item ? item.browser : null; let browser = item ? item.browser : null;
if (browser) { if (browser) {
browser.focus(); browser.focus();
@ -169,9 +168,9 @@ function createSubWindow(args) {
}) })
browser.on('closed', () => { browser.on('closed', () => {
let index = subWindow.findIndex(item => item.name == name); let index = childWindow.findIndex(item => item.name == name);
if (index > -1) { if (index > -1) {
subWindow.splice(index, 1) childWindow.splice(index, 1)
} }
}) })
@ -183,7 +182,7 @@ function createSubWindow(args) {
onShowWindow(browser); onShowWindow(browser);
}) })
subWindow.push({ name, browser }) childWindow.push({ name, browser })
} }
const originalUA = browser.webContents.session.getUserAgent() || browser.webContents.getUserAgent() const originalUA = browser.webContents.session.getUserAgent() || browser.webContents.getUserAgent()
browser.webContents.setUserAgent(originalUA + " SubTaskWindow/" + process.platform + "/" + os.arch() + "/1.0" + (args.userAgent ? (" " + args.userAgent) : "")); browser.webContents.setUserAgent(originalUA + " SubTaskWindow/" + process.platform + "/" + os.arch() + "/1.0" + (args.userAgent ? (" " + args.userAgent) : ""));
@ -219,7 +218,7 @@ function createSubWindow(args) {
* @param browser * @param browser
* @param args * @param args
*/ */
function updateSubWindow(browser, args) { function updateChildWindow(browser, args) {
if (!args) { if (!args) {
return; return;
} }
@ -239,7 +238,7 @@ function updateSubWindow(browser, args) {
} }
} }
if (args.name) { if (args.name) {
const er = subWindow.find(item => item.browser == browser); const er = childWindow.find(item => item.browser == browser);
if (er) { if (er) {
er.name = args.name; er.name = args.name;
} }
@ -250,7 +249,7 @@ function updateSubWindow(browser, args) {
* 创建内置浏览器 * 创建内置浏览器
* @param args {url, ?} * @param args {url, ?}
*/ */
function createWebWindow(args) { function createWebTabWindow(args) {
if (!args) { if (!args) {
return; return;
} }
@ -264,8 +263,8 @@ function createWebWindow(args) {
} }
// 创建父级窗口 // 创建父级窗口
if (!webWindow) { if (!webTabWindow) {
let config = Object.assign(args.config || {}, userConf.get('webWindow', {})); let config = Object.assign(args.config || {}, userConf.get('webTabWindow', {}));
let webPreferences = args.webPreferences || {}; let webPreferences = args.webPreferences || {};
const titleBarOverlay = { const titleBarOverlay = {
height: webTabHeight height: webTabHeight
@ -274,7 +273,7 @@ function createWebWindow(args) {
titleBarOverlay.color = '#3B3B3D' titleBarOverlay.color = '#3B3B3D'
titleBarOverlay.symbolColor = '#C5C5C5' titleBarOverlay.symbolColor = '#C5C5C5'
} }
webWindow = new BrowserWindow(Object.assign({ webTabWindow = new BrowserWindow(Object.assign({
x: mainWindow.getBounds().x + webTabHeight, x: mainWindow.getBounds().x + webTabHeight,
y: mainWindow.getBounds().y + webTabHeight, y: mainWindow.getBounds().y + webTabHeight,
width: 1280, width: 1280,
@ -295,55 +294,59 @@ function createWebWindow(args) {
}, webPreferences), }, webPreferences),
}, config)) }, config))
webWindow.on('resize', () => { webTabWindow.on('resize', () => {
resizeWebTab(0) resizeWebTab(0)
}) })
webWindow.on('enter-full-screen', () => { webTabWindow.on('enter-full-screen', () => {
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'enter-full-screen', event: 'enter-full-screen',
}).then(_ => { }) }).then(_ => { })
}) })
webWindow.on('leave-full-screen', () => { webTabWindow.on('leave-full-screen', () => {
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'leave-full-screen', event: 'leave-full-screen',
}).then(_ => { }) }).then(_ => { })
}) })
webWindow.on('close', event => { webTabWindow.on('close', event => {
if (!willQuitApp) { if (!willQuitApp) {
closeWebTab(0) closeWebTab(0)
event.preventDefault() event.preventDefault()
} else { } else {
userConf.set('webWindow', webWindow.getBounds()) userConf.set('webTabWindow', webTabWindow.getBounds())
} }
}) })
webWindow.on('closed', () => { webTabWindow.on('closed', () => {
webWindow = null webTabView.forEach(({view}) => {
view.webContents.close()
})
webTabView = []
webTabWindow = null
}) })
webWindow.once('ready-to-show', () => { webTabWindow.once('ready-to-show', () => {
onShowWindow(webWindow); onShowWindow(webTabWindow);
}) })
webWindow.webContents.once('dom-ready', () => { webTabWindow.webContents.once('dom-ready', () => {
onShowWindow(webWindow); onShowWindow(webTabWindow);
}) })
webWindow.webContents.on('before-input-event', (event, input) => { webTabWindow.webContents.on('before-input-event', (event, input) => {
if (utils.isMetaOrControl(input) && input.key.toLowerCase() === 'r') { if (utils.isMetaOrControl(input) && input.key.toLowerCase() === 'r') {
reloadWebTab(0) reloadWebTab(0)
event.preventDefault() event.preventDefault()
} }
}) })
webWindow.loadFile('./render/tabs/index.html', {}).then(_ => { webTabWindow.loadFile('./render/tabs/index.html', {}).then(_ => {
}) })
} }
webWindow.focus(); webTabWindow.focus();
// 创建子窗口 // 创建子窗口
const browserView = new BrowserView({ const browserView = new BrowserView({
@ -364,18 +367,18 @@ function createWebWindow(args) {
browserView.setBounds({ browserView.setBounds({
x: 0, x: 0,
y: webTabHeight, y: webTabHeight,
width: webWindow.getContentBounds().width || 1280, width: webTabWindow.getContentBounds().width || 1280,
height: (webWindow.getContentBounds().height || 800) - webTabHeight, height: (webTabWindow.getContentBounds().height || 800) - webTabHeight,
}) })
browserView.webContents.setWindowOpenHandler(({url}) => { browserView.webContents.setWindowOpenHandler(({url}) => {
if (allowedCalls.test(url)) { if (allowedCalls.test(url)) {
return {action: 'allow'} return {action: 'allow'}
} }
createWebWindow({url}) createWebTabWindow({url})
return {action: 'deny'} return {action: 'deny'}
}) })
browserView.webContents.on('page-title-updated', (event, title) => { browserView.webContents.on('page-title-updated', (event, title) => {
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'title', event: 'title',
id: browserView.webContents.id, id: browserView.webContents.id,
title: title, title: title,
@ -386,7 +389,7 @@ function createWebWindow(args) {
if (!errorDescription) { if (!errorDescription) {
return return
} }
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'title', event: 'title',
id: browserView.webContents.id, id: browserView.webContents.id,
title: errorDescription, title: errorDescription,
@ -394,20 +397,20 @@ function createWebWindow(args) {
}).then(_ => { }) }).then(_ => { })
}) })
browserView.webContents.on('page-favicon-updated', (event, favicons) => { browserView.webContents.on('page-favicon-updated', (event, favicons) => {
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'favicon', event: 'favicon',
id: browserView.webContents.id, id: browserView.webContents.id,
favicons favicons
}).then(_ => { }) }).then(_ => { })
}) })
browserView.webContents.on('did-start-loading', _ => { browserView.webContents.on('did-start-loading', _ => {
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'start-loading', event: 'start-loading',
id: browserView.webContents.id, id: browserView.webContents.id,
}).then(_ => { }) }).then(_ => { })
}) })
browserView.webContents.on('did-stop-loading', _ => { browserView.webContents.on('did-stop-loading', _ => {
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'stop-loading', event: 'stop-loading',
id: browserView.webContents.id, id: browserView.webContents.id,
}).then(_ => { }) }).then(_ => { })
@ -422,18 +425,18 @@ function createWebWindow(args) {
}) })
browserView.webContents.loadURL(args.url).then(_ => { }).catch(_ => { }) browserView.webContents.loadURL(args.url).then(_ => { }).catch(_ => { })
webWindow.addBrowserView(browserView) webTabWindow.addBrowserView(browserView)
webTabView.push({ webTabView.push({
id: browserView.webContents.id, id: browserView.webContents.id,
view: browserView view: browserView
}) })
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'create', event: 'create',
id: browserView.webContents.id, id: browserView.webContents.id,
url: args.url, url: args.url,
}).then(_ => { }) }).then(_ => { })
switchWebTab(browserView.webContents.id) activateWebTab(browserView.webContents.id)
} }
/** /**
@ -441,7 +444,7 @@ function createWebWindow(args) {
* @returns {Electron.BrowserView|undefined} * @returns {Electron.BrowserView|undefined}
*/ */
function currentWebTab() { function currentWebTab() {
const views = webWindow.getBrowserViews() const views = webTabWindow.getBrowserViews()
const view = views.length ? views[views.length - 1] : undefined const view = views.length ? views[views.length - 1] : undefined
if (!view) { if (!view) {
return undefined return undefined
@ -473,8 +476,8 @@ function resizeWebTab(id) {
item.view.setBounds({ item.view.setBounds({
x: 0, x: 0,
y: webTabHeight, y: webTabHeight,
width: webWindow.getContentBounds().width || 1280, width: webTabWindow.getContentBounds().width || 1280,
height: (webWindow.getContentBounds().height || 800) - webTabHeight, height: (webTabWindow.getContentBounds().height || 800) - webTabHeight,
}) })
} }
@ -482,15 +485,15 @@ function resizeWebTab(id) {
* 切换内置浏览器标签 * 切换内置浏览器标签
* @param id * @param id
*/ */
function switchWebTab(id) { function activateWebTab(id) {
const item = id === 0 ? currentWebTab() : webTabView.find(item => item.id == id) const item = id === 0 ? currentWebTab() : webTabView.find(item => item.id == id)
if (!item) { if (!item) {
return return
} }
resizeWebTab(item.id) resizeWebTab(item.id)
webWindow.setTopBrowserView(item.view) webTabWindow.setTopBrowserView(item.view)
item.view.webContents.focus() item.view.webContents.focus()
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'switch', event: 'switch',
id: item.id, id: item.id,
}).then(_ => { }) }).then(_ => { })
@ -506,9 +509,9 @@ function closeWebTab(id) {
return return
} }
if (webTabView.length === 1) { if (webTabView.length === 1) {
webWindow.hide() webTabWindow.hide()
} }
webWindow.removeBrowserView(item.view) webTabWindow.removeBrowserView(item.view)
item.view.webContents.close() item.view.webContents.close()
const index = webTabView.findIndex(({id}) => item.id == id) const index = webTabView.findIndex(({id}) => item.id == id)
@ -516,16 +519,16 @@ function closeWebTab(id) {
webTabView.splice(index, 1) webTabView.splice(index, 1)
} }
utils.onDispatchEvent(webWindow.webContents, { utils.onDispatchEvent(webTabWindow.webContents, {
event: 'close', event: 'close',
id: item.id, id: item.id,
}).then(_ => { }) }).then(_ => { })
if (webTabView.length === 0) { if (webTabView.length === 0) {
userConf.set('webWindow', webWindow.getBounds()) userConf.set('webTabWindow', webTabWindow.getBounds())
webWindow.destroy() webTabWindow.destroy()
} else { } else {
switchWebTab(0) activateWebTab(0)
} }
} }
@ -612,9 +615,6 @@ app.on('browser-window-focus', () => {
if (mainWindow) { if (mainWindow) {
mainWindow.webContents.send("browserWindowFocus", {}) mainWindow.webContents.send("browserWindowFocus", {})
} }
if (storageBrowser) {
storageBrowser.webContents.reload()
}
}) })
/** /**
@ -649,8 +649,8 @@ ipcMain.on('windowQuit', (event) => {
* 创建路由窗口 * 创建路由窗口
* @param args {path, ?} * @param args {path, ?}
*/ */
ipcMain.on('windowRouter', (event, args) => { ipcMain.on('openChildWindow', (event, args) => {
createSubWindow(args) createChildWindow(args)
event.returnValue = "ok" event.returnValue = "ok"
}) })
@ -658,9 +658,9 @@ ipcMain.on('windowRouter', (event, args) => {
* 更新路由窗口 * 更新路由窗口
* @param args {?name, ?path} // name: 不是要更改的窗口名,是要把窗口名改成什么, path: 地址 * @param args {?name, ?path} // name: 不是要更改的窗口名,是要把窗口名改成什么, path: 地址
*/ */
ipcMain.on('updateRouter', (event, args) => { ipcMain.on('updateChildWindow', (event, args) => {
const browser = BrowserWindow.fromWebContents(event.sender); const browser = BrowserWindow.fromWebContents(event.sender);
updateSubWindow(browser, args) updateChildWindow(browser, args)
event.returnValue = "ok" event.returnValue = "ok"
}) })
@ -668,8 +668,8 @@ ipcMain.on('updateRouter', (event, args) => {
* 内置浏览器 - 打开创建 * 内置浏览器 - 打开创建
* @param args {url, ?} * @param args {url, ?}
*/ */
ipcMain.on('openWebWindow', (event, args) => { ipcMain.on('openWebTabWindow', (event, args) => {
createWebWindow(args) createWebTabWindow(args)
event.returnValue = "ok" event.returnValue = "ok"
}) })
@ -677,8 +677,8 @@ ipcMain.on('openWebWindow', (event, args) => {
* 内置浏览器 - 激活标签 * 内置浏览器 - 激活标签
* @param id * @param id
*/ */
ipcMain.on('webTabSwitch', (event, id) => { ipcMain.on('webTabActivate', (event, id) => {
switchWebTab(id) activateWebTab(id)
event.returnValue = "ok" event.returnValue = "ok"
}) })
@ -694,7 +694,7 @@ ipcMain.on('webTabClose', (event, id) => {
/** /**
* 内置浏览器 - 在外部浏览器打开 * 内置浏览器 - 在外部浏览器打开
*/ */
ipcMain.on('webTabBrowser', (event) => { ipcMain.on('webTabExternal', (event) => {
const item = currentWebTab() const item = currentWebTab()
if (!item) { if (!item) {
return return
@ -715,6 +715,16 @@ ipcMain.on('webTabOpenDevTools', (event) => {
event.returnValue = "ok" event.returnValue = "ok"
}) })
/**
* 内置浏览器 - 销毁所有标签及窗口
*/
ipcMain.on('webTabDestroyAll', (event) => {
if (webTabWindow) {
webTabWindow.destroy()
}
event.returnValue = "ok"
})
/** /**
* 隐藏窗口macwin隐藏其他关闭 * 隐藏窗口macwin隐藏其他关闭
*/ */
@ -748,8 +758,8 @@ ipcMain.on('windowDestroy', (event) => {
/** /**
* 关闭所有子窗口 * 关闭所有子窗口
*/ */
ipcMain.on('subWindowCloseAll', (event) => { ipcMain.on('childWindowCloseAll', (event) => {
subWindow.some(({browser}) => { childWindow.some(({browser}) => {
browser && browser.close() browser && browser.close()
}) })
event.returnValue = "ok" event.returnValue = "ok"
@ -758,8 +768,8 @@ ipcMain.on('subWindowCloseAll', (event) => {
/** /**
* 销毁所有子窗口 * 销毁所有子窗口
*/ */
ipcMain.on('subWindowDestroyAll', (event) => { ipcMain.on('childWindowDestroyAll', (event) => {
subWindow.some(({browser}) => { childWindow.some(({browser}) => {
browser && browser.destroy() browser && browser.destroy()
}) })
event.returnValue = "ok" event.returnValue = "ok"
@ -852,34 +862,6 @@ ipcMain.on('windowMax', (event) => {
event.returnValue = "ok" event.returnValue = "ok"
}) })
/**
* 创建子窗口存储浏览器
* @param args {url}
*/
ipcMain.on('storageBrowser', (event, args) => {
if (utils.isJson(args) && allowedUrls.test(args.url)) {
if (storageBrowser === null) {
storageBrowser = new BrowserWindow({
show: false,
frame: false,
transparent: true,
webPreferences: {
preload: path.join(__dirname, 'electron-preload.js'),
webSecurity: true,
nodeIntegration: true,
contextIsolation: true,
nativeWindowOpen: true
},
})
storageBrowser.on('closed', () => {
storageBrowser = null
})
}
storageBrowser.loadURL(args.url).then(_ => { }).catch(_ => { })
}
event.returnValue = "ok"
})
/** /**
* 给主窗口发送信息 * 给主窗口发送信息
* @param args {channel, data} * @param args {channel, data}
@ -1087,7 +1069,7 @@ ipcMain.on('mainWindowActive', (event) => {
ipcMain.on('updateQuitAndInstall', (event) => { ipcMain.on('updateQuitAndInstall', (event) => {
event.returnValue = "ok" event.returnValue = "ok"
willQuitApp = true willQuitApp = true
subWindow.some(({browser}) => { childWindow.some(({browser}) => {
browser && browser.destroy() browser && browser.destroy()
}) })
setTimeout(_ => { setTimeout(_ => {

View File

@ -120,7 +120,7 @@
}, },
methods: { methods: {
onSwitch(item) { onSwitch(item) {
this.sendMessage('webTabSwitch', item.id) this.sendMessage('webTabActivate', item.id)
}, },
onClose(item) { onClose(item) {
@ -128,7 +128,7 @@
}, },
onBrowser() { onBrowser() {
this.sendMessage('webTabBrowser') this.sendMessage('webTabExternal')
}, },
iconStyle(item) { iconStyle(item) {

View File

@ -41,7 +41,6 @@ import NetworkException from "./components/NetworkException";
import GuidePage from "./components/GuidePage"; import GuidePage from "./components/GuidePage";
import TaskOperation from "./pages/manage/components/TaskOperation"; import TaskOperation from "./pages/manage/components/TaskOperation";
import {mapState} from "vuex"; import {mapState} from "vuex";
import {languageName} from "./language";
export default { export default {
components: {TaskOperation, NetworkException, PreviewImageState, RightBottom, FloatSpinner, GuidePage}, components: {TaskOperation, NetworkException, PreviewImageState, RightBottom, FloatSpinner, GuidePage},
@ -132,13 +131,6 @@ export default {
} }
}) })
} }
//
window.localStorage.setItem("__system:userId__", this.userId)
window.localStorage.setItem("__system:userToken__", this.userToken)
$A.storageByBrowser({
userId: this.userId,
userToken: this.userToken,
})
}, },
immediate: true immediate: true
}, },
@ -273,7 +265,7 @@ export default {
} }
} catch (e) { } } catch (e) { }
} }
this.$Electron.sendMessage('openWebWindow', {url}); this.$store.dispatch("openWebTabWindow", url)
return true; return true;
} }
this.$Electron.registerMsgListener('dispatch', args => { this.$Electron.registerMsgListener('dispatch', args => {

View File

@ -2,6 +2,27 @@ const isElectron = !!(window && window.process && window.process.type);
const isEEUiApp = window && window.navigator && /eeui/i.test(window.navigator.userAgent); const isEEUiApp = window && window.navigator && /eeui/i.test(window.navigator.userAgent);
const isSoftware = isElectron || isEEUiApp; const isSoftware = isElectron || isEEUiApp;
const urlParams = $A.urlParameterAll()
if (urlParams.language
|| urlParams.theme
|| urlParams.userid
|| urlParams.token) {
if (urlParams.language) {
window.localStorage.setItem("__system:languageName__", urlParams.language)
}
if (urlParams.theme) {
window.localStorage.setItem("__system:themeConf__", urlParams.language)
}
if (urlParams.userid) {
window.localStorage.setItem("__system:userId__", urlParams.userid)
}
if (urlParams.token) {
window.localStorage.setItem("__system:userToken__", urlParams.token)
}
const newUrl = $A.removeURLParameter(window.location.href, ['theme', 'language', 'userid', 'token'])
window.history.replaceState(null, '', newUrl)
}
import microappInit from "./microapp" import microappInit from "./microapp"
import {switchLanguage as $L} from "./language"; import {switchLanguage as $L} from "./language";

View File

@ -915,37 +915,6 @@ import {MarkdownPreview} from "../store/markdown";
} }
return false; return false;
}, },
/**
* 通过结果存储同步本地数据
* @param json
*/
storageByBrowser(json) {
if ($A.isSoftware) {
json = Object.assign({}, this.__storageByBrowser, json)
const obj = {}
Object.keys(json).sort().map(item => {
obj[item] = json[item]
})
if (JSON.stringify(obj) == JSON.stringify(this.__storageByBrowser)) {
return
}
this.__storageByBrowser = obj
const value = encodeURIComponent(JSON.stringify(this.__storageByBrowser))
const url = $A.apiUrl(`../storage/synch?value=${value}`)
if ($A.isEEUiApp) {
$A.eeuiAppSendMessage({
action: 'storageBrowser',
url,
});
} else {
$A.Electron.sendMessage('storageBrowser', {
url
});
}
}
},
__storageByBrowser: {}
}); });
/** /**

View File

@ -12,15 +12,22 @@ export default {
mounted() { mounted() {
if (/^https*:/i.test(window.location.protocol)) { if (/^https*:/i.test(window.location.protocol)) {
let redirect = null
if (this.$router.mode === "hash") { if (this.$router.mode === "hash") {
if ($A.stringLength(window.location.pathname) > 2) { if ($A.stringLength(window.location.pathname) > 2) {
window.location.href = `${window.location.origin}/#${window.location.pathname}${window.location.search}` redirect = `${window.location.origin}/#${window.location.pathname}${window.location.search}`
} }
} else if (this.$router.mode === "history") { } else if (this.$router.mode === "history") {
if ($A.strExists(window.location.href, "/#/")) { if ($A.strExists(window.location.href, "/#/")) {
window.location.href = window.location.href.replace("/#/", "/") redirect = window.location.href.replace("/#/", "/")
} }
} }
if (redirect) {
this.$store.dispatch("userUrl", redirect).then(redirect => {
window.location.href = redirect
})
throw SyntaxError()
}
} }
}, },

View File

@ -238,7 +238,8 @@ export default {
this.getNeedStartHome(); this.getNeedStartHome();
// //
if (this.$Electron) { if (this.$Electron) {
this.$Electron.sendMessage('subWindowDestroyAll') this.$Electron.sendMessage('webTabDestroyAll')
this.$Electron.sendMessage('childWindowDestroyAll')
} }
}, },

View File

@ -537,7 +537,7 @@ export default {
} }
if (/^https*:\/\//i.test(text)) { if (/^https*:\/\//i.test(text)) {
// //
$A.eeuiAppOpenPage({ this.$store.dispatch('openAppChildPage', {
pageType: 'app', pageType: 'app',
pageTitle: ' ', pageTitle: ' ',
url: 'web.js', url: 'web.js',

View File

@ -2977,7 +2977,7 @@ export default {
} }
const path = `/single/file/msg/${data.id}`; const path = `/single/file/msg/${data.id}`;
if (this.$Electron) { if (this.$Electron) {
this.$Electron.sendMessage('windowRouter', { this.$store.dispatch('openChildWindow', {
name: `file-msg-${data.id}`, name: `file-msg-${data.id}`,
path: path, path: path,
userAgent: "/hideenOfficeTitle/", userAgent: "/hideenOfficeTitle/",
@ -2994,7 +2994,7 @@ export default {
}, },
}); });
} else if (this.$isEEUiApp) { } else if (this.$isEEUiApp) {
$A.eeuiAppOpenPage({ this.$store.dispatch('openAppChildPage', {
pageType: 'app', pageType: 'app',
pageTitle: `${msg.name} (${$A.bytesToSize(msg.size)})`, pageTitle: `${msg.name} (${$A.bytesToSize(msg.size)})`,
url: 'web.js', url: 'web.js',
@ -3003,7 +3003,7 @@ export default {
allowAccess: true, allowAccess: true,
url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}` url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}`
}, },
}); })
} else { } else {
window.open($A.apiUrl(`..${path}`)) window.open($A.apiUrl(`..${path}`))
} }

View File

@ -180,7 +180,7 @@ export default {
case 'preview': case 'preview':
const path = `/single/file/${this.fileId}?history_id=${row.id}&history_at=${row.created_at}`; const path = `/single/file/${this.fileId}?history_id=${row.id}&history_at=${row.created_at}`;
if (this.$Electron) { if (this.$Electron) {
this.$Electron.sendMessage('windowRouter', { this.$store.dispatch('openChildWindow', {
name: `file-${this.fileId}-${row.id}`, name: `file-${this.fileId}-${row.id}`,
path: path, path: path,
userAgent: "/hideenOfficeTitle/", userAgent: "/hideenOfficeTitle/",
@ -197,7 +197,7 @@ export default {
}, },
}); });
} else if (this.$isEEUiApp) { } else if (this.$isEEUiApp) {
$A.eeuiAppOpenPage({ this.$store.dispatch('openAppChildPage', {
pageType: 'app', pageType: 'app',
pageTitle: $A.getFileName(this.file) + ` [${row.created_at}]`, pageTitle: $A.getFileName(this.file) + ` [${row.created_at}]`,
url: 'web.js', url: 'web.js',
@ -206,7 +206,7 @@ export default {
allowAccess: true, allowAccess: true,
url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}` url: $A.rightDelete(window.location.href, window.location.hash) + `#${path}`
}, },
}); })
} else { } else {
window.open($A.apiUrl(`..${path}`)) window.open($A.apiUrl(`..${path}`))
} }

View File

@ -111,7 +111,7 @@ export default {
width: Math.min(window.screen.availWidth, 1440), width: Math.min(window.screen.availWidth, 1440),
height: Math.min(window.screen.availHeight, 900), height: Math.min(window.screen.availHeight, 900),
} }
this.$Electron.sendMessage('windowRouter', { this.$store.dispatch('openChildWindow', {
name: `report-detail-${row.id}`, name: `report-detail-${row.id}`,
path: `/single/report/detail/${row.id}`, path: `/single/report/detail/${row.id}`,
force: false, force: false,
@ -134,7 +134,7 @@ export default {
width: Math.min(window.screen.availWidth, 1440), width: Math.min(window.screen.availWidth, 1440),
height: Math.min(window.screen.availHeight, 900), height: Math.min(window.screen.availHeight, 900),
} }
this.$Electron.sendMessage('windowRouter', { this.$store.dispatch('openChildWindow', {
name: `report-edit-${id}`, name: `report-edit-${id}`,
path: `/single/report/edit/${id}`, path: `/single/report/edit/${id}`,
force: false, force: false,

View File

@ -1551,7 +1551,7 @@ export default {
config.minWidth = 800; config.minWidth = 800;
config.minHeight = 600; config.minHeight = 600;
} }
this.$Electron.sendMessage('windowRouter', { this.$store.dispatch('openChildWindow', {
name: `task-${this.taskDetail.id}`, name: `task-${this.taskDetail.id}`,
path: `/single/task/${this.taskDetail.id}?navActive=${this.navActive}`, path: `/single/task/${this.taskDetail.id}?navActive=${this.navActive}`,
force: false, force: false,
@ -1609,7 +1609,7 @@ export default {
} }
const path = `/single/file/task/${file.id}`; const path = `/single/file/task/${file.id}`;
if (this.$Electron) { if (this.$Electron) {
this.$Electron.sendMessage('windowRouter', { this.$store.dispatch('openChildWindow', {
name: `file-task-${file.id}`, name: `file-task-${file.id}`,
path: path, path: path,
userAgent: "/hideenOfficeTitle/", userAgent: "/hideenOfficeTitle/",
@ -1626,7 +1626,7 @@ export default {
}, },
}); });
} else if (this.$isEEUiApp) { } else if (this.$isEEUiApp) {
$A.eeuiAppOpenPage({ this.$store.dispatch('openAppChildPage', {
pageType: 'app', pageType: 'app',
pageTitle: `${file.name} (${$A.bytesToSize(file.size)})`, pageTitle: `${file.name} (${$A.bytesToSize(file.size)})`,
url: 'web.js', url: 'web.js',

View File

@ -1121,7 +1121,7 @@ export default {
openFileSingle(item) { openFileSingle(item) {
const path = `/single/file/${item.id}`; const path = `/single/file/${item.id}`;
if (this.$Electron) { if (this.$Electron) {
this.$Electron.sendMessage('windowRouter', { this.$store.dispatch('openChildWindow', {
name: `file-${item.id}`, name: `file-${item.id}`,
path: path, path: path,
userAgent: "/hideenOfficeTitle/", userAgent: "/hideenOfficeTitle/",
@ -1138,7 +1138,7 @@ export default {
}, },
}); });
} else if (this.$isEEUiApp) { } else if (this.$isEEUiApp) {
$A.eeuiAppOpenPage({ this.$store.dispatch('openAppChildPage', {
pageType: 'app', pageType: 'app',
pageTitle: $A.getFileName(item), pageTitle: $A.getFileName(item),
url: 'web.js', url: 'web.js',

View File

@ -182,7 +182,7 @@ export default {
openPrivacy() { openPrivacy() {
const url = $A.apiUrl('privacy') const url = $A.apiUrl('privacy')
if (this.$isEEUiApp) { if (this.$isEEUiApp) {
$A.eeuiAppOpenPage({ this.$store.dispatch('openAppChildPage', {
pageType: 'app', pageType: 'app',
pageTitle: ' ', pageTitle: ' ',
url: 'web.js', url: 'web.js',

View File

@ -50,6 +50,16 @@ export default {
state.userToken = state.userInfo.token state.userToken = state.userInfo.token
state.userIsAdmin = $A.inArray("admin", state.userInfo.identity) state.userIsAdmin = $A.inArray("admin", state.userInfo.identity)
} }
const localId = $A.runNum(window.localStorage.getItem("__system:userId__"))
const localToken = window.localStorage.getItem("__system:userToken__") || ""
if (localId || localToken) {
if (!state.userId && !state.userToken) {
state.userId = localId
state.userToken = localToken
}
window.localStorage.removeItem("__system:userId__")
window.localStorage.removeItem("__system:userToken__")
}
// ServerUrl // ServerUrl
if (state.cacheServerUrl) { if (state.cacheServerUrl) {
@ -85,7 +95,6 @@ export default {
`language/web/key.js`, `language/web/key.js`,
`language/web/${languageName}.js`, `language/web/${languageName}.js`,
]) ])
$A.storageByBrowser({languageName})
resolve(action) resolve(action)
}) })
@ -365,6 +374,10 @@ export default {
*/ */
needHome({dispatch, state}) { needHome({dispatch, state}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if ($A.isSoftware) {
reject()
return
}
dispatch("systemSetting").then(data => { dispatch("systemSetting").then(data => {
if (data.start_home === 'open') { if (data.start_home === 'open') {
resolve() resolve()
@ -524,7 +537,6 @@ export default {
themeName: state.themeName, themeName: state.themeName,
}); });
} }
$A.storageByBrowser({themeConf: state.themeConf})
}, },
/** /**
@ -900,6 +912,66 @@ export default {
}); });
}, },
/** *****************************************************************************************/
/** *************************************** 新窗口打开 ****************************************/
/** *****************************************************************************************/
/**
* 链接添加用户身份
* @param state
* @param url
* @returns {Promise<unknown>}
*/
userUrl({state}, url) {
return new Promise(resolve => {
const newUrl = $A.urlAddParams(url, {
language: languageName,
theme: state.themeConf,
userid: state.userId,
token: state.userToken,
})
resolve(newUrl)
})
},
/**
* 打开子窗口App
* @param dispatch
* @param objects
*/
openAppChildPage({dispatch}, objects) {
dispatch("userUrl", objects.params.url).then(url => {
objects.params.url = url
$A.eeuiAppOpenPage(objects)
})
},
/**
* 打开子窗口客户端
* @param dispatch
* @param params
*/
openChildWindow({dispatch}, params) {
dispatch("userUrl", params.path).then(path => {
$A.Electron.sendMessage('openChildWindow', Object.assign(params, {path}))
})
},
/**
* 打开新标签窗口客户端
* @param dispatch
* @param url
*/
openWebTabWindow({dispatch}, url) {
if ($A.getDomain(url) != $A.getDomain($A.apiUrl('../'))) {
$A.Electron.sendMessage('openWebTabWindow', {url})
return
}
dispatch("userUrl", url).then(url => {
$A.Electron.sendMessage('openWebTabWindow', {url})
})
},
/** *****************************************************************************************/ /** *****************************************************************************************/
/** ************************************** 文件 **********************************************/ /** ************************************** 文件 **********************************************/
/** *****************************************************************************************/ /** *****************************************************************************************/
@ -1900,7 +1972,7 @@ export default {
} }
if ($A.isSubElectron) { if ($A.isSubElectron) {
if (task_id > 0) { if (task_id > 0) {
$A.Electron.sendMessage('updateRouter', { $A.Electron.sendMessage('updateChildWindow', {
name: `task-${task_id}`, name: `task-${task_id}`,
path: `/single/task/${task_id}`, path: `/single/task/${task_id}`,
}); });

View File

@ -1,21 +0,0 @@
<script>
function isArray(obj) {
return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == '[object array]' && typeof obj.length == "number";
}
function isJson(obj) {
return typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && typeof obj.length == "undefined";
}
let storages = {!! $value !!};
if (isArray(storages)) {
storages.forEach(storage => {
window.localStorage.setItem(`__system:${storage.key}__`, storage.value);
})
} else if (isJson(storages)) {
for (let key in storages) {
let value = storages[key];
window.localStorage.setItem(`__system:${key}__`, value);
}
}
</script>