index.vue 6.6 KB

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