replyForm.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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="24">
  15. <a-form-item label="内容:" name="replyContent">
  16. <xn-editor v-model="formData.replyContent" placeholder="请输入" :height="300"></xn-editor>
  17. </a-form-item>
  18. </a-col>
  19. </a-row>
  20. </a-form>
  21. <template #footer>
  22. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  23. <a-button type="primary" :loading="submitLoading" @click="onSubmit">保存</a-button>
  24. </template>
  25. </xn-form-container>
  26. </template>
  27. <script setup>
  28. import { required } from '@/utils/formRules'
  29. import SnowflakeId from 'snowflake-id'
  30. import tool from '@/utils/tool'
  31. import forumApi from '@/api/forum/forumApi'
  32. import XnEditor from '@/components/Editor/index.vue'
  33. // 默认是关闭状态
  34. const visible = ref(false)
  35. const emit = defineEmits({ successful: null })
  36. const formRef = ref()
  37. const treeData = ref([])
  38. // 表单数据,也就是默认给一些数据
  39. const formData = ref({})
  40. // 默认展开的节点(顶级)
  41. const submitLoading = ref(false)
  42. // 模块ID
  43. const moduleId = ref('')
  44. //回复ID
  45. const replyid = ref('')
  46. //类型
  47. const typeOptions = ref([])
  48. const handleChange = (value) => {
  49. searchFormState.typeId = value
  50. table.value.refresh(true)
  51. }
  52. const filterOption = (input, option) => {
  53. return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
  54. }
  55. // 打开抽屉
  56. const onOpen = (record, module, childId, formType) => {
  57. moduleId.value = module ?? record.postId
  58. replyid.value = childId ?? '-1'
  59. visible.value = true
  60. formData.value.formType = formType
  61. if (formType) {
  62. formData.value.replyContent = record.replyContent
  63. } else {
  64. formData.value.replyContent = ''
  65. }
  66. }
  67. // 关闭抽屉
  68. const onClose = () => {
  69. formRef.value.resetFields()
  70. visible.value = false
  71. }
  72. // 默认要校验的
  73. const formRules = {
  74. replyContent: [required('请输入内容')]
  75. }
  76. const categoryOptions = tool.dictList('MENU_TYPE')
  77. const visibleOptions = tool.dictList('MENU_VISIBLE')
  78. // 验证并提交数据
  79. const onSubmit = () => {
  80. submitLoading.value = true
  81. formRef.value.validate().then(() => {
  82. let params = {}
  83. if (formData.value.formType) {
  84. params = {
  85. ...formData.value,
  86. replyId: replyid.value
  87. }
  88. } else {
  89. params = {
  90. ...formData.value,
  91. postId: moduleId.value,
  92. parentId: replyid.value
  93. }
  94. }
  95. forumApi
  96. .submitPostreply(params, formData.value.formType)
  97. .then(() => {
  98. onClose()
  99. emit('successful')
  100. })
  101. .finally(() => {
  102. submitLoading.value = false
  103. })
  104. })
  105. }
  106. // 调用这个函数将子组件的一些数据和方法暴露出去
  107. defineExpose({
  108. onOpen
  109. })
  110. </script>