element-request-fullscreen.uvue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <scroll-view class="content" direction="vertical">
  3. <view id="fullscreen" class="view1" @click="fullscreen" @fullscreenchange="fullscreenchange" @fullscreenerror="fullscreenerror">
  4. <text style="color: white;">{{ text }}</text>
  5. </view>
  6. <enum-data :items="orientation_enum" title="orientation" @change="radio_change_orientation"></enum-data>
  7. <enum-data :items="navigationUI_enum" title="navigationUI" @change="radio_change_ui"></enum-data>
  8. </scroll-view>
  9. </template>
  10. <script>
  11. import { ItemType } from '@/components/enum-data/enum-data-types';
  12. export default {
  13. data() {
  14. return {
  15. orientation_enum: [{ "value": 0, "name": "auto" }, { "value": 1, "name": "landscape" }, { "value": 2, "name": "landscape-primary" }, { "value": 3, "name": "landscape-secondary" }, { "value": 4, "name": "portrait" }] as ItemType[],
  16. navigationUI_enum: [{ "value": 0, "name": "auto" }, { "value": 1, "name": "hide" }, { "value": 2, "name": "show" }] as ItemType[],
  17. text: "点击进入全屏",
  18. fullscreenElement: null as UniElement | null,
  19. isFullscreen: false,
  20. orientation: "landscape",
  21. navigationUI: "hide",
  22. fullscreenchangeCount: 0
  23. }
  24. },
  25. onReady() {
  26. this.fullscreenElement = uni.getElementById('fullscreen') as UniElement
  27. },
  28. methods: {
  29. getCurrentPage() : UniPage {
  30. const pages = getCurrentPages()
  31. return pages[pages.length - 1]
  32. },
  33. fullscreen() {
  34. if (this.isFullscreen) {
  35. const page = this.getCurrentPage()
  36. page.exitFullscreen({
  37. success: () => {
  38. this.text = "点击进入全屏"
  39. },
  40. fail: (err) => {
  41. console.log('fail', err)
  42. },
  43. complete: () => {
  44. console.log('complete')
  45. }
  46. })
  47. } else {
  48. this.fullscreenElement?.requestFullscreen({
  49. navigationUI: this.navigationUI,
  50. orientation: this.orientation,
  51. success: () => {
  52. this.text = "点击退出全屏"
  53. },
  54. fail: (err) => {
  55. console.log('fail', err)
  56. },
  57. complete: () => {
  58. console.log('complete')
  59. }
  60. })
  61. }
  62. this.isFullscreen = !this.isFullscreen
  63. },
  64. fullscreenchange(e : UniEvent) {
  65. console.log(e.type)
  66. this.fullscreenchangeCount++
  67. console.log(this.fullscreenchangeCount)
  68. },
  69. fullscreenerror(e : UniEvent) {
  70. console.log(e.type)
  71. },
  72. radio_change_orientation(checked : number) {
  73. console.log(checked)
  74. this.orientation = this.orientation_enum[checked]['name'] as string
  75. },
  76. radio_change_ui(checked : number) {
  77. console.log(checked)
  78. this.navigationUI = this.navigationUI_enum[checked]['name'] as string
  79. }
  80. }
  81. }
  82. </script>
  83. <style>
  84. .content {
  85. flex: 1;
  86. background-color: #f0f0f0;
  87. }
  88. .view1 {
  89. width: 100%;
  90. height: 150px;
  91. align-items: center;
  92. justify-content: center;
  93. background-color: black;
  94. }
  95. </style>