feat: refactoring API

This commit is contained in:
kailong321200875
2022-06-25 21:56:24 +08:00
parent 43518532f1
commit 37b75839a5
29 changed files with 198 additions and 339 deletions

View File

@@ -4,9 +4,11 @@ import { useI18n } from '@/hooks/web/useI18n'
import { reactive, unref } from 'vue'
import { Form } from '@/components/Form'
import { ElFormItem, ElInput, ElButton } from 'element-plus'
import { required } from '@/utils/formRules'
import { useValidator } from '@/hooks/web/useValidator'
import { useForm } from '@/hooks/web/useForm'
const { required } = useValidator()
const { t } = useI18n()
const data = reactive({
@@ -53,11 +55,11 @@ const form = reactive({
})
const rules = reactive({
username: [required],
nickName: [required],
phone: [required],
email: [required],
addr: [required]
username: [required()],
nickName: [required()],
phone: [required()],
email: [required()],
addr: [required()]
})
const { register, elFormRef } = useForm()

View File

@@ -4,7 +4,9 @@ import { ContentWrap } from '@/components/ContentWrap'
import { useI18n } from '@/hooks/web/useI18n'
import { reactive, unref, ref } from 'vue'
import { ElButton } from 'element-plus'
import { required } from '@/utils/formRules'
import { useValidator } from '@/hooks/web/useValidator'
const { required } = useValidator()
const { t } = useI18n()
@@ -14,7 +16,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{

View File

@@ -5,7 +5,9 @@ import { useI18n } from '@/hooks/web/useI18n'
import { useForm } from '@/hooks/web/useForm'
import { reactive, unref, ref } from 'vue'
import { ElButton } from 'element-plus'
import { required } from '@/utils/formRules'
import { useValidator } from '@/hooks/web/useValidator'
const { required } = useValidator()
const { t } = useI18n()
@@ -15,7 +17,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{

View File

@@ -3,9 +3,11 @@ import { ContentWrap } from '@/components/ContentWrap'
import { useI18n } from '@/hooks/web/useI18n'
import { Search } from '@/components/Search'
import { reactive, ref, unref } from 'vue'
import { required } from '@/utils/formRules'
import { useValidator } from '@/hooks/web/useValidator'
import { ElButton } from 'element-plus'
const { required } = useValidator()
const { t } = useI18n()
const schema = reactive<FormSchema[]>([
@@ -14,7 +16,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -69,7 +71,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -77,7 +79,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -85,7 +87,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -93,7 +95,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -101,7 +103,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -109,7 +111,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -117,7 +119,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -125,7 +127,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -133,7 +135,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -141,7 +143,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
},
{
@@ -149,7 +151,7 @@ const schema = reactive<FormSchema[]>([
label: t('formDemo.input'),
component: 'Input',
formItemProps: {
rules: [required]
rules: [required()]
}
}
])

View File

@@ -65,12 +65,12 @@ const loading = ref(true)
let tableDataList = ref<TableData[]>([])
const getTableList = async (params?: Params) => {
const res = await getTableListApi({
params: params || {
const res = await getTableListApi(
params || {
pageIndex: 1,
pageSize: 10
}
})
)
.catch(() => {})
.finally(() => {
loading.value = false

View File

@@ -62,13 +62,7 @@ const columns = reactive<TableColumn[]>([
}
])
const { register, tableObject, methods } = useTable<
{
total: number
list: TableData[]
},
TableData
>({
const { register, tableObject, methods } = useTable<TableData>({
getListApi: getTableListApi,
response: {
list: 'list',

View File

@@ -8,13 +8,7 @@ import { ref, h, reactive, unref } from 'vue'
import { ElTag, ElButton } from 'element-plus'
import { useTable } from '@/hooks/web/useTable'
const { register, tableObject, methods } = useTable<
{
total: number
list: TableData[]
},
TableData
>({
const { register, tableObject, methods } = useTable<TableData>({
getListApi: getTableListApi,
response: {
list: 'list',