mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2026-08-06 10:57:25 +08:00
feat: 添加直播房间页面及相关样式和功能
- 新增直播房间页面,支持竖屏直播模式 - 实现直播播放器和消息展示功能 - 增加购物车按钮和商品推荐展示 - 更新样式以适应新页面布局 - 移除不再使用的 MQTT 相关文件和 API 调用
This commit is contained in:
41
pages/promotion/live/utils/liveSetting.js
Normal file
41
pages/promotion/live/utils/liveSetting.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { getLiveRoomById } from "@/api/live.js";
|
||||
|
||||
const cachedSettings = {};
|
||||
const fetchingPromises = {};
|
||||
|
||||
export function seedLiveSetting(liveId, setting) {
|
||||
if (liveId && setting) {
|
||||
cachedSettings[liveId] = setting;
|
||||
}
|
||||
}
|
||||
|
||||
export async function fetchLiveSetting(liveId, force = false) {
|
||||
if (!liveId) return null;
|
||||
if (!force && cachedSettings[liveId]) return cachedSettings[liveId];
|
||||
if (!force && fetchingPromises[liveId]) return fetchingPromises[liveId];
|
||||
|
||||
fetchingPromises[liveId] = (async () => {
|
||||
try {
|
||||
const res = await getLiveRoomById(liveId);
|
||||
if (res.data?.success && res.data?.result) {
|
||||
cachedSettings[liveId] = res.data.result;
|
||||
return cachedSettings[liveId];
|
||||
}
|
||||
console.warn("获取直播配置失败", res.data);
|
||||
return null;
|
||||
} catch (error) {
|
||||
console.error("获取直播配置异常:", error);
|
||||
return null;
|
||||
} finally {
|
||||
fetchingPromises[liveId] = null;
|
||||
}
|
||||
})();
|
||||
|
||||
return fetchingPromises[liveId];
|
||||
}
|
||||
|
||||
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