EditorHead.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  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. //开场校验
  311. if (this.baseInfo?.workCoverType?.isShowCover === 1) {
  312. if (this.baseInfo.workCoverType.coverSelect === "videoAndImg") {
  313. if (!this.baseInfo.workCoverType.coverPc || !this.baseInfo.workCoverType.coverMo || !this.baseInfo.workCoverType.videoPc || !this.baseInfo.workCoverType.videoMo) {
  314. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  315. return false;
  316. }
  317. }
  318. if (this.baseInfo.workCoverType.coverSelect === "video") {
  319. if (!this.baseInfo.workCoverType.videoPc || !this.baseInfo.workCoverType.videoMo || this.baseInfo.workCoverType.videoPc == "" || this.baseInfo.workCoverType.videoMo == "") {
  320. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  321. return false;
  322. }
  323. }
  324. if (this.baseInfo.workCoverType.coverSelect === "img") {
  325. if (!this.baseInfo.workCoverType.coverPc || !this.baseInfo.workCoverType.coverMo || this.baseInfo.workCoverType.coverPc == "" || this.baseInfo.workCoverType.coverMo == "") {
  326. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  327. return false;
  328. }
  329. }
  330. //新增不上传背景底图限制
  331. if (this.baseInfo.workCoverType.coverImgBac === "imgTile") {
  332. if (!this.baseInfo.workCoverType.coverBac) {
  333. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  334. return false;
  335. }
  336. }
  337. }
  338. return true;
  339. // this.lockHotspotResourceTree();
  340. // fodderId:[] 资源引用给后端
  341. },
  342. /**
  343. * 给热点的资源引用上锁
  344. */
  345. lockHotspotResourceTree(sceneIndex, hotspots) {
  346. hotspots.forEach((item, index) => {
  347. const target = this.info.scenes[sceneIndex].someData.hotspots[index];
  348. let fodderId = [];
  349. switch (item.hotspotType) {
  350. case "image":
  351. fodderId = target.image.reduce((p, c) => p.concat(c["id"]), []).map((i) => i);
  352. target.fodderId = fodderId;
  353. break;
  354. case "audio":
  355. target.fodderId = [target.audio.id].map((i) => i);
  356. break;
  357. case "imageText":
  358. fodderId = target.imageTextInfo.imageList.reduce((p, c) => p.concat(c["id"]), []).map((i) => i);
  359. target.imageTextInfo.audio.id && fodderId.push(target.imageTextInfo.audio.id);
  360. target.fodderId = fodderId;
  361. break;
  362. case "video":
  363. target.fodderId = [target.video.id];
  364. break;
  365. default:
  366. target.fodderId = [];
  367. break;
  368. }
  369. });
  370. },
  371. onSave() {
  372. if (!this.checkParams()) {
  373. return;
  374. }
  375. const isFixData = this.fixData();
  376. if (isFixData) {
  377. // this.sceneList = this.sceneList.map((item) => {
  378. // if (typeof item.someData == "string") {
  379. // item.someData = item.someData.replace(hhhreg, "");
  380. // }
  381. // return item;
  382. // });
  383. $waiting.show();
  384. // console.error(this.$router.name)
  385. let promises = [];
  386. if (this.saveApiList.length) {
  387. let idx = this.saveApiList.find((item) => item == "navigation");
  388. console.error(idx);
  389. let length = 0;
  390. if (idx) {
  391. //优先保存导航树
  392. this.$store.dispatch(`navigation/save`).then((res) => {
  393. this.saveApiList.forEach((item) => {
  394. if (item != "navigation") {
  395. promises.push(this.$store.dispatch(`${item}/save`));
  396. // this.$store.dispatch(`${item}/save`).then((res) => {});
  397. }
  398. });
  399. let currentRouter = this.saveApiList.find((item) => item == this.$route.name);
  400. if (!currentRouter) {
  401. promises.push(this.$store.dispatch(`${this.$route.name}/save`));
  402. }
  403. Promise.all(promises)
  404. .then((res) => {
  405. console.log("Promise.all success", res);
  406. this.$store.commit(`scene/removeSaveApi`);
  407. this.$msg.success(i18n.t("gather.save_done"));
  408. })
  409. .catch((err) => {
  410. console.error("Promise.all failed", err);
  411. });
  412. });
  413. } else {
  414. this.saveApiList.forEach((item) => {
  415. promises.push(this.$store.dispatch(`${item}/save`));
  416. // this.$store.dispatch(`${item}/save`).then((res) => {});
  417. });
  418. let currentRouter = this.saveApiList.find((item) => item == this.$route.name);
  419. if (!currentRouter) {
  420. promises.push(this.$store.dispatch(`${this.$route.name}/save`));
  421. }
  422. Promise.all(promises)
  423. .then((res) => {
  424. console.log("Promise.all success", res);
  425. this.$store.commit(`scene/removeSaveApi`);
  426. this.$msg.success(i18n.t("gather.save_done"));
  427. })
  428. .catch((err) => {
  429. console.error("Promise.all failed", err);
  430. });
  431. }
  432. } else {
  433. this.$store.dispatch(`${this.$route.name}/save`).then((res) => {
  434. this.$store.commit(`scene/removeSaveApi`);
  435. this.$msg.success(i18n.t("gather.save_done"));
  436. });
  437. }
  438. // this.$store.commit(`scene/removeSaveApi`);
  439. // this.$msg.success(i18n.t("gather.save_done"));
  440. // saveWorks(
  441. // {
  442. // password: this.info.password,
  443. // someData: { ...this.info, status: 1 },
  444. // },
  445. // () => {
  446. // this.$msg.success(this.$i18n.t("gather.save_done"));
  447. // // document.title = this.info.name;
  448. // document.title = this.info.name || this.$i18n.t("gather.no_title");
  449. // $waiting.hide();
  450. // // this.getInfo();
  451. // // this.$store.commit("UpdateIsShowState", true);
  452. // this.$store.commit("TakeInfoSnapShotAtSave");
  453. // },
  454. // () => {}
  455. // );
  456. }
  457. },
  458. getInfo() {
  459. return checkLogin().then((res) => {
  460. return new Promise((resolve, reject) => {
  461. $waiting.hide();
  462. if (res.code == 0) {
  463. // $waiting.show();
  464. // getPanoInfo(
  465. // "",
  466. // (data) => {
  467. // this.$store.commit("SetInfo", data);
  468. // this.$store.commit("scene/setScenes", data.scenes);
  469. // $waiting.hide();
  470. // let firstScene = "";
  471. // if (data.firstScene) {
  472. // firstScene = data.scenes.find((item) => item.sceneCode == data.firstScene.sceneCode);
  473. // }
  474. // //判断列表里是否有全景图
  475. // if (data.scenes.some((item) => item.type == "pano") && firstScene && firstScene.type == "4dkk") {
  476. // console.log(this.currentScene.sceneCode);
  477. // //如果当前有选中场景,则激活选中场景,无则显示第一个全景图
  478. // firstScene = this.currentScene.sceneCode ? this.currentScene : data.scenes.find((item) => item.type == "pano");
  479. // }
  480. // console.log(firstScene, "firstScene");
  481. // this.$store.commit("scene/setCurrentScene", firstScene || data.scenes[0]);
  482. // // 查询初始场景的所在1级分组
  483. // let catalog = data.catalogs.find((item) => item.id == this.currentScene.category);
  484. // data.catalogRoot.forEach((item) => {
  485. // let temp = item.children && item.children.find((sub) => sub == catalog.id);
  486. // if (temp) {
  487. // this.$store.commit("scene/setCurrentCatalogRoot", item);
  488. // return;
  489. // }
  490. // });
  491. // resolve();
  492. // },
  493. // (err) => {
  494. // reject(err);
  495. // }
  496. // );
  497. } else {
  498. reject();
  499. }
  500. });
  501. });
  502. },
  503. getSettingsInfo() {
  504. // this.$store.commit("base/setData", this.info);
  505. getWorkInfo(
  506. {},
  507. (res) => {
  508. let data = res.data;
  509. this.$store.commit("base/initbaseInfo", data);
  510. this.$store.commit("UpdateIsShowState", true);
  511. // OnlineDetector.valid();
  512. },
  513. () => {}
  514. );
  515. },
  516. },
  517. };
  518. </script>
  519. <style lang="less">
  520. .app-head {
  521. width: 100%;
  522. min-width: 50px;
  523. height: 60px;
  524. position: relative;
  525. }
  526. .app-head-back {
  527. color: white;
  528. display: flex;
  529. align-items: baseline;
  530. font-size: 16px;
  531. position: absolute;
  532. left: 24px;
  533. top: 50%;
  534. transform: translateY(-50%);
  535. > i {
  536. margin-right: 15px;
  537. }
  538. }
  539. .app-head-title {
  540. position: absolute;
  541. left: 50%;
  542. top: 50%;
  543. transform: translate(-50%, -50%);
  544. font-size: 16px;
  545. color: white;
  546. }
  547. .app-head-save {
  548. cursor: pointer;
  549. display: flex;
  550. justify-content: center;
  551. align-items: center;
  552. position: absolute;
  553. top: 50%;
  554. transform: translateY(-50%);
  555. right: 10px;
  556. i {
  557. font-size: 14px;
  558. margin-right: 4px;
  559. }
  560. }
  561. .ui-preview {
  562. background: #313131;
  563. }
  564. .app-head-view {
  565. right: 120px;
  566. }
  567. </style>