menuDrop.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div class="dropMap drop-default">
  3. <div class="drop-menus">
  4. <div v-for="item in menus"
  5. :key="item.typeKey"
  6. :class="`menu ${nowMenuKey===item.typeKey?'now':''}`"
  7. @mouseenter="toMenuHandle(item)"
  8. >
  9. <span >{{lang===langType.cn?item.text:getAbbrText(item.text)}}</span>
  10. </div>
  11. </div>
  12. <div class="drop-view noScroll">
  13. <div
  14. v-for="(item,i) in showMenuItems"
  15. :class="`sub-item ${nowSubMenuId===item.id?'now-sub':''}`"
  16. :key=" `${nowMenuKey}-${item.id}-${i}`"
  17. @mouseenter="subItemHandle(item.id)"
  18. @click="subItemClickHandle(item)"
  19. >
  20. <div class="con">
  21. <div class="img-box">
  22. <img :src="'public/'+item.image" :alt="item.name" class="img"/>
  23. </div>
  24. <div class="text-box">
  25. <div class="name">{{item.name}}</div>
  26. <div class="remark">{{item.remark}}</div>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import langMap from "~/map/langMap";
  35. import handle from "~/until/handle";
  36. const productMenus = [
  37. {
  38. text: "M2M产品",
  39. typeKey: "m2m"
  40. },
  41. {
  42. text: "智能终端",
  43. typeKey: "sm"
  44. },
  45. {
  46. text: "输电线路摄像头",
  47. typeKey: "eCam"
  48. },
  49. {
  50. text: "4G低功耗摄像头",
  51. typeKey: "4gCam"
  52. },
  53. {
  54. text: "自动变焦双目协同摄像头",
  55. typeKey: "nCam"
  56. }
  57. ];
  58. /**
  59. * 解决方案
  60. * @type {[{typeKey: string, text: string}, {typeKey: string, text: string}]}
  61. */
  62. const solutionMenus = [
  63. {
  64. text: "M2M产品",
  65. typeKey: "m2m"
  66. },
  67. {
  68. text: "智能终端",
  69. typeKey: "sm"
  70. },
  71. ];
  72. export default {
  73. name: "menuDrop",
  74. props:{
  75. lang:{
  76. default: langMap.lang.cn
  77. },
  78. type:{default:'product'}
  79. },
  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. },
  94. methods:{
  95. getLangText(str){
  96. return langMap.getText(this.lang,str);
  97. },
  98. getAbbrText(str){
  99. return langMap.getAbbrText(this.lang,str);
  100. },
  101. loadMenus(){
  102. if(this.type === "solution"){
  103. console.log("solution data")
  104. this.menus = solutionMenus;
  105. }else{
  106. this.menus = productMenus;
  107. }
  108. },
  109. subItemHandle(id){
  110. this.nowSubMenuId = id;
  111. },
  112. toMenuHandle(item){
  113. this.nowMenuKey = item.typeKey;
  114. this.loadMenuItems();
  115. },
  116. async loadMenuItems(){
  117. if(this.menuSubItems[this.nowMenuKey]){
  118. console.log('load catch');
  119. this.showMenuItems = this.menuSubItems[this.nowMenuKey];
  120. return null;
  121. }
  122. let url = '';
  123. if(this.type === "solution"){
  124. url = 'api/loadSolution.php'
  125. }else{
  126. url = 'api/loadProduct.php'
  127. }
  128. url+=`?key=${this.nowMenuKey}&p=1&l=10`
  129. // 请求服务端接口
  130. let [err,result] = await handle(this.$axios.get(url));
  131. if(err){
  132. console.log(err);
  133. return;
  134. }
  135. let res = result.data;
  136. console.log(res)
  137. if(res.rcode === 1){
  138. this.menuSubItems[this.nowMenuKey] = res.data;
  139. this.showMenuItems = this.menuSubItems[this.nowMenuKey];
  140. this.nowSubMenuId = this.showMenuItems[0].id;
  141. console.log(this.nowSubMenuId);
  142. // console.log(this.menuSubItems);
  143. }else{
  144. console.error(res);
  145. console.log(res.msg);
  146. }
  147. },
  148. subItemClickHandle(item){
  149. if(item.sourceType == "1"){
  150. // 尝试加载特定静态页面
  151. window.location.href = item.source
  152. }else{
  153. window.location.href = `${this.nowMenuKey}.html?id=${item.id}`
  154. }
  155. }
  156. }
  157. }
  158. </script>
  159. <style scoped>
  160. </style>