添加注释

master
于肖磊 2025-12-05 17:19:24 +08:00
parent ff54de3d53
commit e4477da8e6
1 changed files with 277 additions and 15 deletions

View File

@ -180,11 +180,20 @@
componentLikeButton,
componentSharePopup
},
/**
* 直播内容组件属性
*/
props: {
/**
* 直播配置信息
*/
propLiveConfig: {
type: Object,
default: () => {}
},
/**
* 直播展示图片
*/
propLiveShowImgs: {
type: Array,
default: () => []
@ -297,6 +306,9 @@
}
},
watch: {
/**
* 监听直播配置信息变更
*/
propLiveConfig: {
handler(new_value) {
if (new_value != null) {
@ -308,6 +320,9 @@
deep: true
}
},
/**
* 组件挂载后执行初始化操作
*/
mounted() {
//
this.init_window_info();
@ -318,6 +333,9 @@
//
this.bind_keyboard_listener();
},
/**
* 组件销毁前清理资源
*/
beforeDestroy() {
// socket
this.clear_interval_task();
@ -330,6 +348,10 @@
methods: {
isEmpty,
//#region
/**
* 初始化窗口信息
* 获取屏幕宽高并根据不同平台设置头部样式
*/
init_window_info() {
const data = uni.getWindowInfo();
this.windowWidth = data.windowWidth;
@ -365,13 +387,18 @@
},
//#endregion
// 退, 退
/**
* 退出直播
* 触发父组件的liveBack事件
*/
live_back() {
this.$emit('liveBack');
},
//#region
//
/**
* 滚动到评论区最底部
*/
scroll_to_lower() {
this.$nextTick(() => {
//#ifndef APP-NVUE
@ -388,14 +415,25 @@
//#endif
})
},
// nvue使flex
/**
* 将文本拆分为字符数组用于NVUE环境
* @param {String} val - 需要拆分的文本
* @returns {Array} 拆分后的字符数组
*/
split_text(val) {
return val.split('');
},
/**
* 滚动事件处理
* @param {Event} e - 滚动事件对象
*/
scroll_event(e) {
this.is_scroll_to_lower = false;
},
//
/**
* 滚动到底部事件处理
* @param {Event} e - 滚动事件对象
*/
scroll_to_lower_event(e) {
//
setTimeout(() => {
@ -404,13 +442,20 @@
this.is_scroll_to_lower = true;
}, 0);
},
//
/**
* 新消息提示点击事件处理
* 点击后滚动到评论区底部
*/
message_num_event() {
this.scroll_to_lower();
},
//#endregion
//#region socket
/**
* 初始化用户信息
* 从缓存获取用户头像并建立WebSocket连接
*/
init_user_info() {
const new_user = uni.getStorageSync(uni.$store?.state?.cache_user_info_key ?? '') || null;
if (new_user != null) {
@ -419,13 +464,18 @@
// socket
this.socket_connect();
},
// socket
/**
* 手动连接WebSocket
*/
socket_connect_manual() {
if (!this.is_socket_error) {
this.socket_connect(true);
}
},
// socket
/**
* 建立WebSocket连接
* @param {Boolean} is_manual - 是否手动连接
*/
socket_connect(is_manual = false) {
// false
this.is_socket_error = false;
@ -490,7 +540,10 @@
});
},
//
/**
* WebSocket消息回调处理
* @param {Object} e - WebSocket消息事件对象
*/
socket_message_back_handle(e) {
let res = JSON.parse(e.data);
if(res.code !== 0) {
@ -555,7 +608,9 @@
}
},
//
/**
* WebSocket心跳处理
*/
socket_ping_handle() {
//
this.clear_interval_task();
@ -565,6 +620,9 @@
this.socket_send('ping', app.globalData.get_timestamp());
}, this.ping_interval * 1000);
},
/**
* 清除定时任务
*/
clear_interval_task() {
if (this.ping_timer != null) {
clearInterval(this.ping_timer);
@ -572,8 +630,11 @@
}
},
//
// type init, ping, message
/**
* 发送WebSocket消息
* @param {String} type - 消息类型(init初始化, ping心跳, message消息)
* @param {String} content - 消息内容
*/
socket_send(type = 'message', content = '') {
if(this.task === null) {
app.globalData.showToast('socket连接失败');
@ -599,12 +660,18 @@
//#endregion
//#region
/**
* 添加评论
*/
add_comment() {
//#ifndef H5
this.is_add_comment = true;
//#endif
},
//
/**
* 键盘高度变化监听处理
* @param {Object} res - 键盘高度变化事件对象
*/
listener(res) {
// 1
if (res.height > 0) {
@ -613,13 +680,23 @@
this.listener_height = 0;
}
},
/**
* 绑定键盘高度变化监听事件
*/
bind_keyboard_listener() {
uni.onKeyboardHeightChange(this.listener);
},
/**
* 解绑键盘高度变化监听事件
*/
unbind_keyboard_listener() {
uni.offKeyboardHeightChange(this.listener);
},
/**
* 评论输入确认事件处理
* @param {Event} e - 输入确认事件对象
*/
comment_input_confirm(e) {
const value = e.detail.value;
if (value != '') {
@ -630,10 +707,18 @@
//#endregion
//#region
/**
* 添加商品
* 打开商品弹出框
*/
add_goods() {
this.$refs.popupGoodsRef.open();
},
//#endregion
/**
* 分享事件处理
*/
share_event() {
//
app.globalData.page_share_handle();
@ -651,11 +736,19 @@
});
}
},
//
/**
* 点赞点击事件处理
* @param {Event} e - 点击事件对象
*/
like_click(e) {
this.$refs.likeButton.handleClick(e);
},
//
/**
* 点赞按钮点击事件处理
* @param {Event} e - 点击事件对象
*/
like_button_click(e) {
//
this.casual_like_count++;
@ -923,4 +1016,173 @@
}
}
/* #endif */
</style>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>
</script>
</style>
</template>