EditorHead.vue 6.5 KB

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