menuDrop.vue 4.3 KB

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