blogs.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <div class="blogs-page">
  3. <div class="title">个人博客管理</div>
  4. <el-table :data="tableData" border style="width: 100%">
  5. <el-table-column fixed prop="id" label="博客id" />
  6. <el-table-column fixed prop="name" label="博客名称">
  7. <template slot-scope="scope">
  8. <el-button type="text" @click="showBlog(scope.row)" size="small">{{
  9. scope.row.name
  10. }}</el-button>
  11. </template>
  12. </el-table-column>
  13. <el-table-column fixed prop="time" label="发布时间" />
  14. <el-table-column fixed prop="updateTime" label="修改时间" />
  15. <el-table-column fixed prop="likes" label="点赞量" />
  16. <el-table-column label="操作">
  17. <!-- <template slot-scope="scope">-->
  18. <template slot-scope="scope">
  19. <!-- <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>-->
  20. <el-button type="text" @click="editBlog(scope.row)" size="small"
  21. >编辑</el-button
  22. >
  23. <el-button type="text" @click="deleteBlog(scope.row)" size="small"
  24. >删除</el-button
  25. >
  26. </template>
  27. </el-table-column>
  28. </el-table>
  29. <br />
  30. <el-pagination
  31. background
  32. layout="prev, pager, next"
  33. :current-page="size"
  34. :total="total"
  35. @current-change="sizeChange"
  36. :pager-count="this.pageSize"
  37. >
  38. </el-pagination>
  39. </div>
  40. </template>
  41. <script>
  42. import { getBlogs, delBlog } from "@/api";
  43. export default {
  44. name: " blogs",
  45. data() {
  46. return {
  47. tableData: [],
  48. total: 0,
  49. pageSize: 15,
  50. size: 1,
  51. };
  52. },
  53. props: {
  54. userInfo: {
  55. type: Object,
  56. default: () => {},
  57. },
  58. },
  59. mounted() {
  60. this.pageInit();
  61. },
  62. methods: {
  63. async pageInit() {
  64. if (!this.userInfo?.id) return;
  65. const res = await getBlogs({
  66. userId: this.userInfo.id,
  67. size: this.size,
  68. pageSize: this.pageSize,
  69. });
  70. console.log(48, res);
  71. this.tableData = res.data.list;
  72. this.total = res.data.total;
  73. },
  74. deleteBlog(row) {
  75. this.$confirm("此操作将永久删除该文章, 是否继续?", "提示", {
  76. confirmButtonText: "确定",
  77. cancelButtonText: "取消",
  78. type: "warning",
  79. })
  80. .then(async () => {
  81. const res = await delBlog({ id: row.id });
  82. this.$message({
  83. type: "success",
  84. message: "删除成功!",
  85. });
  86. })
  87. .catch(() => {
  88. this.$message({
  89. type: "info",
  90. message: "已取消删除",
  91. });
  92. });
  93. },
  94. editBlog(row) {
  95. this.$router.push({
  96. path: "blog",
  97. query: {
  98. id: row.id,
  99. },
  100. });
  101. },
  102. sizeChange(size) {
  103. this.size = size;
  104. this.pageInit();
  105. },
  106. showBlog(row) {
  107. this.$router.push({
  108. path: "/blogDetails",
  109. query: {
  110. id: row.id,
  111. },
  112. });
  113. },
  114. },
  115. };
  116. </script>
  117. <style lang="less" scoped>
  118. .blogs-page {
  119. //margin-left: 0;
  120. //width: 100vw;
  121. background-color: #f8f9fb;
  122. padding: 24px;
  123. //margin-top: 350px;
  124. .title {
  125. text-align: left;
  126. }
  127. }
  128. </style>