mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-ui.git
synced 2026-08-06 02:47:29 +08:00
feat: 添加直播聊天功能与相关配置
- 在 LiveChatPanel.vue 中实现直播间聊天功能,支持发送和接收消息。 - 新增 useChat.js 组合式 API,管理聊天逻辑与状态。 - 更新 Live.vue 控制面板,集成聊天组件并优化直播状态显示。 - 更新 package.json 和 pnpm-lock.yaml,添加 @tencentcloud/chat 和 hls.js 依赖。
This commit is contained in:
44
manager/src/views/live/composables/useLiveSetting.js
Normal file
44
manager/src/views/live/composables/useLiveSetting.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import { getSetting } from "@/api/index";
|
||||
|
||||
/** @type {Record<string, any> | null} */
|
||||
let cachedSetting = null;
|
||||
/** @type {Promise<Record<string, any> | null> | null} */
|
||||
let fetchingPromise = null;
|
||||
|
||||
/** 获取直播配置(带缓存) */
|
||||
export async function fetchLiveSetting(force = false) {
|
||||
if (!force && cachedSetting) {
|
||||
return cachedSetting;
|
||||
}
|
||||
if (!force && fetchingPromise) {
|
||||
return fetchingPromise;
|
||||
}
|
||||
|
||||
fetchingPromise = (async () => {
|
||||
try {
|
||||
const res = await getSetting("LIVE_SETTING");
|
||||
if (res?.success && res?.result) {
|
||||
cachedSetting = res.result;
|
||||
return cachedSetting;
|
||||
}
|
||||
console.warn("获取直播配置失败", res);
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error("获取直播配置异常:", error);
|
||||
return null;
|
||||
} finally {
|
||||
fetchingPromise = null;
|
||||
}
|
||||
})();
|
||||
|
||||
return fetchingPromise;
|
||||
}
|
||||
|
||||
/** 解析 IM SDK AppID */
|
||||
export function resolveSdkAppId(setting) {
|
||||
if (!setting?.imSdkAppid) {
|
||||
return 0;
|
||||
}
|
||||
const id = Number(setting.imSdkAppid);
|
||||
return Number.isNaN(id) ? 0 : id;
|
||||
}
|
||||
Reference in New Issue
Block a user