在vue项目中如何使用html页面

如果有需求在vue页面要跳转新链接页页面可以使用原生html页面,下面将讲述从跳转到使用的过程
1、跳转到html页面

 <el-button style="background:#04FFFD;border:none;position:absolute;top:2px;right:100px;z-index:2001;font-weight:bold" round>
    <a target="_blank" :href="hreft">视频监控大屏</a>
 </el-button>

2、在html页面中获取后台数据,如果用原生ajax会有不方便,所以在这里我们使用html中嵌套vue页面写,并且使用axios请求服务器

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>123</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="./static/CDN/custom-theme.css">
    <link href="https://cdn.bootcss.com/video.js/7.6.5/alt/video-js-cdn.min.css" rel="stylesheet">
</head>

<body>
    <div id="cons" class="container">

    </div>
</body>

</html>
<script src="./static//CDN/axios.min.js"></script>
<script src="./static/CDN/vue.js"></script>
<script src="./static/CDN/vue-router.min.js"></script>
<script src="./static/CDN/index.js"></script>
<script src="./static/config/index.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="./static/CDN/indextree.js"></script>
<script src="./static/CDN/vue-video-player.js"></script>
<script src="./static/CDN/videojs-contrib-hls.js"></script>
<script src="https://cdn.bootcss.com/video.js/6.6.2/video.js"></script>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script type="module">
    var init = axios.create({
        baseURL: '接口地址',
        headers: {
            "content-type": "multipart/form-data",
            "token": window.location.search.split('=')[1]
        }
    })
    // 假设如果很多接口都需要使用 token验证,可以把token信息放在请求头
    new Vue({
        el: "#cons",//预留填坑位置,比如html页面有一个<div id='app'></div>的元素
        components: {},
        template: `<div id="cons" class="container">
                    <header class="headers"></header>
                    <div class="body">
                        <div class="one"  v-if="showone">
                            <div class="ones">
                                <div class="bgicon1">
                                    <div class="bgiconone1"></div>    
                                    <div class="bgicontwo1"></div>    
                                    <div class="bgiconthree1"></div>    
                                    <div class="bgiconfour1"></div>    
                                </div>
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[0]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="ones">
                                <div class="bgicon1">
                                    <div class="bgiconone1"></div>    
                                    <div class="bgicontwo1"></div>    
                                    <div class="bgiconthree1"></div>    
                                    <div class="bgiconfour1"></div>    
                                </div>
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[1]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="ones">
                                <div class="bgicon1">
                                    <div class="bgiconone1"></div>    
                                    <div class="bgicontwo1"></div>    
                                    <div class="bgiconthree1"></div>    
                                    <div class="bgiconfour1"></div>    
                                </div>
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[2]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="ones">
                                <div class="bgicon1">
                                    <div class="bgiconone1"></div>    
                                    <div class="bgicontwo1"></div>    
                                    <div class="bgiconthree1"></div>    
                                    <div class="bgiconfour1"></div>    
                                </div>
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[3]" type="application/x-mpegURL">
                                </video>
                            </div>
                        </div>
                        <div class="two" v-if="showtwo">
                            <div class="twos">
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[0]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="twos">
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[1]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="twos">
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[2]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="twos">
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[3]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="twos">
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[4]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="twos">
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[5]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="twos">
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[6]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="twos">
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[7]" type="application/x-mpegURL">
                                </video>
                            </div>
                            <div class="twos">
                                <video style="width:100%;height:100%" controls>
                                    <source :src="url[8]" type="application/x-mpegURL">
                                </video>
                            </div>
                        </div>
                        <div class="three" v-if="showthree">
                            <div class="threes">
                                <div class="bgicon">
                                    <div class="bgiconone"></div>    
                                    <div class="bgicontwo"></div>    
                                    <div class="bgiconthree"></div>    
                                    <div class="bgiconfour"></div>    
                                </div>
                                <video id="my_video" preload="auto" style="width:100%;height:100%" controls>
                                    <source :src="url[0]" type="application/x-mpegURL">
                                </video>
                            </div>
                        </div>
                        <div class="maskbox"  @mouseenter="showLeftTree=true" @mouseleave="showLeftTree=false">
                            <div class="tran"></div>
                            <div class="lefts" v-show="showLeftTree">
                                <div id="leftBar" class="left-content-neworg" >
                                    <el-row class="left-tree-botder">
                                        <div class="left-tree-title">辖区企业</div>
                                    </el-row>
                                    <el-row>
                                    <el-input
                                        class="left-tree-search"
                                        placeholder="输入关键字进行过滤"
                                        clearable
                                        v-model="filterText">
                                    </el-input>
                                    </el-row>

                                    <div class="left-tree-1-neworg">
                                    <el-tree
                                        v-loading="dataTreeListLoading"
                                        ref="districtTree"
                                        :data="data"
                                        style="border: none; padding: 10px 10px 0px 20px;"
                                        :default-expanded-keys="[saveSecondId]"
                                        :expand-on-click-node="false"
                                        :filter-node-method="filterNode"
                                        :props="defaultProps"
                                        node-key="id"
                                        @node-click="handleNodeClick">
                                        <span class="custom-tree-node" slot-scope="{node,data}">
                                            <span :title="data.label" class="show-ellipsis">{{getTreeName(data.label)}}</span>
                                            <el-badge :value="data.childrenTotal" class="item" type="primary" v-if="data.childrenTotal != 0"></el-badge>
                                        </span>
                                    </el-tree>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                    </div>
                </div>`,

        watch: {
            filterText(val) {
                this.$refs.districtTree.filter(val);
            },

        },
        data: function () {
            return {
                //代表要在template使用的数据,所以在template中将text变量添加进去,用{{}}包裹
                text: 'hellow word',
                data: [],
                saveSecondId: '',
                saveThreeDlist: [],
                threeLon: '',
                threeLat: '',
                saveBackMapData: {},
                filterText: '',
                showLeftTree: false,
                dataTreeListLoading: false,
                defaultProps: {
                    children: 'children',
                    label: 'label'
                },
                idone:'',
                url:[],
                showone:false,
                showtwo:false,
                showthree:false
            }

        },
        mounted() {
            this.getTree()
        },
        methods: {
            videoslist(data){
                let _=this
                // api/v1/cameras
                init({
                    method: 'get',
                    url: '后台接口',
                    headers: {
                        'Authorization': _.token
                    },
                    params: {
                        'unitId': data
                    }
                }).then(res => {
                    _.url=[]
                    if(res.data.code==0){
                        if(res.data.data.length==1){
                            _.showthree=true
                            _.showone=false
                            _.showtwo=false
                        }
                        else if(res.data.data.length>1&&res.data.data.length<=4){
                            _.showtwo=true
                            _.showthree=false
                            _.showone=false
                        }
                        else if(res.data.data.length>4&&res.data.data.length<=9){
                            _.showone=true
                            _.showthree=false
                            _.showtwo=false
                        }else if(res.data.data.length==0){
                            _.showthree=true
                            _.showone=false
                            _.showtwo=false
                        }
                        res.data.data.map(v=>{
                            let ar=v.addr.split('?')
                            if(ar){
                                _.url.push(ar[0])
                            }else{
                                _.url.push(v.addr)
                            }
                            _.playVideo('')//播放其它视频前执行,清空之前的url
                            _.playVideo(_.url[0])
                        })
                    }
                })
            },
            getTree() {
                let _ = this
                _.dataTreeListLoading = true
                init({
                    method: 'get',
                    url: '后台接口',
                    headers: {
                        'Authorization': _.token
                    },
                    params: {
                        'statusType': '1'
                    }
                }).then(data => {
                    if (data && data.data.code === 0) {
                        let $data = data.data.data;
                        let newArr = [];
                        for (let i = 0, len = $data.length; i < len; i++) {
                            let newJson = {};
                            newJson.id = $data[i].id;
                            newJson.parent = $data[i].parent;
                            newJson.parentName = $data[i].parentName;
                            newJson.label = $data[i].text;
                            newJson.lon = $data[i].lon;
                            newJson.lat = $data[i].lat;
                            newJson.types = $data[i].types;
                            newJson.childrenTotal = $data[i].childrenTotal;
                            newJson.cameraType = $data[i].cameraType;
                            newJson.threeType = $data[i].threeType;
                            newArr.push(newJson);
                        }
                        const result = construct(newArr, {
                            id: 'id',
                            pid: 'parent',
                            lable: 'label',
                            children: 'children'
                        });
                        _.saveSecondId = result[0].id;

                        _.data = result;
                        _.idone=_.data[0].children[0].children[0].id
                        _.videoslist(_.idone)
                        this.dataTreeListLoading = false

                        _.saveThreeDlist = _.data;


                        if (_.saveThreeDlist[0].lon == undefined && _.saveThreeDlist[0].lat == undefined) {
                            _.threeLon = _.saveThreeDlist[0].longitude;
                            _.threeLat = _.saveThreeDlist[0].latitude;


                        } else {
                            _.threeLon = _.saveThreeDlist[0].lon;
                            _.threeLat = _.saveThreeDlist[0].lat;

                        }

                        _.saveBackMapData = _.saveThreeDlist[0];

                    }
                })
            },
            filterNode(value, data) {
                if (!value) return true;
                return data.label.indexOf(value) !== -1;
            },
            getTreeName(lable) {
                const _ = this;
                if (lable.length > 14) {
                    lable = lable.substring(0, 13) + '...'
                } else {
                    lable = lable;
                }
                return lable
            },
            handleNodeClick(data) {
                let idselect=data.id
                this.videoslist(idselect)
            },
            playVideo(e){//e为视频的m3u8 url
                             this.$nextTick(()=>{
                    var myPlayertwos1 = document.getElementById('my_videotwos1')
                    if(Hls.isSupported()) {
                        var hls = new Hls();
                        hls.loadSource(e);
                        hls.attachMedia(myPlayertwos1);
                        hls.on(Hls.Events.MANIFEST_PARSED,function() {
                            myPlayertwos1.play();
                        });
                    }
                })
                this.$nextTick(()=>{
                    var myPlayertwos2 = document.getElementById('my_videotwos2')
                    if(Hls.isSupported()) {
                        var hls = new Hls();
                        hls.loadSource(e);
                        hls.attachMedia(myPlayertwos2);
                        hls.on(Hls.Events.MANIFEST_PARSED,function() {
                            myPlayertwos2.play();
                        });
                    }
                })
                this.$nextTick(()=>{
                    var myPlayertwos3 = document.getElementById('my_videotwos3')
                    if(Hls.isSupported()) {
                        var hls = new Hls();
                        hls.loadSource(e);
                        hls.attachMedia(myPlayertwos3);
                        hls.on(Hls.Events.MANIFEST_PARSED,function() {
                            myPlayertwos3.play();
                        });
                    }
                })
                this.$nextTick(()=>{
                    var myPlayertwos4 = document.getElementById('my_videotwos4')
                    if(Hls.isSupported()) {
                        var hls = new Hls();
                        hls.loadSource(e);
                        hls.attachMedia(myPlayertwos4);
                        hls.on(Hls.Events.MANIFEST_PARSED,function() {
                            myPlayertwos4.play();
                        });
                    }
                })
                this.$nextTick(()=>{
                    var myPlayertwos5 = document.getElementById('my_videotwos5')
                    if(Hls.isSupported()) {
                        var hls = new Hls();
                        hls.loadSource(e);
                        hls.attachMedia(myPlayertwos5);
                        hls.on(Hls.Events.MANIFEST_PARSED,function() {
                            myPlayertwos5.play();
                        });
                    }
                })
                this.$nextTick(()=>{
                    var myPlayertwos6 = document.getElementById('my_videotwos6')
                    if(Hls.isSupported()) {
                        var hls = new Hls();
                        hls.loadSource(e);
                        hls.attachMedia(myPlayertwos6);
                        hls.on(Hls.Events.MANIFEST_PARSED,function() {
                            myPlayertwos6.play();
                        });
                    }
                })
                this.$nextTick(()=>{
                    var myPlayertwos7 = document.getElementById('my_videotwos7')
                    if(Hls.isSupported()) {
                        var hls = new Hls();
                        hls.loadSource(e);
                        hls.attachMedia(myPlayertwos7);
                        hls.on(Hls.Events.MANIFEST_PARSED,function() {
                            myPlayertwos7.play();
                        });
                    }
                })
                this.$nextTick(()=>{
                    var myPlayertwos8 = document.getElementById('my_videotwos8')
                    if(Hls.isSupported()) {
                        var hls = new Hls();
                        hls.loadSource(e);
                        hls.attachMedia(myPlayertwos8);
                        hls.on(Hls.Events.MANIFEST_PARSED,function() {
                            myPlayertwos8.play();
                        });
                    }
                })
                this.$nextTick(()=>{
                    var myPlayertwos9 = document.getElementById('my_videotwos9')
                    if(Hls.isSupported()) {
                        var hls = new Hls();
                        hls.loadSource(e);
                        hls.attachMedia(myPlayertwos9);
                        hls.on(Hls.Events.MANIFEST_PARSED,function() {
                            myPlayertwos9.play();
                        });
                    }
                })
            },

        }


    })

</script>

<style scoped>
    .container {
        width: 100%;
        height: 100vh;
        background-image: url('./src/assets/img/videomoniters/bg.png');
        background-repeat: no-repeat;
        background-size: 100% 100%;
        box-sizing: border-box;
        padding: 0 30px;
        position: relative;
    }

    .headers {
        width: 100%;
        height: 100px;
        background-image: url('./src/assets/img/videomoniters/header.png');
        background-repeat: no-repeat;
        background-size: 100% 100%;
        margin-bottom: 5px;
    }

    .body {
        width: 100%;
        height: 85vh;
        background-image: url('./src/assets/img/videomoniters/bg1.png');
        background-repeat: no-repeat;
        background-size: 100% 100%;
    }
    .el-tree-node__content:hover{
        background: rgba(0,0,0,0.4);
    }
    .one,
    .two,
    .three {
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        box-sizing: border-box;
        padding: 10px 50px;
    }

    .ones {
        width: 48%;
        height: 40vh;
        position: relative;
    }

    .twos {
        width: 33%;
        height: 27vh;
        position: relative;
    }
    .threes{
        width: 100%;
        height: 100%;
        position: relative;
    }
    .bgicon,.bgicon1{
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
    }
    .bgiconone,.bgicontwo,.bgiconthree,.bgiconfour,.bgiconone1,.bgicontwo1,.bgiconthree1,.bgiconfour1{
        width: 30px;
        height: 30px;
        position: absolute;
        top: 0;
        left: -2%;
        background-image: url('./src/assets/img/videomoniters/topleft.png');
        background-repeat: no-repeat;
        background-size: 100% 100%;
    }
    .bgicontwo,.bgicontwo1{
        left: 100%;
        background-image: url('./src/assets/img/videomoniters/topright.png');
    }
    .bgiconthree,.bgiconthree1{
        top: 95%;
        background-image: url('./src/assets/img/videomoniters/bottomleft.png');
    }
    .bgiconfour,.bgiconfour1{
        top: 95%;
        left: 100%;
        background-image: url('./src/assets/img/videomoniters/bottomright.png');
    }

    .lefts {
        width: 360px;
        height: 100vh;
        background-image: url('./src/assets/img/videomoniters/mak.png');
        background-repeat: no-repeat;
        background-size: 100% 100%;
        position: absolute;
        top: -40vh;
        left: 0;
        box-sizing: border-box;
        padding: 50px 30px;
    }
    .left-tree-botder{
      height: 50px;
      line-height: 50px;
      border-bottom: 1px solid #142c49;
      
    }
    .left-tree-title{
        float: left;
        font-size: 16px;
        color: #02e5d1;
        padding-left: 20px;
      }
    .left-tree-search{
      padding: 0px 4px 0px 0px;
      margin-top: 10px;
    }
    .left-tree-1-neworg{
      height: 90vh;
      overflow-y: auto;
      
    }
    .el-tree{
        min-height: 500px;
        background:rgba(0,0,0,0.8);
    }
    .show-ellipsis {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      color: #00BEFF;
      font-size: 14px;
    }
    .el-input--suffix .el-input__inner{
        background: rgba(0,0,0,0.8);
        color: #fff;
    }
    .maskbox{
        width: 10px;
        height: 10vh;
        /* background: rgba(0,0,0,0); */
        background:#01BEEF;
        position: absolute;
        top: 40vh;
        left: 0;
        border-top-left-radius: 0;
        border-top-right-radius: 10px;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 10px;
    }
    .tran{
        width: 10px;
        height: 10px;
        background-image: url('./src/assets/img/videomoniters/triangle.png');
        background-repeat: no-repeat;
        background-size: 100% 100%;
        position: absolute;
        top: 45%;
        left: 10%;
    }
</style>
  • 8
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值