From b4541b6f787ec391514fb2626e03ddb171c8396d Mon Sep 17 00:00:00 2001
From: zlong <953829746@qq.com>
Date: Thu, 21 Nov 2024 17:39:36 +0800
Subject: [PATCH] =?UTF-8?q?add:=E5=A2=9E=E5=8A=A0=E7=BC=96=E8=BE=91?=
=?UTF-8?q?=E3=80=81=E5=88=A0=E9=99=A4=E7=AD=89=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components.d.ts | 3 +
src/api/carousal.ts | 6 +-
src/components/ImageUpload.vue | 23 +++-
.../carousal/components/CarousalDialog.vue | 124 +++++++-----------
src/pages/carousal/index.vue | 106 +++++++++++++--
5 files changed, 171 insertions(+), 91 deletions(-)
diff --git a/components.d.ts b/components.d.ts
index 4b333bc..cc947d0 100644
--- a/components.d.ts
+++ b/components.d.ts
@@ -16,14 +16,17 @@ declare module 'vue' {
TAvatar: typeof import('tdesign-vue-next')['Avatar']
TButton: typeof import('tdesign-vue-next')['Button']
TCard: typeof import('tdesign-vue-next')['Card']
+ TCheckbox: typeof import('tdesign-vue-next')['Checkbox']
TDialog: typeof import('tdesign-vue-next')['Dialog']
TDropdown: typeof import('tdesign-vue-next')['Dropdown']
TForm: typeof import('tdesign-vue-next')['Form']
TFormItem: typeof import('tdesign-vue-next')['FormItem']
THeader: typeof import('tdesign-vue-next')['Header']
TIcon: typeof import('tdesign-vue-next')['Icon']
+ TImageViewer: typeof import('tdesign-vue-next')['ImageViewer']
TInput: typeof import('tdesign-vue-next')['Input']
TLayout: typeof import('tdesign-vue-next')['Layout']
+ TLink: typeof import('tdesign-vue-next')['Link']
TMenu: typeof import('tdesign-vue-next')['Menu']
TMenuItem: typeof import('tdesign-vue-next')['MenuItem']
TRadioButton: typeof import('tdesign-vue-next')['RadioButton']
diff --git a/src/api/carousal.ts b/src/api/carousal.ts
index 6b14df9..7771609 100644
--- a/src/api/carousal.ts
+++ b/src/api/carousal.ts
@@ -16,14 +16,14 @@ export const updateCarousalItem = (id:number,updateCarousalsRequest: CreateCarou
return httpClient.put(`/carousals/${id}`,updateCarousalsRequest)
}
-export const deleteCarousal = (id:number) => {
+export const deleteCarousal = (id:string | number) => {
return httpClient.delete(`/carousals/${id}`)
}
-export const activeCarousal = (id: { id: string | number }) => {
+export const activeCarousal = (id: string | number) => {
return httpClient.put(`/carousals/${id}/active`)
}
-export const inactiveCarousal = (id: { id: string | number }) => {
+export const inactiveCarousal = (id: string | number ) => {
return httpClient.put(`/carousals/${id}/inactive`)
}
\ No newline at end of file
diff --git a/src/components/ImageUpload.vue b/src/components/ImageUpload.vue
index 5522c8b..ede5ae7 100644
--- a/src/components/ImageUpload.vue
+++ b/src/components/ImageUpload.vue
@@ -1,6 +1,6 @@
diff --git a/src/pages/carousal/components/CarousalDialog.vue b/src/pages/carousal/components/CarousalDialog.vue
index cb9ef46..629b1c5 100644
--- a/src/pages/carousal/components/CarousalDialog.vue
+++ b/src/pages/carousal/components/CarousalDialog.vue
@@ -8,9 +8,9 @@
@confirm="fetchSaveClassifyData"
>
-
+
-
+
@@ -32,17 +32,19 @@ 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'
-import { createCarousal } from '@/api/carousal'
+import { createCarousal, updateCarousalItem } from '@/api/carousal'
const props = defineProps<{
isEdit?: Boolean | null
headerTitle?: String | null
- classify: Classify | {}
- count:number
+ classify: Classify | {} | number
}>()
+const emit = defineEmits(['success'])
const form = ref(null)
const header = computed(() => `${props.isEdit ? '编辑' : '创建'}${props.headerTitle || ''}`)
+const formType = computed(() => `${props.isEdit ? 'update' : 'add'}`)
const confirmBtn = computed(() => (props.isEdit ? '保存' : '确定'))
-const carousalData: FormProps['data'] = reactive({})
+const carousalData: FormProps['data'] = ref({})
+const imgUrl = ref({})
const rules = computed(() => {
const commonRules = {
imageUrl: [
@@ -68,82 +70,32 @@ const rules = computed(() => {
},
],
};
- return carousalData.targetType === 'article'
+ return carousalData.value.targetType === 'article'
? {...commonRules, targetId: [{ required: true, message: '文章 id 不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '文章 id 不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] }
: {...commonRules, targetUrl: [{ required: true, message: '网址路径不能为空', type: 'error', trigger: 'blur' }, { required: true, message: '网址路径不能为空', type: 'error', trigger: 'change' }, { whitespace: true, message: '网址路径不能为空' }] };
});
-// const rules: FormProps['rules'] = {
-// imageUrl:[
-// {
-// required: true,
-// message:'轮播图必须是上传',
-// type:'error',
-// trigger: 'change'
-// }
-// ],
-// targetType:[
-// {
-// required: true,
-// message: '请选择跳转类型',
-// type: 'error',
-// trigger: 'blur'
-// },
-// {
-// required: true,
-// message: '请选择跳转类型',
-// type: 'error',
-// trigger: 'change'
-// },
-// ],
-// targetId:[
-// {
-// required: true,
-// message: '文章id不能为空',
-// type: 'error',
-// trigger: 'blur'
-// },
-// {
-// required: true,
-// message: '文章id不能为空',
-// type: 'error',
-// trigger: 'change'
-// },
-// {
-// whitespace: true,
-// message: '网址路径不能为空'
-// },
-// ],
-// targetUrl:[
-// {
-// required: true,
-// message: '网址路径不能为空',
-// type: 'error',
-// trigger: 'blur'
-// },
-// {
-// required: true,
-// message: '网址路径不能为空',
-// type: 'error',
-// trigger: 'change'
-// },
-// {
-// whitespace: true,
-// message: '网址路径不能为空'
-// },
-// ],
-// }
const handleSuccessImg = (res:string) => {
- carousalData.imageUrl = res
+ console.log(res,'图片地址')
+ carousalData.value.imageUrl = res
}
const typeOption = reactive([
{ value: 'article', label: '文章' },
{ value: 'url', label: '地址' },
])
+const handleFormTypeData = () => {
+ if (carousalData.value.targetType === 'article') {
+ delete carousalData.value.targetUrl
+ } else if (carousalData.value.targetType === 'url') {
+ delete carousalData.value.targetId
+ }
+}
+
watch(
() => props.classify,
(newClassify) => {
- Object.assign(carousalData, newClassify)
- console.log(carousalData)
+ carousalData.value = Object.assign({}, newClassify)
+ const carousalObj = Object.assign({},newClassify)
+ imgUrl.value.url = carousalObj.imageUrl || ''
},
{
deep: true,
@@ -157,13 +109,33 @@ const fetchSaveClassifyData = async () => {
// console.log(valid,'valid')
if (valid && typeof valid === 'boolean') {
/* TODO: 校验通过保存分类数据 */
- if (carousalData.targetType === 'article') {
- delete carousalData.targetUrl
- } else if (carousalData.targetType === 'url') {
- delete carousalData.targetId
+ handleFormTypeData()
+ // console.log(formType.value,'formType')
+ let res
+ switch (formType.value){
+ case 'create':
+ res = await createCarousal(carousalData.value)
+ emit('success', true)
+ 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', res)
+ break;
+ default:
+ res = await createCarousal(carousalData.value)
+ break;
}
- const createCarousalApi = createCarousal(carousalData)
- console.log(createCarousalApi,'createCarousalApi')
+ // const createCarousalApi = createCarousal(carousalData.value)
+ // console.log(createCarousalApi,'createCarousalApi')
return
}
}
diff --git a/src/pages/carousal/index.vue b/src/pages/carousal/index.vue
index e97cdcf..17678e7 100644
--- a/src/pages/carousal/index.vue
+++ b/src/pages/carousal/index.vue
@@ -4,18 +4,20 @@ import { onMounted, ref, reactive } from 'vue'
import type { BaseTableColumns } from 'tdesign-vue-next'
import type { Classify } from '@/model/classify'
import ClassifyDialog from '@/pages/carousal/components/CarousalDialog.vue'
-import { activeCarousal, getCarousalList, inactiveCarousal } from '@/api/carousal'
+import { activeCarousal, deleteCarousal, getCarousalList, inactiveCarousal } from '@/api/carousal'
+import { BrowseIcon } from 'tdesign-icons-vue-next'
+import { aS } from 'vitest/dist/reporters-yx5ZTtEV'
const columns: BaseTableColumns = [
{
title: 'ID',
colKey: 'id',
- width: 100
+ width: 100,
},
{
title: '轮播图',
colKey: 'imageUrl',
- width: 100
+ width: 100,
},
{
title: '显示状态',
@@ -25,7 +27,7 @@ const columns: BaseTableColumns = [
{
title: '操作',
colKey: 'operation',
- width: 100
+ width: 100,
}
]
const loading = ref(false)
@@ -53,27 +55,41 @@ const fetchClassifyTableData = async () => {
onMounted(fetchClassifyTableData)
const editClick = (row:object) => {
isEdit.value = true
- currentTableData.value = row
+ currentTableData.value = Object.assign({}, row)
carousalDialogVisible.value = true
}
const showClick = async (res:object) => {
if (res.status === 'active'){
- await inactiveCarousal({ id: res.id })
+ await inactiveCarousal(res.id)
} else {
- await activeCarousal({ id: res.id })
+ await activeCarousal(res.id)
}
await fetchClassifyTableData()
- console.log(res)
+}
+const delClick = async (row:object) => {
+ console.log(row,'删除')
+ await deleteCarousal(row.id)
+ await fetchClassifyTableData()
+}
+const handleCreateCarousal = () => {
+ isEdit.value = false
+ carousalDialogVisible.value = true
+ currentTableData.value = {}
}
const onPageChange = () => {
/* TODO: 分页切换 */
}
+const handleSuccessDialog = async (res) => {
+ if (res){
+ await fetchClassifyTableData()
+ }
+}
- 创建轮播图
+ 创建轮播图
{
onChange: onPageChange
}"
>
+
+
+
+
+
+
![test]()
+
+ 预览
+
+
+
+
+
+
{{row.status === 'active' ? '显示中' : '已关闭'}}
@@ -100,19 +130,21 @@ const onPageChange = () => {
{{
- role.label
- }}
+ role.label
+ }}
编辑
{{ row.status === 'active' ? '关闭显示' : '开启显示'}}
+ 删除
@@ -123,4 +155,56 @@ const onPageChange = () => {
flex: 1;
min-height: 0;
}
+.tdesign-demo-image-viewer__ui-image {
+ width: 100%;
+ height: 100%;
+ display: inline-flex;
+ position: relative;
+ justify-content: center;
+ align-items: center;
+ border-radius: var(--td-radius-small);
+ overflow: hidden;
+}
+
+.tdesign-demo-image-viewer__ui-image--hover {
+ width: 100%;
+ height: 100%;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ position: absolute;
+ left: 0;
+ top: 0;
+ opacity: 0;
+ background-color: rgba(0, 0, 0, 0.6);
+ color: var(--td-text-color-anti);
+ line-height: 22px;
+ transition: 0.2s;
+}
+
+.tdesign-demo-image-viewer__ui-image:hover .tdesign-demo-image-viewer__ui-image--hover {
+ opacity: 1;
+ cursor: pointer;
+}
+
+.tdesign-demo-image-viewer__ui-image--img {
+ width: auto;
+ height: auto;
+ max-width: 100%;
+ max-height: 100%;
+ cursor: pointer;
+ position: absolute;
+}
+
+
+.tdesign-demo-image-viewer__ui-image--icons .tdesign-demo-icon {
+ cursor: pointer;
+}
+
+.tdesign-demo-image-viewer__base {
+ width: 100px;
+ height: 100px;
+ border: 4px solid var(--td-bg-color-secondarycontainer);
+ border-radius: var(--td-radius-medium);
+}