feat: refactoring API
This commit is contained in:
@@ -13,13 +13,7 @@ import Write from './components/Write.vue'
|
||||
import Detail from './components/Detail.vue'
|
||||
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
||||
|
||||
const { register, tableObject, methods } = useTable<
|
||||
{
|
||||
total: number
|
||||
list: TableData[]
|
||||
},
|
||||
TableData
|
||||
>({
|
||||
const { register, tableObject, methods } = useTable<TableData>({
|
||||
getListApi: getTableListApi,
|
||||
delListApi: delTableListApi,
|
||||
response: {
|
||||
@@ -196,9 +190,7 @@ const save = async () => {
|
||||
if (isValid) {
|
||||
loading.value = true
|
||||
const data = (await write?.getFormData()) as TableData
|
||||
const res = await saveTableApi({
|
||||
data
|
||||
})
|
||||
const res = await saveTableApi(data)
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
|
||||
@@ -3,7 +3,9 @@ import { Form } from '@/components/Form'
|
||||
import { useForm } from '@/hooks/web/useForm'
|
||||
import { PropType, reactive, watch } from 'vue'
|
||||
import { TableData } from '@/api/table/types'
|
||||
import { required } from '@/utils/formRules'
|
||||
import { useValidator } from '@/hooks/web/useValidator'
|
||||
|
||||
const { required } = useValidator()
|
||||
|
||||
const props = defineProps({
|
||||
currentRow: {
|
||||
@@ -17,12 +19,12 @@ const props = defineProps({
|
||||
})
|
||||
|
||||
const rules = reactive({
|
||||
title: [required],
|
||||
author: [required],
|
||||
importance: [required],
|
||||
pageviews: [required],
|
||||
display_time: [required],
|
||||
content: [required]
|
||||
title: [required()],
|
||||
author: [required()],
|
||||
importance: [required()],
|
||||
pageviews: [required()],
|
||||
display_time: [required()],
|
||||
content: [required()]
|
||||
})
|
||||
|
||||
const { register, methods, elFormRef } = useForm({
|
||||
|
||||
@@ -25,9 +25,7 @@ const save = async () => {
|
||||
if (isValid) {
|
||||
loading.value = true
|
||||
const data = (await write?.getFormData()) as TableData
|
||||
const res = await saveTableApi({
|
||||
data
|
||||
})
|
||||
const res = await saveTableApi(data)
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
|
||||
@@ -16,11 +16,7 @@ const { t } = useI18n()
|
||||
const currentRow = ref<Nullable<TableData>>(null)
|
||||
|
||||
const getTableDet = async () => {
|
||||
const res = await getTableDetApi({
|
||||
params: {
|
||||
id: query.id as string
|
||||
}
|
||||
})
|
||||
const res = await getTableDetApi(query.id as string)
|
||||
if (res) {
|
||||
currentRow.value = res.data
|
||||
}
|
||||
|
||||
@@ -20,11 +20,7 @@ const { t } = useI18n()
|
||||
const currentRow = ref<Nullable<TableData>>(null)
|
||||
|
||||
const getTableDet = async () => {
|
||||
const res = await getTableDetApi({
|
||||
params: {
|
||||
id: query.id as string
|
||||
}
|
||||
})
|
||||
const res = await getTableDetApi(query.id as string)
|
||||
if (res) {
|
||||
currentRow.value = res.data
|
||||
}
|
||||
@@ -42,9 +38,7 @@ const save = async () => {
|
||||
if (validate) {
|
||||
loading.value = true
|
||||
const data = (await write?.getFormData()) as TableData
|
||||
const res = await saveTableApi({
|
||||
data
|
||||
})
|
||||
const res = await saveTableApi(data)
|
||||
.catch(() => {})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
|
||||
@@ -18,13 +18,7 @@ defineOptions({
|
||||
|
||||
const { push } = useRouter()
|
||||
|
||||
const { register, tableObject, methods } = useTable<
|
||||
{
|
||||
total: number
|
||||
list: TableData[]
|
||||
},
|
||||
TableData
|
||||
>({
|
||||
const { register, tableObject, methods } = useTable<TableData>({
|
||||
getListApi: getTableListApi,
|
||||
delListApi: delTableListApi,
|
||||
response: {
|
||||
|
||||
@@ -4,9 +4,11 @@ import { useForm } from '@/hooks/web/useForm'
|
||||
import { PropType, reactive, watch } from 'vue'
|
||||
import { TableData } from '@/api/table/types'
|
||||
import { useI18n } from '@/hooks/web/useI18n'
|
||||
import { required } from '@/utils/formRules'
|
||||
import { useValidator } from '@/hooks/web/useValidator'
|
||||
import { IDomEditor } from '@wangeditor/editor'
|
||||
|
||||
const { required } = useValidator()
|
||||
|
||||
const props = defineProps({
|
||||
currentRow: {
|
||||
type: Object as PropType<Nullable<TableData>>,
|
||||
@@ -22,7 +24,7 @@ const schema = reactive<FormSchema[]>([
|
||||
label: t('exampleDemo.title'),
|
||||
component: 'Input',
|
||||
formItemProps: {
|
||||
rules: [required]
|
||||
rules: [required()]
|
||||
},
|
||||
colProps: {
|
||||
span: 24
|
||||
@@ -33,7 +35,7 @@ const schema = reactive<FormSchema[]>([
|
||||
label: t('exampleDemo.author'),
|
||||
component: 'Input',
|
||||
formItemProps: {
|
||||
rules: [required]
|
||||
rules: [required()]
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -45,7 +47,7 @@ const schema = reactive<FormSchema[]>([
|
||||
valueFormat: 'YYYY-MM-DD HH:mm:ss'
|
||||
},
|
||||
formItemProps: {
|
||||
rules: [required]
|
||||
rules: [required()]
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -53,7 +55,7 @@ const schema = reactive<FormSchema[]>([
|
||||
label: t('exampleDemo.importance'),
|
||||
component: 'Select',
|
||||
formItemProps: {
|
||||
rules: [required]
|
||||
rules: [required()]
|
||||
},
|
||||
componentProps: {
|
||||
options: [
|
||||
@@ -78,7 +80,7 @@ const schema = reactive<FormSchema[]>([
|
||||
component: 'InputNumber',
|
||||
value: 0,
|
||||
formItemProps: {
|
||||
rules: [required]
|
||||
rules: [required()]
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -101,12 +103,12 @@ const schema = reactive<FormSchema[]>([
|
||||
])
|
||||
|
||||
const rules = reactive({
|
||||
title: [required],
|
||||
author: [required],
|
||||
importance: [required],
|
||||
pageviews: [required],
|
||||
display_time: [required],
|
||||
content: [required]
|
||||
title: [required()],
|
||||
author: [required()],
|
||||
importance: [required()],
|
||||
pageviews: [required()],
|
||||
display_time: [required()],
|
||||
content: [required()]
|
||||
})
|
||||
|
||||
const { register, methods, elFormRef } = useForm({
|
||||
|
||||
Reference in New Issue
Block a user