menuDrop.vue 4.2 KB

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