EditorHead.vue 7.8 KB

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