add:增加编辑、删除等功能

This commit is contained in:
zlong committed 2024-11-21 17:39:36 +08:00
1 parent b3ae608daa
commit b4541b6f78
5 files changed
+171 -91

No files matched your search

+95 -11
View File
@@ -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()
}
}
</script>
<template>
<RegularPage title="轮播图管理">
<template #right-area>
<TButton @click="carousalDialogVisible = true">创建轮播图</TButton>
<TButton @click="handleCreateCarousal">创建轮播图</TButton>
</template>
<TTable
class="w-full h-full"
@@ -92,6 +108,20 @@ const onPageChange = () => {
onChange: onPageChange
}"
>
<template #imageUrl="{row}">
<div class="tdesign-demo-image-viewer__base">
<t-image-viewer :images="[row.imageUrl]">
<template #trigger="{ open }">
<div class="tdesign-demo-image-viewer__ui-image">
<img alt="test" :src="row.imageUrl" class="tdesign-demo-image-viewer__ui-image--img" />
<div class="tdesign-demo-image-viewer__ui-image--hover" @click="open">
<span><BrowseIcon size="1.4em" /> 预览</span>
</div>
</div>
</template>
</t-image-viewer>
</div>
</template>
<template #status="{row}">
<TSpace>
<TTag :theme="row.status === 'active' ? 'success' : 'danger'" variant="light">{{row.status === 'active' ? '显示中' : '已关闭'}}</TTag>
@@ -100,19 +130,21 @@ const onPageChange = () => {
<template #roles="{ row }">
<TSpace>
<TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{
role.label
}}</TTag>
role.label
}}</TTag>
</TSpace>
</template>
<template #operation="{ row }">
<TButton variant="text" size="small" theme="primary" @click="editClick(row)">编辑</TButton>
<TButton variant="text" size="small" theme="primary" @click="showClick(row)">{{ row.status === 'active' ? '关闭显示' : '开启显示'}}</TButton>
<TButton variant="text" size="small" theme="danger" @click="delClick(row)">删除</TButton>
</template>
</TTable>
<ClassifyDialog
:classify="currentTableData"
v-model:visible="carousalDialogVisible"
:isEdit="isEdit"
@success="handleSuccessDialog"
headerTitle="轮播图"
></ClassifyDialog>
</RegularPage>
@@ -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);
}
</style>