perf: post

This commit is contained in:
xingyu4j 2022-11-10 17:40:42 +08:00
parent d2a4eb9254
commit 414c191472
3 changed files with 32 additions and 27 deletions

View File

@ -113,19 +113,21 @@
</Table>
</div>
</el-card>
<Dialog v-model="dialogVisible" :title="dialogTitle">
<Form
v-if="['typeCreate', 'typeUpdate'].includes(actionType)"
:schema="DictTypeSchemas.allSchemas.formSchema"
:rules="DictTypeSchemas.dictTypeRules"
ref="typeFormRef"
/>
<Form
v-if="['dataCreate', 'dataUpdate'].includes(actionType)"
:schema="DictDataSchemas.allSchemas.formSchema"
:rules="DictDataSchemas.dictDataRules"
ref="dataFormRef"
/>
<XModal id="dictModel" v-model="dialogVisible" :title="dialogTitle">
<template #default>
<Form
v-if="['typeCreate', 'typeUpdate'].includes(actionType)"
:schema="DictTypeSchemas.allSchemas.formSchema"
:rules="DictTypeSchemas.dictTypeRules"
ref="typeFormRef"
/>
<Form
v-if="['dataCreate', 'dataUpdate'].includes(actionType)"
:schema="DictDataSchemas.allSchemas.formSchema"
:rules="DictDataSchemas.dictDataRules"
ref="dataFormRef"
/>
</template>
<!-- 操作按钮 -->
<template #footer>
<XButton
@ -144,7 +146,7 @@
/>
<XButton :title="t('dialog.close')" @click="dialogVisible = false" />
</template>
</Dialog>
</XModal>
</div>
</template>
<script setup lang="ts">

View File

@ -79,35 +79,31 @@ import { rules, allSchemas } from './post.data'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useVxeGrid } from '@/hooks/web/useVxeGrid'
import { VxeFormEvents, VxeGridInstance } from 'vxe-table'
import { VxeGridInstance } from 'vxe-table'
import { FormExpose } from '@/components/Form'
const { t } = useI18n() //
const message = useMessage() //
const xGrid = ref<VxeGridInstance>()
const formRef = ref<FormExpose>() // Ref
const dialogVisible = ref(false) //
const dialogTitle = ref('edit') //
const actionType = ref('') //
const actionLoading = ref(false) // Loading
const xGrid = ref<VxeGridInstance>() // grid Ref
const formRef = ref<FormExpose>() // Ref
const detailRef = ref() // Ref
const { gridOptions } = useVxeGrid<PostVO>({
allSchemas: allSchemas,
getListApi: PostApi.getPostPageApi
})
//
const setDialogTile = (type: string) => {
dialogTitle.value = t('action.' + type)
actionType.value = type
dialogVisible.value = true
}
// ========== ==========
const detailRef = ref() // Ref
//
const handleDetail = (row: PostVO) => {
setDialogTile('detail')
detailRef.value = row
}
//
const handleCreate = () => {
setDialogTile('create')
@ -115,6 +111,12 @@ const handleCreate = () => {
unref(formRef)?.getElFormRef()?.resetFields()
}
//
const handleDetail = (row: PostVO) => {
setDialogTile('detail')
detailRef.value = row
}
//
const handleUpdate = async (rowId: number) => {
setDialogTile('update')
@ -122,6 +124,7 @@ const handleUpdate = async (rowId: number) => {
const res = await PostApi.getPostApi(rowId)
unref(formRef)?.setValues(res)
}
//
const handleDelete = async (rowId: number) => {
message
@ -134,8 +137,9 @@ const handleDelete = async (rowId: number) => {
xGrid.value?.commitProxy('query')
})
}
//
const submitForm: VxeFormEvents.Submit = async () => {
const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return
elForm.validate(async (valid) => {
@ -151,7 +155,6 @@ const submitForm: VxeFormEvents.Submit = async () => {
await PostApi.updatePostApi(data)
message.success(t('common.updateSuccess'))
}
//
dialogVisible.value = false
} finally {
actionLoading.value = false

View File

@ -1,8 +1,8 @@
import { reactive } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { required } from '@/utils/formRules'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
import { DICT_TYPE } from '@/utils/dict'
import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas'
const { t } = useI18n() // 国际化
// 表单校验