scene.ts 2.4 KB

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