scene.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { ref } from 'vue'
  2. import { fetchScenes, getSyncSceneInfo, SceneType, SceneTypeDesc } from '@/api'
  3. import { fetchStoreItems } from '@/utils'
  4. import type { Scene, Scenes } from '@/api'
  5. import { Dialog } from 'bill/expose-common'
  6. import { getUserInfo } from '@/api/user'
  7. export type { Scene, Scenes } from '@/api'
  8. export const scenes = ref<Scenes>([])
  9. export const getScene = (sceneId: Scene['id']) => scenes.value.find(scene => scene.id === sceneId)
  10. export const initialScenes = fetchStoreItems(
  11. scenes,
  12. fetchScenes,
  13. )
  14. export { SceneType, SceneTypeDesc, SceneStatus } from '@/api'
  15. export const SceneTypePaths: { [key in SceneType]: string[] } = {
  16. [SceneType.SWKK]: [
  17. "/swkk/spg.html",
  18. "/swkk/epg.html",
  19. `/livestream/fd/criminal.html`,
  20. ],
  21. [SceneType.SWKJ]: ["/swkk/spg.html", "/swkk/epg.html"],
  22. [SceneType.DSFXJ]: ["/swkk/spg.html", "/swkk/epg.html"],
  23. [SceneType.SWSS]: ["/swss/index.html", "/swss/index.html"],
  24. [SceneType.SWMX]: import.meta.env.DEV
  25. ? ["/dev-code/index.html", "/dev-code/index.html"]
  26. : ["/code/index.html", "/code/index.html"],
  27. [SceneType.SWSSMX]: ["/swkk/spg.html", "/swkk/epg.html"],
  28. [SceneType.SWYDSS]: ["/swss/index.html", "/swss/index.html"],
  29. [SceneType.SWYDMX]: ["/swkk/spg.html", "/swkk/epg.html"],
  30. };
  31. export const getSWKKSyncLink = async (scene: Scene) => {
  32. console.log('scene', scene)
  33. const supportTypes = [SceneType.SWKJ, SceneType.SWSSMX, SceneType.SWYDMX, SceneType.DSFXJ];
  34. const kkScenes = scenes.value.filter((scene) =>
  35. supportTypes.includes(scene.type)
  36. );
  37. let msg: string | null = null;
  38. if (!kkScenes.length) {
  39. msg = `带看仅支持${supportTypes
  40. .map((type) => SceneTypeDesc[type])
  41. .join("、")}类型场景,请添加此类型场景。`;
  42. }
  43. if (msg) {
  44. Dialog.alert(msg);
  45. throw msg;
  46. }
  47. const url = new URL(SceneTypePaths[SceneType.SWKK][2], window.location.href);
  48. const userInfo = await getUserInfo();
  49. const roomId = await getSyncSceneInfo(scene);
  50. const params = {
  51. vruserId: userInfo.userName,
  52. // platform: "fd",
  53. roomId,
  54. // domain: location.href,
  55. // fromMiniApp: "0",
  56. role: "leader",
  57. // avatar: '/code/favicon.ico',
  58. redirect: encodeURIComponent(location.href),
  59. name: userInfo.userName,
  60. m: scene.raw.num,
  61. };
  62. for (const [name, val] of Object.entries(params)) {
  63. url.searchParams.append(name, val || "");
  64. }
  65. return url;
  66. };