global.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import store from '@/store/index'
  2. export default {
  3. windowInfo: null,
  4. deviceOrientation: 'portrait', // 设备方向(竖屏 portrait | 横屏 landscape)
  5. windowHeight: 0,
  6. windowWidth: 0,
  7. // 全屏展示
  8. fullscreen() {
  9. var fullscreenFlag = false
  10. if (document.fullscreenElement || document.webkitFullScreenElement || document.mozFullScreenElement ||
  11. document.msFullScreenElement) {
  12. // alert('当前是全屏')
  13. if (document.webkitCancelFullScreen) {
  14. document.webkitCancelFullScreen();
  15. } else if (document.mozCancelFullScreen) {
  16. document.mozCancelFullScreen();
  17. } else if (document.exitFullscreen) {
  18. document.exitFullscreen();
  19. } else {
  20. uni.showToast({
  21. title: '浏览器不支持全屏API或已被禁用',
  22. icon: 'none'
  23. })
  24. }
  25. fullscreenFlag = false
  26. store.commit('setFullScreen', fullscreenFlag)
  27. } else {
  28. let elem = document.body;
  29. if (elem.webkitRequestFullScreen) {
  30. elem.webkitRequestFullScreen();
  31. fullscreenFlag = true
  32. } else if (elem.mozRequestFullScreen) {
  33. elem.mozRequestFullScreen();
  34. fullscreenFlag = true
  35. } else if (elem.requestFullScreen) {
  36. elem.requestFullscreen();
  37. fullscreenFlag = true
  38. } else {
  39. uni.showToast({
  40. title: '浏览器不支持全屏API或已被禁用',
  41. icon: 'none'
  42. })
  43. fullscreenFlag = false
  44. }
  45. store.commit('setFullScreen', fullscreenFlag)
  46. }
  47. },
  48. // 获取系统信息
  49. getWindowInfo(windowSize = '') {
  50. if (windowSize == '') {
  51. // this.windowInfo = uni.getSystemInfoSync()
  52. this.windowInfo = uni.getWindowInfo()
  53. this.windowHeight = this.windowInfo.windowHeight
  54. this.windowWidth = this.windowInfo.windowWidth
  55. // console.log('[getWindowInfo] this.windowHeight', this.windowHeight, this.windowInfo)
  56. } else {
  57. this.windowInfo = windowSize
  58. this.windowHeight = windowSize.windowHeight
  59. this.windowWidth = windowSize.windowWidth
  60. // console.log('[getWindowInfo] this.windowHeight 2', this.windowHeight)
  61. }
  62. if (this.windowHeight > this.windowWidth) {
  63. console.log('[getWindowInfo] 竖屏 windowWidth:' + this.windowWidth + ' windowHeight:' + this.windowHeight)
  64. // uni.showToast({
  65. // title: '竖屏 windowWidth=' + this.windowWidth + ' windowHeight:' + this.windowHeight,
  66. // icon: 'none',
  67. // duration: 2000
  68. // })
  69. this.deviceOrientation = 'portrait'
  70. } else { // 横屏
  71. console.log('[getWindowInfo] 横屏 windowWidth:' + this.windowWidth + ' windowHeight:' + this.windowHeight)
  72. // uni.showToast({
  73. // title: '横屏 windowWidth=' + this.windowWidth + ' windowHeight:' + this.windowHeight,
  74. // icon: 'none',
  75. // duration: 2000
  76. // })
  77. this.deviceOrientation = 'landscape'
  78. }
  79. return this.windowInfo
  80. },
  81. }