scene.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { defineStore } from 'pinia';
  2. import { KankanMetaDataType } from '/#/sdk';
  3. import { getApp } from '/@/hooks/userApp';
  4. // useApp,
  5. export interface FloorsType {
  6. id: string;
  7. subgroup?: string;
  8. name: string;
  9. segment?: any[];
  10. tagging?: any[];
  11. ['vertex-xy']?: any[];
  12. }
  13. interface SceneState {
  14. tags: any[];
  15. floors: FloorsType[];
  16. metadata: KankanMetaDataType;
  17. }
  18. export const getStaticURL = (path: string) => {
  19. return import.meta.env.BASE_URL + import.meta.env.VITE_APP_STATIC_DIR + '/' + path;
  20. };
  21. export const useSceneStore = defineStore({
  22. id: 'scene',
  23. state: (): SceneState => ({
  24. tags: [],
  25. floors: [],
  26. metadata: {} as KankanMetaDataType,
  27. }),
  28. getters: {
  29. musicURL(): Nullable<string> {
  30. const musicURl = this.metadata.music;
  31. if (musicURl) {
  32. if (/^0\d$/.test(musicURl)) {
  33. return getStaticURL(`static/music/${musicURl}.mp3`);
  34. } else {
  35. const app = getApp();
  36. return app.resource.getUserResourceURL(
  37. this.metadata.musicFile.replace(/(.+)\.(.+)/, 'music-user.$2'),
  38. );
  39. }
  40. }
  41. return null;
  42. },
  43. loadingLogoFile(): Nullable<string> {
  44. if (this.metadata.loadingLogo == 'user') {
  45. const app = getApp();
  46. return app.resource.getUserResourceURL(this.metadata.loadingLogoFile);
  47. }
  48. return null;
  49. },
  50. },
  51. actions: {
  52. load(metadata: KankanMetaDataType): void {
  53. this.metadata = metadata;
  54. document.title = metadata.title;
  55. },
  56. loadFloorData(floors: FloorsType[]) {
  57. if (floors?.length) {
  58. this.floors = floors.map((item) => {
  59. return { id: item.subgroup, name: item.name };
  60. }) as FloorsType[];
  61. }
  62. },
  63. },
  64. });