comments.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <div class="blogs-page">
  3. <div class="title">
  4. <div>评论管理</div>
  5. </div>
  6. <el-table :data="tableData" border style="width: 100%">
  7. <el-table-column fixed prop="id" label="评论id" />
  8. <el-table-column fixed prop="content" label="评论内容">
  9. <template slot-scope="scope">
  10. <div v-html="scope.row.content"></div>
  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 label="操作">
  16. <!-- <template slot-scope="scope">-->
  17. <template slot-scope="scope">
  18. <!-- <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>-->
  19. <el-button type="text" @click="editComments(scope.row)" size="small"
  20. >编辑</el-button
  21. >
  22. <el-button type="text" @click="deleteTag(scope.row)" size="small"
  23. >删除</el-button
  24. >
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. <br />
  29. <el-pagination
  30. background
  31. layout="prev, pager, next"
  32. :current-page="size"
  33. :total="total"
  34. @current-change="sizeChange"
  35. :pager-count="this.pageSize"
  36. >
  37. </el-pagination>
  38. <el-dialog
  39. :title="form.id ? '编辑' : '新增'"
  40. :visible.sync="dialogVisible"
  41. width="70%"
  42. :before-close="handleClose"
  43. >
  44. <div>
  45. <vue2-tinymce-editor
  46. :options="options"
  47. ref="tinymce"
  48. v-model="form.content"
  49. ></vue2-tinymce-editor>
  50. </div>
  51. <span slot="footer" class="dialog-footer">
  52. <el-button @click="dialogVisible = false">取 消</el-button>
  53. <el-button type="primary" @click="pushCommentFn">确 定</el-button>
  54. </span>
  55. </el-dialog>
  56. </div>
  57. </template>
  58. <script>
  59. import { getComments, delComments, pushComment } from "@/api";
  60. import loginCom from "@/components/login.vue";
  61. import { Vue2TinymceEditor } from "vue2-tinymce-editor";
  62. export default {
  63. name: " blogs",
  64. data() {
  65. return {
  66. tableData: [],
  67. total: 0,
  68. pageSize: 15,
  69. size: 1,
  70. dialogVisible: false,
  71. form: {
  72. content: "",
  73. },
  74. options: {
  75. language_url: "./tinymce/lang/zh-Hans.js",
  76. language: "zh-Hans", // 注意大小写
  77. },
  78. tinymceKey: "12131",
  79. };
  80. },
  81. components: { Vue2TinymceEditor, loginCom },
  82. props: {
  83. userInfo: {
  84. type: Object,
  85. default: () => {},
  86. },
  87. },
  88. mounted() {
  89. this.pageInit();
  90. },
  91. methods: {
  92. async pageInit() {
  93. if (!this.userInfo?.id) return;
  94. const res = await getComments({
  95. userId: this.userInfo.id,
  96. size: this.size,
  97. pageSize: this.pageSize,
  98. });
  99. this.tableData = res.data.list;
  100. this.total = res.data.total;
  101. },
  102. deleteTag(row) {
  103. this.$confirm("此操作将永久删除该评论, 是否继续?", "提示", {
  104. confirmButtonText: "确定",
  105. cancelButtonText: "取消",
  106. type: "warning",
  107. })
  108. .then(async () => {
  109. const res = await delComments({ id: row.id });
  110. this.$message({
  111. type: "success",
  112. message: "删除成功!",
  113. });
  114. this.pageSize = 15;
  115. this.size = 1;
  116. this.pageInit();
  117. })
  118. .catch(() => {
  119. this.$message({
  120. type: "info",
  121. message: "已取消删除",
  122. });
  123. });
  124. },
  125. editComments(row) {
  126. this.dialogVisible = true;
  127. this.form = {
  128. ...row,
  129. };
  130. },
  131. openAddTag() {
  132. this.dialogVisible = true;
  133. this.form = {};
  134. },
  135. async pushCommentFn() {
  136. if (this.form?.id) {
  137. const res = await pushComment({
  138. ...this.form,
  139. userId: this.userInfo.id,
  140. token: window.localStorage.getItem("token"),
  141. });
  142. console.log(res);
  143. this.dialogVisible = false;
  144. this.$message({
  145. type: "success",
  146. message: "编辑成功!",
  147. });
  148. }
  149. this.pageSize = 15;
  150. this.size = 1;
  151. this.pageInit();
  152. },
  153. sizeChange(size) {
  154. this.size = size;
  155. this.pageInit();
  156. },
  157. handleClose() {},
  158. },
  159. };
  160. </script>
  161. <style lang="less" scoped>
  162. .blogs-page {
  163. //margin-left: 0;
  164. //width: 100vw;
  165. background-color: #f8f9fb;
  166. padding: 24px;
  167. //margin-top: 350px;
  168. .title {
  169. text-align: left;
  170. display: flex;
  171. justify-content: space-between;
  172. align-items: center;
  173. }
  174. }
  175. </style>