navbar.vue 8.16 KB
Newer Older
程智春 committed
1 2 3 4 5 6 7 8
<template>
    <div 
        class="navbar" 
        :style="{'height' : navHeight + 'px','padding-top':navTop+'px'}"
    >
        <div class="back" @click="back">
            <span class="iconfont iconzuo"></span>
        </div>
程智春 committed
9 10 11 12 13 14
        <div class="user-info"  v-if="!isSetBeauty" :style="{'width' : liveInfo.liveBroadcastState != 0 ? '160px' : '114px'}">
            <div class="user-info-left">
                <div class="avatar">
                    <img :src="liveInfo.logoUrl" alt="">
                </div>
                <div class="username text-overflow" v-if="!status">{{liveInfo.shopName}}</div>
程智春 committed
15
            </div>
程智春 committed
16 17
            
            <div class="logining-info" v-if="status">
程智春 committed
18
                <div class="info-left">
程智春 committed
19
                    <div class="login-name text-overflow">{{liveInfo.shopName}}</div>
程智春 committed
20 21 22 23
                    <div class="login-time">{{time}}</div>
                </div>
                
            </div>
程智春 committed
24
            <div class="over-live" @click="endLive" v-if="liveInfo.liveBroadcastState ==1 || liveInfo.liveBroadcastState == 3">结束</div>
程智春 committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
        </div>
    </div>
</template>

<script>
import { setTimes } from '../../utils'
import liveApi from '@/api/liveing'
export default {
    props:{
        navTop:{
            type:Number,
            default:0
        },
        navHeight:{
            type:Number,
            default:0
        },
        type:{ //1:直播间 2:结束直播间
            type:Number,
            default:1
        },
        isLive : {
            type:Boolean,
            default : false
        },
        //直播间id
        id : {
            type : Number,
            default:0
        },
        isSetBeauty : {
            type:Boolean,
            default:false
        },
        pusher:{
            type:Object,
            default:null
        },
        realStartTime:{
            type:Number,
            default:0
        },
        liveInfo:{
            type:Object,
            default : null
        }
    },
    data(){
        return{
            status : false,
            userInfo : null,

            time : '00:00:00',

            starttime : 0,

            timer : null,

        }
    },
    watch:{
        isLive(newVal,oldVal){
            this.status = newVal && this.type == 1 ? true : false
            
            this.starttime = this.realStartTime
            if(newVal){
                this.liveTimeHandler()
            }
        }
    },
    created(){
    },  
    onShow(){
        clearInterval(this.timer)
    },
    onReady(){
        this.userInfo = this.$store.state.userInfo;
    },
    onHide(){
        clearInterval(this.timer)
    },
    onUnload(){
        clearInterval(this.timer)
    },
    
    methods:{
        //结束直播
        endLive(){
            wx.showModal({
                title: '',
                content: '是否结束本场直播',
                confirmText : '结束直播',
                confirmColor : '#07c160',
                success : res => {
                    if (res.confirm) {
程智春 committed
120 121

                        this.$emit('changeOver',0);
程智春 committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
                        this.changeLiveStatus(2);
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })
        },
        back(){

            if(this.isSetBeauty){
                this.$emit('closeSetBeauty',false)
            }else{
                if(this.type == 1 && this.liveInfo.liveBroadcastState == 1){
                    liveApi.updateLiveStatus({
                        id : this.id,
                        liveBroadcastState : 3
                    }).then(res => {
                        if(res.data.code == '200'){
                            console.log('stop')
                            this.pusher.pause()
                            clearInterval(this.timer); //结束直播
                            wx.reLaunch({url:'../liveList/main'})
                        }
                    })
                }else if(this.type == 1 && this.liveInfo.liveBroadcastState == 0){
                    wx.reLaunch({url:'../liveList/main'})
                }else if(this.type == 2){
                    wx.reLaunch({url:'../liveList/main'})
                }else if(this.type == 3){
                    wx.redirectTo({url:`../historyLive/main`})
                }else{
                    wx.navigateBack();
                }
            }
            
            
            
        },
        //改变直播状态
        changeLiveStatus(val){
            liveApi.updateLiveStatus({
                id : this.id,
                liveBroadcastState : val
            }).then(res => {
                if(res.data.code == '200'){
程智春 committed
167
                    this.$set(this.liveInfo,'liveBroadcastState',2);
程智春 committed
168 169 170 171 172 173 174 175 176 177 178 179
                    if(val == 2){
                        // console.log(this.queryDataTimer + '2222222')
                        console.log('over')
                        clearInterval(this.timer); //结束直播
                        this.$emit('clearAllInterval')
                    }
                    // 
                    console.log(this.id)
                    console.log(JSON.stringify(this.liveInfo))

                    this.$set(this.liveInfo,'boStream','')
                    this.$set(this.liveInfo,'tuiStream','')
程智春 committed
180
                    this.pusher.stop();
程智春 committed
181
                    
程智春 committed
182
                    wx.navigateTo({url:`../liveOver/main?id=${this.id}&liveInfo=${JSON.stringify(this.liveInfo)}`})
程智春 committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
                }
            })
        },
        liveTimeHandler(){
            if(this.isLive){
                this.time = setTimes(++this.starttime);
                this.timer = setInterval(() => {
                    this.time = setTimes(++this.starttime);
                },1000)
            }
        }
    }
}
</script>

<style scoped lang="scss">
.navbar{
    box-sizing: border-box;
    width: 100%;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    .back{
        width: 33.5px;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        .iconzuo{
            color: white;
            font-size: 13px;
        }
    }
    .user-info{
程智春 committed
220 221 222 223
        .user-info-left{
            display: flex;
            justify-content: flex-start;
            align-items: center;
程智春 committed
224
            padding-left: 2px;
程智春 committed
225
        }
程智春 committed
226 227 228 229 230 231
        height: 30px;
        line-height: 30px;
        background-color: rgba(0,0,0,.6);
        border-radius: 15px;
        display: flex;
        align-items: center;
程智春 committed
232
        justify-content: space-between;
程智春 committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
        .avatar{
            width: 26px;
            height: 26px;
            border-radius: 50%;
            overflow: hidden;
            // background-color: rosybrown;
            // padding: 4px;
            display: flex;
            align-items: center;
            justify-content: center;
            box-sizing: border-box;
            img{
                width: 100%;
                height: 100%;
            }
        }
        .username{
            width: 75px;
            text-align: center;
            font-size: 12px;
            color: white;

        }
        .logining-info{
            .info-left{
                text-align: center;
                width: 70px;
                color: white;
                margin-left: 10px;
                .login-name{
                    width: 70px;
                    font-size: 12px;
                    line-height: 14px;
                }
                .login-time{
                    font-size: 10px;
                    line-height: 14px;
                }
            }
            
        }
        .over-live{
            width: 35px;
            height: 19px;
            border-radius: 9.5px;
            text-align: center;
            line-height: 19px;
            font-size: 12px;
            color: white;
程智春 committed
282
            margin-right : 4px;
程智春 committed
283 284 285 286 287 288 289 290
            background-image:-webkit-linear-gradient(to right,#FF877D, #FB566D);
            background-image:-moz-linear-gradient(to right,#FF877D, #FB566D);
            background-image:-o-linear-gradient(to right,#FF877D, #FB566D);
            background-image: linear-gradient(to right,#FF877D, #FB566D);
        }
    }
}
</style>