fix: refactoring

This commit is contained in:
ilhamtahir committed 2024-11-26 11:05:18 +08:00
1 parent c827568088
commit 21b59e8272
6 files changed
+16 -15

No files matched your search

@@ -36,13 +36,12 @@ import { createCategoryRequest, updateCategoryByIdRequest } from '@/api/category
import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
import { MessagePlugin } from 'tdesign-vue-next'
const props = defineProps<{
isEdit?: Boolean | null
headerTitle?: String | null
category: Category | {}
headerTitle?: string
category: Category | null
}>()
const form = ref<FormInstanceFunctions | null>(null)
const header = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
const confirmBtn = computed(() => (props.isEdit ? '保存' : '确定'))
const header = computed(() => `${props.category ? '编辑' : '创建'}${props.headerTitle || ''}`)
const confirmBtn = computed(() => (props.category ? '保存' : '确定'))
const categoryData: FormProps['data'] = reactive({ name: '', order: 1 })
const rules: FormProps['rules'] = {
name: [
+5 -5
View File
@@ -2,7 +2,7 @@
import { onMounted, ref } from 'vue'
import type { Category, CategorySearchFilter } from '@/model/category'
import RegularPage from '@/components/RegularPage.vue'
import { searchCategoryRequest, deleteCategoryRequest } from '@/api/category'
import { searchCategories, deleteCategoryRequest } from '@/api/category'
import type { BaseTableColumns } from 'tdesign-vue-next'
import { useSearchable } from '@/composables/useSearchable'
import CategoryDialog from '@/pages/category/components/CategoryDialog.vue'
@@ -11,7 +11,7 @@ import { MessagePlugin } from 'tdesign-vue-next'
const { data, loading, pagination, onPageChange, fetchData } = useSearchable<
CategorySearchFilter,
Category
>(searchCategoryRequest)
>(searchCategories)
const columns: BaseTableColumns = [
{
title: '分类名称',
@@ -36,7 +36,7 @@ const columns: BaseTableColumns = [
]
const categoryDialogVisible = ref(false)
const isEdit = ref(false)
const currentTableData = ref<Category | {}>({})
const currentTableData = ref<Category | null>(null)
onMounted(fetchData)
const editClick = (category: Category) => {
isEdit.value = true
@@ -49,8 +49,9 @@ const handleCategoryDialogSuccess = () => {
}
const handleCategoryDialogClosed = () => {
isEdit.value = false
currentTableData.value = {}
currentTableData.value = null
}
const deleteCategoryClick = async (id: string) => {
await deleteCategoryRequest(id)
fetchData()
@@ -97,7 +98,6 @@ const deleteCategoryClick = async (id: string) => {
</TTable>
<CategoryDialog
headerTitle="分类"
:isEdit="isEdit"
:category="currentTableData"
v-model:visible="categoryDialogVisible"
@closed="handleCategoryDialogClosed"