uniapp H5 touchstart执行完成并返回成功再执行touchend 失败则不执行touchend
- 直接上代码
<tmmplate>
<view class="mp_yun_item">
<view class="mp-ptz-btn mp-yun-top" @touchstart="yunControl">
</view>
<view class="mp-ptz-btn mp-yun-right" @touchstart="yunControl">
</view>
<view class="mp-ptz-btn mp-yun-bottom" @touchstart="yunControl">
</view>
<view class="mp-ptz-btn mp-yun-left" @touchstart="yunControl">
</view>
</view>
</template>
<script>
export default {
data (){
return {
robotId:"",
isfirst:true,
loadingHide:false
}
},
methods:{
yunControl() {
let that = this;
let params = {
robotId: this.robotId,
action: 'move',
action_params: {},
}
let p = new Promise((resolve, reject) => {
FridApi.setPtzAction(params)
.then((result) => {
const res = result
if (res && res.code === 0) {
this.isfirst = true
resolve();
} else {
this.$refs.uToast.show({
message: res?.msg || "云台操作失败",
duration: 1000,
})
}
})
.finally(() => {
this.loading = false
})
});
window.addEventListener("touchend", (event) => {
p.then(value => {
this.yunControlEnd(params)
})
}, {
once: true
});
},
yunControlEnd(params) {
this.loadingHide = true
FridApi.setPtzAction(params)
.then((result) => {
const res = result
this.loadingHide = false
if (res && res.code === 0) {
} else {
this.$refs.uToast.show({
message: res?.msg || "云台操作失败",
duration: 1000,
})
if (this.isfirst) {
this.isfirst = false;
this.yunControlEnd(params)
}
}
})
.finally(() => {
this.loadingHide = false
})
},
}
}
</script>
- 完成! (日常记录)