EditorHead.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <template>
  2. <header class="app-head" app-border dir-bottom>
  3. <a class="app-head-back" :href="`./material.html?lang=${$lang}#/works`">
  4. <i class="iconfont icon-editor_return"></i>
  5. {{ back_myworks }}
  6. </a>
  7. <span class="app-head-title">{{ info.name }}</span>
  8. <div
  9. class="app-head-save ui-button deepcancel app-head-view"
  10. @click="onView"
  11. :class="{ disable: !canLoad || isEditing }"
  12. >
  13. <i class="iconfont icon-editor_play"></i>
  14. {{ preview }}
  15. </div>
  16. <div
  17. class="ui-button submit app-head-save"
  18. @click="onSave"
  19. :class="{ disable: !canLoad || isEditing }"
  20. >
  21. <i class="iconfont icon-editor_save"></i>
  22. {{ savetips }}
  23. </div>
  24. <preview
  25. v-if="info"
  26. :key="Math.random()"
  27. :name="info.name"
  28. :show="showPreview"
  29. :ifr="`./show.html?id=${info.id}&lang=${$lang}&rnd=${Math.random()}`"
  30. @close="showPreview = false"
  31. />
  32. </header>
  33. </template>
  34. <script>
  35. import { saveWorks, getPanoInfo, checkLogin } from "@/api";
  36. import { mapGetters } from "vuex";
  37. // import config from '@/config'
  38. import preview from "@/components/preview";
  39. import { i18n } from "@/lang";
  40. import { $waiting } from "@/components/shared/loading";
  41. let hhhreg = /\\\\\\\\/g;
  42. export default {
  43. name: "app-head",
  44. data() {
  45. return {
  46. back_myworks: i18n.t("edit_page.back_myworks"),
  47. preview: i18n.t("edit_page.preview"),
  48. savetips: i18n.t("edit_page.save"),
  49. showPreview: false,
  50. canLoad: false,
  51. };
  52. },
  53. components: { preview },
  54. mounted() {
  55. this.$bus.on("canLoad", (data) => {
  56. this.canLoad = data;
  57. if (data) {
  58. this.getInfo().then((res) => {
  59. // getInfo里调用了后端接口,底层用了jquery的网络请求方法,为啥会导致promise嵌套没有展平,res拿到的不是promise 对象的resolve值而是promise对象本身????
  60. res.then(() => {
  61. this.$store.commit("TakeInfoSnapShotAtSave");
  62. });
  63. });
  64. }
  65. });
  66. },
  67. computed: {
  68. ...mapGetters({
  69. info: "info",
  70. isShow: "isShow",
  71. catalogTopology: "catalogTopology",
  72. currentScene: "scene/currentScene",
  73. isEditing: "isEditing",
  74. }),
  75. },
  76. methods: {
  77. checkParams() {
  78. if (
  79. !this.info.name &&
  80. !this.info.icon &&
  81. !this.info.description &&
  82. this.info.scenes.length <= 0
  83. ) {
  84. this.$alert({
  85. content: this.$i18n.t("gather.nothing_edit"),
  86. ok: () => {
  87. this.$router.push({ path: "/base" });
  88. },
  89. });
  90. return false;
  91. }
  92. return true;
  93. },
  94. onView() {
  95. if (!this.checkParams()) {
  96. return;
  97. }
  98. const isFixData = this.fixData();
  99. if (isFixData) {
  100. this.info.scenes = this.info.scenes.map((item) => {
  101. if (typeof item.someData == "string") {
  102. item.someData = item.someData.replace(hhhreg, "");
  103. }
  104. return item;
  105. });
  106. $waiting.show();
  107. saveWorks(
  108. {
  109. password: this.info.password,
  110. someData: { ...this.info, status: 1 },
  111. },
  112. () => {
  113. this.$msg.success(this.$i18n.t("gather.save_done"));
  114. // document.title = this.info.name;
  115. document.title = this.info.name || this.$i18n.t("gather.no_title");
  116. // this.getInfo().then((res) => {
  117. // // getInfo里调用了后端接口,底层用了jquery的网络请求方法,为啥会导致promise嵌套没有展平,res拿到的不是promise 对象的resolve值而是promise对象本身????
  118. // res.then(() => {
  119. // this.$store.commit("UpdateIsShowState", true);
  120. // $waiting.hide()
  121. // setTimeout(() => {
  122. // if (this.info.scenes.length <= 0 && this.isShow) {
  123. // return this.$alert({
  124. // content: this.$i18n.t('gather.at_least_one_scene'),
  125. // });
  126. // }
  127. // this.showPreview = true;
  128. // }, 500);
  129. // })
  130. // });
  131. $waiting.hide();
  132. if (this.info.scenes.length <= 0 && this.isShow) {
  133. return this.$alert({
  134. content: this.$i18n.t("gather.at_least_one_scene"),
  135. });
  136. }
  137. this.showPreview = true;
  138. }
  139. );
  140. }
  141. },
  142. fixData() {
  143. // 如果没有设置作品封面,拿第一个一级分组内第一个二级分组内第一个场景作为作品封面。
  144. if (!this.info.icon) {
  145. this.info.icon = this.catalogTopology[0].children[0].children[0].icon;
  146. }
  147. if (this.info.firstScene) {
  148. this.info.firstScene = this.info.scenes.find(
  149. (item) => item.sceneCode == this.info.firstScene.sceneCode
  150. );
  151. }
  152. const scenes = this.info.scenes;
  153. if (scenes && scenes.length > 0) {
  154. scenes.forEach((scene, index) => {
  155. if (
  156. scene.someData &&
  157. scene.someData.hotspots &&
  158. scene.someData.hotspots.length > 0
  159. ) {
  160. this.lockHotspotResourceTree(index, scene.someData.hotspots);
  161. }
  162. });
  163. }
  164. //开场校验
  165. if (this.info.coverInfo.isShowCover === 1) {
  166. if (this.info.coverInfo.coverSelect === "videoAndImg") {
  167. if (
  168. !this.info.coverInfo.coverPc ||
  169. !this.info.coverInfo.coverMo ||
  170. !this.info.coverInfo.videoPc ||
  171. !this.info.coverInfo.videoMo
  172. ) {
  173. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  174. return false;
  175. }
  176. }
  177. if (this.info.coverInfo.coverSelect === "video") {
  178. if (
  179. !this.info.coverInfo.videoPc ||
  180. !this.info.coverInfo.videoMo ||
  181. this.info.coverInfo.videoPc == "" ||
  182. this.info.coverInfo.videoMo == ""
  183. ) {
  184. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  185. return false;
  186. }
  187. }
  188. if (this.info.coverInfo.coverSelect === "img") {
  189. if (
  190. !this.info.coverInfo.coverPc ||
  191. !this.info.coverInfo.coverMo ||
  192. this.info.coverInfo.coverPc == "" ||
  193. this.info.coverInfo.coverMo == ""
  194. ) {
  195. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  196. return false;
  197. }
  198. }
  199. //新增不上传背景底图限制
  200. if (this.info.coverInfo.coverImgBac === "imgTile") {
  201. if (!this.info.coverInfo.coverBac) {
  202. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  203. return false;
  204. }
  205. }
  206. }
  207. return true;
  208. // this.lockHotspotResourceTree();
  209. // fodderId:[] 资源引用给后端
  210. },
  211. /**
  212. * 给热点的资源引用上锁
  213. */
  214. lockHotspotResourceTree(sceneIndex, hotspots) {
  215. hotspots.forEach((item, index) => {
  216. const target = this.info.scenes[sceneIndex].someData.hotspots[index];
  217. let fodderId = [];
  218. switch (item.hotspotType) {
  219. case "image":
  220. fodderId = target.image
  221. .reduce((p, c) => p.concat(c["id"]), [])
  222. .map((i) => i);
  223. target.fodderId = fodderId;
  224. break;
  225. case "audio":
  226. target.fodderId = [target.audio.id].map((i) => i);
  227. break;
  228. case "imageText":
  229. fodderId = target.imageTextInfo.imageList
  230. .reduce((p, c) => p.concat(c["id"]), [])
  231. .map((i) => i);
  232. target.imageTextInfo.audio.id &&
  233. fodderId.push(target.imageTextInfo.audio.id);
  234. target.fodderId = fodderId;
  235. break;
  236. case "video":
  237. target.fodderId = [target.video.id];
  238. break;
  239. default:
  240. target.fodderId = [];
  241. break;
  242. }
  243. });
  244. },
  245. onSave() {
  246. if (!this.checkParams()) {
  247. return;
  248. }
  249. const isFixData = this.fixData();
  250. if (isFixData) {
  251. this.info.scenes = this.info.scenes.map((item) => {
  252. if (typeof item.someData == "string") {
  253. item.someData = item.someData.replace(hhhreg, "");
  254. }
  255. return item;
  256. });
  257. $waiting.show();
  258. saveWorks(
  259. {
  260. password: this.info.password,
  261. someData: { ...this.info, status: 1 },
  262. },
  263. () => {
  264. this.$msg.success(this.$i18n.t("gather.save_done"));
  265. // document.title = this.info.name;
  266. document.title = this.info.name || this.$i18n.t("gather.no_title");
  267. $waiting.hide();
  268. // this.getInfo();
  269. // this.$store.commit("UpdateIsShowState", true);
  270. this.$store.commit("TakeInfoSnapShotAtSave");
  271. },
  272. () => {}
  273. );
  274. }
  275. },
  276. getInfo() {
  277. return checkLogin().then((res) => {
  278. return new Promise((resolve, reject) => {
  279. $waiting.hide();
  280. if (res.code == 0) {
  281. $waiting.show();
  282. getPanoInfo(
  283. "",
  284. (data) => {
  285. this.$store.commit("SetInfo", data);
  286. this.$store.commit("scene/setScenes", data.scenes);
  287. $waiting.hide();
  288. let firstScene = "";
  289. if (data.firstScene) {
  290. firstScene = data.scenes.find(
  291. (item) => item.sceneCode == data.firstScene.sceneCode
  292. );
  293. }
  294. //判断列表里是否有全景图
  295. if (
  296. data.scenes.some((item) => item.type == "pano") &&
  297. firstScene &&
  298. firstScene.type == "4dkk"
  299. ) {
  300. console.log(this.currentScene.sceneCode);
  301. //如果当前有选中场景,则激活选中场景,无则显示第一个全景图
  302. firstScene = this.currentScene.sceneCode
  303. ? this.currentScene
  304. : data.scenes.find((item) => item.type == "pano");
  305. }
  306. console.log(firstScene, "firstScene");
  307. this.$store.commit(
  308. "scene/setCurrentScene",
  309. firstScene || data.scenes[0]
  310. );
  311. // 查询初始场景的所在1级分组
  312. let catalog = data.catalogs.find(
  313. (item) => item.id == this.currentScene.category
  314. );
  315. data.catalogRoot.forEach((item) => {
  316. let temp =
  317. item.children &&
  318. item.children.find((sub) => sub == catalog.id);
  319. if (temp) {
  320. this.$store.commit("scene/setCurrentCatalogRoot", item);
  321. return;
  322. }
  323. });
  324. resolve();
  325. },
  326. (err) => {
  327. reject(err);
  328. }
  329. );
  330. } else {
  331. reject();
  332. }
  333. });
  334. });
  335. },
  336. },
  337. };
  338. </script>
  339. <style lang="less">
  340. .app-head {
  341. width: 100%;
  342. min-width: 50px;
  343. height: 60px;
  344. position: relative;
  345. }
  346. .app-head-back {
  347. color: white;
  348. display: flex;
  349. align-items: baseline;
  350. font-size: 16px;
  351. position: absolute;
  352. left: 24px;
  353. top: 50%;
  354. transform: translateY(-50%);
  355. > i {
  356. margin-right: 15px;
  357. }
  358. }
  359. .app-head-title {
  360. position: absolute;
  361. left: 50%;
  362. top: 50%;
  363. transform: translate(-50%, -50%);
  364. font-size: 16px;
  365. color: white;
  366. }
  367. .app-head-save {
  368. cursor: pointer;
  369. display: flex;
  370. justify-content: center;
  371. align-items: center;
  372. position: absolute;
  373. top: 50%;
  374. transform: translateY(-50%);
  375. right: 10px;
  376. i {
  377. font-size: 14px;
  378. margin-right: 4px;
  379. }
  380. }
  381. .ui-preview {
  382. background: #313131;
  383. }
  384. .app-head-view {
  385. right: 120px;
  386. }
  387. </style>