feat: 优化post界面

This commit is contained in:
xingyuv 2023-02-09 18:41:48 +08:00
parent a379e3a206
commit 563eb8ba90
2 changed files with 21 additions and 21 deletions

View File

@ -39,7 +39,7 @@ const emit = defineEmits(['success'])
// //
const modelVisible = ref(false) // const modelVisible = ref(false) //
const modelTitle = ref('edit') // const modelTitle = ref('update') //
const modelLoading = ref(false) // loading const modelLoading = ref(false) // loading
const actionType = ref('') // const actionType = ref('') //
const actionLoading = ref(false) // Loading const actionLoading = ref(false) // Loading
@ -67,26 +67,25 @@ const openModal = async (type: string, rowId?: number) => {
const submitForm = async () => { const submitForm = async () => {
const elForm = unref(formRef)?.getElFormRef() const elForm = unref(formRef)?.getElFormRef()
if (!elForm) return if (!elForm) return
elForm.validate(async (valid) => { const valid = await elForm.validate()
if (valid) { if (valid) {
actionLoading.value = true actionLoading.value = true
// //
try { try {
const data = unref(formRef)?.formModel as PostApi.PostVO const data = unref(formRef)?.formModel as PostApi.PostVO
if (actionType.value === 'create') { if (actionType.value === 'create') {
await PostApi.createPostApi(data) await PostApi.createPostApi(data)
message.success(t('common.createSuccess')) message.success(t('common.createSuccess'))
} else { } else {
await PostApi.updatePostApi(data) await PostApi.updatePostApi(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
}
modelVisible.value = false
emit('success')
} finally {
actionLoading.value = false
} }
modelVisible.value = false
emit('success')
} finally {
actionLoading.value = false
} }
}) }
} }
defineExpose({ openModal: openModal }) defineExpose({ openModal: openModal })

View File

@ -51,7 +51,7 @@ import { allSchemas } from './post.data'
import PostForm from './PostForm.vue' import PostForm from './PostForm.vue'
const { t } = useI18n() // const { t } = useI18n() //
const modalRef = ref()
// //
const [registerTable, { reload, deleteData, exportList }] = useXTable({ const [registerTable, { reload, deleteData, exportList }] = useXTable({
allSchemas: allSchemas, allSchemas: allSchemas,
@ -59,7 +59,8 @@ const [registerTable, { reload, deleteData, exportList }] = useXTable({
deleteApi: PostApi.deletePostApi, deleteApi: PostApi.deletePostApi,
exportListApi: PostApi.exportPostApi exportListApi: PostApi.exportPostApi
}) })
//
const modalRef = ref()
const openModal = (type: string, rowId?: number) => { const openModal = (type: string, rowId?: number) => {
modalRef.value.openModal(type, rowId) modalRef.value.openModal(type, rowId)
} }