131 lines
3.7 KiB
Vue
131 lines
3.7 KiB
Vue
<script setup lang="ts">
|
|
import RegularPage from '@/components/RegularPage.vue'
|
|
import { onMounted, ref } from 'vue'
|
|
import type { BaseTableColumns } from 'tdesign-vue-next'
|
|
import CarousalDialog from '@/pages/carousal/components/CarousalDialog.vue'
|
|
import { activeCarousal, deleteCarousal, searchCarousals, inactiveCarousal } from '@/api/carousal'
|
|
import type { CarousalResult, SearchCarousalsFilter } from '@/model/carousals'
|
|
import ImagePreviewer from '@/components/ImagePreviewer.vue'
|
|
import { useSearchable } from '@/composables/useSearchable'
|
|
|
|
const columns: BaseTableColumns = [
|
|
{
|
|
title: 'ID',
|
|
colKey: 'id',
|
|
width: 100
|
|
},
|
|
{
|
|
title: '轮播图',
|
|
colKey: 'imageUrl',
|
|
width: 100
|
|
},
|
|
{
|
|
title: '显示状态',
|
|
colKey: 'status',
|
|
width: 100
|
|
},
|
|
{
|
|
title: '操作',
|
|
colKey: 'operation',
|
|
width: 100
|
|
}
|
|
]
|
|
|
|
const { loading, data, pagination, fetchData, onPageChange } = useSearchable<CarousalResult, SearchCarousalsFilter>(searchCarousals)
|
|
onMounted(fetchData)
|
|
|
|
|
|
const carousalDialogVisible = ref<boolean>(false)
|
|
const isEdit = ref<boolean>(false)
|
|
const currentTableData = ref<CarousalResult | null>(null)
|
|
|
|
|
|
const handleEdit = (row: object): void => {
|
|
isEdit.value = true
|
|
currentTableData.value = Object.assign({}, row)
|
|
carousalDialogVisible.value = true
|
|
}
|
|
const handleShow = async (res: CarousalResult): Promise<void> => {
|
|
if (res.status === 'active') {
|
|
await inactiveCarousal(res.id)
|
|
} else {
|
|
await activeCarousal(res.id)
|
|
}
|
|
await fetchData()
|
|
}
|
|
const handleDelete = async (row: CarousalResult): Promise<void> => {
|
|
await deleteCarousal(row.id)
|
|
await fetchData()
|
|
}
|
|
const handleCreateCarousal = (): void => {
|
|
isEdit.value = false
|
|
carousalDialogVisible.value = true
|
|
currentTableData.value = {}
|
|
}
|
|
const handleSuccessDialog = async (): Promise<void> => {
|
|
await fetchData()
|
|
carousalDialogVisible.value = false
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<RegularPage title="轮播图管理">
|
|
<template #right-area>
|
|
<TButton @click="handleCreateCarousal">创建轮播图</TButton>
|
|
</template>
|
|
<TTable
|
|
class="w-full h-full"
|
|
row-key="id"
|
|
table-layout="auto"
|
|
height="92%"
|
|
:data="data"
|
|
:loading="loading"
|
|
:columns="columns"
|
|
cell-empty-content="-"
|
|
:paginationAffixedBottom="true"
|
|
:pagination="{
|
|
total: pagination.total,
|
|
current: pagination.page,
|
|
pageSize: pagination.size,
|
|
onChange: onPageChange
|
|
}"
|
|
>
|
|
<template #imageUrl="{ row }">
|
|
<ImagePreviewer :url="row.imageUrl"/>
|
|
</template>
|
|
<template #status="{ row }">
|
|
<TSpace>
|
|
<TTag :theme="row.status === 'active' ? 'success' : 'danger'" variant="light">{{
|
|
row.status === 'active' ? '显示中' : '已关闭'
|
|
}}</TTag>
|
|
</TSpace>
|
|
</template>
|
|
<template #roles="{ row }">
|
|
<TSpace>
|
|
<TTag v-for="role in row.roles" :key="role.id" theme="success" variant="light">{{
|
|
role.label
|
|
}}</TTag>
|
|
</TSpace>
|
|
</template>
|
|
<template #operation="{ row }">
|
|
<TButton variant="text" size="small" theme="primary" @click="handleEdit(row)">编辑</TButton>
|
|
<TButton variant="text" size="small" theme="primary" @click="handleShow(row)">{{
|
|
row.status === 'active' ? '关闭显示' : '开启显示'
|
|
}}</TButton>
|
|
<TButton variant="text" size="small" theme="danger" @click="handleDelete(row)">删除</TButton>
|
|
</template>
|
|
</TTable>
|
|
<CarousalDialog
|
|
:carousal="currentTableData"
|
|
v-model:visible="carousalDialogVisible"
|
|
:isEdit="isEdit"
|
|
@success="handleSuccessDialog"
|
|
headerTitle="轮播图"
|
|
></CarousalDialog>
|
|
</RegularPage>
|
|
</template>
|
|
|
|
<style scoped>
|
|
|
|
</style>
|