feat: 咨询管理代码审查

This commit is contained in:
ilhamtahir committed 2024-12-19 22:13:37 +08:00
1 parent de50ca5f66
commit aed501d308
2 files changed
+14 -20

No files matched your search

+2 -2
View File
@@ -6,7 +6,7 @@ export const searchArticlesRequest = (articleFilterParam:ArticleSearchFilter ) =
return httpClient.get<PageResult<Article>>('/articles',articleFilterParam) return httpClient.get<PageResult<Article>>('/articles',articleFilterParam)
} }
export const createArticlesRequest = (article: CreateArticleRequest) => { export const createArticle = (article: CreateArticleRequest) => {
return httpClient.post<Article>('/articles',article) return httpClient.post<Article>('/articles',article)
} }
@@ -18,7 +18,7 @@ export const searchArticlesByIdRequest = (id: string) => {
return httpClient.get<Article>(`/articles/${id}`) return httpClient.get<Article>(`/articles/${id}`)
} }
export const updateArticlesByIdRequest = (id: string,article:CreateArticleRequest) => { export const updateArticle = (id: string, article:CreateArticleRequest) => {
return httpClient.put<Article>(`/articles/${id}`,article) return httpClient.put<Article>(`/articles/${id}`,article)
} }
+12 -18
View File
@@ -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 article: Article | null
categoryList: Category[] | [] 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 () => { const handleSave = async () => {
if (formRef.value) { 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"> <TFormItem label="内容:" name="content"><TTextarea v-model="articleData.content"></TTextarea> </TFormItem>
<TTextarea v-model="articleData.content"></TTextarea>
</TFormItem>
</TForm> </TForm>
</t-space> </t-space>
</t-dialog> </t-dialog>