_type.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <!-- <product-index :p-type="type" :p-product="products"/>-->
  3. <!-- <solution-index :p-type="type" :p-solution="solutions"></solution-index>-->
  4. <news-index :p-type="type" :p-news="news" :p-page-data="basePageData"></news-index>
  5. </template>
  6. <script>
  7. import {handle} from "~/until/handle";
  8. import axios from "axios";
  9. import NewsIndex from "@/pages/news/index";
  10. import {apiMap, baseUrl} from "~/map/apiMap";
  11. import {isEmpty} from "@/until/typeTool";
  12. export default {
  13. name: "typeNewsPage",
  14. props:[],
  15. async asyncData(ctx){
  16. // 获取数据
  17. let url = baseUrl + apiMap.searchNews.path;
  18. let type = ctx.params.type?ctx.params.type:'all';
  19. url += `?type=${type}&p=1`
  20. let [err,res] = await handle(axios.get( url));
  21. if(err){
  22. console.log(err);
  23. return {};
  24. }
  25. // 获取页面的seo优化关键字
  26. let types = ctx.store.getters.pTypes;
  27. let title = "合方圆-新闻中心"
  28. let seo_key = "合方圆,合方圆科技,深圳合方圆";
  29. let seoDescription = "合方圆科技新闻中心,摄像头行为";
  30. // 判断是否有数据
  31. if(!isEmpty(types)){
  32. // console.log(`已经获取到类型数据`);
  33. // 获取当前类型的数据
  34. let typeData = types.find(item=>item.type_key === type);
  35. // console.log(typeData);
  36. if(typeData){
  37. seo_key += `,合方圆${typeData.type_name},${typeData.type_name},${typeData.seo_key}`;
  38. seoDescription = `深圳市合方圆科技${typeData.type_name}`;
  39. title = `合方圆-${typeData.type_name}`;
  40. }
  41. }
  42. let result = res.data;
  43. if(result.code === 1){
  44. let pageData = {
  45. limit: result.limit,
  46. page: result.page,
  47. total: result.total,
  48. count: result.count,
  49. }
  50. return {
  51. news: result.data,
  52. basePageData: pageData,
  53. title,
  54. seo_key,
  55. seoDescription
  56. }
  57. }else{
  58. return {
  59. news:[],
  60. title,
  61. seo_key,
  62. seoDescription
  63. }
  64. }
  65. },
  66. head(){
  67. return {
  68. title: this.title,
  69. meta: [
  70. {
  71. hid: 'description',
  72. name: 'description',
  73. content: this.seoDescription
  74. },
  75. {
  76. hid: 'keywords',
  77. name: 'keywords',
  78. content: this.seo_key
  79. },
  80. ]
  81. }
  82. },
  83. data(){
  84. return {
  85. title: "",
  86. seo_key: "合方圆,合方圆科技",
  87. seoDescription: "合方圆科技,合天地方圆,新闻中心",
  88. type: 'all',
  89. basePageData: {},
  90. news: []
  91. }
  92. },
  93. beforeMount() {
  94. this.type = this.$route.params.type?this.$route.params.type:'all';
  95. },
  96. components:{
  97. NewsIndex,
  98. }
  99. }
  100. </script>
  101. <style scoped>
  102. </style>