index.vue 5.1 KB

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