fix:修复dialog无法关闭的问题
This commit is contained in:
1 parent
f8425de967
commit
a859521682
3 files changed
+20
-27
No files matched your search
@@ -1,12 +1,11 @@
|
||||
<template>
|
||||
<t-dialog
|
||||
width="70%"
|
||||
v-model:visible="visible"
|
||||
:header="header"
|
||||
:confirmBtn="confirmBtn"
|
||||
:closeOnOverlayClick="false"
|
||||
@close="handleCloseDialog"
|
||||
@confirm="fetchSaveClassifyData"
|
||||
@confirm="fetchSaveCarousalData"
|
||||
>
|
||||
<t-space direction="vertical" style="width: 100%">
|
||||
<TForm ref="form" :data="carousalData" :rules="rules" resetType="initial" label-width="100">
|
||||
@@ -29,7 +28,6 @@
|
||||
</t-dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import type { Classify } from '@/model/classify'
|
||||
import { computed, ref, reactive, watch } from 'vue'
|
||||
import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
|
||||
import ImageUpload from '@/components/ImageUpload.vue'
|
||||
@@ -37,7 +35,7 @@ import { createCarousal, updateCarousalItem } from '@/api/carousal'
|
||||
const props = defineProps<{
|
||||
isEdit?: Boolean | null
|
||||
headerTitle?: String | null
|
||||
classify: Classify | {} | number
|
||||
carousal: {} | number
|
||||
}>()
|
||||
const emit = defineEmits(['success'])
|
||||
const form = ref<FormInstanceFunctions | null>(null)
|
||||
@@ -46,7 +44,6 @@ const formType = computed(() => `${props.isEdit ? 'update' : 'add'}`)
|
||||
const confirmBtn = computed(() => (props.isEdit ? '保存' : '确定'))
|
||||
const carousalData: FormProps['data'] = ref({})
|
||||
const imgUrl = ref({})
|
||||
const visible = ref(false)
|
||||
const rules = computed(() => {
|
||||
const commonRules = {
|
||||
imageUrl: [
|
||||
@@ -93,7 +90,7 @@ const handleFormTypeData = () => {
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.classify,
|
||||
() => props.carousal,
|
||||
(newClassify) => {
|
||||
carousalData.value = Object.assign({}, newClassify)
|
||||
const carousalObj = Object.assign({},newClassify)
|
||||
@@ -105,7 +102,7 @@ watch(
|
||||
immediate: true
|
||||
},
|
||||
)
|
||||
const fetchSaveClassifyData = async () => {
|
||||
const fetchSaveCarousalData = async () => {
|
||||
/* TODO: 保存分类数据 */
|
||||
if (form.value) {
|
||||
const valid = await form.value.validate()
|
||||
@@ -118,7 +115,7 @@ const fetchSaveClassifyData = async () => {
|
||||
switch (formType.value){
|
||||
case 'create':
|
||||
res = await createCarousal(carousalData.value)
|
||||
emit('success', true)
|
||||
emit('success')
|
||||
break;
|
||||
case 'update':
|
||||
const fieldsToKeep = ["imageUrl", "targetType", "targetUrl", "targetId"];
|
||||
@@ -131,10 +128,11 @@ const fetchSaveClassifyData = async () => {
|
||||
}
|
||||
handleFormTypeData()
|
||||
res = await updateCarousalItem(carousalData.value.id,requestObj)
|
||||
emit('success', res)
|
||||
emit('success')
|
||||
break;
|
||||
default:
|
||||
res = await createCarousal(carousalData.value)
|
||||
emit('success')
|
||||
break;
|
||||
}
|
||||
// const createCarousalApi = createCarousal(carousalData.value)
|
||||
|
||||
Reference in new issue
Block a user