index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="content">
  3. <lucency-header :lang="lang" page-key="news" :is-phone="isPhone" />
  4. <item-banner :title="'合方圆'" :sub-title="solutionDetail.title"></item-banner>
  5. <big-title>
  6. {{solutionDetail.title}}
  7. <span class="author">
  8. {{solutionDetail.author}}
  9. </span>
  10. </big-title>
  11. <div class="conBox solution-view" v-html="solutionDetail.content">
  12. </div>
  13. <div class="conBox solution-info">
  14. <span class="viewer">
  15. {{solutionDetail.hits}}人浏览
  16. </span>
  17. <span class="time">
  18. 发布日期: {{solutionDetail.date_time}}
  19. </span>
  20. </div>
  21. <default-footer :lang="lang"/>
  22. <site-bar wechat-src="/image/wechat.jpg"></site-bar>
  23. </div>
  24. </template>
  25. <script>
  26. import axios from "axios";
  27. import langMap from "~/map/langMap";
  28. import defaultFooter from "~/components/footer/defaultFooter";
  29. import {getTypeSubText, getTypeText} from "~/map/newMap";
  30. import {handle} from "~/until/handle";
  31. import {timestampToTime} from "~/until/time";
  32. import {unescapeHtml} from "~/until/unescapeHtml";
  33. import {isMediaView} from "@/until/mediaView";
  34. import BigTitle from "~/components/public/bigTitle.vue";
  35. import LucencyHeader from "~/components/header/lucencyHeader.vue";
  36. import ItemBanner from "~/components/banner/itemBanner.vue";
  37. import {apiMap, baseUrl} from "~/map/apiMap";
  38. import {toNumber,isEmpty} from "../../../until/typeTool";
  39. export default {
  40. name: "newsItemIndex",
  41. props:['uLang','pType', 'pInfo', "pId"],
  42. components:{ItemBanner, LucencyHeader, BigTitle, defaultFooter},
  43. async asyncData(ctx){
  44. let err,res;
  45. let id = ctx.query.id;
  46. // id转数字
  47. let url = baseUrl + apiMap.newsInfo.path ;
  48. if(!toNumber(id)){ctx.redirect(`/news`);}
  49. console.log(`开始获取文章 id:${id}`);
  50. url += `/${id}`;
  51. [err,res] = await handle(axios.get(url));
  52. if(err){
  53. // 加载失败,返回至产品页面
  54. console.log(`查询数据失败`);
  55. ctx.redirect(`/news`);
  56. return {solutionId:id}
  57. }
  58. let result = res.data;
  59. if(result.code === 1){
  60. console.log(result.data);
  61. return {solutionId:id, solutionDetail:result.data}
  62. }else{
  63. console.log(`查询数据失败,服务器异常`);
  64. ctx.redirect(`/news`);
  65. }
  66. return {solutionId:id}
  67. },
  68. data(){
  69. return {
  70. langType: langMap.lang,
  71. lang: this.uLang?this.uLang:langMap.lang.cn,
  72. solutionId: null,
  73. solutionDetail: {},
  74. productTypeText: getTypeText(this.pType),
  75. productTypeSubText: getTypeSubText(this.pType),
  76. timer: null,
  77. isPhone: false,
  78. }
  79. },
  80. beforeMount() {
  81. console.log(this.pInfo);
  82. if(isEmpty(this.pInfo) && isEmpty(this.solutionDetail)){
  83. console.log('无法获取文章数据');
  84. this.$router.push('/news');
  85. }
  86. if(isEmpty(this.solutionDetail)){
  87. this.solutionDetail = this.pInfo;
  88. }
  89. if(isEmpty(this.solutionId)){
  90. this.solutionId = this.pId;
  91. }
  92. this.solutionDetail.content = unescapeHtml(this.solutionDetail.content);
  93. this.solutionDetail.date_time = timestampToTime(this.solutionDetail.date_time);
  94. this.timer = setTimeout(()=>{
  95. this.addRead();
  96. },1000*10)
  97. },
  98. mounted() {
  99. this.$root.$on('changeLang',this.switchLang)
  100. this.isPhone = isMediaView(0,1024);
  101. // console.log(this.isPhone);
  102. // console.log(`this.isPhone:${this.isPhone}`);
  103. },
  104. beforeDestroy() {
  105. if (this.timer){
  106. clearTimeout(this.timer);
  107. }
  108. },
  109. methods:{
  110. getLangText(str) {
  111. return langMap.getText(this.lang, str);
  112. },
  113. getAbbrText(str) {
  114. return langMap.getAbbrText(this.lang, str);
  115. },
  116. async addRead(){
  117. let err,res;
  118. let url = apiMap.addPageRead.path;
  119. url += `?id=${this.solutionId}`;
  120. [err,res] = await handle(this.$axios.$get(url));
  121. if(err) {
  122. console.log(err);
  123. return alert(err.message);
  124. }
  125. console.log(typeof res.code)
  126. if(res.code === 1){
  127. // this.solutionDetail.hits = res.data;
  128. console.log('page add hits ok')
  129. }else{
  130. console.log('not match result');
  131. console.log(res);
  132. }
  133. },
  134. }
  135. }
  136. </script>
  137. <style scoped>
  138. .big-title {
  139. margin: 5px auto;
  140. justify-content: left;
  141. }
  142. .solution-info{
  143. /* 两边布局*/
  144. display: flex;
  145. flex-direction: row;
  146. justify-content: space-between;
  147. align-items: flex-start;
  148. flex-wrap: wrap;
  149. font-size: 0.8rem;
  150. color: #999999;
  151. cursor: default;
  152. }
  153. </style>