menuDrop.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="dropMap drop-default">
  3. <div class="drop-menus">
  4. <a v-for="item in menus"
  5. :key="item.typeKey"
  6. :class="`menu ${nowMenuKey===item.typeKey?'now':''}`"
  7. :href="pHref+item.href"
  8. @mouseenter="toMenuHandle(item)"
  9. >
  10. <span >{{lang===langType.cn?item.text:getAbbrText(item.text)}}</span>
  11. </a>
  12. </div>
  13. <div class="drop-view noScroll">
  14. <div
  15. v-for="(item,i) in showMenuItems"
  16. :class="`sub-item ${nowSubMenuId===item.id?'now-sub':''}`"
  17. :key=" `${nowMenuKey}-${item.id}-${i}`"
  18. @mouseenter="subItemHandle(item.id)"
  19. @click="subItemClickHandle(item)"
  20. >
  21. <div class="con">
  22. <div class="img-box">
  23. <img :src="'/public/'+item.image" :alt="item.name" class="img"/>
  24. </div>
  25. <div class="text-box">
  26. <div class="name">{{item.name}}</div>
  27. <div class="remark">{{item.remark}}</div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import langMap from "~/map/langMap";
  36. import {handle} from "~/until/handle";
  37. import {indexTypes} from "../../../store";
  38. import {mapGetters} from "vuex";
  39. import {productMenus} from "~/map/productMap";
  40. /**
  41. * 解决方案
  42. * @type {[{typeKey: string, text: string}, {typeKey: string, text: string}]}
  43. */
  44. const solutionMenus = [
  45. {
  46. text: "解决方案",
  47. typeKey: "sol",
  48. href: '/sol'
  49. },
  50. {
  51. text: "行业应用",
  52. typeKey: "acs",
  53. href: '/acs'
  54. },
  55. {
  56. text: "电力案例",
  57. typeKey: "epower",
  58. href: '/epower'
  59. },
  60. ];
  61. export default {
  62. name: "menuDrop",
  63. props:{
  64. lang:{
  65. default: langMap.lang.cn
  66. },
  67. type:{default:'product'},
  68. pHref: {default:''}
  69. },
  70. computed:{
  71. products(){
  72. return this.$store.getters.productTypes.filter(item=>item.typeKey!=='all')
  73. },
  74. solutions(){return this.$store.getters.solutionTypes},
  75. },
  76. // 使用vuex getter 获取数据
  77. data(){
  78. return {
  79. langType: langMap.lang,
  80. menus: [
  81. ],
  82. menuSubItems: {},
  83. showMenuItems: [],
  84. nowMenuKey: "",
  85. nowSubMenuId: ""
  86. }
  87. },
  88. beforeMount() {
  89. this.loadMenus();
  90. console.log(this.menus);
  91. if(this.menus && this.menus.length){
  92. this.nowMenuKey = this.menus[0].typeKey;
  93. this.loadMenuItems();
  94. }else{
  95. console.log('no menu data');
  96. }
  97. },
  98. methods:{
  99. getLangText(str){
  100. return langMap.getText(this.lang,str);
  101. },
  102. getAbbrText(str){
  103. return langMap.getAbbrText(this.lang,str);
  104. },
  105. loadMenus(){
  106. if(this.type === "solution"){
  107. console.log("solution data")
  108. this.menus = this.solutions;
  109. console.log(this.menus);
  110. }else{
  111. this.menus = this.products;
  112. console.log(this.menus);
  113. }
  114. },
  115. subItemHandle(id){
  116. this.nowSubMenuId = id;
  117. },
  118. toMenuHandle(item){
  119. this.nowMenuKey = item.typeKey;
  120. this.loadMenuItems();
  121. },
  122. async loadMenuItems(){
  123. if(this.menuSubItems[this.nowMenuKey]){
  124. console.log('load catch');
  125. this.showMenuItems = this.menuSubItems[this.nowMenuKey];
  126. return null;
  127. }
  128. let url = '';
  129. if(this.type === "solution"){
  130. url = 'api/solution/load'
  131. }else{
  132. url = 'api/product/load'
  133. }
  134. url+=`?key=${this.nowMenuKey}&p=1&l=10`
  135. // 请求服务端接口
  136. let [err,result] = await handle(this.$axios.get(url));
  137. if(err){
  138. console.log(err);
  139. return;
  140. }
  141. let res = result.data;
  142. console.log(res)
  143. if(res.code === 1){
  144. this.menuSubItems[this.nowMenuKey] = res.data;
  145. this.showMenuItems = this.menuSubItems[this.nowMenuKey];
  146. this.nowSubMenuId = this.showMenuItems[0].id;
  147. console.log(this.nowSubMenuId);
  148. // console.log(this.menuSubItems);
  149. }else{
  150. console.error(res);
  151. console.log(res.msg);
  152. }
  153. },
  154. subItemClickHandle(item){
  155. if(item.sourceType == "1"){
  156. // 尝试加载特定静态页面
  157. window.location.href = item.source
  158. }else{
  159. window.location.href = `${this.pHref}/info/${this.nowMenuKey}?id=${item.id}`
  160. }
  161. }
  162. }
  163. }
  164. </script>
  165. <style scoped>
  166. </style>