info.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <script>
  2. import RoundedTitle from "@/components/public/roundedTitle.vue";
  3. import {getQueryString} from "@/until/domTool";
  4. import {apiMap} from "@/map/apiMap";
  5. import {rCode} from "@/map/rcodeMap_esm";
  6. import {handle} from "@/until/handle";
  7. import {unescapeHtml} from "@/until/unescapeHtml";
  8. import {timestampToTime} from "@/until/time";
  9. export default {
  10. name: "newsInfo",
  11. components: {RoundedTitle},
  12. data(){
  13. return {
  14. loading: false,
  15. newsInfo: {},
  16. }
  17. },
  18. beforeMount() {
  19. // 获取路径中的id值
  20. this.newsId = getQueryString('id');
  21. if( !this.newsId ){
  22. this.$message.error('未获取到文章id');
  23. window.location.href = "/manger/news";
  24. return ;
  25. }
  26. console.log(this.newsId);
  27. this.loadNewsInfo();
  28. },
  29. methods: {
  30. async loadNewsInfo(){
  31. let newsId = this.newsId;
  32. if( !newsId ){
  33. this.$message.error('未获取到文章id');
  34. return;
  35. }
  36. this.loading = true;
  37. let [err,res] = await handle(this.$axios.get(`${apiMap.newsInfo.path}/${newsId}`));
  38. this.loading = false;
  39. if(err){
  40. this.$message.error('获取文章信息失败');
  41. return console.log(err);
  42. }
  43. let result = res.data;
  44. if (result.code === rCode.OK){
  45. this.$message.success('');
  46. let pageData = result.data;
  47. pageData.htmlContent = unescapeHtml(pageData.content);
  48. pageData.createTime = timestampToTime(pageData.date_time);
  49. //
  50. this.newsInfo = result.data;
  51. console.log(this.newsInfo);
  52. }else{
  53. this.$message.error(`获取文章信息失败,${result.msg}`);
  54. }
  55. }
  56. }
  57. }
  58. </script>
  59. <template>
  60. <div class="w-full p-2">
  61. <rounded-title class="text-xl">
  62. <span>文章详情</span>
  63. <a href="/manger/news"
  64. class="px-10 h-full ml-5 rounded bg-blue-400 text-white cursor-pointer
  65. hover:text-orange-500 ">文章中心</a>
  66. </rounded-title>
  67. <div class="page-content-box w-full mt-2 p-0.5 rounded bg-white">
  68. <div class="page-title">{{newsInfo.title}}</div>
  69. <div class="w-full mt-2">
  70. <div class="w-full">
  71. <div class="w-full flex justify-between">
  72. <div class="w-1/2">
  73. <span>作者:</span>
  74. <span>{{newsInfo.author}}</span>
  75. </div>
  76. <div class="w-1/2">
  77. <span>发布时间:</span>
  78. <span>{{newsInfo.createTime}}</span>
  79. </div>
  80. </div>
  81. </div>
  82. </div>
  83. <div class="w-full mt-2">
  84. <div class="w-full">
  85. <div class="w-full mt-2 border border-gray-400 rounded p-0.5" v-html="newsInfo.htmlContent">
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. </template>
  92. <style scoped>
  93. .page-title{
  94. font-size: 1.5rem;
  95. font-weight: bold;
  96. }
  97. </style>