index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 langMap from "~/map/langMap";
  27. import defaultFooter from "~/components/footer/defaultFooter";
  28. import {getTypeSubText, getTypeText} from "~/map/newMap";
  29. import handle from "~/until/handle";
  30. import {timestampToTime} from "~/until/time";
  31. import {unescapeHtml} from "~/until/unescapeHtml";
  32. import {isMediaView} from "@/until/mediaView";
  33. export default {
  34. name: "newsItemIndex",
  35. props:['uLang','pType'],
  36. components:{defaultFooter},
  37. data(){
  38. return {
  39. langType: langMap.lang,
  40. lang: this.uLang?this.uLang:langMap.lang.cn,
  41. solutionId: null,
  42. solutionDetail: {},
  43. productTypeText: getTypeText(this.pType),
  44. productTypeSubText: getTypeSubText(this.pType),
  45. timer: null,
  46. isPhone: false,
  47. }
  48. },
  49. beforeMount() {
  50. const queryString = window.location.search;
  51. const params = new URLSearchParams(queryString);
  52. if(params&&params.get('id')){
  53. this.solutionId = params.get('id');
  54. }else{
  55. window.location.href = '/news'
  56. }
  57. this.loadSolutionDetail();
  58. this.timer = setTimeout(()=>{
  59. this.addRead();
  60. },1000*10)
  61. },
  62. mounted() {
  63. this.$root.$on('changeLang',this.switchLang)
  64. this.isPhone = isMediaView(0,1024);
  65. // console.log(this.isPhone);
  66. // console.log(`this.isPhone:${this.isPhone}`);
  67. },
  68. beforeDestroy() {
  69. if (this.timer){
  70. clearTimeout(this.timer);
  71. }
  72. },
  73. methods:{
  74. getLangText(str) {
  75. return langMap.getText(this.lang, str);
  76. },
  77. getAbbrText(str) {
  78. return langMap.getAbbrText(this.lang, str);
  79. },
  80. async loadSolutionDetail(){
  81. let err,res;
  82. let url = `/api/getSolution.php?id=${this.solutionId}`;
  83. [err,res] = await handle(this.$axios.$get(url));
  84. if(err) {
  85. console.log(err);
  86. return alert(err.message);
  87. }
  88. console.log(typeof res.rcode)
  89. if(res.rcode === 1){
  90. this.solutionDetail = res.data;
  91. // console.log(this.solutionDetail.detail)
  92. this.solutionDetail.content = unescapeHtml(this.solutionDetail.content);
  93. // console.log(this.solutionDetail.detail)
  94. this.solutionDetail.date_time = timestampToTime(this.solutionDetail.date_time);
  95. }else{
  96. console.log('not match result');
  97. console.log(res);
  98. return alert('加载解决方案失败!!!');
  99. }
  100. },
  101. async addRead(){
  102. let err,res;
  103. let url = `/api/addNewsRead.php?id=${this.solutionId}`;
  104. [err,res] = await handle(this.$axios.$get(url));
  105. if(err) {
  106. console.log(err);
  107. return alert(err.message);
  108. }
  109. console.log(typeof res.rcode)
  110. if(res.rcode === 1){
  111. // this.solutionDetail.hits = res.data;
  112. console.log('page add hits ok')
  113. }else{
  114. console.log('not match result');
  115. console.log(res);
  116. }
  117. },
  118. }
  119. }
  120. </script>
  121. <style scoped>
  122. .big-title {
  123. margin: 5px auto;
  124. justify-content: left;
  125. }
  126. .solution-info{
  127. /* 两边布局*/
  128. display: flex;
  129. flex-direction: row;
  130. justify-content: space-between;
  131. align-items: flex-start;
  132. flex-wrap: wrap;
  133. font-size: 0.8rem;
  134. color: #999999;
  135. cursor: default;
  136. }
  137. </style>