feat: 咨询管理代码审查

This commit is contained in:
ilhamtahir committed 2024-12-19 22:03:31 +08:00
1 parent f2db16447d
commit de50ca5f66
4 files changed
+27 -29

No files matched your search

+1
View File
@@ -37,6 +37,7 @@ declare module 'vue' {
TSpace: typeof import('tdesign-vue-next')['Space'] TSpace: typeof import('tdesign-vue-next')['Space']
TTable: typeof import('tdesign-vue-next')['Table'] TTable: typeof import('tdesign-vue-next')['Table']
TTag: typeof import('tdesign-vue-next')['Tag'] TTag: typeof import('tdesign-vue-next')['Tag']
TTextarea: typeof import('tdesign-vue-next')['Textarea']
TUpload: typeof import('tdesign-vue-next')['Upload'] TUpload: typeof import('tdesign-vue-next')['Upload']
} }
} }
+1 -1
View File
@@ -25,5 +25,5 @@ export interface ArticleSearchFilter extends Partial<Paging>{
export interface CreateArticleRequest{ export interface CreateArticleRequest{
categoryId: string categoryId: string
title: string title: string
content: number content: string
} }
+23 -25
View File
@@ -1,11 +1,10 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { Category } from '@/model/category' import type { Category } from '@/model/category'
import type { Article } from '@/model/article' import type { Article, CreateArticleRequest } from '@/model/article'
import { computed, ref, reactive, watch } from 'vue' import { computed, ref, reactive, watch } from 'vue'
import type { import type {
FormInstanceFunctions, FormInstanceFunctions,
FormProps, FormRules,
SelectInputProps,
TdSelectProps TdSelectProps
} from 'tdesign-vue-next' } from 'tdesign-vue-next'
import { MessagePlugin } from 'tdesign-vue-next' import { MessagePlugin } from 'tdesign-vue-next'
@@ -14,19 +13,16 @@ import { searchCategories } from '@/api/category'
const props = defineProps<{ const props = defineProps<{
isEdit?: Boolean | null 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.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`) const headerText = computed(() => `${props.article ? '编辑' : '创建'}${props.headerTitle || ''}`)
const confirmBtnText = computed(() => (props.isEdit ? '保存' : '确定')) const confirmBtnText = computed(() => (props.article ? '保存' : '确定'))
const articleData = reactive<{ const articleData = reactive<CreateArticleRequest>({ title: '', categoryId: '', content: ''})
categoryName: string,
title: string
}>({ categoryName: '', title: '' })
const rules: FormProps['rules'] = { const rules: FormRules<CreateArticleRequest> = {
name: [ title: [
{ {
required: true, required: true,
message: '咨询标题不能为空', message: '咨询标题不能为空',
@@ -56,7 +52,7 @@ const rules: FormProps['rules'] = {
trigger: 'blur' trigger: 'blur'
} }
], ],
code: [ categoryId: [
{ {
required: true, required: true,
message: '咨询分类不能为空', message: '咨询分类不能为空',
@@ -86,7 +82,9 @@ const rules: FormProps['rules'] = {
watch( watch(
() => props.article, () => props.article,
(newArticleData) => { (newArticleData) => {
Object.assign(articleData, newArticleData) articleData.categoryId = newArticleData?.category.id || ''
articleData.title = newArticleData?.title || ''
articleData.content = newArticleData?.content || ''
}, },
{ deep: true } { deep: true }
) )
@@ -98,11 +96,10 @@ const saveArticleData = async () => {
if (formRef.value) { if (formRef.value) {
const valid = await formRef.value.validate() const valid = await formRef.value.validate()
if (valid && typeof valid === 'boolean') { if (valid && typeof valid === 'boolean') {
const { title, categoryId, content, id } = articleData if (props.article) {
if (!props.isEdit) { await updateArticlesByIdRequest(props.article.id, articleData)
await createArticlesRequest({ title, categoryId, content })
} else { } else {
await updateArticlesByIdRequest(id, { title, categoryId, content }) await createArticlesRequest(articleData)
} }
MessagePlugin.success(`${props.isEdit ? '编辑' : '创建'}咨询成功`) MessagePlugin.success(`${props.isEdit ? '编辑' : '创建'}咨询成功`)
emit('success') emit('success')
@@ -119,10 +116,9 @@ const handleCloseDialog = () => {
} }
const categoryOptions = ref<TdSelectProps['options']>([]) const categoryOptions = ref<TdSelectProps['options']>([])
const categoryName = ref('')
const fetchCategories = async () => { const fetchCategories = async (search: string) => {
const { data } = await searchCategories({ name: categoryName.value }) const { data } = await searchCategories({ name: search })
categoryOptions.value = data.map((category) => { categoryOptions.value = data.map((category) => {
return { return {
label: category.name, label: category.name,
@@ -131,7 +127,8 @@ const fetchCategories = async () => {
}) })
} }
fetchCategories() fetchCategories('')
</script> </script>
<template> <template>
@@ -150,15 +147,16 @@ fetchCategories()
</TFormItem> </TFormItem>
<TFormItem label="咨询分类:" name="categoryId"> <TFormItem label="咨询分类:" name="categoryId">
<TSelect <TSelect
v-model="categoryName" v-model="articleData.categoryId"
:options="categoryOptions" :options="categoryOptions"
placeholder="请选择咨询分类" placeholder="请选择咨询分类"
clearable
filterable filterable
@search="fetchCategories" @search="fetchCategories"
/> />
</TFormItem> </TFormItem>
<TFormItem label="内容:" name="content"> </TFormItem> <TFormItem label="内容:" name="content">
<TTextarea v-model="articleData.content"></TTextarea>
</TFormItem>
</TForm> </TForm>
</t-space> </t-space>
</t-dialog> </t-dialog>
+2 -3
View File
@@ -52,7 +52,7 @@ const columns: BaseTableColumns = [
] ]
const articleDialogVisble = ref(false) const articleDialogVisble = ref(false)
const isEdit = ref(false) const isEdit = ref(false)
const currentTableData = ref<Article | {}>({}) const currentTableData = ref<Article | null>(null)
const categoryList = ref<Category[]>([]) const categoryList = ref<Category[]>([])
onMounted(fetchData) onMounted(fetchData)
watch(articleDialogVisble, (newValue) => { watch(articleDialogVisble, (newValue) => {
@@ -79,7 +79,7 @@ const handleArticleDialogSuccess = () => {
} }
const handleArticleDialogClosed = () => { const handleArticleDialogClosed = () => {
isEdit.value = false isEdit.value = false
currentTableData.value = {} currentTableData.value = null
} }
const toggleArticleStatus = async (article: Article) => { const toggleArticleStatus = async (article: Article) => {
if (article.status === 'published') { if (article.status === 'published') {
@@ -147,7 +147,6 @@ const deleteCategoryClick = async (article: Article) => {
</TTable> </TTable>
<ArticleDialog <ArticleDialog
headerTitle="咨询" headerTitle="咨询"
:isEdit="isEdit"
:article="currentTableData" :article="currentTableData"
:categoryList="categoryList" :categoryList="categoryList"
v-model:visible="articleDialogVisble" v-model:visible="articleDialogVisble"