EditorHead.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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 iconeditor_preview"></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 iconeditor_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. // this.getInfo().then((res) => {
  116. // // getInfo里调用了后端接口,底层用了jquery的网络请求方法,为啥会导致promise嵌套没有展平,res拿到的不是promise 对象的resolve值而是promise对象本身????
  117. // res.then(() => {
  118. // this.$store.commit("UpdateIsShowState", true);
  119. // $waiting.hide()
  120. // setTimeout(() => {
  121. // if (this.info.scenes.length <= 0 && this.isShow) {
  122. // return this.$alert({
  123. // content: this.$i18n.t('gather.at_least_one_scene'),
  124. // });
  125. // }
  126. // this.showPreview = true;
  127. // }, 500);
  128. // })
  129. // });
  130. $waiting.hide();
  131. if (this.info.scenes.length <= 0 && this.isShow) {
  132. return this.$alert({
  133. content: this.$i18n.t("gather.at_least_one_scene"),
  134. });
  135. }
  136. this.showPreview = true;
  137. }
  138. );
  139. }
  140. },
  141. fixData() {
  142. // 如果没有设置作品封面,拿第一个一级分组内第一个二级分组内第一个场景作为作品封面。
  143. if (!this.info.icon) {
  144. this.info.icon = this.catalogTopology[0].children[0].children[0].icon;
  145. }
  146. if (this.info.firstScene) {
  147. this.info.firstScene = this.info.scenes.find(
  148. (item) => item.sceneCode == this.info.firstScene.sceneCode
  149. );
  150. }
  151. const scenes = this.info.scenes;
  152. if (scenes && scenes.length > 0) {
  153. scenes.forEach((scene, index) => {
  154. if (
  155. scene.someData &&
  156. scene.someData.hotspots &&
  157. scene.someData.hotspots.length > 0
  158. ) {
  159. this.lockHotspotResourceTree(index, scene.someData.hotspots);
  160. }
  161. });
  162. }
  163. //开场校验
  164. if (this.info.coverInfo.isShowCover === 1) {
  165. if (this.info.coverInfo.coverSelect === "videoAndImg") {
  166. if (
  167. this.info.coverInfo.coverPc === "" ||
  168. this.info.coverInfo.coverMo === "" ||
  169. this.info.coverInfo.videoPc === "" ||
  170. this.info.coverInfo.videoMo === ""
  171. ) {
  172. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  173. return false;
  174. }
  175. }
  176. if (this.info.coverInfo.coverSelect === "video") {
  177. if (
  178. this.info.coverInfo.videoPc === "" ||
  179. this.info.coverInfo.videoMo === ""
  180. ) {
  181. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  182. return false;
  183. }
  184. }
  185. if (this.info.coverInfo.coverSelect === "img") {
  186. if (
  187. this.info.coverInfo.coverPc === "" ||
  188. this.info.coverInfo.coverMo === ""
  189. ) {
  190. this.$msg.warning(this.$i18n.t("gather.converinfo_no_valid"));
  191. return false;
  192. }
  193. }
  194. }
  195. return true;
  196. // this.lockHotspotResourceTree();
  197. // fodderId:[] 资源引用给后端
  198. },
  199. /**
  200. * 给热点的资源引用上锁
  201. */
  202. lockHotspotResourceTree(sceneIndex, hotspots) {
  203. hotspots.forEach((item, index) => {
  204. const target = this.info.scenes[sceneIndex].someData.hotspots[index];
  205. let fodderId = [];
  206. switch (item.hotspotType) {
  207. case "image":
  208. fodderId = target.image
  209. .reduce((p, c) => p.concat(c["id"]), [])
  210. .map((i) => i);
  211. target.fodderId = fodderId;
  212. break;
  213. case "audio":
  214. target.fodderId = [target.audio.id].map((i) => i);
  215. break;
  216. case "imageText":
  217. fodderId = target.imageTextInfo.imageList.reduce(
  218. (p, c) => p.concat(c["id"]),
  219. []
  220. ).map((i) => i);
  221. target.imageTextInfo.audio.id &&
  222. fodderId.push(target.imageTextInfo.audio.id);
  223. target.fodderId = fodderId;
  224. break;
  225. case "video":
  226. target.fodderId = [target.video.id];
  227. break;
  228. default:
  229. target.fodderId = [];
  230. break;
  231. }
  232. });
  233. },
  234. onSave() {
  235. if (!this.checkParams()) {
  236. return;
  237. }
  238. const isFixData = this.fixData();
  239. if (isFixData) {
  240. this.info.scenes = this.info.scenes.map((item) => {
  241. if (typeof item.someData == "string") {
  242. item.someData = item.someData.replace(hhhreg, "");
  243. }
  244. return item;
  245. });
  246. $waiting.show();
  247. saveWorks(
  248. {
  249. password: this.info.password,
  250. someData: { ...this.info, status: 1 },
  251. },
  252. () => {
  253. this.$msg.success(this.$i18n.t("gather.save_done"));
  254. document.title = this.info.name;
  255. $waiting.hide();
  256. // this.getInfo();
  257. // this.$store.commit("UpdateIsShowState", true);
  258. this.$store.commit("TakeInfoSnapShotAtSave");
  259. },
  260. () => {}
  261. );
  262. }
  263. },
  264. getInfo() {
  265. return checkLogin().then((res) => {
  266. return new Promise((resolve, reject) => {
  267. $waiting.hide();
  268. if (res.code == 0) {
  269. $waiting.show();
  270. getPanoInfo(
  271. "",
  272. (data) => {
  273. this.$store.commit("SetInfo", data);
  274. this.$store.commit("scene/setScenes", data.scenes);
  275. $waiting.hide();
  276. let firstScene = "";
  277. if (data.firstScene) {
  278. firstScene = data.scenes.find(
  279. (item) => item.sceneCode == data.firstScene.sceneCode
  280. );
  281. }
  282. //判断列表里是否有全景图
  283. if (
  284. data.scenes.some((item) => item.type == "pano") &&
  285. firstScene &&
  286. firstScene.type == "4dkk"
  287. ) {
  288. console.log(this.currentScene.sceneCode);
  289. //如果当前有选中场景,则激活选中场景,无则显示第一个全景图
  290. firstScene = this.currentScene.sceneCode
  291. ? this.currentScene
  292. : data.scenes.find((item) => item.type == "pano");
  293. }
  294. console.log(firstScene, "firstScene");
  295. this.$store.commit(
  296. "scene/setCurrentScene",
  297. firstScene || data.scenes[0]
  298. );
  299. // 查询初始场景的所在1级分组
  300. let catalog = data.catalogs.find(
  301. (item) => item.id == this.currentScene.category
  302. );
  303. data.catalogRoot.forEach((item) => {
  304. let temp =
  305. item.children &&
  306. item.children.find((sub) => sub == catalog.id);
  307. if (temp) {
  308. this.$store.commit("scene/setCurrentCatalogRoot", item);
  309. return;
  310. }
  311. });
  312. resolve();
  313. },
  314. (err) => {
  315. reject(err);
  316. }
  317. );
  318. } else {
  319. reject();
  320. }
  321. });
  322. });
  323. },
  324. },
  325. };
  326. </script>
  327. <style lang="less">
  328. .app-head {
  329. width: 100%;
  330. min-width: 50px;
  331. height: 60px;
  332. position: relative;
  333. }
  334. .app-head-back {
  335. color: white;
  336. display: flex;
  337. align-items: baseline;
  338. font-size: 16px;
  339. position: absolute;
  340. left: 24px;
  341. top: 50%;
  342. transform: translateY(-50%);
  343. > i {
  344. margin-right: 15px;
  345. }
  346. }
  347. .app-head-title {
  348. position: absolute;
  349. left: 50%;
  350. top: 50%;
  351. transform: translate(-50%, -50%);
  352. font-size: 16px;
  353. color: white;
  354. }
  355. .app-head-save {
  356. cursor: pointer;
  357. display: flex;
  358. justify-content: center;
  359. align-items: center;
  360. position: absolute;
  361. top: 50%;
  362. transform: translateY(-50%);
  363. right: 10px;
  364. i {
  365. font-size: 14px;
  366. margin-right: 4px;
  367. }
  368. }
  369. .ui-preview {
  370. background: #313131;
  371. }
  372. .app-head-view {
  373. right: 120px;
  374. }
  375. </style>