index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. <a :href="`/news/${type.type_key}`">{{type.type_name}}</a>-
  7. {{solutionDetail.title}}
  8. <span class="author">
  9. {{solutionDetail.author}}
  10. </span>
  11. </big-title>
  12. <div class="conBox solution-view" v-html="solutionDetail.content">
  13. </div>
  14. <div class="conBox solution-info">
  15. <span class="viewer">
  16. {{solutionDetail.hits}}人浏览
  17. </span>
  18. <span class="time">
  19. 发布日期: {{solutionDetail.date_time}}
  20. </span>
  21. </div>
  22. <default-footer :lang="lang"/>
  23. <site-bar></site-bar>
  24. </div>
  25. </template>
  26. <script>
  27. import axios from "axios";
  28. import langMap from "~/map/langMap";
  29. import defaultFooter from "~/components/footer/defaultFooter";
  30. import {getTypeSubText, getTypeText} from "~/map/newMap";
  31. import {handle} from "~/until/handle";
  32. import {timestampToTime} from "~/until/time";
  33. import {unescapeHtml} from "~/until/unescapeHtml";
  34. import {isMediaView} from "@/until/mediaView";
  35. import BigTitle from "~/components/public/bigTitle.vue";
  36. import LucencyHeader from "~/components/header/lucencyHeader.vue";
  37. import ItemBanner from "~/components/banner/itemBanner.vue";
  38. import {apiMap, baseUrl} from "~/map/apiMap";
  39. import {toNumber,isEmpty} from "../../../until/typeTool";
  40. export default {
  41. name: "newsItemIndex",
  42. props:['uLang','pType', 'pInfo', "pId"],
  43. components:{ItemBanner, LucencyHeader, BigTitle, defaultFooter},
  44. head() {
  45. let headInfo = {
  46. meta: []
  47. }
  48. if (this.title)
  49. {
  50. headInfo.title = this.title;
  51. }
  52. if (this.desc)
  53. {
  54. headInfo.meta.push({
  55. hid: "description",
  56. name: "description",
  57. content: this.desc,
  58. })
  59. }
  60. if(this.seo_key)
  61. {
  62. headInfo.meta.push({
  63. hid: "keywords",
  64. name: "keywords",
  65. content: this.seo_key,
  66. })
  67. }
  68. return headInfo
  69. },
  70. async asyncData(ctx){
  71. let err,res;
  72. let id = ctx.query.id;
  73. // id转数字
  74. let url = baseUrl + apiMap.newsInfo.path ;
  75. if(!toNumber(id)){ctx.redirect(`/news`);}
  76. console.log(`开始获取文章 id:${id}`);
  77. url += `/${id}`;
  78. [err,res] = await handle(axios.get(url));
  79. if(err){
  80. // 加载失败,返回至产品页面
  81. console.log(`查询数据失败`);
  82. ctx.redirect(`/news`);
  83. return {solutionId:id}
  84. }
  85. let result = res.data;
  86. if(result.code === 1){
  87. console.log(result.data);
  88. let desc = result.data.remark
  89. let enDesc = ctx.lang !== langMap.lang.cn ? result.data.remark_en || result.data.remark : result.data.remark
  90. let seoKey = result.data.seo_key
  91. return {
  92. desc: desc,
  93. enDesc: enDesc,
  94. seo_key: seoKey? seoKey : `合方圆-新闻中心,合方圆科技-新闻中心`,
  95. title: `合方圆-${result.data.title}`,
  96. solutionId:id,
  97. solutionDetail:result.data
  98. }
  99. }else{
  100. console.log(`查询数据失败,服务器异常`);
  101. ctx.redirect(`/news`);
  102. }
  103. return {solutionId:id}
  104. },
  105. data(){
  106. return {
  107. title: ``,
  108. desc: '',
  109. enDesc: '',
  110. seo_key: '',
  111. langType: langMap.lang,
  112. lang: this.uLang?this.uLang:langMap.lang.cn,
  113. solutionId: null,
  114. solutionDetail: {},
  115. productTypeText: getTypeText(this.pType),
  116. productTypeSubText: getTypeSubText(this.pType),
  117. timer: null,
  118. isPhone: false,
  119. }
  120. },
  121. computed: {
  122. type(){
  123. let info = isEmpty(this.solutionDetail)?this.pInfo:this.solutionDetail
  124. let types = this.$store.getters.allNewsTypes || this.types;
  125. let type = types.find(val => val.type_key === info.type_key);
  126. let resultType = {}
  127. if(this.lang !== langMap.lang.cn)
  128. {
  129. resultType.type_name = type.type_name_en;
  130. resultType.sub_text = type.sub_text_en;
  131. }
  132. if(!resultType.type_name) resultType.type_name = type.type_name;
  133. if(!resultType.sub_text) resultType.sub_text = type.sub_text;
  134. resultType.type_key = type.type_key;
  135. return resultType;
  136. }
  137. },
  138. beforeMount() {
  139. console.log(this.pInfo);
  140. if(isEmpty(this.pInfo) && isEmpty(this.solutionDetail)){
  141. console.log('无法获取文章数据');
  142. this.$router.push('/news');
  143. }
  144. if(isEmpty(this.solutionDetail)){
  145. this.solutionDetail = this.pInfo;
  146. }
  147. if(isEmpty(this.solutionId)){
  148. this.solutionId = this.pId;
  149. }
  150. this.solutionDetail.content = unescapeHtml(this.solutionDetail.content);
  151. this.solutionDetail.date_time = timestampToTime(this.solutionDetail.date_time);
  152. this.timer = setTimeout(()=>{
  153. this.addRead();
  154. },1000*10)
  155. },
  156. mounted() {
  157. this.$root.$on('changeLang',this.switchLang)
  158. this.isPhone = isMediaView(0,1024);
  159. // console.log(this.isPhone);
  160. // console.log(`this.isPhone:${this.isPhone}`);
  161. },
  162. beforeDestroy() {
  163. if (this.timer){
  164. clearTimeout(this.timer);
  165. }
  166. },
  167. methods:{
  168. getLangText(str) {
  169. return langMap.getText(this.lang, str);
  170. },
  171. getAbbrText(str) {
  172. return langMap.getAbbrText(this.lang, str);
  173. },
  174. async addRead(){
  175. let err,res;
  176. let url = apiMap.addPageRead.path;
  177. url += `?id=${this.solutionId}`;
  178. [err,res] = await handle(this.$axios.$get(url));
  179. if(err) {
  180. console.log(err);
  181. return alert(err.message);
  182. }
  183. console.log(typeof res.code)
  184. if(res.code === 1){
  185. // this.solutionDetail.hits = res.data;
  186. console.log('page add hits ok')
  187. }else{
  188. console.log('not match result');
  189. console.log(res);
  190. }
  191. },
  192. }
  193. }
  194. </script>
  195. <style scoped>
  196. .big-title {
  197. margin: 5px auto;
  198. justify-content: left;
  199. }
  200. .solution-info{
  201. /* 两边布局*/
  202. display: flex;
  203. flex-direction: row;
  204. justify-content: space-between;
  205. align-items: flex-start;
  206. flex-wrap: wrap;
  207. font-size: 0.8rem;
  208. color: #999999;
  209. cursor: default;
  210. }
  211. </style>