EditorHead.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <header class="app-head" app-border dir-bottom>
  3. <a class="app-head-back" href="./material.html#/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 class="app-head-save ui-button deepcancel app-head-view" @click="onView" :class="{ disable: !canLoad || isEditing }">
  9. <i class="iconfont iconeditor_preview"></i>
  10. {{preview}}
  11. </div>
  12. <div class="ui-button submit app-head-save" @click="onSave" :class="{ disable: !canLoad || isEditing }">
  13. <i class="iconfont iconeditor_save"></i>
  14. {{savetips}}
  15. </div>
  16. <preview v-if="info" :key="Math.random()" :name="info.name" :show="showPreview" :ifr="`./show.html?id=${info.id}&rnd=${Math.random()}`" @close="showPreview = false" />
  17. </header>
  18. </template>
  19. <script>
  20. import { saveWorks, getPanoInfo, checkLogin } from "@/api";
  21. import { mapGetters } from "vuex";
  22. // import config from '@/config'
  23. import preview from "@/components/preview";
  24. import {i18n} from "@/lang"
  25. let hhhreg = /\\\\\\\\/g;
  26. export default {
  27. name: "app-head",
  28. data() {
  29. return {
  30. back_myworks: i18n.t("edit_page.back_myworks"),
  31. preview: i18n.t("edit_page.preview"),
  32. savetips: i18n.t("edit_page.save"),
  33. showPreview: false,
  34. canLoad: false,
  35. };
  36. },
  37. components: { preview },
  38. mounted() {
  39. this.$bus.on("canLoad", (data) => {
  40. this.canLoad = data;
  41. if (data) {
  42. this.getInfo().then((res) => {
  43. // getInfo里调用了后端接口,底层用了jquery的网络请求方法,为啥会导致promise嵌套没有展平,res拿到的不是promise 对象的resolve值而是promise对象本身????
  44. res.then(() => {
  45. this.$store.commit("TakeInfoSnapShotAtSave")
  46. })
  47. });
  48. }
  49. });
  50. },
  51. computed: {
  52. ...mapGetters({
  53. info: "info",
  54. isShow: "isShow",
  55. catalogTopology: "catalogTopology",
  56. currentScene: "scene/currentScene",
  57. isEditing: "isEditing",
  58. }),
  59. },
  60. methods: {
  61. checkParams() {
  62. if (!this.info.name && !this.info.icon && !this.info.description && this.info.scenes.length <= 0) {
  63. this.$alert({
  64. content: "您还未创建任何内容哦",
  65. ok: () => {
  66. this.$router.push({ path: "/base" });
  67. },
  68. });
  69. return false;
  70. }
  71. // if (this.info.scenes.length <= 0 && this.isShow) {
  72. // this.$alert({
  73. // content: "至少添加一个场景才保存/预览,请前往“场景导航”添加",
  74. // forceOK: true,
  75. // ok: () => {
  76. // this.$router.push({ path: "/navigation" });
  77. // },
  78. // });
  79. // return false;
  80. // }
  81. return true;
  82. },
  83. onView() {
  84. if (!this.checkParams()) {
  85. return;
  86. }
  87. this.fixData();
  88. this.info.scenes = this.info.scenes.map((item) => {
  89. if (typeof item.someData == "string") {
  90. item.someData = item.someData.replace(hhhreg, "");
  91. }
  92. return item;
  93. });
  94. saveWorks(
  95. {
  96. password: this.info.password,
  97. someData: { ...this.info, status: 1 },
  98. },
  99. () => {
  100. this.$msg.success("保存成功");
  101. document.title = this.info.name;
  102. this.getInfo();
  103. this.$store.commit("UpdateIsShowState", true);
  104. setTimeout(() => {
  105. if (this.info.scenes.length <= 0 && this.isShow) {
  106. return this.$alert({
  107. content: "至少添加一个场景才可预览,请前往“场景导航”添加",
  108. });
  109. }
  110. this.showPreview = true;
  111. }, 500);
  112. }
  113. );
  114. },
  115. fixData() {
  116. // 如果没有设置作品封面,拿第一个一级分组内第一个二级分组内第一个场景作为作品封面。
  117. if (!this.info.icon) {
  118. this.info.icon = this.catalogTopology[0].children[0].children[0].icon;
  119. }
  120. if (this.info.firstScene) {
  121. this.info.firstScene = this.info.scenes.find((item) => item.sceneCode == this.info.firstScene.sceneCode);
  122. }
  123. },
  124. onSave() {
  125. if (!this.checkParams()) {
  126. return;
  127. }
  128. this.fixData();
  129. this.info.scenes = this.info.scenes.map((item) => {
  130. if (typeof item.someData == "string") {
  131. item.someData = item.someData.replace(hhhreg, "");
  132. }
  133. return item;
  134. });
  135. saveWorks(
  136. {
  137. password: this.info.password,
  138. someData: { ...this.info, status: 1 },
  139. },
  140. () => {
  141. this.$msg.success("保存成功");
  142. document.title = this.info.name;
  143. this.getInfo();
  144. this.$store.commit("UpdateIsShowState", true);
  145. this.$store.commit("TakeInfoSnapShotAtSave")
  146. },
  147. () => {}
  148. );
  149. },
  150. getInfo() {
  151. return checkLogin().then((res) => {
  152. return new Promise((resolve, reject) => {
  153. if (res.code == 0) {
  154. getPanoInfo("", (data) => {
  155. this.$store.commit("SetInfo", data);
  156. this.$store.commit("scene/setScenes", data.scenes);
  157. let firstScene = "";
  158. if (data.firstScene) {
  159. firstScene = data.scenes.find((item) => item.sceneCode == data.firstScene.sceneCode);
  160. }
  161. this.$store.commit("scene/setCurrentScene", firstScene || data.scenes[0]);
  162. // 查询初始场景的所在1级分组
  163. let catalog = data.catalogs.find((item) => item.id == this.currentScene.category);
  164. data.catalogRoot.forEach((item) => {
  165. let temp = item.children && item.children.find((sub) => sub == catalog.id);
  166. if (temp) {
  167. this.$store.commit("scene/setCurrentCatalogRoot", item);
  168. return;
  169. }
  170. });
  171. resolve()
  172. }, (err) => {
  173. reject(err)
  174. });
  175. } else {
  176. reject()
  177. }
  178. })
  179. });
  180. },
  181. },
  182. };
  183. </script>
  184. <style lang="less">
  185. .app-head {
  186. width: 100%;
  187. min-width: 50px;
  188. height: 60px;
  189. position: relative;
  190. }
  191. .app-head-back {
  192. color: white;
  193. display: flex;
  194. align-items: baseline;
  195. font-size: 16px;
  196. position: absolute;
  197. left: 24px;
  198. top: 50%;
  199. transform: translateY(-50%);
  200. > i {
  201. margin-right: 15px;
  202. }
  203. }
  204. .app-head-title {
  205. position: absolute;
  206. left: 50%;
  207. top: 50%;
  208. transform: translate(-50%, -50%);
  209. font-size: 16px;
  210. color: white;
  211. }
  212. .app-head-save {
  213. cursor: pointer;
  214. display: flex;
  215. justify-content: center;
  216. align-items: center;
  217. position: absolute;
  218. top: 50%;
  219. transform: translateY(-50%);
  220. right: 10px;
  221. i {
  222. font-size: 14px;
  223. margin-right: 4px;
  224. }
  225. }
  226. .ui-preview {
  227. background: #313131;
  228. }
  229. .app-head-view {
  230. right: 120px;
  231. }
  232. </style>