|
@@ -27,14 +27,15 @@
|
|
|
</template>
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
import { computed, ref, reactive, watch } from 'vue'
|
|
import { computed, ref, reactive, watch } from 'vue'
|
|
|
-import type { FormInstanceFunctions, FormProps } from 'tdesign-vue-next'
|
|
|
|
|
|
|
+import type { FormInstanceFunctions } from 'tdesign-vue-next'
|
|
|
import ImageUpload from '@/components/ImageUpload.vue'
|
|
import ImageUpload from '@/components/ImageUpload.vue'
|
|
|
import { createCarousal, updateCarousalItem } from '@/api/carousal'
|
|
import { createCarousal, updateCarousalItem } from '@/api/carousal'
|
|
|
|
|
+import type {CarousalResult, CreateCarousalsRequest, UpdateCarousalsRequest} from "@/model/carousals";
|
|
|
// Todo: 改为ts方式
|
|
// Todo: 改为ts方式
|
|
|
const props = defineProps<{
|
|
const props = defineProps<{
|
|
|
isEdit?: Boolean | null
|
|
isEdit?: Boolean | null
|
|
|
headerTitle?: String | null
|
|
headerTitle?: String | null
|
|
|
- carousal: {} | number
|
|
|
|
|
|
|
+ carousal: CarousalResult | null
|
|
|
}>()
|
|
}>()
|
|
|
const emit = defineEmits<{
|
|
const emit = defineEmits<{
|
|
|
success: [void]
|
|
success: [void]
|
|
@@ -44,7 +45,7 @@ const headerText = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.
|
|
|
const confirmBtnText = computed(() => (props.isEdit ? '保存' : '确定'))
|
|
const confirmBtnText = computed(() => (props.isEdit ? '保存' : '确定'))
|
|
|
const formType = computed(() => `${props.isEdit ? 'update' : 'add'}`)
|
|
const formType = computed(() => `${props.isEdit ? 'update' : 'add'}`)
|
|
|
|
|
|
|
|
-const carousalData = ref<FormProps['data']>({
|
|
|
|
|
|
|
+const carousalData = ref<UpdateCarousalsRequest>({
|
|
|
imageUrl: '',
|
|
imageUrl: '',
|
|
|
targetType: 'article',
|
|
targetType: 'article',
|
|
|
targetId: '',
|
|
targetId: '',
|
|
@@ -98,10 +99,9 @@ const handleFormTypeData = () => {
|
|
|
|
|
|
|
|
watch(
|
|
watch(
|
|
|
() => props.carousal,
|
|
() => props.carousal,
|
|
|
- (newClassify) => {
|
|
|
|
|
|
|
+ (newClassify: CarousalResult) => {
|
|
|
carousalData.value = Object.assign({}, newClassify)
|
|
carousalData.value = Object.assign({}, newClassify)
|
|
|
const carousalObj = Object.assign({},newClassify)
|
|
const carousalObj = Object.assign({},newClassify)
|
|
|
- // imgUrl.value.url = carousalObj.imageUrl || ''
|
|
|
|
|
imgUrl.value = { url: carousalObj.imageUrl || '' }
|
|
imgUrl.value = { url: carousalObj.imageUrl || '' }
|
|
|
},
|
|
},
|
|
|
{
|
|
{
|
|
@@ -113,39 +113,10 @@ const fetchSaveCarousalData = async () => {
|
|
|
/* TODO: 保存分类数据 */
|
|
/* TODO: 保存分类数据 */
|
|
|
if (formRef.value) {
|
|
if (formRef.value) {
|
|
|
const valid = await formRef.value.validate()
|
|
const valid = await formRef.value.validate()
|
|
|
- // console.log(valid,'valid')
|
|
|
|
|
if (valid && typeof valid === 'boolean') {
|
|
if (valid && typeof valid === 'boolean') {
|
|
|
/* TODO: 校验通过保存分类数据 */
|
|
/* TODO: 校验通过保存分类数据 */
|
|
|
handleFormTypeData()
|
|
handleFormTypeData()
|
|
|
- // console.log(formType.value,'formType')
|
|
|
|
|
- formType.value === 'create' ? await createCarousalData() : await updateCarousalData()
|
|
|
|
|
- // let res
|
|
|
|
|
- //
|
|
|
|
|
- // switch (formType.value){
|
|
|
|
|
- // case 'create':
|
|
|
|
|
- // res = await createCarousal(carousalData.value)
|
|
|
|
|
- // emit('success')
|
|
|
|
|
- // break;
|
|
|
|
|
- // case 'update':
|
|
|
|
|
- // const fieldsToKeep = ["imageUrl", "targetType", "targetUrl", "targetId"];
|
|
|
|
|
- // const requestObj = {};
|
|
|
|
|
- //
|
|
|
|
|
- // for (const field of fieldsToKeep) {
|
|
|
|
|
- // if (carousalData.value[field]!== null && carousalData.value[field]!== undefined) {
|
|
|
|
|
- // requestObj[field] = carousalData.value[field];
|
|
|
|
|
- // }
|
|
|
|
|
- // }
|
|
|
|
|
- // handleFormTypeData()
|
|
|
|
|
- // res = await updateCarousalItem(carousalData.value.id,requestObj)
|
|
|
|
|
- // emit('success')
|
|
|
|
|
- // break;
|
|
|
|
|
- // default:
|
|
|
|
|
- // res = await createCarousal(carousalData.value)
|
|
|
|
|
- // emit('success')
|
|
|
|
|
- // break;
|
|
|
|
|
- // }
|
|
|
|
|
- // const createCarousalApi = createCarousal(carousalData.value)
|
|
|
|
|
- // console.log(createCarousalApi,'createCarousalApi')
|
|
|
|
|
|
|
+ formType.value === 'add' ? await createCarousalData() : await updateCarousalData()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -155,15 +126,8 @@ const createCarousalData = async () => {
|
|
|
emit('success')
|
|
emit('success')
|
|
|
}
|
|
}
|
|
|
const updateCarousalData = async () => {
|
|
const updateCarousalData = async () => {
|
|
|
- const fieldsToKeep = ["imageUrl", "targetType", "targetUrl", "targetId"];
|
|
|
|
|
- const requestObj = {};
|
|
|
|
|
-
|
|
|
|
|
- for (const field of fieldsToKeep) {
|
|
|
|
|
- if (carousalData.value[field] !== null && carousalData.value[field] !== undefined) {
|
|
|
|
|
- requestObj[field] = carousalData.value[field];
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
handleFormTypeData()
|
|
handleFormTypeData()
|
|
|
|
|
+ const requestObj: CreateCarousalsRequest = {imageUrl: carousalData.value.imageUrl,targetType:carousalData.value.targetType,targetUrl:carousalData.value.targetUrl,targetId:carousalData.value.targetId}
|
|
|
await updateCarousalItem(carousalData.value.id, requestObj)
|
|
await updateCarousalItem(carousalData.value.id, requestObj)
|
|
|
emit('success')
|
|
emit('success')
|
|
|
}
|
|
}
|