|
|
|
|
@ -39,7 +39,7 @@ const emit = defineEmits(['success'])
|
|
|
|
|
|
|
|
|
|
// 弹窗相关的变量
|
|
|
|
|
const modelVisible = ref(false) // 是否显示弹出层
|
|
|
|
|
const modelTitle = ref('edit') // 弹出层标题
|
|
|
|
|
const modelTitle = ref('update') // 弹出层标题
|
|
|
|
|
const modelLoading = ref(false) // 弹出层loading
|
|
|
|
|
const actionType = ref('') // 操作按钮的类型
|
|
|
|
|
const actionLoading = ref(false) // 按钮 Loading
|
|
|
|
|
@ -67,26 +67,25 @@ const openModal = async (type: string, rowId?: number) => {
|
|
|
|
|
const submitForm = async () => {
|
|
|
|
|
const elForm = unref(formRef)?.getElFormRef()
|
|
|
|
|
if (!elForm) return
|
|
|
|
|
elForm.validate(async (valid) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
actionLoading.value = true
|
|
|
|
|
// 提交请求
|
|
|
|
|
try {
|
|
|
|
|
const data = unref(formRef)?.formModel as PostApi.PostVO
|
|
|
|
|
if (actionType.value === 'create') {
|
|
|
|
|
await PostApi.createPostApi(data)
|
|
|
|
|
message.success(t('common.createSuccess'))
|
|
|
|
|
} else {
|
|
|
|
|
await PostApi.updatePostApi(data)
|
|
|
|
|
message.success(t('common.updateSuccess'))
|
|
|
|
|
}
|
|
|
|
|
modelVisible.value = false
|
|
|
|
|
emit('success')
|
|
|
|
|
} finally {
|
|
|
|
|
actionLoading.value = false
|
|
|
|
|
const valid = await elForm.validate()
|
|
|
|
|
if (valid) {
|
|
|
|
|
actionLoading.value = true
|
|
|
|
|
// 提交请求
|
|
|
|
|
try {
|
|
|
|
|
const data = unref(formRef)?.formModel as PostApi.PostVO
|
|
|
|
|
if (actionType.value === 'create') {
|
|
|
|
|
await PostApi.createPostApi(data)
|
|
|
|
|
message.success(t('common.createSuccess'))
|
|
|
|
|
} else {
|
|
|
|
|
await PostApi.updatePostApi(data)
|
|
|
|
|
message.success(t('common.updateSuccess'))
|
|
|
|
|
}
|
|
|
|
|
modelVisible.value = false
|
|
|
|
|
emit('success')
|
|
|
|
|
} finally {
|
|
|
|
|
actionLoading.value = false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defineExpose({ openModal: openModal })
|
|
|
|
|
|