| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <template>
- <xn-form-container
- :title="formData.recordId ? '编辑敏感词过滤记录' : '增加敏感词过滤记录'"
- :width="700"
- :visible="visible"
- :destroy-on-close="true"
- @close="onClose"
- >
- <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
- <a-form-item label="过滤词语:" name="sensitivityWord">
- <a-input v-model:value="formData.sensitivityWord" placeholder="请输入过滤词语" allow-clear />
- </a-form-item>
- <a-form-item label="帖子:" name="postId">
- <a-select
- v-model:value="formData.typeId"
- show-search
- placeholder="请选择帖子"
- style="width: 100%"
- :options="invitationList"
- :filter-option="filterOption"
- ></a-select>
- </a-form-item>
- <a-form-item label="过滤类型:" name="recordType">
- <a-select
- v-model:value="formData.recordType"
- show-search
- placeholder="请选择类型"
- style="width: 100%"
- :options="typeList"
- :filter-option="filterOption"
- ></a-select>
- </a-form-item>
- <a-form-item label="用户:" name="userId">
- <a-select
- v-model:value="formData.userId"
- show-search
- placeholder="请选择用户"
- style="width: 100%"
- :options="usertypeOptions"
- :filter-option="filterOption"
- ></a-select>
- </a-form-item>
- </a-form>
- <template #footer>
- <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
- <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
- </template>
- </xn-form-container>
- </template>
- <script setup name="forumSensitivityRecordForm">
- import { cloneDeep } from 'lodash-es'
- import { required } from '@/utils/formRules'
- import forumSensitivityRecordApi from '@/api/forum/forumSensitivityRecordApi'
- import forumApi from '@/api/forum/forumApi'
- // 抽屉状态
- const visible = ref(false)
- const emit = defineEmits({ successful: null })
- const formRef = ref()
- // 表单数据
- const formData = ref({})
- const submitLoading = ref(false)
- //用户
- const usertypeOptions = ref([])
- //帖子
- const invitationList = ref([])
- // 打开抽屉
- const onOpen = (record) => {
- visible.value = true
- if (record) {
- let recordData = cloneDeep(record)
- formData.value = Object.assign({}, recordData)
- }
- forumApi.allUserList().then((data) => {
- usertypeOptions.value = data.map((r) => {
- return {
- label: r.name,
- value: r.id,
- ...r
- }
- })
- })
- forumApi
- .forumList({
- current: 1,
- size: 999999999,
- sortOrder: 0
- })
- .then((data) => {
- invitationList.value = data.records.map((r) => {
- return {
- label: r.postTitle,
- value: r.postId,
- ...r
- }
- })
- })
- }
- // 关闭抽屉
- const onClose = () => {
- formRef.value.resetFields()
- formData.value = {}
- visible.value = false
- }
- //类型
- const typeList = ref([
- {
- label: '发帖',
- value: 0
- },
- {
- label: '回复',
- value: 1
- }
- ])
- const filterOption = (input, option) => {
- return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
- }
- // 默认要校验的
- const formRules = {}
- // 验证并提交数据
- const onSubmit = () => {
- formRef.value.validate().then(() => {
- submitLoading.value = true
- const formDataParam = cloneDeep(formData.value)
- forumSensitivityRecordApi
- .forumSensitivityRecordSubmitForm(formDataParam, formDataParam.recordId)
- .then(() => {
- onClose()
- emit('successful')
- })
- .finally(() => {
- submitLoading.value = false
- })
- })
- }
- // 抛出函数
- defineExpose({
- onOpen
- })
- </script>
|