import { ref } from 'vue' import { fetchScenes, getSyncSceneInfo, SceneType, SceneTypeDesc } from '@/api' import { fetchStoreItems } from '@/utils' import type { Scene, Scenes } from '@/api' import { Dialog } from 'bill/expose-common' import { getUserInfo } from '@/api/user' import { ui18n } from '@/lang' export type { Scene, Scenes } from '@/api' export const scenes = ref([]) export const getScene = (sceneId: Scene['id']) => scenes.value.find(scene => scene.id === sceneId) export const initialScenes = fetchStoreItems( scenes, fetchScenes, ) export { SceneType, SceneTypeDesc, SceneStatus } from '@/api' export const SceneTypePaths: { [key in SceneType]: string[] } = { [SceneType.SWKK]: [ "/swkk/spg.html", "/swkk/epg.html", `/livestream/fd/criminal.html`, ], [SceneType.SWKJ]: ["/swkk/spg.html", "/swkk/epg.html"], [SceneType.DSFXJ]: ["/swkk/spg.html", "/swkk/epg.html"], [SceneType.SWSS]: ["/swss/index.html", "/swss/index.html"], [SceneType.SWMX]: import.meta.env.DEV ? ["/dev-code/index.html", "/dev-code/index.html"] : ["/code/index.html", "/code/index.html"], [SceneType.SWSSMX]: ["/swkk/spg.html", "/swkk/epg.html"], [SceneType.SWYDSS]: ["/swss/index.html", "/swss/index.html"], [SceneType.SWYDMX]: ["/swkk/spg.html", "/swkk/epg.html"], }; export const getSWKKSyncLink = async (scene: Scene) => { console.log('scene', scene) const supportTypes = [SceneType.SWKJ, SceneType.SWSSMX, SceneType.SWYDMX, SceneType.DSFXJ]; const kkScenes = scenes.value.filter((scene) => supportTypes.includes(scene.type) ); let msg: string | null = null; if (!kkScenes.length) { msg = ui18n.t('fuse.syncErr', {types: supportTypes .map((type) => SceneTypeDesc[type]) .join("、")}); } if (msg) { Dialog.alert(msg); throw msg; } const url = new URL(SceneTypePaths[SceneType.SWKK][2], window.location.href); const userInfo = await getUserInfo(); const roomId = await getSyncSceneInfo(scene); const params = { vruserId: userInfo.userName, // platform: "fd", roomId, // domain: location.href, // fromMiniApp: "0", role: "leader", // avatar: '/code/favicon.ico', redirect: encodeURIComponent(location.href), name: userInfo.userName, m: scene.raw.num, }; for (const [name, val] of Object.entries(params)) { url.searchParams.append(name, val || ""); } return url; };