| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <template>
- <xn-form-container
- :title="formData.id ? '编辑主题' : '增加主题'"
- :width="700"
- :visible="visible"
- :destroy-on-close="true"
- @close="onClose"
- >
- <a-alert
- class="mb-3"
- message="欢迎来到论坛 — 衷心感谢你参与讨论!
- 标题是否清晰明了地描述了主题?看
- 起来有意思么?
- 谁会感兴趣?
- 它为什么重要?
- 你期望从社区中获得什么样的回应?
- 选择常用的词句以便别人能找到你的主题。若想要给主题和类似主题分组,选择一个分类。"
- type="warning"
- />
- <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
- <a-row :gutter="16">
- <a-col :span="12">
- <a-form-item label="标题:" name="postTitle">
- <a-input v-model:value="formData.postTitle" placeholder="请输入显示名称" allow-clear />
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item label="分类:" name="typeId">
- <a-select
- v-model:value="formData.typeId"
- show-search
- placeholder="所有分类"
- style="width: 200px"
- :options="typeOptions"
- :filter-option="filterOption"
- ></a-select>
- </a-form-item>
- </a-col>
- <a-col :span="24">
- <a-form-item label="内容:" name="postContent">
- <xn-editor v-model="formData.postContent" placeholder="请输入" :height="400"></xn-editor>
- </a-form-item>
- </a-col>
- </a-row>
- </a-form>
- <template #footer>
- <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
- <a-button type="primary" :loading="submitLoading" @click="onSubmit">保存</a-button>
- </template>
- </xn-form-container>
- </template>
- <script setup>
- import { required } from '@/utils/formRules'
- import SnowflakeId from 'snowflake-id'
- import tool from '@/utils/tool'
- import forumApi from '@/api/forum/forumApi'
- import XnEditor from '@/components/Editor/index.vue'
- const userInfo = tool.data.get('USER_INFO')
- const typeOptions = ref([])
- // 默认是关闭状态
- const visible = ref(false)
- const emit = defineEmits({ successful: null })
- const formRef = ref()
- const treeData = ref([])
- // 表单数据,也就是默认给一些数据
- const formData = ref({
- postType: 0
- })
- // 默认展开的节点(顶级)
- const defaultExpandedKeys = ref([0])
- const submitLoading = ref(false)
- // 模块ID
- const moduleId = ref('')
- const filterOption = (input, option) => {
- return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0
- }
- // 打开抽屉
- const onOpen = (record, module) => {
- moduleId.value = module
- visible.value = true
- forumApi.forumTypeList().then((data) => {
- typeOptions.value = data.map((r) => {
- return {
- label: r.typeName,
- value: r.typeId,
- ...r
- }
- })
- })
- if (module) {
- formData.value = Object.assign(formData.value, record)
- }
- }
- // 关闭抽屉
- const onClose = () => {
- formRef.value.resetFields()
- visible.value = false
- }
- // 默认要校验的
- const formRules = {
- postTitle: [required('请输入标题')],
- typeId: [required('请选择分类')],
- postContent: [required('请输入内容')]
- }
- const categoryOptions = tool.dictList('MENU_TYPE')
- const visibleOptions = tool.dictList('MENU_VISIBLE')
- // 验证并提交数据
- const onSubmit = () => {
- formRef.value
- .validate()
- .then(() => {
- submitLoading.value = true
- forumApi.submitForm(formData.value, formData.value.postId).then(() => {
- onClose()
- emit('successful')
- })
- })
- .finally(() => {
- submitLoading.value = false
- })
- }
- // 调用这个函数将子组件的一些数据和方法暴露出去
- defineExpose({
- onOpen
- })
- </script>
|