You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

394 lines
10 KiB

<template>
<div class="carousel-container">
<!-- 搜索区域 -->
<div class="search-panel">
<el-form :model="searchForm" inline>
<el-form-item label="标题:">
<el-input v-model="searchForm.title" placeholder="请输入关键字" class="search-input" clearable
@keyup.enter="handleSearch" />
</el-form-item>
<el-form-item label="发布时间:">
<el-date-picker v-model="searchForm.timeRange" type="datetimerange" range-separator="至"
start-placeholder="开始时间" end-placeholder="结束时间" class="date-picker" format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss" />
</el-form-item>
<el-form-item label="内容发布到:">
<el-select v-model="searchForm.publishTo" placeholder="请选择" class="search-select" clearable>
<el-option label="企业端" value="enterprise" />
<el-option label="执法端" value="law_enforcement" />
<el-option label="监管端" value="supervision" />
</el-select>
</el-form-item>
<el-form-item label="状态:">
<el-select v-model="searchForm.status" placeholder="请选择" class="search-select" clearable>
<el-option label="在线" value="online" />
<el-option label="下架" value="offline" />
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleSearch" :loading="loading">搜索</el-button>
</el-form-item>
<el-form-item>
<el-button @click="handleReset">重置</el-button>
</el-form-item>
</el-form>
</div>
<!-- 操作栏 -->
<div class="action-bar">
<div class="action-left">
<el-button type="primary" @click="handleAdd">新增</el-button>
<el-button @click="handleBatchDelete" :disabled="selectedRows.length === 0">删除</el-button>
</div>
</div>
<!-- 数据表格 -->
<div class="table-container">
<el-table v-loading="loading" :data="tableData" border
:header-cell-style="{ backgroundColor: '#f5f7fa', fontWeight: 'bold' }"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column prop="title" label="标题" min-width="200" show-overflow-tooltip />
<el-table-column prop="publishTime" label="发布时间" width="180" />
<el-table-column prop="displayDays" label="显示时长" width="120" />
<el-table-column prop="publishTo" label="内容发布到" width="150" />
<el-table-column prop="windowName" label="橱窗" width="120" />
<el-table-column prop="status" label="状态" width="100">
<template #default="scope">
<div class="status-badge">
<span :class="scope.row.status === 'online' ? 'status-dot online' : 'status-dot offline'"></span>
{{ scope.row.status === 'online' ? '在线' : '下架' }}
</div>
</template>
</el-table-column>
<el-table-column label="操作" fixed="right">
<template #default="scope">
<el-button size="small" type="text" @click="handleView(scope.row)">查看</el-button>
<el-button size="small" type="text" @click="handleEdit(scope.row)">编辑</el-button>
<el-button size="small" type="text" :class="scope.row.status === 'online' ? 'offline-btn' : 'online-btn'"
@click="handleStatusChange(scope.row)">
{{ scope.row.status === 'online' ? '下架' : '上架' }}
</el-button>
<el-button size="small" type="text" class="delete-btn" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<!-- 分页 -->
<div class="pagination-container">
<span class="total-text">共 {{ total }} 条数据</span>
<el-pagination v-model:current-page="currentPage" v-model:page-size="pageSize" :total="total"
:page-sizes="[10, 20, 50, 100]" layout="prev, pager, next, jumper, ->, total, sizes"
@size-change="handleSizeChange" @current-change="handleCurrentChange" />
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import { useRouter } from 'vue-router';
import { listCarouselBanner, deleteCarouselBanner } from '@/api/supervision/carouselBanner';
const router = useRouter();
const loading = ref(false);
const tableData = ref<any[]>([]);
const total = ref(0);
const currentPage = ref(1);
const pageSize = ref(10);
const selectedRows = ref<any[]>([]);
const searchForm = reactive({
title: '',
timeRange: [] as string[],
publishTo: '',
status: ''
});
const getList = async () => {
loading.value = true;
try {
const queryParams = {
...searchForm,
startTime: searchForm.timeRange[0] || '',
endTime: searchForm.timeRange[1] || '',
pageNum: currentPage.value,
pageSize: pageSize.value
};
delete queryParams.timeRange;
const res: any = await listCarouselBanner(queryParams);
if (res.code === 200) {
tableData.value = res.rows || [];
total.value = res.total || 0;
} else {
ElMessage.error(res.msg || '获取数据失败');
}
} catch (error) {
console.error('获取列表数据失败:', error);
ElMessage.error('获取数据失败,请检查网络连接');
} finally {
loading.value = false;
}
};
const handleSearch = () => {
currentPage.value = 1;
getList();
};
const handleReset = () => {
searchForm.title = '';
searchForm.timeRange = [];
searchForm.publishTo = '';
searchForm.status = '';
currentPage.value = 1;
handleSearch();
ElMessage.info('已重置搜索条件');
};
const handleAdd = () => {
router.push('/supervision/carouselBanner/add');
};
const handleBatchDelete = () => {
if (selectedRows.value.length === 0) {
ElMessage.warning('请选择要删除的数据');
return;
}
ElMessageBox.confirm(`确定要删除选中的 ${selectedRows.value.length} 条数据吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消'
}).then(() => {
ElMessage.success('批量删除成功');
getList();
selectedRows.value = [];
}).catch(() => {
ElMessage.info('已取消删除');
});
};
const handleSelectionChange = (selection: any[]) => {
selectedRows.value = selection;
};
const handleTop = (row: any) => {
ElMessage.success(`"${row.title}" 已置顶`);
};
const handleStatusChange = (row: any) => {
const newStatus = row.status === 'online' ? 'offline' : 'online';
const actionText = newStatus === 'online' ? '上架' : '下架';
ElMessageBox.confirm(`确定要${actionText}轮播图"${row.title}"吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消'
}).then(() => {
row.status = newStatus;
ElMessage.success(`${actionText}成功`);
}).catch(() => {
ElMessage.info('已取消操作');
});
};
const handleEdit = (row: any) => {
console.log('编辑:', row);
ElMessage.info(`编辑标题: ${row.title}`);
};
const handleView = (row: any) => {
console.log('查看:', row);
ElMessage.info(`查看标题: ${row.title}`);
};
const handleDelete = async (row: any) => {
try {
await ElMessageBox.confirm('确定要删除这条数据吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消'
});
const res: any = await deleteCarouselBanner(row.id);
if (res.code === 200) {
ElMessage.success('删除成功');
getList();
} else {
ElMessage.error(res.msg || '删除失败');
}
} catch (error: any) {
if (error !== 'cancel') {
console.error('删除失败:', error);
ElMessage.error('删除失败,请重试');
}
}
};
const handleSizeChange = (val: number) => {
pageSize.value = val;
currentPage.value = 1;
getList();
};
const handleCurrentChange = (val: number) => {
currentPage.value = val;
getList();
};
onMounted(() => {
getList();
});
</script>
<style scoped>
.carousel-container {
padding: 20px;
background: #f5f7fa;
min-height: calc(100vh - 100px);
}
.search-panel {
background: #fff;
padding: 16px 20px;
border-radius: 8px;
margin-bottom: 16px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
:deep(.el-form-item__label) {
white-space: nowrap;
margin-right: 8px;
}
.search-input,
.date-picker,
.search-select {
width: 150px;
}
.action-bar {
display: flex;
justify-content: space-between;
align-items: flex-start;
background: #fff;
padding: 12px 20px;
border-radius: 8px;
margin-bottom: 16px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.action-left {
display: flex;
gap: 8px;
}
.action-right {
max-width: 600px;
}
.tips-label {
font-weight: bold;
color: #303133;
display: block;
margin-bottom: 8px;
}
.tips-list {
margin: 0;
padding-left: 20px;
font-size: 12px;
color: #606266;
line-height: 1.8;
}
.tips-list li {
margin-bottom: 4px;
}
.table-container {
background: #fff;
border-radius: 8px;
padding: 16px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
margin-bottom: 16px;
}
.status-badge {
display: flex;
align-items: center;
gap: 6px;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
.status-dot.online {
background: #67c23a;
}
.status-dot.offline {
background: #909399;
}
.pagination-container {
display: flex;
justify-content: space-between;
align-items: center;
background: #fff;
padding: 12px 20px;
border-radius: 8px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}
.total-text {
color: #909399;
}
:deep(.el-button--text) {
padding: 4px 8px;
}
:deep(.online-btn) {
color: #67c23a;
}
:deep(.online-btn:hover) {
color: #67c23a;
background: rgba(103, 194, 58, 0.1);
}
:deep(.offline-btn) {
color: #e6a23c;
}
:deep(.offline-btn:hover) {
color: #e6a23c;
background: rgba(230, 162, 60, 0.1);
}
:deep(.delete-btn) {
color: #f56c6c;
}
:deep(.delete-btn:hover) {
color: #f56c6c;
background: rgba(245, 108, 108, 0.1);
}
</style>