menuDrop.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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(){return this.$store.getters.productTypes},
  72. solutions(){return this.$store.getters.solutionTypes},
  73. },
  74. // 使用vuex getter 获取数据
  75. data(){
  76. return {
  77. langType: langMap.lang,
  78. menus: [
  79. ],
  80. menuSubItems: {},
  81. showMenuItems: [],
  82. nowMenuKey: "",
  83. nowSubMenuId: ""
  84. }
  85. },
  86. beforeMount() {
  87. this.loadMenus();
  88. console.log(this.menus);
  89. if(this.menus && this.menus.length){
  90. this.nowMenuKey = this.menus[0].typeKey;
  91. this.loadMenuItems();
  92. }else{
  93. console.log('no menu data');
  94. }
  95. },
  96. methods:{
  97. getLangText(str){
  98. return langMap.getText(this.lang,str);
  99. },
  100. getAbbrText(str){
  101. return langMap.getAbbrText(this.lang,str);
  102. },
  103. loadMenus(){
  104. if(this.type === "solution"){
  105. console.log("solution data")
  106. this.menus = this.solutions;
  107. console.log(this.menus);
  108. }else{
  109. this.menus = this.products;
  110. console.log(this.menus);
  111. }
  112. },
  113. subItemHandle(id){
  114. this.nowSubMenuId = id;
  115. },
  116. toMenuHandle(item){
  117. this.nowMenuKey = item.typeKey;
  118. this.loadMenuItems();
  119. },
  120. async loadMenuItems(){
  121. if(this.menuSubItems[this.nowMenuKey]){
  122. console.log('load catch');
  123. this.showMenuItems = this.menuSubItems[this.nowMenuKey];
  124. return null;
  125. }
  126. let url = '';
  127. if(this.type === "solution"){
  128. url = 'api/solution/load'
  129. }else{
  130. url = 'api/product/load'
  131. }
  132. url+=`?key=${this.nowMenuKey}&p=1&l=10`
  133. // 请求服务端接口
  134. let [err,result] = await handle(this.$axios.get(url));
  135. if(err){
  136. console.log(err);
  137. return;
  138. }
  139. let res = result.data;
  140. console.log(res)
  141. if(res.code === 1){
  142. this.menuSubItems[this.nowMenuKey] = res.data;
  143. this.showMenuItems = this.menuSubItems[this.nowMenuKey];
  144. this.nowSubMenuId = this.showMenuItems[0].id;
  145. console.log(this.nowSubMenuId);
  146. // console.log(this.menuSubItems);
  147. }else{
  148. console.error(res);
  149. console.log(res.msg);
  150. }
  151. },
  152. subItemClickHandle(item){
  153. if(item.sourceType == "1"){
  154. // 尝试加载特定静态页面
  155. window.location.href = item.source
  156. }else{
  157. window.location.href = `${this.pHref}/info/${this.nowMenuKey}?id=${item.id}`
  158. }
  159. }
  160. }
  161. }
  162. </script>
  163. <style scoped>
  164. </style>