cms.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <div class="content">
  3. <Header @handleTitleClick="handleTitleClick" ref="header"/>
  4. <div class="page">
  5. <div class="navigation">
  6. <Navgation :navgationData="navgationData" @menuSelect="menuSelect" />
  7. </div>
  8. <div class="router-map">
  9. <Crumbs :crumbs="crumbs" />
  10. <transition :name="transitionName">
  11. <keep-alive>
  12. <router-view
  13. v-if="$route.meta.keepAlive"
  14. :class="[
  15. 'router-style',
  16. $route.query.title == '首页' ||
  17. $route.name == 'ProductionCharts'
  18. ? 'router-style-home'
  19. : 'router-style-page',
  20. ]"
  21. />
  22. </keep-alive>
  23. </transition>
  24. <transition :name="transitionName">
  25. <router-view
  26. v-if="!$route.meta.keepAlive"
  27. :class="[
  28. 'router-style',
  29. $route.query.title == '首页' || $route.name == 'ProductionCharts'
  30. ? 'router-style-home'
  31. : 'router-style-page',
  32. ]"
  33. />
  34. </transition>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. import Header from "../components/header/index";
  41. import Navgation from "../components/navgation/index";
  42. import Crumbs from "../components/crumbs/index";
  43. import { mapState, mapMutations, mapActions } from "vuex";
  44. export default {
  45. data() {
  46. return {
  47. w_arr:[],
  48. transitionName: "slide-left",
  49. // navgationData:[]
  50. };
  51. },
  52. watch: {
  53. $route(to, from) {
  54. let toName = to.name;
  55. const toIndex = to.meta.index;
  56. const fromIndex = from.meta.index;
  57. this.transitionName = toIndex < fromIndex ? "slide-right" : "slide-left";
  58. },
  59. },
  60. computed: {
  61. ...mapState(["navgationData", "crumbs"]),
  62. },
  63. created() {
  64. this.undata_side_navData();
  65. if(!sessionStorage.getItem('open-menu')){
  66. console.log(1)
  67. this.axios({ method: "get", url: "/api/menu" }).then((res) => {
  68. this.w_arr = res.data;
  69. // this.undata_navData();
  70. this.handleTitleClick(this.w_arr[0])
  71. });
  72. }
  73. },
  74. // beforeRouteEnter(to, from, next){
  75. // next();
  76. // if(!sessionStorage.getItem('open-menu')){
  77. // console.log(1)
  78. // let arr = [];
  79. // this.axios({ method: "get", url: "/api/menu" }).then((res) => {
  80. // arr = res.data;
  81. // // this.undata_navData();
  82. // });
  83. // this.handleTitleClick(arr[0])
  84. // }
  85. // },
  86. mounted() {
  87. if (sessionStorage.getItem("crumbs")) {
  88. let data = JSON.parse(sessionStorage.getItem("crumbs"));
  89. this.$store.commit("updateCrumbs", data);
  90. }
  91. },
  92. methods: {
  93. ...mapMutations(["updateCrumbs"]),
  94. ...mapActions(["undata_side_navData"]),
  95. menuSelect(name, data) {
  96. let permisssions_id = "";
  97. sessionStorage.setItem("open-menu", name);
  98. sessionStorage.removeItem("crumbs");
  99. if (this.func.isType(name) == "Number") {
  100. //若一级菜单带page的情况下
  101. let s = data[name];
  102. this.$store.commit("updateCrumbs", { s });
  103. sessionStorage.setItem(
  104. "crumbs",
  105. JSON.stringify({ parantData, childData, lastChild })
  106. );
  107. return this.$router.push({
  108. path: data[name].page,
  109. query: {
  110. title: s.title,
  111. id: s.id,
  112. },
  113. });
  114. }
  115. let split_array = name.split("-");
  116. let [parant, child, last, end, next_end] = split_array;
  117. let parantData = data[parant],
  118. childData = parantData.sub[child],
  119. lastChild,
  120. endChild,
  121. nextEndChild;
  122. if (last) {
  123. lastChild = childData.sub[last];
  124. if (lastChild.type_id) {
  125. permisssions_id = childData.id;
  126. }
  127. }
  128. if (end) {
  129. endChild = lastChild.sub[end];
  130. if (endChild.type_id) {
  131. permisssions_id = childData.id;
  132. }
  133. }
  134. if (next_end) {
  135. nextEndChild = endChild.sub[next_end];
  136. }
  137. this.$store.commit("updateCrumbs", {
  138. parantData,
  139. childData,
  140. lastChild,
  141. endChild,
  142. nextEndChild,
  143. });
  144. sessionStorage.setItem(
  145. "crumbs",
  146. JSON.stringify({
  147. parantData,
  148. childData,
  149. lastChild,
  150. endChild,
  151. nextEndChild,
  152. })
  153. );
  154. let page = nextEndChild
  155. ? nextEndChild.page
  156. : endChild
  157. ? endChild.page
  158. : lastChild
  159. ? lastChild.page
  160. : childData.page;
  161. let title = nextEndChild
  162. ? nextEndChild.title
  163. : endChild
  164. ? endChild.title
  165. : lastChild
  166. ? lastChild.title
  167. : childData.title;
  168. let id = nextEndChild
  169. ? nextEndChild.id
  170. : endChild
  171. ? endChild.id
  172. : lastChild
  173. ? lastChild.id
  174. : childData.id || "";
  175. this.$router.push({
  176. path: page,
  177. query: {
  178. title: title,
  179. id: id,
  180. permisssions_id: permisssions_id,
  181. },
  182. });
  183. },
  184. handleTitleClick(row) {
  185. this.$store.commit("updataNavgation", row.sub);
  186. sessionStorage.setItem("navgation", JSON.stringify(row.sub));
  187. // if (row.title == '首页') {
  188. this.$router.push({ path: "/cms/home", query: { title: "首页" } });
  189. // } else {
  190. // }
  191. },
  192. },
  193. components: { Header, Navgation, Crumbs },
  194. };
  195. </script>
  196. <style lang="scss" scoped>
  197. .content {
  198. height: 100%;
  199. }
  200. .page {
  201. display: flex;
  202. height: 100%;
  203. width: 100%;
  204. padding-top: 80px;
  205. .navigation {
  206. width: 230px;
  207. height: 100%;
  208. }
  209. .router-map {
  210. width: calc(100% - 230px);
  211. height: 100%;
  212. padding: 10px 20px;
  213. background: #f0f1f4;
  214. .router-style {
  215. height: 93%;
  216. border-radius: 5px;
  217. background: #fff;
  218. position: relative;
  219. }
  220. .router-style-page {
  221. padding: 0 36px;
  222. }
  223. .router-style-home {
  224. padding: 0;
  225. }
  226. }
  227. }
  228. .slide-right-enter-active,
  229. .slide-right-leave-active,
  230. .slide-left-enter-active,
  231. .slide-left-leave-active {
  232. will-change: transform;
  233. transition: all 500ms;
  234. position: absolute;
  235. }
  236. .slide-right-enter {
  237. opacity: 0;
  238. transform: translate3d(-100%, 0, 0);
  239. }
  240. .slide-right-leave-active {
  241. opacity: 0;
  242. transform: translate3d(100%, 0, 0);
  243. }
  244. .slide-left-enter {
  245. opacity: 0;
  246. transform: translate3d(100%, 0, 0);
  247. }
  248. .slide-left-leave-active {
  249. opacity: 0;
  250. transform: translate3d(-100%, 0, 0);
  251. }
  252. </style>