IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> JavaScript知识库 -> Vue F11监听切大屏 -> 正文阅读

[JavaScript知识库]Vue F11监听切大屏

用Datav插件做大屏可视化时,有一个全屏需求,我的想法是监听F11键,然后触发浏览器的大屏功能API。百度一下,竟有插件,大喜。插件的好处大家都知道,时间熬出来的,并且BUG极少,代码精简,做了全浏览器兼容。

Rec 0001

步骤

1.插件

npm install --save screenfull

2.引入(可全局,也可需要的文件中引入)

import screenfull from 'screenfull'

3.datav的全屏(这个全屏是做了页面级的全屏处理,如不是单页布局不结合这个用会有问题)

  <dv-full-screen-container style="background-color: rgb(11, 8, 53);">
</dv-full-screen-container>

4.html的放大按钮

 <el-button
                          style="font-size:20px;"
                          type="text"
                          size="mini"
                          icon="el-icon-full-screen"
                          @click="clickFullscreen()"
                        ></el-button>

5.全屏插件结合datav的全屏js代码

 data() {
    return {
      show_big: false,
      fullscreen:false

    }
  },
  computed: {
  },
  watch: {
    fullscreen(newvalue, oldvalue) {
      if (newvalue != oldvalue) {
        // 进行退出全屏的后的事件
        console.log('退出全屏')
      }
    }
  },
  mounted() {
    const that = this
    window.addEventListener('keydown', this.KeyDown, true)
    window.onresize = () => {
      // 调用判断全屏的方法,用来监听
      that.checkFull()
    }
  },
  created() {
  },
  beforeDestroy() {
  },
  methods: {

    KeyDown(event) {
      if (event.keyCode === 122) {
        event.returnValue = false
        this.clickFullscreen() // 触发全屏的按钮
      }
    },

    clickFullscreen() {
      screenfull.toggle()	// 全屏状态切换
      this.fullscreen = !this.fullscreen
      this.show_big = !this.show_big
    },
    checkFull() {
      const fullscreen = window.fullScreen || document.webkitIsFullScreen
      this.fullscreen = fullscreen
      return fullscreen
    }
  }

大功就告成了

================================如果遇到问题==========================

vue screenfull全屏插件 安装之后 npm run serve报错
 Module parse failed: Unexpected token (55:42) You may need a

解决办法,用低版本插件,执行如下

npm install --save-dev screenfull@5.1.0

想看我的全部代码,贴上

<template>
  <div class="big-screen-container" @dblclick="clickFullscreen()">
    <div v-if="show_big">
      <dv-full-screen-container style="background-color: rgb(11, 8, 53);">
        <dv-border-box-11
          :title="$t('programModel.faceTempMonitor')"
          style="height:800px;width:100%;padding-top:60px;padding-left:22px;"
          background-color="transparent">
          <!-- <div style="text-align:right;margin-right:10px">
          <el-button
            style="font-size:15px;"
            type="text"
            size="mini"
            icon="el-icon-full-screen"
            @click="showBig()"
          ></el-button>
        </div> -->
          <el-row>
            <el-col :span="8">
              <el-row>
                <el-col>
                  <div style="margin-top:10px;">
                    <man-card :bean="bean"></man-card>
                  </div>
                </el-col>
              </el-row>
              <el-row>
                <el-col>
                  <div >
                    <acid-card :bean="bean"></acid-card>
                  </div>
                </el-col>
              </el-row>
              <el-row>
                <el-col>
                  <div >
                    <temp-card :bean="bean"></temp-card>
                  </div>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="8">
              <el-row style="margin:10px 10px 0px 10px;">
                <el-col>
                  <abnormal-card :bean="bean">
                  </abnormal-card>
                </el-col>
              </el-row>
              <el-row>
                <el-col>
                  <total-card :bean="bean">
                  </total-card>
                </el-col>
              </el-row>
              <el-row style="margin:0 10px 0 10px;">
                <el-col>
                  <device-card :bean="bean">
                  </device-card>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="8">
              <el-row style="margin:10px 25px 10px 0px ">
                <el-col>
                  <normal-img-card :bean="bean">
                  </normal-img-card>
                </el-col>
              </el-row>
              <el-row style="margin-right:25px">
                <el-col>
                  <abnormal-img-card :bean="bean">
                  </abnormal-img-card>
                </el-col>
              </el-row>
              <el-row style="margin-top:10px;margin-right:25px">
                <el-col>
                  <div class="img-abnormal-card" style="height:53px;width:100%;background-color:transparent;">
                    <dv-border-box-10 background-color="transparent" style="text-align:center;margin-right:20px">
                      <div style="display:flex;flex-dirction:row">
                        <div style="width:100%;line-height:50px;margin-right:20px;font-size:12px;color:#67C23A">
                          <span v-show="count >0">{{ count }}{{ $t('screenbig.afterFresh') }}</span>
                        </div>
                        <div style="line-height:60px;margin-right:20px;font-size:12px;color:#67C23A">
                          <el-button
                            style="font-size:20px;"
                            type="text"
                            size="mini"
                            icon="el-icon-full-screen"
                            @click="clickFullscreen()"
                          ></el-button>
                        </div>
                      </div>
                    </dv-border-box-10>
                  </div>
                </el-col>
              </el-row>
            </el-col>
          </el-row>
        </dv-border-box-11>
      </dv-full-screen-container>
    </div>
    <div v-else>

      <dv-border-box-11
        :title="$t('programModel.faceTempMonitor')"
        style="height:800px;width:100%;padding-top:60px;padding-left:22px;"
        background-color="transparent">
        <!-- <div style="text-align:right;margin-right:10px">
          <el-button
            style="font-size:15px;"
            type="text"
            size="mini"
            icon="el-icon-full-screen"
            @click="showBig()"
          ></el-button>
        </div> -->
        <el-row>
          <el-col :span="8">
            <el-row>
              <el-col>
                <div style="margin-top:10px;">
                  <man-card :bean="bean"></man-card>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <div >
                  <acid-card :bean="bean"></acid-card>
                </div>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <div >
                  <temp-card :bean="bean"></temp-card>
                </div>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="8">
            <el-row style="margin:10px 10px 0px 10px;">
              <el-col>
                <abnormal-card :bean="bean">
                </abnormal-card>
              </el-col>
            </el-row>
            <el-row>
              <el-col>
                <total-card :bean="bean">
                </total-card>
              </el-col>
            </el-row>
            <el-row style="margin:0 10px 0 10px;">
              <el-col>
                <device-card :bean="bean">
                </device-card>
              </el-col>
            </el-row>
          </el-col>
          <el-col :span="8">
            <el-row style="margin:10px 25px 10px 0px ">
              <el-col>
                <normal-img-card :bean="bean">
                </normal-img-card>
              </el-col>
            </el-row>
            <el-row style="margin-right:25px">
              <el-col>
                <abnormal-img-card :bean="bean">
                </abnormal-img-card>
              </el-col>
            </el-row>
            <el-row style="margin-top:10px;margin-right:25px">
              <el-col>
                <div class="img-abnormal-card" style="height:53px;width:100%;background-color:transparent;">
                  <dv-border-box-10 background-color="transparent" style="text-align:center;margin-right:20px">
                    <div style="display:flex;flex-dirction:row">
                      <div style="width:100%;line-height:50px;margin-right:20px;font-size:12px;color:#67C23A">
                        <span v-show="count >0">{{ count }}{{ $t('screenbig.afterFresh') }}</span>
                      </div>
                      <div style="line-height:60px;margin-right:20px;font-size:12px;color:#67C23A">
                        <el-button
                          style="font-size:20px;"
                          type="text"
                          size="mini"
                          icon="el-icon-full-screen"
                          @click="clickFullscreen()"
                        ></el-button>
                      </div>
                    </div>
                  </dv-border-box-10>
                </div>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </dv-border-box-11>
    </div>

  </div>
</template>

<script>
import screenfull from 'screenfull'
import {
  getAetMonitor
} from '@/api/user'
import manCard from './components/man-card'
import acidCard from './components/acid-card'
import tempCard from './components/temp-card'
import totalCard from './components/total-card'
import temperCard from './components/temper-card'
import deviceCard from './components/device-card'
import abnormalCard from './components/abnormal-card'
import abnormalImgCard from './components/abnormal-img-card'
import normalImgCard from './components/normal-img-card'
export default {
  name: 'Home',
  components: {
    manCard,
    normalImgCard,
    acidCard,
    temperCard,
    deviceCard,
    abnormalCard,
    abnormalImgCard,
    tempCard,
    totalCard
  },
  data() {
    return {
      show_big: false,
      bean: undefined,
      fullscreen:flase,
      timer: null,
      count: 10

    }
  },
  computed: {
  },
  watch: {
    fullscreen(newvalue, oldvalue) {
      if (newvalue != oldvalue) {
        // 进行退出全屏的后的事件
        console.log('退出全屏')
      }
    }
  },
  mounted() {
    const that = this
    window.addEventListener('keydown', this.KeyDown, true)
    window.onresize = () => {
      // 调用判断全屏的方法,用来监听
      that.checkFull()
    }
  },
  created() {
    clearInterval(this.timer)
    this.init()
    this.countDown(10)
  },
  beforeDestroy() {
    clearInterval(this.timer)
  },
  methods: {
    init() {
      getAetMonitor()
        .then(res => {
          this.bean = res.data
        })
        .catch(err => {
          console.log('err', err)
        })
    },
    countDown(count) {
      this.count = count
      this.timer = setInterval(() => {
        if (this.count > 0 && this.count <= count) {
          --this.count
        } else {
          this.count = 10
          this.init()
        }
      }, 1000)

      this.$once('hook:beforeDestroy', () => {
        clearInterval(this.timer)
      })
    },
    showBig(bool) {

    },
    KeyDown(event) {
      if (event.keyCode === 122) {
        event.returnValue = false
        this.clickFullscreen() // 触发全屏的按钮
      }
    },

    clickFullscreen() {
      screenfull.toggle()	// 全屏状态切换
      this.fullscreen = !this.fullscreen
      this.show_big = !this.show_big
    },
    checkFull() {
      const fullscreen = window.fullScreen || document.webkitIsFullScreen
      this.fullscreen = fullscreen
      return fullscreen
    }
  }

}
</script>

<style lang="scss" scoped>
.big-screen-container {
  margin:20px;
  height:800px;
  background-color: rgb(11, 8, 53);
  box-shadow: 0px 2px 5px rgba(18, 32, 231, 0.788);
}
</style>

  JavaScript知识库 最新文章
ES6的相关知识点
react 函数式组件 & react其他一些总结
Vue基础超详细
前端JS也可以连点成线(Vue中运用 AntVG6)
Vue事件处理的基本使用
Vue后台项目的记录 (一)
前后端分离vue跨域,devServer配置proxy代理
TypeScript
初识vuex
vue项目安装包指令收集
上一篇文章      下一篇文章      查看所有文章
加:2022-05-16 11:16:35  更:2022-05-16 11:16:58 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/27 11:26:36-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码