EditorHead.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 }">
  9. <i class="iconfont iconeditor_preview"></i>
  10. 预览
  11. </div>
  12. <div
  13. class="ui-button submit app-head-save"
  14. @click="onSave"
  15. :class="{ disable: !canLoad }"
  16. >
  17. <i class="iconfont iconeditor_save"></i>
  18. 保存
  19. </div>
  20. <preview
  21. v-if="info"
  22. :name="info.name"
  23. :show="showPreview"
  24. :ifr="`./show.html?id=${info.id}`"
  25. @close="showPreview = false"
  26. />
  27. </header>
  28. </template>
  29. <script>
  30. import { saveWorks, getPanoInfo, checkLogin } from "@/api";
  31. import { mapGetters } from "vuex";
  32. // import config from '@/config'
  33. import preview from "@/components/preview";
  34. let hhhreg = /\\\\\\\\/g
  35. export default {
  36. name: "app-head",
  37. data() {
  38. return {
  39. showPreview: false,
  40. canLoad: false,
  41. };
  42. },
  43. components: { preview },
  44. mounted() {
  45. this.$bus.on('canLoad',(data)=>{
  46. this.canLoad = data
  47. if (data) {
  48. this.getInfo()
  49. }
  50. })
  51. },
  52. computed: {
  53. ...mapGetters({
  54. info: "info",
  55. isShow: "isShow",
  56. catalogTopology: 'catalogTopology',
  57. }),
  58. },
  59. methods: {
  60. checkParams() {
  61. if (!this.info.name && !this.info.icon && !this.info.description && this.info.scenes.length<=0) {
  62. this.$alert({
  63. content: "您还未创建任何内容哦",
  64. ok: () => {
  65. this.$router.push({ path: "/base" });
  66. },
  67. });
  68. return false;
  69. }
  70. // if (this.info.scenes.length <= 0 && this.isShow) {
  71. // this.$alert({
  72. // content: "至少添加一个场景才保存/预览,请前往“场景导航”添加",
  73. // forceOK: true,
  74. // ok: () => {
  75. // this.$router.push({ path: "/navigation" });
  76. // },
  77. // });
  78. // return false;
  79. // }
  80. return true;
  81. },
  82. onView() {
  83. if (!this.checkParams()) {
  84. return;
  85. }
  86. this.fixData()
  87. this.info.scenes = this.info.scenes.map(item=>{
  88. if (typeof item.someData == 'string') {
  89. item.someData = item.someData.replace(hhhreg,'')
  90. }
  91. return item
  92. })
  93. saveWorks(
  94. {
  95. password: this.info.password,
  96. someData: { ...this.info, status: 1 },
  97. },
  98. () => {
  99. this.$msg.success("保存成功");
  100. document.title = this.info.name
  101. this.getInfo();
  102. this.$store.commit("UpdateIsShowState", true);
  103. setTimeout(() => {
  104. if (this.info.scenes.length <= 0 && this.isShow) {
  105. return this.$alert({
  106. content: "至少添加一个场景才可预览,请前往“场景导航”添加",
  107. });
  108. }
  109. this.showPreview = true;
  110. }, 500);
  111. }
  112. );
  113. },
  114. fixData() {
  115. // 如果没有设置作品封面,拿第一个一级分组内第一个二级分组内第一个场景作为作品封面。
  116. if (!this.info.icon) {
  117. this.info.icon = this.catalogTopology[0].children[0].children[0].icon
  118. }
  119. if (this.info.firstScene) {
  120. this.info.firstScene = this.info.scenes.find(item=>item.sceneCode==this.info.firstScene.sceneCode)
  121. }
  122. },
  123. onSave() {
  124. if (!this.checkParams()) {
  125. return;
  126. }
  127. this.fixData();
  128. this.info.scenes = this.info.scenes.map(item=>{
  129. if (typeof item.someData == 'string') {
  130. item.someData = item.someData.replace(hhhreg,'')
  131. }
  132. return item
  133. })
  134. saveWorks(
  135. {
  136. password: this.info.password,
  137. someData: { ...this.info, status: 1 },
  138. },
  139. () => {
  140. this.$msg.success("保存成功")
  141. document.title = this.info.name
  142. this.getInfo();
  143. this.$store.commit("UpdateIsShowState", true);
  144. },
  145. () => {}
  146. );
  147. },
  148. getInfo() {
  149. checkLogin().then((res) => {
  150. if (res.code == 0) {
  151. getPanoInfo("", (data) => {
  152. this.$store.commit("SetInfo", data);
  153. document.title = this.info.name || '无标题'
  154. });
  155. }
  156. });
  157. },
  158. },
  159. };
  160. </script>
  161. <style lang="less">
  162. .app-head {
  163. width: 100%;
  164. min-width: 50px;
  165. height: 60px;
  166. position: relative;
  167. }
  168. .app-head-back {
  169. color: white;
  170. display: flex;
  171. align-items: baseline;
  172. font-size: 16px;
  173. position: absolute;
  174. left: 24px;
  175. top: 50%;
  176. transform: translateY(-50%);
  177. > i {
  178. margin-right: 15px;
  179. }
  180. }
  181. .app-head-title {
  182. position: absolute;
  183. left: 50%;
  184. top: 50%;
  185. transform: translate(-50%, -50%);
  186. font-size: 16px;
  187. color: white;
  188. }
  189. .app-head-save {
  190. cursor: pointer;
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. position: absolute;
  195. top: 50%;
  196. transform: translateY(-50%);
  197. right: 10px;
  198. i {
  199. font-size: 14px;
  200. margin-right: 4px;
  201. }
  202. }
  203. .ui-preview{
  204. background: #313131;
  205. }
  206. .app-head-view {
  207. right: 120px;
  208. }
  209. </style>