CommentList.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="app-container">
  3. <a-card :bordered="false">
  4. <SearchForm ref="SearchForm" @reloadData="reloadData"/>
  5. <s-table
  6. ref="table"
  7. size="default"
  8. rowKey="id"
  9. :columns="columns"
  10. :data="loadData"
  11. :alert="options.alert"
  12. :rowSelection="options.rowSelection"
  13. showPagination="true"
  14. >
  15. <span slot="parentUserName" slot-scope="text">
  16. <template>
  17. <a v-if="text==null">自主留言</a>
  18. <a v-else>{{text}}</a>
  19. </template>
  20. </span>
  21. <span slot="content" slot-scope="text">
  22. <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
  23. </span>
  24. <span slot="postTitle" slot-scope="text">
  25. <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
  26. </span>
  27. <!-- 添加操作 -->
  28. <span slot="action" slot-scope="text, record">
  29. <template>
  30. <a @click="handleEdit(record)">回复</a>
  31. <a-divider type="vertical" />
  32. <a-popconfirm
  33. title="确定删除这条评论?"
  34. @confirm="handleDelete(record)"
  35. @cancel="cancel"
  36. okText="Yes"
  37. cancelText="No"
  38. >
  39. <a href="#">删除</a>
  40. </a-popconfirm>
  41. </template>
  42. </span>
  43. </s-table>
  44. <CreateForm
  45. :formType="formType"
  46. :visible="visible"
  47. ref="createCommentForm"
  48. @resetData="resetData"
  49. @refreshTable="refreshTable"
  50. />
  51. </a-card>
  52. </div>
  53. </template>
  54. <script>
  55. import { STable, Ellipsis } from '@/components'
  56. import { table, filters } from './comment-constants'
  57. import CreateForm from './modules/CreateForm'
  58. import { fetchCommentLists, deleteComment } from '@/api/comment'
  59. import SearchForm from './modules/SearchForm'
  60. export default {
  61. name: 'CommentList',
  62. components: {
  63. CreateForm,
  64. STable,
  65. Ellipsis,
  66. SearchForm
  67. },
  68. filters: filters,
  69. data () {
  70. return {
  71. queryParam: {},
  72. loadData: parameter => {
  73. return fetchCommentLists(Object.assign(parameter, this.queryParam))
  74. .then(res => {
  75. return res
  76. })
  77. },
  78. options: {
  79. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  80. rowSelection: {
  81. selectedRowKeys: this.selectedRowKeys,
  82. onChange: this.handleSelectChange
  83. }
  84. },
  85. columns: table.columns,
  86. visible: false,
  87. formType: 'create'
  88. }
  89. },
  90. methods: {
  91. resetData (flag) {
  92. this.visible = flag
  93. this.record = null
  94. },
  95. refreshTable () {
  96. this.$refs.table.refresh()
  97. },
  98. reloadData (queryParam) {
  99. this.queryParam = queryParam
  100. this.refreshTable()
  101. },
  102. createHandler () {
  103. this.formType = 'create'
  104. this.visible = true
  105. this.$refs.createCommentForm.resetForm()
  106. },
  107. handleEdit (record) {
  108. this.$refs.createCommentForm.handleEdit(record)
  109. this.formType = 'edit'
  110. this.visible = true
  111. },
  112. handleSub () {
  113. this.visible = true
  114. },
  115. handleDelete (row) {
  116. deleteComment(row.id).then(res => {
  117. this.$refs.table.refresh()
  118. })
  119. },
  120. cancel () {},
  121. handleSelectChange (value) {
  122. console.log(`Selected: ${value}`)
  123. }
  124. }
  125. }
  126. </script>
  127. <style scoped>
  128. .edit-input {
  129. padding-right: 100px;
  130. }
  131. .cancel-btn {
  132. position: absolute;
  133. right: 15px;
  134. top: 10px;
  135. }
  136. </style>