优化图纸编辑功能和提交逻辑
This commit is contained in:
@ -32,8 +32,9 @@
|
||||
import { reactive, ref, onMounted, computed } from 'vue'
|
||||
|
||||
import type { TcreateReq } from '~/api/upnew/types'
|
||||
import { create, view } from '~/api/upnew/index'
|
||||
import { create, view, edit } from '~/api/upnew/index'
|
||||
const route = useRoute() // 导入路由实例,用于跳转页面
|
||||
const router = useRouter() // 导入路由实例,用于跳转页面
|
||||
const id = computed(() => {
|
||||
return route.query.id as string
|
||||
})
|
||||
@ -94,28 +95,37 @@
|
||||
const loading = ref(false)
|
||||
const formRef = ref()
|
||||
const handleSubmit = () => {
|
||||
formRef.value.validate((valid: boolean, val: any) => {
|
||||
formRef.value.validate(async (valid: boolean, val: any) => {
|
||||
if (valid) {
|
||||
loading.value = true
|
||||
create(form)
|
||||
.then((res) => {
|
||||
const { code } = res
|
||||
if (code === 0) {
|
||||
// 弹窗提示
|
||||
ElMessage.success('操作成功')
|
||||
// 跳转页面
|
||||
if (form.type === 1) {
|
||||
navigateTo('/drawe')
|
||||
} else if (form.type === 2) {
|
||||
navigateTo('/text')
|
||||
} else if (form.type === 3) {
|
||||
navigateTo('/model')
|
||||
}
|
||||
try {
|
||||
const res =
|
||||
type.value === 'add'
|
||||
? await create(form)
|
||||
: await edit({
|
||||
...form,
|
||||
id: Number(id.value),
|
||||
projectId: Number(projectId.value),
|
||||
})
|
||||
if (res.code === 0) {
|
||||
// 弹窗提示
|
||||
ElMessage.success('操作成功')
|
||||
if (type.value !== 'add') {
|
||||
router.back()
|
||||
return
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false
|
||||
})
|
||||
// 跳转页面
|
||||
if (form.type === 1) {
|
||||
navigateTo('/drawe')
|
||||
} else if (form.type === 2) {
|
||||
navigateTo('/text')
|
||||
} else if (form.type === 3) {
|
||||
navigateTo('/model')
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
} else {
|
||||
console.log('error submit!')
|
||||
// 弹窗提示
|
||||
|
||||
Reference in New Issue
Block a user