menuDrop.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 {productMenus} from "~/map/productMap";
  38. /**
  39. * 解决方案
  40. * @type {[{typeKey: string, text: string}, {typeKey: string, text: string}]}
  41. */
  42. const solutionMenus = [
  43. {
  44. text: "解决方案",
  45. typeKey: "sol",
  46. href: '/sol'
  47. },
  48. {
  49. text: "行业应用",
  50. typeKey: "acs",
  51. href: '/acs'
  52. },
  53. {
  54. text: "电力案例",
  55. typeKey: "epower",
  56. href: '/epower'
  57. },
  58. ];
  59. export default {
  60. name: "menuDrop",
  61. props:{
  62. lang:{
  63. default: langMap.lang.cn
  64. },
  65. type:{default:'product'},
  66. pHref: {default:''}
  67. },
  68. data(){
  69. return {
  70. langType: langMap.lang,
  71. menus: [
  72. ],
  73. menuSubItems: {},
  74. showMenuItems: [],
  75. nowMenuKey: "",
  76. nowSubMenuId: ""
  77. }
  78. },
  79. beforeMount() {
  80. this.loadMenus();
  81. this.nowMenuKey = this.menus[0].typeKey;
  82. this.loadMenuItems();
  83. },
  84. methods:{
  85. getLangText(str){
  86. return langMap.getText(this.lang,str);
  87. },
  88. getAbbrText(str){
  89. return langMap.getAbbrText(this.lang,str);
  90. },
  91. loadMenus(){
  92. if(this.type === "solution"){
  93. console.log("solution data")
  94. this.menus = solutionMenus;
  95. }else{
  96. this.menus = productMenus;
  97. }
  98. },
  99. subItemHandle(id){
  100. this.nowSubMenuId = id;
  101. },
  102. toMenuHandle(item){
  103. this.nowMenuKey = item.typeKey;
  104. this.loadMenuItems();
  105. },
  106. async loadMenuItems(){
  107. if(this.menuSubItems[this.nowMenuKey]){
  108. console.log('load catch');
  109. this.showMenuItems = this.menuSubItems[this.nowMenuKey];
  110. return null;
  111. }
  112. let url = '';
  113. if(this.type === "solution"){
  114. url = 'api/solution/load'
  115. }else{
  116. url = 'api/product/load'
  117. }
  118. url+=`?key=${this.nowMenuKey}&p=1&l=10`
  119. // 请求服务端接口
  120. let [err,result] = await handle(this.$axios.get(url));
  121. if(err){
  122. console.log(err);
  123. return;
  124. }
  125. let res = result.data;
  126. console.log(res)
  127. if(res.code === 1){
  128. this.menuSubItems[this.nowMenuKey] = res.data;
  129. this.showMenuItems = this.menuSubItems[this.nowMenuKey];
  130. this.nowSubMenuId = this.showMenuItems[0].id;
  131. console.log(this.nowSubMenuId);
  132. // console.log(this.menuSubItems);
  133. }else{
  134. console.error(res);
  135. console.log(res.msg);
  136. }
  137. },
  138. subItemClickHandle(item){
  139. if(item.sourceType == "1"){
  140. // 尝试加载特定静态页面
  141. window.location.href = item.source
  142. }else{
  143. window.location.href = `${this.pHref}/item/${this.nowMenuKey}?id=${item.id}`
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style scoped>
  150. </style>