153 lines
5.4 KiB
JavaScript
153 lines
5.4 KiB
JavaScript
const app = getApp();
|
||
import { isEmpty } from '@/common/js/common/common.js';
|
||
export default {
|
||
data() {
|
||
return {
|
||
windowWidth: 0,
|
||
windowHeight: 0,
|
||
is_live_ended: false,
|
||
live_config: {},
|
||
is_loading: true,
|
||
like_show_imgs: [
|
||
'https://new.shopxo.vip/static/plugins/live/images/like/like1.png',
|
||
'https://new.shopxo.vip/static/plugins/live/images/like/like2.png',
|
||
'https://new.shopxo.vip/static/plugins/live/images/like/like3.png',
|
||
'https://new.shopxo.vip/static/plugins/live/images/like/like4.png',
|
||
'https://new.shopxo.vip/static/plugins/live/images/like/like5.png',
|
||
],
|
||
lastTapTime: 0, // 用于检测双击
|
||
lastTapPosition: { x: 0, y: 0 }, // 记录上次点击位置
|
||
lastLikeTime: 0 // 记录上次点赞时间,用于防抖
|
||
}
|
||
},
|
||
onLoad(params) {
|
||
// 调用公共事件方法
|
||
app.globalData.page_event_onload_handle(params);
|
||
// 设置参数
|
||
this.params = app.globalData.launch_params_handle(params);
|
||
},
|
||
|
||
onShow() {
|
||
// 调用公共事件方法
|
||
app.globalData.page_event_onshow_handle();
|
||
|
||
// 分享菜单处理
|
||
app.globalData.page_share_handle();
|
||
|
||
// #ifdef APP-NVUE
|
||
const data = uni.getWindowInfo();
|
||
this.windowWidth = data.windowWidth;
|
||
this.windowHeight = data.windowHeight;
|
||
// #endif
|
||
this.init();
|
||
},
|
||
mounted() {
|
||
this.init();
|
||
},
|
||
methods: {
|
||
init() {
|
||
uni.showLoading({
|
||
title: '直播间数据加载中...',
|
||
mask: true
|
||
});
|
||
uni.request({
|
||
url: app.globalData.get_request_url('index', 'room', 'live'),
|
||
method: 'POST',
|
||
data: {},
|
||
dataType: 'json',
|
||
success: (res) => {
|
||
// 隐藏加载提示
|
||
uni.hideLoading();
|
||
const new_data = res.data;
|
||
// 显示直播内容
|
||
this.is_loading = false;
|
||
// 判断是否有数据
|
||
if(res.data.code == 0) {
|
||
// 获取直播间信息
|
||
this.live_config = new_data.data || {};
|
||
// 如果不存在拉流地址则认为直播已结束,避免因为报错导致的页面异常
|
||
// if (isEmpty(new_data.data.pull_flv_url)) {
|
||
// this.is_live_ended = true;
|
||
// }
|
||
} else {
|
||
uni.showToast({
|
||
title: new_data.msg || '获取直播间信息失败',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
},
|
||
fail: (err) => {
|
||
// 隐藏加载提示
|
||
uni.hideLoading();
|
||
// 显示直播内容
|
||
this.is_loading = false;
|
||
}
|
||
});
|
||
},
|
||
ended() {
|
||
console.log('1111');
|
||
this.is_live_ended = true;
|
||
},
|
||
live_back() {
|
||
app.globalData.page_back_prev_event();
|
||
},
|
||
// 处理鼠标双击事件
|
||
handleDoubleClick(event) {
|
||
if (event.target.dataset.ignore) {
|
||
return;
|
||
}
|
||
// 防抖处理,200ms内只能触发一次
|
||
const currentTime = Date.now();
|
||
if (currentTime - this.lastLikeTime < 200) {
|
||
return;
|
||
}
|
||
|
||
this.lastLikeTime = currentTime;
|
||
|
||
if (this.$refs.likeEffect) {
|
||
this.$refs.likeEffect.addLike(event);
|
||
}
|
||
},
|
||
|
||
// 处理触屏双击事件
|
||
handleTouchEnd(event) {
|
||
if (event.target.dataset.ignore) {
|
||
return;
|
||
}
|
||
// 获取当前位置
|
||
let x, y;
|
||
if (event.changedTouches && event.changedTouches.length > 0) {
|
||
x = event.changedTouches[0].screenX;
|
||
y = event.changedTouches[0].screenY;
|
||
} else {
|
||
x = event.screenX || 0;
|
||
y = event.screenY || 0;
|
||
}
|
||
|
||
const currentTime = new Date().getTime();
|
||
const tapLength = currentTime - this.lastTapTime;
|
||
const distance = Math.sqrt(
|
||
Math.pow(x - this.lastTapPosition.x, 2) +
|
||
Math.pow(y - this.lastTapPosition.y, 2)
|
||
);
|
||
// 判断是否为双击 (300ms内且距离较近)
|
||
if (tapLength < 300 && tapLength > 0 && distance < 50) {
|
||
|
||
// 防抖处理,200ms内只能触发一次
|
||
if (currentTime - this.lastLikeTime < 200) {
|
||
this.lastTapTime = currentTime;
|
||
this.lastTapPosition = { x, y };
|
||
return;
|
||
}
|
||
|
||
this.lastLikeTime = currentTime;
|
||
|
||
if (this.$refs.likeEffect) {
|
||
this.$refs.likeEffect.addLike(event);
|
||
}
|
||
}
|
||
this.lastTapTime = currentTime;
|
||
this.lastTapPosition = { x, y };
|
||
}
|
||
}
|
||
} |