index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. <show-types :lang="lang" :type="type" :types="types"></show-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></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. head(){
  38. let headInfo = {
  39. meta: []
  40. }
  41. if (this.title)
  42. {
  43. headInfo.title = this.title;
  44. }
  45. if (this.seoDescription)
  46. {
  47. headInfo.meta.push({
  48. hid: "description",
  49. name: "description",
  50. content: this.seoDescription,
  51. })
  52. }
  53. if(this.seo_key)
  54. {
  55. headInfo.meta.push({
  56. hid: "keywords",
  57. name: "keywords",
  58. content: this.seo_key,
  59. })
  60. }
  61. return headInfo
  62. },
  63. async asyncData(ctx){
  64. // 获取数据
  65. let url = baseUrl + apiMap.searchSolution.path;
  66. url += `?type=all&p=1&l=5`
  67. let [err,res] = await handle(axios.get( url));
  68. if(err){
  69. console.log(err);
  70. return {};
  71. }
  72. let result = res.data;
  73. let title = "合方圆-解决方案"
  74. let seo_key = "合方圆-解决方案,合方圆科技-解决方案";
  75. let seoDescription = "合方圆科技解决方案,针对不同应用场景定制不同的集中化方案";
  76. if(result.code === 1){
  77. let pageData = {
  78. limit: result.limit,
  79. page: result.page,
  80. total: result.total,
  81. count: result.count,
  82. }
  83. return {
  84. title,
  85. seo_key,
  86. seoDescription,
  87. solutions: result.data,
  88. basePageData: pageData,
  89. }
  90. }else{
  91. console.error(result.msg);
  92. console.log(result);
  93. return {
  94. title,
  95. seo_key,
  96. seoDescription,
  97. solutions:[]
  98. }
  99. }
  100. },
  101. data(){
  102. return {
  103. title: '',
  104. seo_key: '',
  105. seoDescription: '',
  106. lang: this.uLang?this.uLang:langMap.lang.cn,
  107. type: this.pType?this.pType:'all',
  108. types: this.$store.getters.solutionTypes,
  109. key: this.pKey?this.pKey:'',
  110. page: 1,
  111. nowCount: 199,
  112. nowTotal: 2,
  113. limit:pageLimit,
  114. solutions:this.pSolution?this.pSolution:[],
  115. basePageData: {},
  116. pageSave: {},
  117. isPhone: false
  118. }
  119. },
  120. beforeMount() {
  121. let pageData;
  122. if (this.pPageData){
  123. this.basePageData = this.pPageData
  124. }
  125. pageData = this.basePageData;
  126. this.updatePageData(pageData);
  127. },
  128. mounted() {
  129. this.isPhone = isMediaView(0,1024);
  130. this.$root.$on('changeLang',this.switchLang);
  131. // this.$root.$on('changeSolutionType',this.selectType);
  132. this.$root.$on('changeType',this.selectType);
  133. this.$root.$on('changePage',this.changePageHandle);
  134. // this.$root.$on('changeProductType',this.selectType);
  135. },
  136. methods:{
  137. switchLang(nextLang){
  138. if(nextLang){
  139. this.lang = nextLang;
  140. }else{
  141. if(this.lang === langMap.lang.cn){
  142. this.lang = langMap.lang.en
  143. }else{
  144. this.lang = langMap.lang.cn
  145. }
  146. }
  147. },
  148. selectType(nextType){
  149. console.log(nextType)
  150. this.type = nextType;
  151. this.page = 1;
  152. this.searchSolution();
  153. },
  154. changePageHandle(nextPage){
  155. this.page = nextPage;
  156. this.searchSolution();
  157. },
  158. async searchSolution(){
  159. // 获取数据
  160. let url = apiMap.searchSolution.path;
  161. url += `?key=${this.key}&type=${this.type}&p=${this.page}&l=5`
  162. let [err,res] = await handle(axios.get(url));
  163. if(err){ console.log(err); return null; }
  164. let result = res.data;
  165. if(result.code === 1){
  166. this.solutions = result.data;
  167. let pageData;
  168. if(result.total){
  169. // 更新页面信息
  170. pageData = {
  171. limit: result.limit,
  172. page: result.page,
  173. total: result.total,
  174. count: result.count,
  175. }
  176. }else if(this.pageSave[this.type] && this.pageSave[this.type][this.key]){
  177. pageData = this.pageSave[this.type][this.key]
  178. }
  179. this.updatePageData(pageData);
  180. }else{
  181. console.error(result.msg);
  182. console.log(result);
  183. }
  184. },
  185. updatePageData(pageData){
  186. if(!this.pageSave[this.type]){
  187. this.pageSave[this.type] = {}
  188. }
  189. if(!this.pageSave[this.type][this.key]){
  190. this.pageSave[this.type][this.key] = pageData;
  191. }
  192. let nowTotal = Math.ceil(pageData.total / pageData.limit);
  193. let nowCount = pageData.total;
  194. this.nowTotal = nowTotal;
  195. this.nowCount = nowCount;
  196. }
  197. }
  198. }
  199. </script>
  200. <style scoped>
  201. </style>