hotspot.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. import Vue from "vue";
  2. import { i18n } from "@/lang";
  3. import { workHotSave } from "@/api";
  4. import { $waiting } from "@/components/shared/loading";
  5. import browser from "@/utils/browser";
  6. import { deepClone, isSameObject } from "@/utils/other.js";
  7. let vue = new Vue();
  8. export default {
  9. namespaced: true,
  10. state() {
  11. return {
  12. hotspotList: [],
  13. currentHotsopts: [],
  14. hotspot: null,
  15. hotspotTypeList: {
  16. scene: "scene",
  17. image: "image",
  18. video: "video",
  19. audio: "audio",
  20. link: "hyperlink",
  21. textarea: "textarea",
  22. tag: null,
  23. imageText: "imageTextInfo",
  24. article: "articleInfo",
  25. pdf: "pdfInfo",
  26. phone: "phoneInfo",
  27. },
  28. hotspotIconTypeList: {
  29. system_icon: null,
  30. custom_image: "customIconInfo",
  31. serial_frame: "serialFrameInfo",
  32. personalized_tag: "personalizedTagInfo",
  33. },
  34. dataType: {
  35. customIconInfo: {
  36. // 热点图标类型为自定义图标时,图标的数据
  37. img: "",
  38. },
  39. serialFrameInfo: {
  40. // 热点图标类型为序列帧时,序列帧的数据
  41. img: "",
  42. frameNumber: 0, // 总帧数
  43. duration: 0, // 总播放时长(秒)
  44. },
  45. personalizedTagInfo: {
  46. // 热点图标类型为个性标签时,个性标签的数据
  47. isShowLine: true,
  48. lineDirection: "left-top",
  49. fillColor: "rgba(0, 0, 0, 0.5)",
  50. borderColor: "rgba(255, 255, 255, 0.8)",
  51. textColor: "rgba(255, 255, 255, 1)",
  52. textDirection: "left-right",
  53. isTextWrap: false,
  54. textNumPerLine: 10,
  55. },
  56. scene: null,
  57. hyperlink: "",
  58. textarea: "",
  59. image: [],
  60. audio: "",
  61. video: "",
  62. imageTextInfo: {
  63. // 热点类型为图文时,图文内容
  64. imageList: [],
  65. text: "",
  66. isApplyToAll: true,
  67. audio: {},
  68. },
  69. phoneInfo: {
  70. // 热点类型为电话时,对应数据
  71. phone: "",
  72. },
  73. pdfInfo: {
  74. // 热点类型为pdf时,对应数据
  75. name: "",
  76. url: "",
  77. },
  78. articleInfo: {
  79. html: "",
  80. },
  81. },
  82. };
  83. },
  84. getters: {
  85. hotspot: (state) => state.hotspot,
  86. currentHotsopts: (state, getters, rootState, rootGetters) => {
  87. state.currentHotsopts = state.hotspotList.filter((item) => item.navigationId == rootState.scene.currentScene.id || item.navigationId == rootState.scene.currentScene.sid);
  88. return state.currentHotsopts;
  89. },
  90. hotspotList: (state, getters, rootState, rootGetters) => {
  91. let hotspots = rootState.base.baseInfo.workHotList;
  92. if (hotspots.length && !state.hotspotList.length) {
  93. state.hotspotList = hotspots;
  94. }
  95. if (state.hotspotList.length) {
  96. state.hotspotList.forEach((item, index) => {
  97. if (item.content) {
  98. let hotSpotType = item.hotspotType;
  99. for (let key in state.hotspotTypeList) {
  100. let value = state.hotspotTypeList[key];
  101. if (key == hotSpotType && item.content[value]) {
  102. item[value] = item.content[value];
  103. } else if (value) {
  104. item[value] = state.dataType[value];
  105. }
  106. }
  107. let hotSpotIconType = item.hotspotIconType;
  108. for (let key in state.hotspotIconTypeList) {
  109. let value = state.hotspotIconTypeList[key];
  110. if (key == hotSpotIconType && item.content[value]) {
  111. item[value] = item.content[value];
  112. } else if (value) {
  113. item[value] = state.dataType[value];
  114. }
  115. }
  116. }
  117. });
  118. }
  119. return state.hotspotList;
  120. },
  121. // 1.3.0 新增层级后所有热点类型不同汇总显示的ICON
  122. hotspotIcon: (state) => {
  123. const category = state.hotspot && state.hotspot.hotspotIconType ? state.hotspot.hotspotIconType : "";
  124. switch (category) {
  125. case "system_icon":
  126. return {
  127. img: state.hotspot.img,
  128. type: "system_icon",
  129. };
  130. case "custom_image":
  131. return {
  132. ...state.hotspot.customIconInfo,
  133. type: "custom_image",
  134. };
  135. case "serial_frame":
  136. return {
  137. ...state.hotspot.serialFrameInfo,
  138. img: state.hotspot.serialFrameInfo.img,
  139. type: "serial_frame",
  140. };
  141. case "personalized_tag":
  142. return {
  143. ...state.hotspot.personalizedTagInfo,
  144. img: "",
  145. type: "personalized_tag",
  146. };
  147. default:
  148. return {
  149. img: "",
  150. };
  151. }
  152. },
  153. // currentScene: (state) => state.currentScene,
  154. },
  155. mutations: {
  156. SetHotspot(state, data) {
  157. state.hotspot = data;
  158. this.commit("BackupHotSpot", browser.CloneObject(data));
  159. },
  160. updateHotspot(state, payload) {
  161. if (payload.id) {
  162. // 编辑
  163. state.hotspotList.forEach((item, index) => {
  164. if (item.id == payload.id) {
  165. state.hotspotList[index] = payload;
  166. }
  167. });
  168. state.currentHotsopts.forEach((item, index) => {
  169. if (item.id == payload.id) {
  170. state.currentHotsopts[index] = payload;
  171. }
  172. });
  173. } else {
  174. //新增
  175. payload.id = "add_" + new Date().getTime();
  176. state.hotspotList.push(payload);
  177. }
  178. },
  179. processData(state, payload) {
  180. // state.hotspot.content = {};
  181. let list = state.hotspotList;
  182. list.forEach((item) => {
  183. if (!item.content) {
  184. item.content = {};
  185. }
  186. let hotSpotType = item.hotspotType;
  187. for (let key in state.hotspotTypeList) {
  188. let value = state.hotspotTypeList[key];
  189. if (key == hotSpotType) {
  190. if (value) {
  191. item.content[value] = item[value];
  192. }
  193. }
  194. delete item[value];
  195. }
  196. let hotSpotIconType = item.hotspotIconType;
  197. for (let key in state.hotspotIconTypeList) {
  198. let value = state.hotspotIconTypeList[key];
  199. if (key == hotSpotIconType) {
  200. if (value) {
  201. item.content[value] = item[value];
  202. }
  203. }
  204. delete item[value];
  205. }
  206. });
  207. },
  208. },
  209. actions: {
  210. save({ commit, state, rootState }, payload) {
  211. let list = deepClone(state.hotspotList);
  212. list.forEach((item) => {
  213. let current = rootState.base.sceneList.find((s_item) => s_item.sid && s_item.sid == item.navigationId);
  214. if (current) {
  215. item.navigationId = current.id;
  216. }
  217. if (item.hotspotType == "scene" && typeof item.scene.id != "number" && item.scene.id.indexOf("add") != -1) {
  218. //场景类型 如果场景是新增,则scene的id也需要从服务端取值
  219. let current = rootState.base.sceneList.find((s_item) => s_item.sid && s_item.sid == item.scene.sid);
  220. if (current) {
  221. item.scene.id = current.id;
  222. }
  223. }
  224. if (typeof item.id != "number" && item.id.indexOf("add") != -1) {
  225. delete item.id;
  226. }
  227. if (!item.content) {
  228. item.content = {};
  229. }
  230. let hotSpotType = item.hotspotType;
  231. for (let key in state.hotspotTypeList) {
  232. let value = state.hotspotTypeList[key];
  233. if (key == hotSpotType) {
  234. if (value) {
  235. item.content[value] = item[value];
  236. }
  237. }
  238. delete item[value];
  239. }
  240. let hotSpotIconType = item.hotspotIconType;
  241. for (let key in state.hotspotIconTypeList) {
  242. let value = state.hotspotIconTypeList[key];
  243. if (key == hotSpotIconType) {
  244. if (value) {
  245. item.content[value] = item[value];
  246. }
  247. }
  248. delete item[value];
  249. }
  250. });
  251. if (rootState.base.sceneList.length != list.length) {
  252. //如果场景不存在,则对应的热点不保存
  253. list = list.filter((item) => {
  254. let hasTag = false;
  255. rootState.base.sceneList.forEach((s_item) => {
  256. if (s_item.id == item.navigationId) {
  257. hasTag = true;
  258. }
  259. });
  260. return hasTag;
  261. });
  262. }
  263. // $waiting.hide();
  264. // return;
  265. let data = { list, workId: rootState.base.baseInfo.workId };
  266. return new Promise((resolve, reject) => {
  267. workHotSave(
  268. data,
  269. (res) => {
  270. // vue.$msg.success(i18n.t("gather.save_done"));
  271. $waiting.hide();
  272. this.commit("base/updateBaseInfo", {
  273. workHotList: state.hotspotList,
  274. });
  275. resolve(res);
  276. },
  277. (rej) => {
  278. reject(rej);
  279. }
  280. );
  281. });
  282. },
  283. },
  284. };