scene.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import { useI18n, i18n, getLocale } from "@/i18n";
  2. /**
  3. * 兼容自定主义按键为中文的处理器
  4. */
  5. const covertCustomButton = (data) => {
  6. return data.map((item) => {
  7. if ("type" in item) {
  8. if (item.type == "链接") item.type = "link";
  9. if (item.type == "电话") item.type = "phone";
  10. }
  11. if ("openMethod" in item) {
  12. if (item.openMethod == "弹出层打开") item.openMethod = "_self";
  13. if (item.openMethod == "新窗口打开") item.openMethod = "_target";
  14. }
  15. // console.log('当前转换数据!', item);
  16. return item;
  17. });
  18. };
  19. export default {
  20. namespaced: true,
  21. state() {
  22. return {
  23. // 场景列表
  24. list: [],
  25. //当前场景
  26. currentScene: {},
  27. //访问密码
  28. password: "",
  29. //场景数据
  30. metadata: {},
  31. //当前一级分组
  32. currentCatalogRoot: {},
  33. //当前二级分组
  34. currentSecondary: {},
  35. //二级分组
  36. secondaryList: {},
  37. //当前场景分组
  38. currentScenesList: {},
  39. //当时场景的版本
  40. fdkkCurrentVersion: "v4",
  41. // 存在开场动作并动作完成的flag
  42. isDoneforCover: false,
  43. currentSecondId: null,
  44. currentRootId: null,
  45. };
  46. },
  47. getters: {
  48. list: (state) => state.list,
  49. secondaryList: (state) => state.secondaryList,
  50. currentCatalogRoot: (state) => state.currentCatalogRoot,
  51. currentScenesList: (state) => state.currentScenesList,
  52. currentSecondId: (state) => state.currentSecondId,
  53. currentRootId: (state) => state.currentRootId,
  54. currentSecondary: (state) => state.currentSecondary,
  55. currentScene: (state) => state.currentScene,
  56. fdkkCurrentVersion: (state) => state.fdkkCurrentVersion,
  57. password: (state) => state.password,
  58. metadata: (state) => state.metadata,
  59. fdkkBGM: (state) => state.fdkkBGM,
  60. isDoneforCover: (state) => state.isDoneforCover,
  61. customLink: (state, getters, rootState, rootGetters) => {
  62. let metadata = getters.metadata;
  63. if (metadata.customButton) {
  64. let temp = JSON.parse(JSON.stringify(metadata.customButton));
  65. const res = covertCustomButton(temp);
  66. return res.find((item) => item.type == "link");
  67. }
  68. return {};
  69. },
  70. customTelephone: (state, getters, rootState, rootGetters) => {
  71. let metadata = getters.metadata;
  72. if (metadata.customButton) {
  73. // console.log(metadata.customButton);
  74. let temp = JSON.parse(JSON.stringify(metadata.customButton));
  75. const res = covertCustomButton(temp);
  76. return temp.find((item) => item.type == "phone");
  77. }
  78. return {};
  79. },
  80. musicURL: (state, getters, rootState, rootGetters) => {
  81. let metadata = getters.metadata;
  82. if (metadata.backgroundMusic && metadata.backgroundMusic.id) {
  83. return metadata.backgroundMusic.ossPath;
  84. }
  85. return null;
  86. },
  87. earthMask: (state, getters) => {
  88. const { earth } = getters.currentScene.customMask;
  89. return earth || null;
  90. },
  91. skyMask: (state, getters) => {
  92. const { sky } = getters.currentScene.customMask;
  93. return sky || null;
  94. },
  95. },
  96. mutations: {
  97. setData(state, payload) {
  98. for (let key in payload) {
  99. state[key] = payload[key];
  100. }
  101. },
  102. setScenes(state, payload) {
  103. state.list = payload;
  104. },
  105. setPassword(state, payload) {
  106. state.password = payload;
  107. },
  108. setFdkkCurrentVersion(state, payload) {
  109. state.fdkkCurrentVersion = payload;
  110. },
  111. // 设置当前场景
  112. setCurrentScene(state, payload) {
  113. if (payload.someData) {
  114. try {
  115. // someData旧数据有可能是字符串,要parse一下
  116. payload.someData = typeof payload.someData == "string" ? JSON.parse(payload.someData) : payload.someData;
  117. } catch (error) {}
  118. }
  119. state.currentScene = payload;
  120. this.commit("fdkk/setReset");
  121. },
  122. // 设置当前二级分组
  123. setCurrentSecondary(state, payload) {
  124. state.currentSecondary = payload;
  125. let arr = state.list.filter((item) => {
  126. return state.currentSecondary.id == item.category;
  127. });
  128. this.commit(
  129. "scene/setCurrentScenesList",
  130. arr.sort((a, b) => a.weight - b.weight)
  131. );
  132. },
  133. // 设置当前场景列表
  134. setCurrentScenesList(state, payload) {
  135. state.currentScenesList = payload;
  136. },
  137. // 设置当前一级分组
  138. setCurrentCatalogRoot(state, payload) {
  139. state.currentCatalogRoot = payload;
  140. let temp = [];
  141. payload.children &&
  142. payload.children.forEach((item) => {
  143. state.metadata.catalogs.forEach((sub) => {
  144. if (item == sub.id) {
  145. if (state.list.some((iii) => iii.category == sub.id)) {
  146. temp.push(sub);
  147. }
  148. }
  149. });
  150. });
  151. this.commit("scene/setSecondaryList", temp);
  152. },
  153. // 设置当前二级分组列表
  154. setSecondaryList(state, payload) {
  155. state.secondaryList = payload;
  156. if (payload.length > 0) {
  157. this.commit("scene/setCurrentSecondary", payload[0]);
  158. }
  159. },
  160. setMetaData(state, payload) {
  161. state.metadata = payload;
  162. document.title = payload.work.name;
  163. document.querySelector('meta[name="description"]').setAttribute("content", payload.work.description.replace(/<\/?[^>]+(>|$)/g, ""));
  164. document.querySelector('meta[name="cover"]').setAttribute("content", payload.work.icon);
  165. },
  166. setDoneforCover(state, payload) {
  167. state.isDoneforCover = payload;
  168. },
  169. },
  170. };