diff --git a/resources/assets/js/App.vue b/resources/assets/js/App.vue index c8b831c94..f20bf294f 100755 --- a/resources/assets/js/App.vue +++ b/resources/assets/js/App.vue @@ -233,7 +233,7 @@ export default { windowSizeListener() { const windowWidth = $A(window).width(), windowHeight = $A(window).height(), - windowOrientation = $A.strExists(window.screen.orientation.type, 'portrait') ? 'portrait' : 'landscape' + windowOrientation = $A.screenOrientation() this.$store.state.windowTouch = "ontouchend" in document diff --git a/resources/assets/js/functions/common.js b/resources/assets/js/functions/common.js index aa0de14eb..37f88a573 100755 --- a/resources/assets/js/functions/common.js +++ b/resources/assets/js/functions/common.js @@ -547,6 +547,21 @@ const localforage = require("localforage"); }, 250); }, + /** + * 获取屏幕方向 + * @returns {string} + */ + screenOrientation() { + try { + if (typeof window.screen.orientation === "object") { + return $A.strExists(window.screen.orientation.type, 'portrait') ? 'portrait' : 'landscape' + } + } catch (e) { + // + } + return $A(window).width() > $A(window).height() ? "landscape" : "portrait" + }, + /** * 是否IOS * @returns {boolean|string} diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index b5e89919c..4f3fc766d 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -1,6 +1,6 @@ const windowWidth = $A(window).width(), windowHeight = $A(window).height(), - windowOrientation = $A.strExists(window.screen.orientation.type, 'portrait') ? 'portrait' : 'landscape' + windowOrientation = $A.screenOrientation() export default { // 客户端ID(希望不变的,除非清除浏览器缓存或者卸载应用)