SensitiveList.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div>
  3. <a-button-group class="create-operate-group">
  4. <a-button size="small" type="primary" id="uploadFileId" class="btnsy" @click="add">新增</a-button>
  5. </a-button-group>
  6. <a-table :columns="columns" :data-source="tableData" :pagination="false" style="width: 100%">
  7. <template #bodyCell="{ column, record }">
  8. <template v-if="column.key === 'action'">
  9. <a-button type="link" size="small" @click="handleEdit(record)">编辑</a-button>
  10. <a-button type="link" size="small" @click="handleDelete(record)" style="color: #f56c6c">删除</a-button>
  11. </template>
  12. </template>
  13. </a-table>
  14. </div>
  15. </template>
  16. <script setup>
  17. import { ref, onMounted } from 'vue'
  18. import { Modal, message } from 'ant-design-vue'
  19. import { addSensitiveList, updateSensitiveList, delSensitiveList } from '@/api/myResource/file' // 假设路径为 '@/api/myResource/file'
  20. const props = defineProps({
  21. tableData: {
  22. required: true,
  23. type: Array
  24. }
  25. })
  26. const emit = defineEmits(['addSensitiveSuccess'])
  27. const columns = [
  28. {
  29. title: '敏感词',
  30. dataIndex: 'word',
  31. key: 'word'
  32. },
  33. {
  34. title: '操作',
  35. key: 'action',
  36. fixed: 'right',
  37. width: 150
  38. }
  39. ]
  40. const add = () => {
  41. Modal.confirm({
  42. title: '请输入敏感词',
  43. content: '敏感词不能为空',
  44. maskClosable: true,
  45. onOk(inputValue) {
  46. if (!inputValue) {
  47. message.error('敏感词不能为空')
  48. return Promise.reject()
  49. }
  50. return addSensitiveList({
  51. word: inputValue
  52. })
  53. .then((res) => {
  54. if (res.code === 0) {
  55. message.success('新增敏感词成功')
  56. emit('addSensitiveSuccess')
  57. } else {
  58. message.error(res.message || '新增失败')
  59. return Promise.reject()
  60. }
  61. })
  62. .catch((err) => {
  63. message.error(JSON.stringify(err))
  64. return Promise.reject()
  65. })
  66. },
  67. onCancel() {
  68. // 用户取消操作
  69. }
  70. })
  71. }
  72. const handleEdit = (row) => {
  73. Modal.confirm({
  74. title: '请输入敏感词',
  75. content: '敏感词不能为空',
  76. maskClosable: true,
  77. defaultInputValue: row.word,
  78. onOk(inputValue) {
  79. if (!inputValue) {
  80. message.error('敏感词不能为空')
  81. return Promise.reject()
  82. }
  83. return updateSensitiveList({
  84. id: row.id,
  85. word: inputValue
  86. })
  87. .then((res) => {
  88. if (res.code === 0) {
  89. message.success('修改敏感词成功')
  90. emit('addSensitiveSuccess')
  91. } else {
  92. message.error(res.message || '修改失败')
  93. return Promise.reject()
  94. }
  95. })
  96. .catch((err) => {
  97. message.error(JSON.stringify(err))
  98. return Promise.reject()
  99. })
  100. },
  101. onCancel() {
  102. // 用户取消操作
  103. }
  104. })
  105. }
  106. const handleDelete = (row) => {
  107. Modal.confirm({
  108. title: '确定删除该敏感词吗?',
  109. onOk() {
  110. return delSensitiveList(row.id)
  111. .then((res) => {
  112. if (res.code === 0) {
  113. message.success('删除敏感词成功')
  114. emit('addSensitiveSuccess')
  115. } else {
  116. message.error(res.message || '删除失败')
  117. return Promise.reject()
  118. }
  119. })
  120. .catch((err) => {
  121. message.error(JSON.stringify(err))
  122. return Promise.reject()
  123. })
  124. },
  125. onCancel() {
  126. // 用户取消操作
  127. }
  128. })
  129. }
  130. onMounted(() => {
  131. // 初始化逻辑
  132. })
  133. </script>
  134. <style lang="less" scoped>
  135. .btnsy {
  136. background-color: #29175b;
  137. border-color: #29175b;
  138. }
  139. :deep(.ant-modal-content) {
  140. .sensitive-prompt-input {
  141. max-width: calc(100% + 0.1px);
  142. }
  143. }
  144. </style>