Head.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. }),
  57. },
  58. methods: {
  59. checkParams() {
  60. if (!this.info.name && !this.info.icon && !this.info.description && this.info.scenes.length<=0) {
  61. this.$alert({
  62. content: "您还未创建任何内容哦",
  63. ok: () => {
  64. this.$router.push({ path: "/base" });
  65. },
  66. });
  67. return false;
  68. }
  69. // if (this.info.scenes.length <= 0 && this.isShow) {
  70. // this.$alert({
  71. // content: "至少添加一个场景才保存/预览,请前往“场景导航”添加",
  72. // forceOK: true,
  73. // ok: () => {
  74. // this.$router.push({ path: "/information" });
  75. // },
  76. // });
  77. // return false;
  78. // }
  79. return true;
  80. },
  81. onView() {
  82. if (!this.checkParams()) {
  83. return;
  84. }
  85. this.fixData()
  86. this.info.scenes = this.info.scenes.map(item=>{
  87. if (typeof item.someData == 'string') {
  88. item.someData = item.someData.replace(hhhreg,'')
  89. }
  90. return item
  91. })
  92. saveWorks(
  93. {
  94. password: this.info.password,
  95. someData: { ...this.info, status: 1 },
  96. },
  97. () => {
  98. this.$msg.success("保存成功");
  99. document.title = this.info.name
  100. this.getInfo();
  101. this.$store.commit("UpdateIsShowState", true);
  102. setTimeout(() => {
  103. if (this.info.scenes.length <= 0 && this.isShow) {
  104. return this.$alert({
  105. content: "至少添加一个场景才可预览,请前往“场景导航”添加",
  106. });
  107. }
  108. this.showPreview = true;
  109. }, 500);
  110. }
  111. );
  112. },
  113. fixData() {
  114. // let tmp = [];
  115. // this.info.scenes.forEach((item) => {
  116. // this.info.catalogs.forEach((sub) => {
  117. // if (item.category == sub.id) {
  118. // tmp.push(sub);
  119. // }
  120. // });
  121. // });
  122. // tmp = this.$unique(tmp)
  123. // this.info.catalogs = tmp;
  124. // let rootmp = [];
  125. // tmp.forEach((item) => {
  126. // this.info.catalogRoot.forEach((sub) => {
  127. // sub.children = this.$unique(sub.children)
  128. // if (sub.children.indexOf(item.id) > -1) {
  129. // rootmp.push(sub);
  130. // }
  131. // });
  132. // });
  133. // rootmp = this.$unique(rootmp)
  134. // this.info.catalogRoot = rootmp.map((item) => {
  135. // let temp = [];
  136. // item.children = this.$unique(item.children)
  137. // item.children.forEach((sub) => {
  138. // tmp.forEach((jj) => {
  139. // if (jj.id == sub) {
  140. // temp.push(sub);
  141. // }
  142. // });
  143. // });
  144. // return {
  145. // ...item,
  146. // children: temp,
  147. // };
  148. // });
  149. // this.info.catalogs = tmp
  150. // let cid = 'c_'+this.$randomWord(true,8,8)
  151. // if (this.info.catalogRoot.length <= 0) {
  152. // this.info.catalogRoot.push({
  153. // id: 'r_'+this.$randomWord(true,8,8),
  154. // name: "全部场景",
  155. // children:[cid]
  156. // });
  157. // }
  158. // if (this.info.catalogs.length <= 0) {
  159. // this.info.catalogs.push({
  160. // id: cid,
  161. // name: "默认二级分组",
  162. // });
  163. // }
  164. if (this.info.firstScene) {
  165. this.info.firstScene = this.info.scenes.find(item=>item.sceneCode==this.info.firstScene.sceneCode)
  166. }
  167. this.$store.commit("SetInfo", this.info);
  168. },
  169. onSave() {
  170. if (!this.checkParams()) {
  171. return;
  172. }
  173. this.fixData();
  174. this.info.scenes = this.info.scenes.map(item=>{
  175. if (typeof item.someData == 'string') {
  176. item.someData = item.someData.replace(hhhreg,'')
  177. }
  178. return item
  179. })
  180. saveWorks(
  181. {
  182. password: this.info.password,
  183. someData: { ...this.info, status: 1 },
  184. },
  185. () => {
  186. this.$msg.success("保存成功")
  187. document.title = this.info.name
  188. this.getInfo();
  189. this.$store.commit("UpdateIsShowState", true);
  190. },
  191. () => {}
  192. );
  193. },
  194. getInfo() {
  195. checkLogin().then((res) => {
  196. if (res.code == 0) {
  197. getPanoInfo("", (data) => {
  198. this.$store.commit("SetInfo", data);
  199. document.title = this.info.name || '无标题'
  200. });
  201. }
  202. });
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="less">
  208. .app-head {
  209. width: 100%;
  210. min-width: 50px;
  211. height: 60px;
  212. position: relative;
  213. }
  214. .app-head-back {
  215. color: white;
  216. display: flex;
  217. align-items: baseline;
  218. font-size: 16px;
  219. position: absolute;
  220. left: 24px;
  221. top: 50%;
  222. transform: translateY(-50%);
  223. > i {
  224. margin-right: 15px;
  225. }
  226. }
  227. .app-head-title {
  228. position: absolute;
  229. left: 50%;
  230. top: 50%;
  231. transform: translate(-50%, -50%);
  232. font-size: 16px;
  233. color: white;
  234. }
  235. .app-head-save {
  236. cursor: pointer;
  237. display: flex;
  238. justify-content: center;
  239. align-items: center;
  240. position: absolute;
  241. top: 50%;
  242. transform: translateY(-50%);
  243. right: 10px;
  244. i {
  245. font-size: 14px;
  246. margin-right: 4px;
  247. }
  248. }
  249. .ui-preview{
  250. background: #313131;
  251. }
  252. .app-head-view {
  253. right: 120px;
  254. }
  255. </style>