diff --git a/electron/electron.js b/electron/electron.js index e5cff719d..388f379a9 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -434,7 +434,7 @@ function createChildWindow(args) { if (/^https?:/i.test(hash)) { browser.loadURL(hash).then(_ => { }).catch(_ => { }) } else if (isPreload) { - browser.webContents.executeJavaScript(`if(typeof $A.goForward === 'function'){$A.goForward('${hash}')}else{throw new Error('no function')}`, true).catch(() => { + browser.webContents.executeJavaScript(`if(typeof window.__initializeApp === 'function'){window.__initializeApp('${hash}')}else{throw new Error('no function')}`, true).catch(() => { utils.loadUrlOrFile(browser, devloadUrl, hash) }); } else { diff --git a/resources/assets/js/App.vue b/resources/assets/js/App.vue index 4ee5b3c4a..71ee95fcd 100755 --- a/resources/assets/js/App.vue +++ b/resources/assets/js/App.vue @@ -82,19 +82,11 @@ export default { }, mounted() { - window.addEventListener('resize', this.windowSizeListener) - window.addEventListener('scroll', this.windowScrollListener) - window.addEventListener('message', this.windowHandleMessage) - window.addEventListener('fullscreenchange', this.handleFullscreenchange); this.appInter = setInterval(this.appTimerHandler, 1000) $A.loadVConsole() }, beforeDestroy() { - window.removeEventListener('resize', this.windowSizeListener) - window.removeEventListener('scroll', this.windowScrollListener) - window.removeEventListener('message', this.windowHandleMessage) - window.removeEventListener('fullscreenchange', this.handleFullscreenchange); this.appInter && clearInterval(this.appInter) }, @@ -250,59 +242,10 @@ export default { } }, - windowSizeListener() { - const windowWidth = $A(window).width(), - windowHeight = $A(window).height(), - windowOrientation = $A.screenOrientation() - - this.$store.state.windowTouch = "ontouchend" in document - - this.$store.state.windowWidth = windowWidth - this.$store.state.windowHeight = windowHeight - - this.$store.state.windowOrientation = windowOrientation - this.$store.state.windowLandscape = windowOrientation === 'landscape' - this.$store.state.windowPortrait = windowOrientation === 'portrait' - - this.$store.state.formOptions = { - class: windowWidth > 576 ? '' : 'form-label-weight-bold', - labelPosition: windowWidth > 576 ? 'right' : 'top', - labelWidth: windowWidth > 576 ? 'auto' : '', - } - - $A.eeuiAppSendMessage({ - action: 'windowSize', - width: windowWidth, - height: windowHeight, - }); - }, - - windowScrollListener() { - this.$store.state.windowScrollY = window.scrollY - }, - - windowHandleMessage({data}) { - data = $A.jsonParse(data); - if (data.action === 'eeuiAppSendMessage') { - const items = $A.isArray(data.data) ? data.data : [data.data]; - items.forEach(item => { - $A.eeuiAppSendMessage(item); - }) - } - }, - onRouterViewMounted() { document.documentElement.setAttribute("data-platform", $A.isElectron ? "desktop" : $A.isEEUiApp ? "app" : "web") }, - handleFullscreenchange() { - if (document.fullscreenElement) { - $A("body").addClass("fullscreen-mode") - } else { - $A("body").removeClass("fullscreen-mode") - } - }, - /** * 获取链接打开方式 * @param url diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 3e7436276..254837958 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -263,7 +263,8 @@ Vue.config.productionTip = false; Vue.mixin(mixin) let app; -store.dispatch("init").then(action => { +const $init = async () => { + const action = await store.dispatch("init"); microappInit(); @@ -287,4 +288,26 @@ store.dispatch("init").then(action => { if (typeof window.LANGUAGE_DATA[`i_${languageName}`] !== "undefined") { ViewUI.locale(window.LANGUAGE_DATA[`i_${languageName}`]); } -}) +} + +const $preload = async () => { + await store.dispatch("preload"); + const currentPath = (window.location.pathname || window.location.hash).replace(/^[#\/]/, ''); + if (currentPath !== 'preload') { + $init().catch(_ => {}) + return + } + window.__initializeApp = (route) => { + if (/^https?:\/\//.test(route)) { + if ($A.getDomain(route) !== $A.getDomain($A.mainUrl())) { + window.location.href = url; + return; + } + route = route.replace(/^https?:\/\/[^\/]+/, ''); + } + window.history.replaceState(null, '', route) + $init().catch(_ => {}) + } +} + +$preload().catch(_ => {}) diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index fb8c530fa..99176571c 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -4,6 +4,61 @@ import {$callData, $urlSafe, SSEClient} from './utils' import emitter from "./events"; export default { + /** + * 预加载 + * @param state + */ + preload({state}) { + window.addEventListener('resize', () => { + const windowWidth = $A(window).width(), + windowHeight = $A(window).height(), + windowOrientation = $A.screenOrientation() + + state.windowTouch = "ontouchend" in document + + state.windowWidth = windowWidth + state.windowHeight = windowHeight + + state.windowOrientation = windowOrientation + state.windowLandscape = windowOrientation === 'landscape' + state.windowPortrait = windowOrientation === 'portrait' + + state.formOptions = { + class: windowWidth > 576 ? '' : 'form-label-weight-bold', + labelPosition: windowWidth > 576 ? 'right' : 'top', + labelWidth: windowWidth > 576 ? 'auto' : '', + } + + $A.eeuiAppSendMessage({ + action: 'windowSize', + width: windowWidth, + height: windowHeight, + }); + }) + + window.addEventListener('scroll', () => { + state.windowScrollY = window.scrollY + }) + + window.addEventListener('message', ({data}) => { + data = $A.jsonParse(data); + if (data.action === 'eeuiAppSendMessage') { + const items = $A.isArray(data.data) ? data.data : [data.data]; + items.forEach(item => { + $A.eeuiAppSendMessage(item); + }) + } + }) + + window.addEventListener('fullscreenchange', () => { + if (document.fullscreenElement) { + $A("body").addClass("fullscreen-mode") + } else { + $A("body").removeClass("fullscreen-mode") + } + }); + }, + /** * 初始化 * @param state