|
@@ -8,13 +8,12 @@ import type {
|
|
|
TdSelectProps
|
|
TdSelectProps
|
|
|
} from 'tdesign-vue-next'
|
|
} from 'tdesign-vue-next'
|
|
|
import { MessagePlugin } from 'tdesign-vue-next'
|
|
import { MessagePlugin } from 'tdesign-vue-next'
|
|
|
-import { updateArticlesByIdRequest, createArticlesRequest } from '@/api/article'
|
|
|
|
|
|
|
+import { updateArticle, createArticle } from '@/api/article'
|
|
|
import { searchCategories } from '@/api/category'
|
|
import { searchCategories } from '@/api/category'
|
|
|
const props = defineProps<{
|
|
const props = defineProps<{
|
|
|
- isEdit?: Boolean | null
|
|
|
|
|
headerTitle?: String | null
|
|
headerTitle?: String | null
|
|
|
- article?: Article | null
|
|
|
|
|
- categoryList: Category[] | []
|
|
|
|
|
|
|
+ article: Article | null
|
|
|
|
|
+ categoryList: Category[]
|
|
|
}>()
|
|
}>()
|
|
|
const formRef = ref<FormInstanceFunctions | null>(null)
|
|
const formRef = ref<FormInstanceFunctions | null>(null)
|
|
|
const headerText = computed(() => `${props.article ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
|
const headerText = computed(() => `${props.article ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
|
@@ -92,27 +91,24 @@ const emit = defineEmits<{
|
|
|
success: [void]
|
|
success: [void]
|
|
|
onInputChange: [void]
|
|
onInputChange: [void]
|
|
|
}>()
|
|
}>()
|
|
|
-const saveArticleData = async () => {
|
|
|
|
|
- if (formRef.value) {
|
|
|
|
|
|
|
+const handleSave = async () => {
|
|
|
|
|
+ if (!formRef.value) return
|
|
|
const valid = await formRef.value.validate()
|
|
const valid = await formRef.value.validate()
|
|
|
- if (valid && typeof valid === 'boolean') {
|
|
|
|
|
|
|
+ if (valid === true) {
|
|
|
if (props.article) {
|
|
if (props.article) {
|
|
|
- await updateArticlesByIdRequest(props.article.id, articleData)
|
|
|
|
|
|
|
+ await updateArticle(props.article.id, articleData)
|
|
|
} else {
|
|
} else {
|
|
|
- await createArticlesRequest(articleData)
|
|
|
|
|
|
|
+ await createArticle(articleData)
|
|
|
}
|
|
}
|
|
|
- MessagePlugin.success(`${props.isEdit ? '编辑' : '创建'}咨询成功`)
|
|
|
|
|
|
|
+ MessagePlugin.success(`${props.article ? '编辑' : '创建'}咨询成功`)
|
|
|
emit('success')
|
|
emit('success')
|
|
|
- return
|
|
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
const handleCloseDialog = () => {
|
|
const handleCloseDialog = () => {
|
|
|
// 数据&&规则校验结果重置
|
|
// 数据&&规则校验结果重置
|
|
|
- if (formRef.value) {
|
|
|
|
|
|
|
+ if (!formRef.value) return
|
|
|
formRef.value.reset()
|
|
formRef.value.reset()
|
|
|
formRef.value.clearValidate()
|
|
formRef.value.clearValidate()
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const categoryOptions = ref<TdSelectProps['options']>([])
|
|
const categoryOptions = ref<TdSelectProps['options']>([])
|
|
@@ -138,7 +134,7 @@ fetchCategories('')
|
|
|
:confirmBtn="confirmBtnText"
|
|
:confirmBtn="confirmBtnText"
|
|
|
:closeOnOverlayClick="false"
|
|
:closeOnOverlayClick="false"
|
|
|
@close="handleCloseDialog"
|
|
@close="handleCloseDialog"
|
|
|
- @confirm="saveArticleData"
|
|
|
|
|
|
|
+ @confirm="handleSave"
|
|
|
>
|
|
>
|
|
|
<t-space direction="vertical" style="width: 100%">
|
|
<t-space direction="vertical" style="width: 100%">
|
|
|
<TForm ref="formRef" :data="articleData" :rules="rules" resetType="initial">
|
|
<TForm ref="formRef" :data="articleData" :rules="rules" resetType="initial">
|
|
@@ -154,9 +150,7 @@ fetchCategories('')
|
|
|
@search="fetchCategories"
|
|
@search="fetchCategories"
|
|
|
/>
|
|
/>
|
|
|
</TFormItem>
|
|
</TFormItem>
|
|
|
- <TFormItem label="内容:" name="content">
|
|
|
|
|
- <TTextarea v-model="articleData.content"></TTextarea>
|
|
|
|
|
- </TFormItem>
|
|
|
|
|
|
|
+ <TFormItem label="内容:" name="content"><TTextarea v-model="articleData.content"></TTextarea> </TFormItem>
|
|
|
</TForm>
|
|
</TForm>
|
|
|
</t-space>
|
|
</t-space>
|
|
|
</t-dialog>
|
|
</t-dialog>
|