Head.vue 5.5 KB

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