|
@@ -1,14 +1,13 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <t-dialog
|
|
|
|
|
- width="70%"
|
|
|
|
|
- :header="header"
|
|
|
|
|
- :confirmBtn="confirmBtn"
|
|
|
|
|
|
|
+ <TDialog
|
|
|
|
|
+ width="980px"
|
|
|
|
|
+ :header="headerText"
|
|
|
|
|
+ :confirmBtn="confirmBtnText"
|
|
|
:closeOnOverlayClick="false"
|
|
:closeOnOverlayClick="false"
|
|
|
@close="handleCloseDialog"
|
|
@close="handleCloseDialog"
|
|
|
@confirm="fetchSaveCarousalData"
|
|
@confirm="fetchSaveCarousalData"
|
|
|
>
|
|
>
|
|
|
- <t-space direction="vertical" style="width: 100%">
|
|
|
|
|
- <TForm ref="form" :data="carousalData" :rules="rules" resetType="initial" label-width="100">
|
|
|
|
|
|
|
+ <TForm v-if="carousalData" ref="formRef" :data="carousalData" :rules="rules" resetType="initial" label-width="100">
|
|
|
<TFormItem label="轮播图:" name="imageUrl">
|
|
<TFormItem label="轮播图:" name="imageUrl">
|
|
|
<ImageUpload @on-success="handleSuccessImg" :image-url="imgUrl"/>
|
|
<ImageUpload @on-success="handleSuccessImg" :image-url="imgUrl"/>
|
|
|
</TFormItem>
|
|
</TFormItem>
|
|
@@ -24,25 +23,33 @@
|
|
|
<t-input v-model.trim="carousalData.targetUrl" clearable placeholder="请输入网址路径" />
|
|
<t-input v-model.trim="carousalData.targetUrl" clearable placeholder="请输入网址路径" />
|
|
|
</TFormItem>
|
|
</TFormItem>
|
|
|
</TForm>
|
|
</TForm>
|
|
|
- </t-space>
|
|
|
|
|
- </t-dialog>
|
|
|
|
|
|
|
+ </TDialog>
|
|
|
</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, FormProps } 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'
|
|
|
|
|
+// Todo: 改为ts方式
|
|
|
const props = defineProps<{
|
|
const props = defineProps<{
|
|
|
isEdit?: Boolean | null
|
|
isEdit?: Boolean | null
|
|
|
headerTitle?: String | null
|
|
headerTitle?: String | null
|
|
|
carousal: {} | number
|
|
carousal: {} | number
|
|
|
}>()
|
|
}>()
|
|
|
-const emit = defineEmits(['success'])
|
|
|
|
|
-const form = ref<FormInstanceFunctions | null>(null)
|
|
|
|
|
-const header = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
|
|
|
|
|
|
+const emit = defineEmits<{
|
|
|
|
|
+ success: [string]
|
|
|
|
|
+}>()
|
|
|
|
|
+const formRef = ref<FormInstanceFunctions | null>(null)
|
|
|
|
|
+const headerText = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
|
|
|
|
|
+const confirmBtnText = computed(() => (props.isEdit ? '保存' : '确定'))
|
|
|
const formType = computed(() => `${props.isEdit ? 'update' : 'add'}`)
|
|
const formType = computed(() => `${props.isEdit ? 'update' : 'add'}`)
|
|
|
-const confirmBtn = computed(() => (props.isEdit ? '保存' : '确定'))
|
|
|
|
|
-const carousalData: FormProps['data'] = ref({})
|
|
|
|
|
|
|
+
|
|
|
|
|
+const carousalData = ref<FormProps['data']>({
|
|
|
|
|
+ imageUrl: '',
|
|
|
|
|
+ targetType: 'article',
|
|
|
|
|
+ targetId: '',
|
|
|
|
|
+ targetUrl: '',
|
|
|
|
|
+})
|
|
|
const imgUrl = ref({})
|
|
const imgUrl = ref({})
|
|
|
const rules = computed(() => {
|
|
const rules = computed(() => {
|
|
|
const commonRules = {
|
|
const commonRules = {
|
|
@@ -104,14 +111,15 @@ watch(
|
|
|
)
|
|
)
|
|
|
const fetchSaveCarousalData = async () => {
|
|
const fetchSaveCarousalData = async () => {
|
|
|
/* TODO: 保存分类数据 */
|
|
/* TODO: 保存分类数据 */
|
|
|
- if (form.value) {
|
|
|
|
|
- const valid = await form.value.validate()
|
|
|
|
|
|
|
+ if (formRef.value) {
|
|
|
|
|
+ const valid = await formRef.value.validate()
|
|
|
// console.log(valid,'valid')
|
|
// console.log(valid,'valid')
|
|
|
if (valid && typeof valid === 'boolean') {
|
|
if (valid && typeof valid === 'boolean') {
|
|
|
/* TODO: 校验通过保存分类数据 */
|
|
/* TODO: 校验通过保存分类数据 */
|
|
|
handleFormTypeData()
|
|
handleFormTypeData()
|
|
|
// console.log(formType.value,'formType')
|
|
// console.log(formType.value,'formType')
|
|
|
let res
|
|
let res
|
|
|
|
|
+
|
|
|
switch (formType.value){
|
|
switch (formType.value){
|
|
|
case 'create':
|
|
case 'create':
|
|
|
res = await createCarousal(carousalData.value)
|
|
res = await createCarousal(carousalData.value)
|
|
@@ -143,9 +151,9 @@ const fetchSaveCarousalData = async () => {
|
|
|
}
|
|
}
|
|
|
const handleCloseDialog = () => {
|
|
const handleCloseDialog = () => {
|
|
|
// 数据&&规则校验结果重置
|
|
// 数据&&规则校验结果重置
|
|
|
- if (form.value) {
|
|
|
|
|
- form.value.reset()
|
|
|
|
|
- form.value.clearValidate()
|
|
|
|
|
|
|
+ if (formRef.value) {
|
|
|
|
|
+ formRef.value.reset()
|
|
|
|
|
+ formRef.value.clearValidate()
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|