guoshilong
2023-10-27 2311b03aee9db1bebacdd2ced13c071efda6a011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
120
121
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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
220
221
222
223
224
225
226
227
228
229
230
231
232
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
<template>
    <view class="video">
        <view>
            <!-- #ifdef  APP-PLUS -->
            <web-view v-if="webUrl" :src="webUrl" @message="getMessage"></web-view>
            <!-- #endif -->
            <!-- #ifdef MP-WEIXIN -->
            <live-player :style="{'height':livePlayHeight}" :src="livePlayerUrl" style="width: 100vw;"
                 autoplay id="livePlayer" mode="RTC" />
            <view v-if="array.length>0" @click="stationVisible = true">
                <view class="flex content">
                    <view class="flex" style="padding:20rpx;">
                        <view class="uni-input">{{array[index].video_name}}</view>
                        <view class="uni-input" style="margin-left: 20rpx;"
                            :class="[array[index].online=='1'?'active':'disabled']">
                            {{array[index].online=='1'?'在线':'不在线'}}
                        </view>
                    </view>
                    <view style="padding: 0 20rpx;">
                        <u-icon name="arrow-down" size="20"></u-icon>
                    </view>
                </view>
            </view>
            <view class="preset">
                <view class="flex content preContent" @click="preVisible = true" v-if="presetPointOptions.length>0">
                    <view class="flex" style="padding:20rpx;">
                        <view class="uni-input">{{presetPointOptions[preIndex].name}}</view>
                    </view>
 
                    <view style="padding: 0 20rpx;">
                        <u-icon name="arrow-down" size="20"></u-icon>
                    </view>
                </view>
                <div class="right-icon">
                    <u-icon name="plus-circle-fill" size="16" @click="add"></u-icon>
                    <u-icon name="play-right-fill" :color='preValue?"":"#e6e6e6"' size="16" @click="playPre"></u-icon>
                    <u-icon name="trash-fill" :color='preValue?"":"#e6e6e6"' size="16" @click="delSubmit"></u-icon>
                </div>
            </view>
 
            <view class="speed">
                <view style="padding-bottom: 40rpx;">码流</view>
                <u-radio-group v-model="streamType" placement="row" @change="changeBitstream">
                    <u-radio label="主码流" name='0' size="20"></u-radio>
                    <u-radio label="子码流" name='1' size="20"></u-radio>
                </u-radio-group>
            </view>
 
            <view class="speed" v-if="array.length>0">
                <view style="padding-bottom: 40rpx;">云台速度</view>
                <u-radio-group v-model="speed" placement="row">
                    <u-radio label="慢速" name='30' size="20"></u-radio>
                    <u-radio label="正常" name='50' size="20"></u-radio>
                    <u-radio label="快速" name='100' size="20"></u-radio>
                </u-radio-group>
            </view>
 
 
            <view class="control-box" v-if="array.length>0">
                <image src="../static/img/reservoirImg/control.png" style="width: 328rpx;height: 328rpx;"></image>
                <view class="btns-box" @touchstart="startVideoControls" @touchend="endVideoControls">
                    <view class="top" data-speed="20" data-control="UP"></view>
                    <view class="left" data-speed="20" data-control="LEFT"></view>
                    <view class="right" data-speed="20" data-control="RIGHT"></view>
                    <view class="bottom" data-speed="20" data-control="DOWN"></view>
                </view>
            </view>
            <view class="option_btn_right" v-if="array.length>0" @touchstart="startVideoControls"
                @touchend="endVideoControls">
                <image src="../static/img/reservoirImg/zoom-in.png" data-control="ZOOM_IN" data-speed="80"></image>
                <image src="../static/img/reservoirImg/zoom-out.png" data-control="ZOOM_OUT" data-speed="80">
                </image>
            </view>
 
            <my-select height='50vh' v-if="stationVisible" :show="stationVisible" v-model="selectStationValue"
                type="radio" popupTitle="请选择视频站" :dataLists="array" @submit="stationSelect"
                @cancel="stationVisible=false">
            </my-select>
            <my-select height='50vh' v-if="preVisible && presetPointOptions.length>0 && preValue"
                :show="preVisible && presetPointOptions.length>0 && preValue" v-model="preValue" type="radio"
                popupTitle="请选择预置点" :dataLists="presetPointOptions" @submit="preSelect" @cancel="preVisible=false">
            </my-select>
            <!-- #endif -->
        </view>
    </view>
</template>
<script>
    import permision from "@/js_sdk/wa-permission/permission.js"
    import {
        queryHkPreviewUrlCommon,
        handleCameraPosition,
        getPresetsSearchesUrls,
        getTalkURLs,
        setPresetsAddition,
        deletePresetsDeletion
    } from "@/api/hk/hk.js"
    import {
        getAttWmstBase
    } from "@/api/dataCenter/responsiblePerson/responsiblePerson.js"
    import mySelect from "@/components/my-components/my-select.vue"
    export default {
        name: "hkVideo",
        props: ['reservoirId'],
        components: {
            mySelect
        },
        data() {
            return {
                player: "",
                dialogVisible: false,
                webUrl: "",
                type: "",
                videoInfo: {},
                videoUrl: '',
                showWXLivePlayer: false,
                showAPPLivePlayer: false,
                //预制点
                preVisible: false,
                //删除预置点
                isDel: false,
                delValue: "",
                preValue: "",
                preIndex: 0,
                livePlayerUrl: '',
                array: [],
                stationVisible: false,
                selectStationValue: "",
                index: 0,
                talkUrl: "",
                presetPointOptions: [],
                speed: '50',
                streamType: "1",
            }
        },
        mounted() {
            const that = this
            // #ifdef APP-PLUS
            // this.initVideo()
            // #endif
            this.videoStation()
        },
        computed: {
            livePlayHeight() {
                const info = uni.getWindowInfo()
                //设备宽度
                const width = info.screenWidth
                //按照16:9设置高度
                const height = ((width / 16) * 9).toFixed(1)
                return `${height}px`
            },
        },
        methods: {
            async getMessage(data) {
                const platform = uni.getSystemInfoSync().platform
                if (platform == 'ios') {
                    if (!permision.judgeIosPermission("record")) {
                        uni.showModal({
                            content: "目前未获取麦克风权限,是否授权允许使用麦克风",
                            title: "提示",
                            success(res) {
                                if (res.confirm) {
                                    permision.gotoAppPermissionSetting()
                                }
                            }
                        });
                    }
                } else if (platform == 'android') {
                    const record = await permision.requestAndroidPermission("android.permission.RECORD_AUDIO")
                    if (record == 1) {} else {
                        uni.showModal({
                            content: "目前未获取麦克风权限,是否授权允许使用麦克风",
                            title: "提示",
                            success(res) {
                                if (res.confirm) {
                                    permision.gotoAppPermissionSetting()
                                }
                            }
                        });
                    }
                }
            },
            //添加预置点
            add() {
                const that = this
                let curVideo = this.array.find(item => item.video_guid == this.selectStationValue)
                const index = this.presetPointOptions.length > 0 ? this.presetPointOptions.length + 1 : 1
                const param = {
                    cameraIndexCode: this.selectStationValue,
                    protocol: 'wss',
                    type: this.type
                }
                uni.showModal({
                    title: "添加预置点",
                    editable: true,
                    placeholderText: "请输入预置点名称",
                    success: async res => {
                        if (res.confirm) {
                            const setRes = await setPresetsAddition({
                                cameraIndexCode: that.selectStationValue,
                                presetName: res.content,
                                presetIndex: index,
                                type: that.type
                            })
                            that.getPresetsSearchesUrl(param)
                        }
                    }
                })
            },
            //删除预置点
            async delSubmit() {
                if (!this.preValue) return
                const that = this
                const params = {
                    cameraIndexCode: that.selectStationValue,
                    presetIndex: that.preValue,
                    type: that.type
                }
                uni.showModal({
                    title: "提示",
                    content: "确认删除该预置点吗?",
                    async success(res) {
                        if (res.confirm) {
                            const res = await deletePresetsDeletion(params)
                            const presetParam = {
                                cameraIndexCode: that.selectStationValue,
                                protocol: 'wss',
                                type: that.type
                            }
                            uni.showToast({
                                title: "删除成功",
                                icon: "none"
                            })
                            that.getPresetsSearchesUrl(presetParam)
                        }
                    },
                })
            },
            //视频站切换
            stationSelect(data) {
                this.selectStationValue = data.value
                this.stationVisible = false
                this.index = data.index
                this.type = data.sys_resource
                this.queryHkPreviewUrlCommon()
                const param = {
                    cameraIndexCode: data.cameraIndexCode,
                    protocol: 'wss',
                    type: this.type
                }
                getTalkURLs(param).then(res => {
                    let resultUrl = JSON.parse(res.data.data).data.url
                    if (resultUrl.indexOf('36.134.79.80:6014') != -1) {
                        resultUrl = resultUrl.replace('36.134.79.80:6014', 'hubeihaikang.cn:6014')
                    }
                    if (resultUrl.indexOf('223.76.234.232:6014') != -1) {
                        resultUrl = resultUrl.replace('223.76.234.232:6014', 'v.hubeishuiyi.cn:6014')
                    }
                    this.talkUrl = resultUrl.replace('36.134.79.80:6014', 'hubeihaikang.cn:6014')
                })
                this.getPresetsSearchesUrl({
                    cameraIndexCode: this.selectStationValue,
                    type: this.type,
                    protocol: 'wss',
                })
            },
            //码流切换
            changeBitstream() {
                this.queryHkPreviewUrlCommon()
            },
            //预制点切换
            preSelect(data) {
                this.preVisible = false
                this.preValue = data.value
                this.preIndex = data.index
            },
            //预置点播放
            playPre() {
                if (!this.preValue) return
                handleCameraPosition({
                    cameraIndexCode: this.selectStationValue,
                    action: 0,
                    command: 'GOTO_PRESET',
                    presetIndex: this.preValue,
                    type: this.type
                })
            },
            wxPlay() {
                const livePlayer = uni.createLivePlayerContext("livePlayer", this)
                livePlayer.play({
                    success(res) {
                        console.log("success:", res)
                    },
                    fail(err) {
                        console.log("err:", err)
                    }
                })
            },
            startVideoControls(e) {
                handleCameraPosition({
                    cameraIndexCode: this.selectStationValue,
                    action: 0,
                    command: e.target.dataset.control,
                    speed: this.speed,
                    type: this.type
                })
            },
            //获取预置点列表
            getPresetsSearchesUrl(params) {
                this.presetPointOptions = []
                getPresetsSearchesUrls(params).then(res => {
                    console.log(res, "pressssss")
                    let data = JSON.parse(res.data)
                    if (data.msg !== 'success') {
                        return
                    }
                    let result = data.data.list
                    if (result.length > 0) {
                        result.forEach((item, index) => {
                            this.presetPointOptions.push({
                                name: item.presetPointName,
                                value: item.presetPointIndex,
                                index: index
                            })
                        })
                        this.preValue = this.presetPointOptions[0].value || ""
                    } else {
                        this.preValue = ""
                    }
                })
            },
 
            endVideoControls(e) {
                // 调视频控制的接口
                handleCameraPosition({
                    cameraIndexCode: this.selectStationValue,
                    action: 1,
                    command: e.target.dataset.control,
                    speed: this.speed,
                    type: this.type
                })
            },
            //获取视频站
            async videoStation() {
                const obj = {
                    res_cd: this.reservoirId
                }
                const res = await getAttWmstBase(obj)
                console.log(res, "res")
                if (res.resultList.length > 0) {
                    let data = res.resultList
                    data.forEach((e, index) => {
                        const isOnline = e.online ? '在线' : '离线'
                        e.value = e.video_guid
                        e.name = `${e.video_name}--${isOnline}`
                        e.index = index
                    })
                    this.array = data
                    this.type = this.array[0].sys_resource
                    const param = {
                        cameraIndexCode: data[0].value,
                        protocol: 'wss',
                        type: this.type
                    }
                    this.selectStationValue = this.array[0].value
                    // #ifdef MP-WEIXIN
                    this.getPresetsSearchesUrl(param)
                    this.queryHkPreviewUrlCommon()
                    // #endif
 
                    // #ifdef APP-PLUS
                    getTalkURLs(param).then(res => {
                        this.getPresetsSearchesUrl(param)
                        let resultUrl = JSON.parse(res.data).data.url
                        if (resultUrl.indexOf('36.134.79.80:6014') != -1) {
                            resultUrl = resultUrl.replace('36.134.79.80:6014', 'hubeihaikang.cn:6014')
                        }
                        if (resultUrl.indexOf('223.76.234.232:6014') != -1) {
                            resultUrl = resultUrl.replace('223.76.234.232:6014', 'v.hubeishuiyi.cn:6014')
                        }
                        this.talkUrl = resultUrl
                        this.appHKPreviewVideo()
                    })
                    // #endif
                }
            },
            //微信小程序 视频播放
            queryHkPreviewUrlCommon() {
                queryHkPreviewUrlCommon({
                    cameraIndexCode: this.selectStationValue,
                    protocol: 'httpsflv',
                    type: this.type,
                    expand: 'transcode=1&videotype=h264',
                    streamType: this.streamType
                }).then(result => {
                    if (result.data.indexOf('36.134.79.80:6014') != -1) {
                        result.data = result.data.replace('36.134.79.80:6014', 'hubeihaikang.cn:6014')
                    }
                    if (result.data.indexOf('223.76.234.232:6014') != -1) {
                        result.data = result.data.replace('223.76.234.232:6014', 'v.hubeishuiyi.cn:6014')
                    }
                    this.livePlayerUrl = result.data
                    console.log("播放地址", this.livePlayerUrl)
                    this.wxPlay()
                })
            },
            //app视频播放
            appHKPreviewVideo() {
                queryHkPreviewUrlCommon({
                    cameraIndexCode: this.selectStationValue,
                    protocol: 'wss',
                    type: this.type
                }).then(result => {
                    const station = JSON.stringify(this.array)
                    if (result.data.indexOf('36.134.79.80:6014') != -1) {
                        result.data = result.data.replace('36.134.79.80:6014', 'hubeihaikang.cn:6014')
                    }
                    if (result.data.indexOf('223.76.234.232:6014') != -1) {
                        result.data = result.data.replace('223.76.234.232:6014', 'v.hubeishuiyi.cn:6014')
                    }
                    result.data = result.data
                    this.webUrl = 'https://sk.hubeishuiyi.cn/business/hk/h5/demo.html?station=' +
                        encodeURIComponent(station) + '&url=' + result.data + "&talkUrl=" + this
                        .talkUrl
                    // this.livePlayerUrl = result.data
                })
            }
        },
    };
</script>
<style lang="scss" scoped>
    .content {
        margin: 40rpx;
        border: 2rpx solid;
 
        .active {
            color: #1180ff;
        }
 
    }
 
    .disabled {
        color: orangered;
    }
 
    .preContent {
        margin: 0;
        flex: 1;
        // width: 540rpx;
    }
 
    .right-icon {
        width: 180rpx;
        display: flex;
        align-items: center;
        justify-content: space-around;
    }
 
    .preset {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        padding: 40rpx;
    }
 
    .text-label {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
 
    .speed {
        padding: 20rpx 40rpx;
    }
 
    .control-box {
        position: relative;
        width: 328rpx;
        height: 100%;
 
        .btns-box {
            position: absolute;
            top: 0;
            left: 0;
            width: 328rpx;
            height: 328rpx;
 
            &>view {
                position: absolute;
                width: 82rpx;
                height: 80rpx;
                border-radius: 50%;
                cursor: pointer;
 
                &:hover {
                    background: rgba(255, 255, 255, 0.5);
                }
            }
 
            .top {
                top: 24rpx;
                left: 50%;
                transform: translate(-50%, 0);
            }
 
            .left {
                top: 50%;
                left: 24rpx;
                transform: translate(0, -50%);
            }
 
            .right {
                top: 50%;
                right: 24rpx;
                transform: translate(0, -50%);
            }
 
            .bottom {
                left: 50%;
                bottom: 24rpx;
                transform: translate(-50%, 0);
            }
        }
    }
 
    .option_btn_right {
        position: absolute;
        /* width: 100%; */
        font-size: 0;
        top: 1250rpx;
        right: 30px;
        font-size: 0;
 
        image {
            height: 48rpx;
            width: 148rpx;
            margin: 10rpx;
            flex: 1;
            cursor: pointer;
        }
    }
 
    .speak_btn {
        width: 326rpx;
        top: 1240rpx;
 
        button {
            font-size: 28rpx;
            padding: 0 20rpx;
        }
    }
 
    .flex {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
 
    .video {
        width: 100%;
        height: 100%;
 
        .video-controls {
            width: 100%;
            height: 50vh;
        }
    }
</style>