Head.vue 6.0 KB

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