index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="">
  3. <lucency-header :lang="lang" page-key="solution" :is-phone="isPhone" />
  4. <item-banner :lang="lang" :title="`解决方案`" :sub-title="`专业,高效,稳定解决方案`"/>
  5. <solution-types :lang="lang" :type="type"></solution-types>
  6. <solution-list :lang="lang" :solution-list="solutions"></solution-list>
  7. <page-select :page="page" :count="nowCount" :total="nowTotal"></page-select>
  8. <default-footer :lang="lang"/>
  9. <site-bar wechat-src="/image/wechat.jpg"></site-bar>
  10. </div>
  11. </template>
  12. <script>
  13. import qs from "qs"
  14. import productBanner from "~/components/banner/productBanner";
  15. import itemBanner from "~/components/banner/itemBanner";
  16. import solutionTypes from "~/components/solutionTypes";
  17. import solutionList from "~/components/solutionList";
  18. import langMap from "~/map/langMap";
  19. import handle from "~/until/handle";
  20. import axios from "axios";
  21. import {isMediaView} from "@/until/mediaView";
  22. import LucencyHeader from "~/components/header/lucencyHeader.vue";
  23. import DefaultFooter from "~/components/footer/defaultFooter.vue";
  24. import {apiMap, baseUrl} from "~/map/apiMap";
  25. const pageLimit = 5;
  26. export default {
  27. name: "solutionIndex",
  28. props:['uLang','pType','pKey','pSolution','pPageData'],
  29. components:{
  30. DefaultFooter,
  31. LucencyHeader,
  32. productBanner,
  33. itemBanner,
  34. solutionTypes,
  35. solutionList
  36. },
  37. async asyncData(ctx){
  38. // 获取数据
  39. let url = baseUrl + apiMap.searchSolution.path;
  40. url += `?type=all&p=1&l=5`
  41. let [err,res] = await handle(axios.get( url));
  42. if(err){
  43. console.log(err);
  44. return {};
  45. }
  46. let result = res.data;
  47. if(result.code === 1){
  48. let pageData = {
  49. limit: result.limit,
  50. page: result.page,
  51. total: result.total,
  52. count: result.count,
  53. }
  54. return {
  55. solutions: result.data,
  56. basePageData: pageData,
  57. }
  58. }else{
  59. console.error(result.msg);
  60. console.log(result);
  61. return {solutions:[]}
  62. }
  63. },
  64. data(){
  65. return {
  66. lang: this.uLang?this.uLang:langMap.lang.cn,
  67. type: this.pType?this.pType:'all',
  68. key: this.pKey?this.pKey:'',
  69. page: 1,
  70. nowCount: 199,
  71. nowTotal: 2,
  72. limit:pageLimit,
  73. solutions:this.pSolution?this.pSolution:[],
  74. basePageData: {},
  75. pageSave: {},
  76. isPhone: false
  77. }
  78. },
  79. beforeMount() {
  80. let pageData;
  81. if (this.pPageData){
  82. this.basePageData = this.pPageData
  83. }
  84. pageData = this.basePageData;
  85. this.updatePageData(pageData);
  86. },
  87. mounted() {
  88. this.isPhone = isMediaView(0,1024);
  89. this.$root.$on('changeLang',this.switchLang);
  90. this.$root.$on('changeSolutionType',this.selectType);
  91. this.$root.$on('changePage',this.changePageHandle);
  92. // this.$root.$on('changeProductType',this.selectType);
  93. },
  94. methods:{
  95. switchLang(nextLang){
  96. if(nextLang){
  97. this.lang = nextLang;
  98. }else{
  99. if(this.lang === langMap.lang.cn){
  100. this.lang = langMap.lang.en
  101. }else{
  102. this.lang = langMap.lang.cn
  103. }
  104. }
  105. },
  106. selectType(nextType){
  107. console.log(nextType)
  108. this.type = nextType;
  109. this.page = 1;
  110. this.searchSolution();
  111. },
  112. changePageHandle(nextPage){
  113. this.page = nextPage;
  114. this.searchSolution();
  115. },
  116. async searchSolution(){
  117. // 获取数据
  118. let url = apiMap.searchSolution.path;
  119. url += `?key=${this.key}&type=${this.type}&p=${this.page}&l=5`
  120. let [err,res] = await handle(axios.get(url));
  121. if(err){ console.log(err); return null; }
  122. let result = res.data;
  123. if(result.code === 1){
  124. this.solutions = result.data;
  125. let pageData;
  126. if(result.total){
  127. // 更新页面信息
  128. pageData = {
  129. limit: result.limit,
  130. page: result.page,
  131. total: result.total,
  132. count: result.count,
  133. }
  134. }else if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
  135. pageData = this.pageSave[this.type][this.key]
  136. }
  137. this.updatePageData(pageData);
  138. }else{
  139. console.error(result.msg);
  140. console.log(result);
  141. }
  142. },
  143. updatePageData(pageData){
  144. if(!this.pageSave[this.type]){
  145. this.pageSave[this.type] = {}
  146. }
  147. if(!this.pageSave[this.type][this.key]){
  148. this.pageSave[this.type][this.key] = pageData;
  149. }
  150. let nowTotal = Math.ceil(pageData.total / pageData.limit);
  151. let nowCount = pageData.total;
  152. this.nowTotal = nowTotal;
  153. this.nowCount = nowCount;
  154. }
  155. }
  156. }
  157. </script>
  158. <style scoped>
  159. </style>