info.vue 3.0 KB

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