form.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <xn-form-container
  3. :title="formData.recordId ? '编辑敏感词过滤记录' : '增加敏感词过滤记录'"
  4. :width="700"
  5. :visible="visible"
  6. :destroy-on-close="true"
  7. @close="onClose"
  8. >
  9. <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
  10. <a-form-item label="过滤词语:" name="sensitivityWord">
  11. <a-input v-model:value="formData.sensitivityWord" placeholder="请输入过滤词语" allow-clear />
  12. </a-form-item>
  13. <a-form-item label="帖子:" name="postId">
  14. <a-select
  15. v-model:value="formData.typeId"
  16. show-search
  17. placeholder="请选择帖子"
  18. style="width: 100%"
  19. :options="invitationList"
  20. :filter-option="filterOption"
  21. ></a-select>
  22. </a-form-item>
  23. <a-form-item label="过滤类型:" name="recordType">
  24. <a-select
  25. v-model:value="formData.recordType"
  26. show-search
  27. placeholder="请选择类型"
  28. style="width: 100%"
  29. :options="typeList"
  30. :filter-option="filterOption"
  31. ></a-select>
  32. </a-form-item>
  33. <a-form-item label="用户:" name="userId">
  34. <a-select
  35. v-model:value="formData.userId"
  36. show-search
  37. placeholder="请选择用户"
  38. style="width: 100%"
  39. :options="usertypeOptions"
  40. :filter-option="filterOption"
  41. ></a-select>
  42. </a-form-item>
  43. </a-form>
  44. <template #footer>
  45. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  46. <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
  47. </template>
  48. </xn-form-container>
  49. </template>
  50. <script setup name="forumSensitivityRecordForm">
  51. import { cloneDeep } from 'lodash-es'
  52. import { required } from '@/utils/formRules'
  53. import forumSensitivityRecordApi from '@/api/forum/forumSensitivityRecordApi'
  54. import forumApi from '@/api/forum/forumApi'
  55. // 抽屉状态
  56. const visible = ref(false)
  57. const emit = defineEmits({ successful: null })
  58. const formRef = ref()
  59. // 表单数据
  60. const formData = ref({})
  61. const submitLoading = ref(false)
  62. //用户
  63. const usertypeOptions = ref([])
  64. //帖子
  65. const invitationList = ref([])
  66. // 打开抽屉
  67. const onOpen = (record) => {
  68. visible.value = true
  69. if (record) {
  70. let recordData = cloneDeep(record)
  71. formData.value = Object.assign({}, recordData)
  72. }
  73. forumApi.allUserList().then((data) => {
  74. usertypeOptions.value = data.map((r) => {
  75. return {
  76. label: r.name,
  77. value: r.id,
  78. ...r
  79. }
  80. })
  81. })
  82. forumApi
  83. .forumList({
  84. current: 1,
  85. size: 999999999,
  86. sortOrder: 0
  87. })
  88. .then((data) => {
  89. invitationList.value = data.records.map((r) => {
  90. return {
  91. label: r.postTitle,
  92. value: r.postId,
  93. ...r
  94. }
  95. })
  96. })
  97. }
  98. // 关闭抽屉
  99. const onClose = () => {
  100. formRef.value.resetFields()
  101. formData.value = {}
  102. visible.value = false
  103. }
  104. //类型
  105. const typeList = ref([
  106. {
  107. label: '发帖',
  108. value: 0
  109. },
  110. {
  111. label: '回复',
  112. value: 1
  113. }
  114. ])
  115. const filterOption = (input, option) => {
  116. return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
  117. }
  118. // 默认要校验的
  119. const formRules = {}
  120. // 验证并提交数据
  121. const onSubmit = () => {
  122. formRef.value.validate().then(() => {
  123. submitLoading.value = true
  124. const formDataParam = cloneDeep(formData.value)
  125. forumSensitivityRecordApi
  126. .forumSensitivityRecordSubmitForm(formDataParam, formDataParam.recordId)
  127. .then(() => {
  128. onClose()
  129. emit('successful')
  130. })
  131. .finally(() => {
  132. submitLoading.value = false
  133. })
  134. })
  135. }
  136. // 抛出函数
  137. defineExpose({
  138. onOpen
  139. })
  140. </script>