menuDrop.vue 3.9 KB

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