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

View File

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

View File

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