| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import store from '@/store/index'
- export default {
- windowInfo: null,
- deviceOrientation: 'portrait', // 设备方向(竖屏 portrait | 横屏 landscape)
- windowHeight: 0,
- windowWidth: 0,
- // 全屏展示
- fullscreen() {
- var fullscreenFlag = false
- 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'
- })
- }
- fullscreenFlag = false
- store.commit('setFullScreen', fullscreenFlag)
- } else {
- let elem = document.body;
- if (elem.webkitRequestFullScreen) {
- elem.webkitRequestFullScreen();
- fullscreenFlag = true
- } else if (elem.mozRequestFullScreen) {
- elem.mozRequestFullScreen();
- fullscreenFlag = true
- } else if (elem.requestFullScreen) {
- elem.requestFullscreen();
- fullscreenFlag = true
- } else {
- uni.showToast({
- title: '浏览器不支持全屏API或已被禁用',
- icon: 'none'
- })
- fullscreenFlag = false
- }
- store.commit('setFullScreen', fullscreenFlag)
- }
- },
-
- // 获取系统信息
- getWindowInfo(windowSize = '') {
- if (windowSize == '') {
- // this.windowInfo = uni.getSystemInfoSync()
- this.windowInfo = uni.getWindowInfo()
- 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
- },
- }
|