reportForm.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <xn-form-container
  3. title="举报"
  4. :height="500"
  5. placement="bottom"
  6. :mask="false"
  7. style="width: 960px; left: calc(50% - 960px / 2)"
  8. :visible="visible"
  9. :destroy-on-close="true"
  10. @close="onClose"
  11. >
  12. <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
  13. <a-row :gutter="16">
  14. <a-col :span="12">
  15. <a-form-item label="举报类型:" name="reportReasonType">
  16. <a-select
  17. v-model:value="formData.reportReasonType"
  18. placeholder="所有分类"
  19. style="width: 100%"
  20. :options="typeOptions"
  21. @change="handleChange"
  22. ></a-select>
  23. </a-form-item>
  24. </a-col>
  25. <a-col :span="12">
  26. <a-form-item label="证据图片:" name="evidenceScreenshot">
  27. <UpLoadImg ref="upLoadImgRef" urlType="2" @handlerUpImage="handlerUpImage"></UpLoadImg>
  28. </a-form-item>
  29. </a-col>
  30. <a-col :span="24">
  31. <a-form-item label="举报原因:" name="reportDetail">
  32. <a-textarea
  33. v-model:value="formData.reportDetail"
  34. placeholder="请输入举报原因"
  35. :rows="4"
  36. show-count
  37. :maxlength="500"
  38. />
  39. </a-form-item>
  40. </a-col>
  41. </a-row>
  42. </a-form>
  43. <template #footer>
  44. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  45. <a-button type="primary" :loading="submitLoading" @click="onSubmit">保存</a-button>
  46. </template>
  47. </xn-form-container>
  48. </template>
  49. <script setup>
  50. import { required } from '@/utils/formRules'
  51. import SnowflakeId from 'snowflake-id'
  52. import tool from '@/utils/tool'
  53. import forumApi from '@/api/forum/forumApi'
  54. import XnEditor from '@/components/Editor/index.vue'
  55. // 默认是关闭状态
  56. const visible = ref(false)
  57. const emit = defineEmits({ successful: null })
  58. const formRef = ref()
  59. const treeData = ref([])
  60. // 表单数据,也就是默认给一些数据
  61. const formData = ref({})
  62. // 默认展开的节点(顶级)
  63. const submitLoading = ref(false)
  64. // 模块ID
  65. const moduleId = ref('')
  66. //回复ID
  67. const replyid = ref('')
  68. //类型
  69. const typeOptions = ref([
  70. {
  71. label: '垃圾广告',
  72. value: 0
  73. },
  74. {
  75. label: '色情内容',
  76. value: 1
  77. },
  78. {
  79. label: '人身攻击',
  80. value: 2
  81. },
  82. {
  83. label: '整治敏感',
  84. value: 3
  85. },
  86. {
  87. label: '其他',
  88. value: 4
  89. }
  90. ])
  91. const handleChange = (value) => {
  92. formData.value.reportReasonType = value
  93. }
  94. const filterOption = (input, option) => {
  95. return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
  96. }
  97. const handlerUpImage = (id) => {
  98. formData.value.evidenceScreenshot = id
  99. }
  100. // 打开抽屉
  101. const onOpen = (record, module) => {
  102. moduleId.value = module
  103. visible.value = true
  104. }
  105. // 关闭抽屉
  106. const onClose = () => {
  107. formRef.value.resetFields()
  108. visible.value = false
  109. }
  110. // 默认要校验的
  111. const formRules = {
  112. reportReasonType: [required('请选择举报类型')],
  113. reportDetail: [required('请输入举报原因')],
  114. evidenceScreenshot: [required('请上传证据图片')]
  115. }
  116. const categoryOptions = tool.dictList('MENU_TYPE')
  117. const visibleOptions = tool.dictList('MENU_VISIBLE')
  118. // 验证并提交数据
  119. const onSubmit = () => {
  120. formRef.value.validate().then(() => {
  121. submitLoading.value = true
  122. forumApi
  123. .reportinfoAdd({
  124. ...formData.value,
  125. postId: moduleId.value
  126. })
  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>