edit.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <script>
  2. import ArticleAdd from "~/pages/manger/news/add";
  3. import {getQueryString} from "../../../until/domTool";
  4. import {unescapeHtml} from "../../../until/unescapeHtml";
  5. import {timestampToTime} from "../../../until/time";
  6. import {rCode} from "../../../map/rcodeMap_esm";
  7. import {handle} from "~/until/handle";
  8. import {apiMap, baseUrl} from "~/map/apiMap";
  9. export default {
  10. name: "articleEdit",
  11. components: {ArticleAdd},
  12. data() {
  13. return {
  14. articleInfo: {}
  15. }
  16. },
  17. beforeMount() {
  18. // 获取路径中的id值
  19. this.newsId = getQueryString('id');
  20. if( !this.newsId ){
  21. this.$message.error('未获取到文章id');
  22. window.location.href = "/manger/news";
  23. return ;
  24. }
  25. console.log(this.newsId);
  26. this.getArticleInfo();
  27. },
  28. methods: {
  29. async getArticleInfo() {
  30. let newsId = this.newsId;
  31. if( !newsId ){
  32. this.$message.error('未获取到文章id');
  33. return;
  34. }
  35. this.loading = true;
  36. let [err,res] = await handle(this.$axios.get(`${apiMap.newsInfo.path}/${newsId}`));
  37. this.loading = false;
  38. if(err){
  39. this.$message.error('获取文章信息失败');
  40. return console.log(err);
  41. }
  42. let result = res.data;
  43. if (result.code === rCode.OK){
  44. this.$message.success('');
  45. let pageData = result.data;
  46. pageData.htmlContent = unescapeHtml(pageData.content);
  47. pageData.createTime = timestampToTime(pageData.date_time);
  48. //
  49. this.articleInfo = pageData;
  50. console.log(this.newsInfo);
  51. this.$message.success('获取文章信息成功');
  52. }else{
  53. this.$message.error(`获取文章信息失败,${result.msg}`);
  54. }
  55. }
  56. }
  57. }
  58. </script>
  59. <template>
  60. <article-add :article="articleInfo"/>
  61. </template>
  62. <style scoped>
  63. </style>