info.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. deleteArticle(){
  64. this.$confirm({
  65. content: '确定要删除吗?',
  66. okText: '确定',
  67. cancelText: '取消',
  68. onOk: () => {
  69. this.executeDeleteArticle();
  70. }});
  71. },
  72. async executeDeleteArticle(){
  73. let newsId = this.newsInfo.id;
  74. if (!newsId)
  75. return this.$message.error('未获取到文章id');
  76. let url = apiMap.newsDelete.path;
  77. url += `?id=${newsId}`
  78. let [err,res] = await handle(this.$axios.delete(url, {id: newsId}));
  79. if(err){
  80. this.$message.error(`[删除文章] 失败:${err.message}`)
  81. console.log(err)
  82. return err
  83. }
  84. let result = res.data
  85. if(result.code !== rCode.OK) {
  86. this.$message.error(`[删除文章] 失败:${result.msg}`)
  87. return result
  88. }
  89. this.$message.success(`[删除文章] 成功`)
  90. window.location.href = "/manger/news";
  91. }
  92. }
  93. }
  94. </script>
  95. <template>
  96. <div class="w-full p-2">
  97. <rounded-title class="text-xl flex align-items justify-around">
  98. <div>
  99. <span>文章详情</span>
  100. <a href="/manger/news"
  101. class="px-10 h-full ml-5 rounded bg-blue-400 text-white cursor-pointer
  102. hover:text-orange-500 ">文章中心</a>
  103. </div>
  104. <a
  105. :href="editUrl"
  106. class="edit-btn custom-btn btn-13">编辑</a>
  107. <a-button @click="deleteArticle">
  108. <a-icon type="delete" />
  109. </a-button>
  110. </rounded-title>
  111. <div class="page-content-box w-full mt-2 p-0.5 rounded bg-white">
  112. <div class="page-title">{{newsInfo.title}}</div>
  113. <div class="w-full mt-2">
  114. <div class="w-full">
  115. <div class="w-full flex justify-between">
  116. <div class="w-1/2">
  117. <span>作者:</span>
  118. <span>{{newsInfo.author}}</span>
  119. </div>
  120. <div class="w-1/2">
  121. <span>发布时间:</span>
  122. <span>{{newsInfo.createTime}}</span>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. <div class="w-full mt-2">
  128. <div class="w-full">
  129. <div class="w-full mt-2 border border-gray-400 rounded p-0.5" v-html="newsInfo.htmlContent">
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. </div>
  135. </template>
  136. <style scoped>
  137. .page-title{
  138. font-size: 1.5rem;
  139. font-weight: bold;
  140. }
  141. </style>