EditorHead.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. <template>
  2. <header class="app-head" app-border dir-bottom v-if="info">
  3. <a class="app-head-back" :href="`./material.html?lang=${$lang}&from=${routerForm}#/works`">
  4. <i class="iconfont icon-editor_return"></i>
  5. {{ back_myworks }}
  6. </a>
  7. <span class="app-head-title">{{ info.work.name }}</span>
  8. <div class="app-head-save ui-button deepcancel app-head-view" @click="onView" :class="{ disable: !canLoad || isEditing }">
  9. <i class="iconfont icon-editor_play"></i>
  10. {{ preview }}
  11. </div>
  12. <div class="ui-button submit app-head-save" @click="onSave" :class="{ disable: !canLoad || isEditing }">
  13. <i class="iconfont icon-editor_save"></i>
  14. {{ savetips }}
  15. </div>
  16. <preview v-if="info" :key="Math.random()" :name="info.work.name" :show="showPreview" :ifr="`./show.html?id=${info.work.id}&lang=${$lang}&rnd=${Math.random()}`" @close="showPreview = false" />
  17. </header>
  18. </template>
  19. <script>
  20. import { saveWorks, getPanoInfo, checkLogin, getWorkInfo } from "@/api";
  21. import { mapGetters } from "vuex";
  22. // import config from '@/config'
  23. import preview from "@/components/preview";
  24. import { i18n } from "@/lang";
  25. import { $waiting } from "@/components/shared/loading";
  26. import browser from "@/utils/browser";
  27. let hhhreg = /\\\\\\\\/g;
  28. export default {
  29. name: "app-head",
  30. data() {
  31. return {
  32. back_myworks: i18n.t("edit_page.back_myworks"),
  33. preview: i18n.t("edit_page.preview"),
  34. savetips: i18n.t("edit_page.save"),
  35. showPreview: false,
  36. canLoad: false,
  37. hiddenSave: false,
  38. };
  39. },
  40. components: { preview },
  41. watch: {
  42. // "$route.name": {
  43. // immediate: true,
  44. // handler: function (newVal) {
  45. // if (newVal == "hotspot") {
  46. // // this.hiddenSave = true;
  47. // } else {
  48. // // this.hiddenSave = false;
  49. // }
  50. // },
  51. // },
  52. sceneList: {
  53. handler: function (newVal, oldVal) {
  54. if (newVal.length != oldVal.length) {
  55. // console.error("sceneList change");
  56. let currentScene = newVal.find((item) => item.id == this.currentScene.id);
  57. if (!currentScene) {
  58. //如果找不到当前选择的场景,则情况。重新遍历查找
  59. this.$store.commit("scene/setCurrentScene", null);
  60. }
  61. }
  62. },
  63. deep: true,
  64. },
  65. },
  66. mounted() {
  67. this.getSettingsInfo();
  68. this.$bus.on("canLoad", (data) => {
  69. // console.error("canLoad", data);
  70. this.canLoad = data;
  71. // if (data) {
  72. // this.getInfo().then((res) => {
  73. // // getInfo里调用了后端接口,底层用了jquery的网络请求方法,为啥会导致promise嵌套没有展平,res拿到的不是promise 对象的resolve值而是promise对象本身????
  74. // res.then(() => {
  75. // // alert(1);
  76. // this.$store.commit("TakeInfoSnapShotAtSave");
  77. // });
  78. // });
  79. // }
  80. });
  81. },
  82. computed: {
  83. ...mapGetters({
  84. // info: "info",
  85. baseInfo: "base/baseInfo",
  86. sceneList: "base/sceneList",
  87. isShow: "isShow",
  88. catalogTopology: "catalogTopology",
  89. currentScene: "scene/currentScene",
  90. isEditing: "isEditing",
  91. saveApiList: "scene/saveApiList",
  92. currentRootId: "navigation/currentRootId",
  93. currentSecondId: "navigation/currentSecondId",
  94. }),
  95. info() {
  96. if (this.baseInfo) {
  97. this.$store.commit("base/initDefaultData");
  98. //初始化
  99. if (!this.currentScene) {
  100. console.error("初始化");
  101. let firstScene = null;
  102. if (this.baseInfo.firstScene) {
  103. firstScene = this.baseInfo.firstScene;
  104. } else {
  105. // firstScene = this.baseInfo.navigationTrees[0].children[0];
  106. firstScene = this.sceneList[0];
  107. }
  108. this.$store.commit("scene/setCurrentScene", firstScene);
  109. let activeScene = null;
  110. this.baseInfo.navigationTrees.forEach((item, index) => {
  111. activeScene = item.children.find((pano) => pano.id == firstScene.id);
  112. if (activeScene) {
  113. this.$store.commit("scene/setCurrentScenesList", item.children);
  114. this.$store.commit("navigation/setData", { currentSecondId: null, currentRootId: item.id });
  115. // throw new Error("LoopTerminated");
  116. }
  117. item = item.children.forEach((s_item, s_index) => {
  118. activeScene = s_item.children.find((pano) => pano.id == firstScene.id);
  119. if (activeScene) {
  120. this.$store.commit("scene/setCurrentScenesList", s_item.children);
  121. this.$store.commit("navigation/setData", { currentSecondId: s_item.id, currentRootId: item.id });
  122. // throw new Error("LoopTerminated");
  123. }
  124. s_item = s_item.children.forEach((t_item, t_index) => {
  125. activeScene = t_item.children.find((pano) => pano.id == firstScene.id);
  126. if (activeScene) {
  127. this.$store.commit("scene/setCurrentScenesList", s_item.children);
  128. this.$store.commit("navigation/setData", { currentSecondId: s_item.id, currentRootId: item.id });
  129. // throw new Error("LoopTerminated");
  130. }
  131. });
  132. });
  133. });
  134. }
  135. console.error(this.currentSecondId);
  136. // if (data.firstScene) {
  137. // firstScene = data.scenes.find((item) => item.sceneCode == data.firstScene.sceneCode);
  138. // }
  139. // //判断列表里是否有全景图
  140. // if (data.scenes.some((item) => item.type == "pano") && firstScene && firstScene.type == "4dkk") {
  141. // console.log(this.currentScene.sceneCode);
  142. // //如果当前有选中场景,则激活选中场景,无则显示第一个全景图
  143. // firstScene = this.currentScene.sceneCode ? this.currentScene : data.scenes.find((item) => item.type == "pano");
  144. // }
  145. // console.log(firstScene, "firstScene");
  146. // this.$store.commit("scene/setCurrentScene", firstScene || data.scenes[0]);
  147. }
  148. return this.baseInfo;
  149. },
  150. routerForm() {
  151. const from = browser.urlQueryValue("from");
  152. return from;
  153. },
  154. },
  155. methods: {
  156. checkParams() {
  157. // if (!this.info.work.name && !this.info.work.icon && !this.info.work.description && this.info.scenes.length <= 0) {
  158. if (!this.baseInfo.work.name && !this.baseInfo.work.icon && !this.baseInfo.work.description) {
  159. this.$alert({
  160. content: this.$i18n.t("gather.nothing_edit"),
  161. ok: () => {
  162. this.$router.push({ path: "/base" });
  163. },
  164. });
  165. return false;
  166. }
  167. return true;
  168. },
  169. onView() {
  170. if (!this.checkParams()) {
  171. return;
  172. }
  173. const isFixData = this.fixData();
  174. if (isFixData) {
  175. // this.info.scenes = this.info.scenes.map((item) => {
  176. // if (typeof item.someData == "string") {
  177. // item.someData = item.someData.replace(hhhreg, "");
  178. // }
  179. // return item;
  180. // });
  181. $waiting.show();
  182. let promises = [];
  183. if (this.saveApiList.length) {
  184. let idx = this.saveApiList.find((item) => item == "navigation");
  185. console.error(idx);
  186. let length = 0;
  187. if (idx) {
  188. //优先保存导航树
  189. this.$store.dispatch(`navigation/save`).then((res) => {
  190. this.saveApiList.forEach((item) => {
  191. if (item != "navigation") {
  192. promises.push(this.$store.dispatch(`${item}/save`));
  193. }
  194. });
  195. let currentRouter = this.saveApiList.find((item) => item == this.$route.name);
  196. if (!currentRouter) {
  197. promises.push(this.$store.dispatch(`${this.$route.name}/save`));
  198. }
  199. Promise.all(promises)
  200. .then((res) => {
  201. console.log("Promise.all success", res);
  202. this.$store.commit(`scene/removeSaveApi`);
  203. this.$msg.success(i18n.t("gather.save_done"));
  204. //成功后查看
  205. $waiting.hide();
  206. if (this.sceneList <= 0 && this.isShow) {
  207. return this.$alert({
  208. content: this.$i18n.t("gather.at_least_one_scene"),
  209. });
  210. }
  211. this.showPreview = true;
  212. })
  213. .catch((err) => {
  214. console.error("Promise.all failed", err);
  215. });
  216. });
  217. } else {
  218. this.saveApiList.forEach((item) => {
  219. promises.push(this.$store.dispatch(`${item}/save`));
  220. });
  221. let currentRouter = this.saveApiList.find((item) => item == this.$route.name);
  222. if (!currentRouter) {
  223. promises.push(this.$store.dispatch(`${this.$route.name}/save`));
  224. }
  225. Promise.all(promises)
  226. .then((res) => {
  227. console.log("Promise.all success", res);
  228. this.$store.commit(`scene/removeSaveApi`);
  229. this.$msg.success(i18n.t("gather.save_done"));
  230. //成功后查看
  231. $waiting.hide();
  232. if (this.sceneList <= 0 && this.isShow) {
  233. return this.$alert({
  234. content: this.$i18n.t("gather.at_least_one_scene"),
  235. });
  236. }
  237. this.showPreview = true;
  238. })
  239. .catch((err) => {
  240. console.error("Promise.all failed", err);
  241. });
  242. }
  243. } else {
  244. this.$store.dispatch(`${this.$route.name}/save`).then((res) => {
  245. this.$store.commit(`scene/removeSaveApi`);
  246. this.$msg.success(i18n.t("gather.save_done"));
  247. //成功后查看
  248. $waiting.hide();
  249. if (this.sceneList <= 0 && this.isShow) {
  250. return this.$alert({
  251. content: this.$i18n.t("gather.at_least_one_scene"),
  252. });
  253. }
  254. this.showPreview = true;
  255. });
  256. }
  257. // saveWorks(
  258. // {
  259. // password: this.info.work.password,
  260. // someData: { ...this.info, status: 1 },
  261. // },
  262. // () => {
  263. // this.$msg.success(this.$i18n.t("gather.save_done"));
  264. // // document.title = this.info.name;
  265. // document.title = this.info.work.name || this.$i18n.t("gather.no_title");
  266. // // this.getInfo().then((res) => {
  267. // // // getInfo里调用了后端接口,底层用了jquery的网络请求方法,为啥会导致promise嵌套没有展平,res拿到的不是promise 对象的resolve值而是promise对象本身????
  268. // // res.then(() => {
  269. // // this.$store.commit("UpdateIsShowState", true);
  270. // // $waiting.hide()
  271. // // setTimeout(() => {
  272. // // if (this.info.scenes.length <= 0 && this.isShow) {
  273. // // return this.$alert({
  274. // // content: this.$i18n.t('gather.at_least_one_scene'),
  275. // // });
  276. // // }
  277. // // this.showPreview = true;
  278. // // }, 500);
  279. // // })
  280. // // });
  281. // $waiting.hide();
  282. // if (this.info.scenes.length <= 0 && this.isShow) {
  283. // return this.$alert({
  284. // content: this.$i18n.t("gather.at_least_one_scene"),
  285. // });
  286. // }
  287. // this.showPreview = true;
  288. // }
  289. // );
  290. }
  291. },
  292. fixData() {
  293. // 如果没有设置作品封面,拿第一个一级分组内第一个二级分组内第一个场景作为作品封面。
  294. if (!this.baseInfo.work.icon) {
  295. // this.info.work.icon = this.catalogTopology[0].children[0].children[0].icon;
  296. this.baseInfo.work.icon = this.baseInfo.navigationTrees[0].children[0].icon;
  297. }
  298. if (this.baseInfo.firstScene) {
  299. this.baseInfo.firstScene = this.sceneList.find((item) => item.sceneCode == this.baseInfo.firstScene.sceneCode);
  300. }
  301. const scenes = this.sceneList;
  302. // debugger
  303. // if (scenes && scenes.length > 0) {
  304. // scenes.forEach((scene, index) => {
  305. // if (scene.someData && scene.someData.hotspots && scene.someData.hotspots.length > 0) {
  306. // this.lockHotspotResourceTree(index, scene.someData.hotspots);
  307. // }
  308. // });
  309. // }
  310. if (this.baseInfo && this.baseInfo.workHotList && this.baseInfo.workHotList.length > 0) {
  311. this.lockHotspotResourceTree(this.baseInfo.workHotList);
  312. }
  313. //开场校验
  314. if (this.baseInfo?.workCoverType?.isShowCover === 1) {
  315. if (this.baseInfo.workCoverType.coverSelect === "videoAndImg") {
  316. if (!this.baseInfo.workCoverType.coverPc || !this.baseInfo.workCoverType.coverMo || !this.baseInfo.workCoverType.videoPc || !this.baseInfo.workCoverType.videoMo) {
  317. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  318. return false;
  319. }
  320. }
  321. if (this.baseInfo.workCoverType.coverSelect === "video") {
  322. if (!this.baseInfo.workCoverType.videoPc || !this.baseInfo.workCoverType.videoMo || this.baseInfo.workCoverType.videoPc == "" || this.baseInfo.workCoverType.videoMo == "") {
  323. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  324. return false;
  325. }
  326. }
  327. if (this.baseInfo.workCoverType.coverSelect === "img") {
  328. if (!this.baseInfo.workCoverType.coverPc || !this.baseInfo.workCoverType.coverMo || this.baseInfo.workCoverType.coverPc == "" || this.baseInfo.workCoverType.coverMo == "") {
  329. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  330. return false;
  331. }
  332. }
  333. //新增不上传背景底图限制
  334. if (this.baseInfo.workCoverType.coverImgBac === "imgTile") {
  335. if (!this.baseInfo.workCoverType.coverBac) {
  336. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  337. return false;
  338. }
  339. }
  340. }
  341. return true;
  342. // this.lockHotspotResourceTree();
  343. // fodderId:[] 资源引用给后端
  344. },
  345. /**
  346. * 给热点的资源引用上锁
  347. */
  348. // lockHotspotResourceTree(sceneIndex, hotspots) {
  349. lockHotspotResourceTree(hotspots) {
  350. hotspots.forEach((item, index) => {
  351. // const target = this.info.scenes[sceneIndex].someData.hotspots[index];
  352. let fodderId = [];
  353. switch (item.hotspotType) {
  354. case "image":
  355. fodderId = item.image.reduce((p, c) => p.concat(c["id"]), []).map((i) => i);
  356. item.fodderId = fodderId;
  357. // fodderId = item.content.image.reduce((p, c) => p.concat(c["id"]), []).map((i) => i);
  358. // item.fodderId = fodderId;
  359. break;
  360. case "audio":
  361. item.fodderId = [item.audio.id].map((i) => i);
  362. // item.fodderId = [item.content.audio.id].map((i) => i);
  363. break;
  364. case "imageText":
  365. fodderId = item.imageTextInfo.imageList.reduce((p, c) => p.concat(c["id"]), []).map((i) => i);
  366. item.imageTextInfo.audio.id && fodderId.push(item.imageTextInfo.audio.id);
  367. item.fodderId = fodderId;
  368. // fodderId = item.content.imageTextInfo.imageList.reduce((p, c) => p.concat(c["id"]), []).map((i) => i);
  369. // item.imageTextInfo.audio.id && fodderId.push(item.content.imageTextInfo.audio.id);
  370. // item.fodderId = fodderId;
  371. break;
  372. case "video":
  373. item.fodderId = [item.video.id];
  374. // item.fodderId = [item.content.video.id];
  375. break;
  376. case "scene":
  377. item.fodderId = [item.scene.fodderId].map((i) => i);
  378. // item.fodderId = [item.content.scene.fodderId].map((i) => i);
  379. break;
  380. default:
  381. // target.fodderId = [];
  382. item.fodderId = [];
  383. break;
  384. }
  385. });
  386. },
  387. onSave() {
  388. if (!this.checkParams()) {
  389. return;
  390. }
  391. const isFixData = this.fixData();
  392. if (isFixData) {
  393. // this.sceneList = this.sceneList.map((item) => {
  394. // if (typeof item.someData == "string") {
  395. // item.someData = item.someData.replace(hhhreg, "");
  396. // }
  397. // return item;
  398. // });
  399. $waiting.show();
  400. // console.error(this.$router.name)
  401. let promises = [];
  402. if (this.saveApiList.length) {
  403. let idx = this.saveApiList.find((item) => item == "navigation");
  404. console.error(idx);
  405. let length = 0;
  406. if (idx) {
  407. //优先保存导航树
  408. this.$store.dispatch(`navigation/save`).then((res) => {
  409. this.saveApiList.forEach((item) => {
  410. if (item != "navigation") {
  411. promises.push(this.$store.dispatch(`${item}/save`));
  412. // this.$store.dispatch(`${item}/save`).then((res) => {});
  413. }
  414. });
  415. let currentRouter = this.saveApiList.find((item) => item == this.$route.name);
  416. if (!currentRouter) {
  417. promises.push(this.$store.dispatch(`${this.$route.name}/save`));
  418. }
  419. Promise.all(promises)
  420. .then((res) => {
  421. console.log("Promise.all success", res);
  422. this.$store.commit(`scene/removeSaveApi`);
  423. this.$msg.success(i18n.t("gather.save_done"));
  424. })
  425. .catch((err) => {
  426. console.error("Promise.all failed", err);
  427. });
  428. });
  429. } else {
  430. this.saveApiList.forEach((item) => {
  431. promises.push(this.$store.dispatch(`${item}/save`));
  432. // this.$store.dispatch(`${item}/save`).then((res) => {});
  433. });
  434. let currentRouter = this.saveApiList.find((item) => item == this.$route.name);
  435. if (!currentRouter) {
  436. promises.push(this.$store.dispatch(`${this.$route.name}/save`));
  437. }
  438. Promise.all(promises)
  439. .then((res) => {
  440. console.log("Promise.all success", res);
  441. this.$store.commit(`scene/removeSaveApi`);
  442. this.$msg.success(i18n.t("gather.save_done"));
  443. })
  444. .catch((err) => {
  445. console.error("Promise.all failed", err);
  446. });
  447. }
  448. } else {
  449. this.$store.dispatch(`${this.$route.name}/save`).then((res) => {
  450. this.$store.commit(`scene/removeSaveApi`);
  451. this.$msg.success(i18n.t("gather.save_done"));
  452. });
  453. }
  454. // this.$store.commit(`scene/removeSaveApi`);
  455. // this.$msg.success(i18n.t("gather.save_done"));
  456. // saveWorks(
  457. // {
  458. // password: this.info.password,
  459. // someData: { ...this.info, status: 1 },
  460. // },
  461. // () => {
  462. // this.$msg.success(this.$i18n.t("gather.save_done"));
  463. // // document.title = this.info.name;
  464. // document.title = this.info.name || this.$i18n.t("gather.no_title");
  465. // $waiting.hide();
  466. // // this.getInfo();
  467. // // this.$store.commit("UpdateIsShowState", true);
  468. // this.$store.commit("TakeInfoSnapShotAtSave");
  469. // },
  470. // () => {}
  471. // );
  472. }
  473. },
  474. getInfo() {
  475. return checkLogin().then((res) => {
  476. return new Promise((resolve, reject) => {
  477. $waiting.hide();
  478. if (res.code == 0) {
  479. // $waiting.show();
  480. // getPanoInfo(
  481. // "",
  482. // (data) => {
  483. // this.$store.commit("SetInfo", data);
  484. // this.$store.commit("scene/setScenes", data.scenes);
  485. // $waiting.hide();
  486. // let firstScene = "";
  487. // if (data.firstScene) {
  488. // firstScene = data.scenes.find((item) => item.sceneCode == data.firstScene.sceneCode);
  489. // }
  490. // //判断列表里是否有全景图
  491. // if (data.scenes.some((item) => item.type == "pano") && firstScene && firstScene.type == "4dkk") {
  492. // console.log(this.currentScene.sceneCode);
  493. // //如果当前有选中场景,则激活选中场景,无则显示第一个全景图
  494. // firstScene = this.currentScene.sceneCode ? this.currentScene : data.scenes.find((item) => item.type == "pano");
  495. // }
  496. // console.log(firstScene, "firstScene");
  497. // this.$store.commit("scene/setCurrentScene", firstScene || data.scenes[0]);
  498. // // 查询初始场景的所在1级分组
  499. // let catalog = data.catalogs.find((item) => item.id == this.currentScene.category);
  500. // data.catalogRoot.forEach((item) => {
  501. // let temp = item.children && item.children.find((sub) => sub == catalog.id);
  502. // if (temp) {
  503. // this.$store.commit("scene/setCurrentCatalogRoot", item);
  504. // return;
  505. // }
  506. // });
  507. // resolve();
  508. // },
  509. // (err) => {
  510. // reject(err);
  511. // }
  512. // );
  513. } else {
  514. reject();
  515. }
  516. });
  517. });
  518. },
  519. getSettingsInfo() {
  520. // this.$store.commit("base/setData", this.info);
  521. getWorkInfo(
  522. {},
  523. (res) => {
  524. let data = res.data;
  525. this.$store.commit("base/initbaseInfo", data);
  526. this.$store.commit("UpdateIsShowState", true);
  527. // OnlineDetector.valid();
  528. },
  529. () => {}
  530. );
  531. },
  532. },
  533. };
  534. </script>
  535. <style lang="less">
  536. .app-head {
  537. width: 100%;
  538. min-width: 50px;
  539. height: 60px;
  540. position: relative;
  541. }
  542. .app-head-back {
  543. color: white;
  544. display: flex;
  545. align-items: baseline;
  546. font-size: 16px;
  547. position: absolute;
  548. left: 24px;
  549. top: 50%;
  550. transform: translateY(-50%);
  551. > i {
  552. margin-right: 15px;
  553. }
  554. }
  555. .app-head-title {
  556. position: absolute;
  557. left: 50%;
  558. top: 50%;
  559. transform: translate(-50%, -50%);
  560. font-size: 16px;
  561. color: white;
  562. }
  563. .app-head-save {
  564. cursor: pointer;
  565. display: flex;
  566. justify-content: center;
  567. align-items: center;
  568. position: absolute;
  569. top: 50%;
  570. transform: translateY(-50%);
  571. right: 10px;
  572. i {
  573. font-size: 14px;
  574. margin-right: 4px;
  575. }
  576. }
  577. .ui-preview {
  578. background: #313131;
  579. }
  580. .app-head-view {
  581. right: 120px;
  582. }
  583. </style>