选择设备修复下拉

This commit is contained in:
aixianling
2023-01-06 16:49:11 +08:00
parent cec54751ec
commit 2fcd16e2a7

View File

@@ -1,5 +1,5 @@
<template> <template>
<div class="LiveBroadcast" @touchend="onTouchend" @touchmove="onTouchmove"> <div class="LiveBroadcast" @touchend="onTouchend" @touchmove.stop="onTouchmove">
<div class="top" @click="toChoose" hover-class="bg-hover"> <div class="top" @click="toChoose" hover-class="bg-hover">
<div class="left"> <div class="left">
<h2 v-if="!equipmentList.length">请选择设备</h2> <h2 v-if="!equipmentList.length">请选择设备</h2>
@@ -8,18 +8,18 @@
<span v-if="equipmentList.length > 2">{{ equipmentList.length }}</span> <span v-if="equipmentList.length > 2">{{ equipmentList.length }}</span>
<h2 v-if="equipmentList.length > 2">个设备</h2> <h2 v-if="equipmentList.length > 2">个设备</h2>
</div> </div>
<image src="./img/right.png" /> <image src="./img/right.png"/>
</div> </div>
<div class="middle"> <div class="middle">
<div class="record" v-if="isShowRecord"> <div class="record" v-if="isShowRecord">
<h2>喊话记录</h2> <h2>喊话记录</h2>
<scroll-view scroll-y class="record-wrapper"> <scroll-view scroll-y class="record-wrapper">
<div class="record-item" v-for="(item, index) in recordList" :key="index"> <div class="record-item" v-for="(item, index) in recordList" :key="index">
<image :src="user.avatar" /> <image :src="user.avatar"/>
<div class="right-wrapper"> <div class="right-wrapper">
<div class="right" :style="{width: 'calc(83px + ' + (item.duration / 2) + '%)'}" @click="play(item.src, index)"> <div class="right" :style="{width: 'calc(83px + ' + (item.duration / 2) + '%)'}" @click="play(item.src, index)">
<image mode="aspectFit" v-if="!item.isPlay" src="./img/voice-icon.png" /> <image mode="aspectFit" v-if="!item.isPlay" src="./img/voice-icon.png"/>
<image v-else src="./img/voice.gif" /> <image v-else src="./img/voice.gif"/>
<span>{{ item.duration }}"</span> <span>{{ item.duration }}"</span>
</div> </div>
</div> </div>
@@ -27,19 +27,19 @@
</scroll-view> </scroll-view>
</div> </div>
<div class="tips" v-if="!isShowRecord"> <div class="tips" v-if="!isShowRecord">
<image src="./img/body.png" /> <image src="./img/body.png"/>
<p>请先选择设备再按住下方按钮开始喊话~</p> <p>请先选择设备再按住下方按钮开始喊话~</p>
</div> </div>
</div> </div>
<div class="bottom" @touchstart="onLongtap"> <div class="bottom" @touchstart="onLongtap">
<image src="./img/microphone.png" /> <image src="./img/microphone.png"/>
<p>按住说话</p> <p>按住说话</p>
</div> </div>
<div class="voice" :class="[isShow ? 'active' : '']"> <div class="voice" :class="[isShow ? 'active' : '']">
<div class="voice-bottom"> <div class="voice-bottom">
<image src="./img/voice-w.png" /> <image src="./img/voice-w.png"/>
</div> </div>
<image class="close" :class="[isImpact ? 'close-active' : '']" :src="isImpact ? closeW : close" /> <image class="close" :class="[isImpact ? 'close-active' : '']" :src="isImpact ? closeW : close"/>
<p>松开发送</p> <p>松开发送</p>
<div class="header-line"> <div class="header-line">
<span class="line1 animation"></span> <span class="line1 animation"></span>
@@ -69,16 +69,15 @@
</template> </template>
<script> <script>
import { mapState } from 'vuex' import {mapState} from 'vuex'
import Recorder from 'recorder-core' import Recorder from 'recorder-core'
import 'recorder-core/src/engine/mp3' import 'recorder-core/src/engine/mp3'
import 'recorder-core/src/engine/mp3-engine' import 'recorder-core/src/engine/mp3-engine'
export default {
export default {
name: 'LiveBroadcast', name: 'LiveBroadcast',
appName: '实时喊话', appName: '实时喊话',
data() {
data () {
return { return {
x: 0, x: 0,
y: 0, y: 0,
@@ -106,7 +105,7 @@
computed: { computed: {
...mapState(['user']), ...mapState(['user']),
equipmentStr () { equipmentStr() {
if (!this.equipmentList.length) { if (!this.equipmentList.length) {
return '' return ''
} }
@@ -115,24 +114,21 @@
} }
}, },
mounted () { mounted() {
this.$nextTick(() => { this.$nextTick(() => {
const close = document.querySelector('.close') const close = document.querySelector('.close')
this.x = close.offsetLeft this.x = close.offsetLeft
this.y = close.offsetTop this.y = close.offsetTop
this.w = close.clientWidth this.w = close.clientWidth
this.h = close.clientHeight this.h = close.clientHeight
document.body.addEventListener('touchmove', this.bindEvent, { passive: false })
}) })
}, },
destroyed () { destroyed() {
document.body.removeEventListener('touchmove', this.bindEvent)
this.recorder.close() this.recorder.close()
}, },
onLoad () { onLoad() {
this.innerAudioContext = uni.createInnerAudioContext() this.innerAudioContext = uni.createInnerAudioContext()
this.innerAudioContext.autoplay = true this.innerAudioContext.autoplay = true
this.innerAudioContext.onEnded(() => { this.innerAudioContext.onEnded(() => {
@@ -166,11 +162,11 @@
}, },
methods: { methods: {
bindEvent (e) { bindEvent(e) {
e.preventDefault() e.preventDefault()
}, },
onLongtap () { onLongtap() {
this.time = 60 this.time = 60
if (!this.equipmentList.length) { if (!this.equipmentList.length) {
@@ -183,18 +179,18 @@
this.record() this.record()
}, },
toChoose () { toChoose() {
uni.navigateTo({ uni.navigateTo({
url: './selectEquipment' url: './selectEquipment'
}) })
}, },
record () { record() {
this.recorder.start() this.recorder.start()
this.timing() this.timing()
}, },
timing () { timing() {
if (this.time === 0) { if (this.time === 0) {
this.stop() this.stop()
@@ -207,7 +203,7 @@
}, 1000) }, 1000)
}, },
play (url, index) { play(url, index) {
if (this.currIndex === index) { if (this.currIndex === index) {
this.innerAudioContext.destroy() this.innerAudioContext.destroy()
this.recordList.forEach((v, index) => { this.recordList.forEach((v, index) => {
@@ -230,7 +226,7 @@
}) })
}, },
stop (isCancel) { stop(isCancel) {
clearTimeout(this.timingTimeout) clearTimeout(this.timingTimeout)
this.recorder.stop((blob, duration) => { this.recorder.stop((blob, duration) => {
if (isCancel) { if (isCancel) {
@@ -240,7 +236,7 @@
let formData = {} let formData = {}
formData = new FormData() formData = new FormData()
formData.append('file', new window.File([blob], `${(new Date).getTime()}` )) formData.append('file', new window.File([blob], `${(new Date).getTime()}`))
this.$loading() this.$loading()
this.$http.post(`/app/appdlbresource/uploadDlbFile`, formData).then(res => { this.$http.post(`/app/appdlbresource/uploadDlbFile`, formData).then(res => {
@@ -285,7 +281,7 @@
}) })
}, },
onTouchend () { onTouchend() {
if (!this.isShow) return if (!this.isShow) return
if (this.isShow && new Date().getTime() - this.startTime < 1500) { if (this.isShow && new Date().getTime() - this.startTime < 1500) {
@@ -306,7 +302,7 @@
this.stop() this.stop()
}, },
onTouchmove (e) { onTouchmove(e) {
if (this.isShow) { if (this.isShow) {
const x = e.touches[0].clientX const x = e.touches[0].clientX
const y = e.touches[0].clientY const y = e.touches[0].clientY
@@ -319,15 +315,15 @@
} }
}, },
submit () { submit() {
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.LiveBroadcast { .LiveBroadcast {
height: 100vh; height: 100vh;
overflow: hidden; overflow: hidden;
user-select: none; user-select: none;
@@ -685,5 +681,5 @@
.header-line span.line20 { .header-line span.line20 {
animation-delay: -0.1s; animation-delay: -0.1s;
} }
} }
</style> </style>