| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import store from '@/store/index'
- export default {
- windowInfo: null,
- deviceOrientation: 'portrait', // 设备方向(竖屏 portrait | 横屏 landscape)
- screenWidth: 0, // 屏幕宽度
- screenHeight: 0,// 屏幕高度
- windowHeight: 0,// 可使用窗口宽度
- windowWidth: 0, // 可使用窗口高度
- fullscreenFlag: false,
-
- // 全屏展示
- fullscreen() {
- if (document.fullscreenElement || document.webkitFullScreenElement || document.mozFullScreenElement ||
- document.msFullScreenElement) {
- // alert('当前是全屏')
- if (document.webkitCancelFullScreen) {
- document.webkitCancelFullScreen();
- } else if (document.mozCancelFullScreen) {
- document.mozCancelFullScreen();
- } else if (document.exitFullscreen) {
- document.exitFullscreen();
- } else {
- uni.showToast({
- title: '浏览器不支持全屏API或已被禁用',
- icon: 'none'
- })
- }
- this.fullscreenFlag = false
- store.commit('setFullScreen', this.fullscreenFlag)
- } else {
- let elem = document.body;
- if (elem.webkitRequestFullScreen) {
- elem.webkitRequestFullScreen();
- this.fullscreenFlag = true
- } else if (elem.mozRequestFullScreen) {
- elem.mozRequestFullScreen();
- this.fullscreenFlag = true
- } else if (elem.requestFullScreen) {
- elem.requestFullscreen();
- this.fullscreenFlag = true
- } else {
- uni.showToast({
- title: '浏览器不支持全屏API或已被禁用',
- icon: 'none'
- })
- this.fullscreenFlag = false
- }
- store.commit('setFullScreen', this.fullscreenFlag)
- }
-
- // 去除foucs红框(微信浏览器全屏时偶尔会出现foucs红框)
- document.activeElement.blur();
- },
-
- // 获取系统信息
- getWindowInfo(windowSize = '') {
- if (windowSize == '') {
- // this.windowInfo = uni.getSystemInfoSync()
- this.windowInfo = uni.getWindowInfo()
- this.screenWidth = this.windowInfo.screenWidth
- this.screenHeight = this.windowInfo.screenHeight
- this.windowHeight = this.windowInfo.windowHeight
- this.windowWidth = this.windowInfo.windowWidth
- // console.log('[getWindowInfo] this.windowHeight', this.windowHeight, this.windowInfo)
- } else {
- this.windowInfo = windowSize
- this.windowHeight = windowSize.windowHeight
- this.windowWidth = windowSize.windowWidth
- // console.log('[getWindowInfo] this.windowHeight 2', this.windowHeight)
- }
- if (this.windowHeight > this.windowWidth) {
- console.log('[getWindowInfo] 竖屏 windowWidth:' + this.windowWidth + ' windowHeight:' + this.windowHeight)
- // uni.showToast({
- // title: '竖屏 windowWidth=' + this.windowWidth + ' windowHeight:' + this.windowHeight,
- // icon: 'none',
- // duration: 2000
- // })
- this.deviceOrientation = 'portrait'
- } else { // 横屏
- console.log('[getWindowInfo] 横屏 windowWidth:' + this.windowWidth + ' windowHeight:' + this.windowHeight)
- // uni.showToast({
- // title: '横屏 windowWidth=' + this.windowWidth + ' windowHeight:' + this.windowHeight,
- // icon: 'none',
- // duration: 2000
- // })
- this.deviceOrientation = 'landscape'
- }
-
- return this.windowInfo
- },
- }
|