<template>
|
<div class="points-rule-list">
|
<!-- 页面标题 -->
|
<div class="page-title">积分规则管理</div>
|
|
<!-- 规则列表卡片 -->
|
<el-card shadow="never" class="rule-list-card">
|
<!-- 筛选条件 -->
|
<div class="filter-section">
|
<div class="filter-row">
|
<div class="filter-item">
|
<span class="filter-label">生效时间:</span>
|
<el-date-picker
|
v-model="queryParams.dateRange"
|
type="datetimerange"
|
range-separator="至"
|
start-placeholder="开始日期"
|
end-placeholder="结束日期"
|
format="YYYY-MM-DD HH:mm:ss"
|
value-format="YYYY-MM-DD HH:mm:ss"
|
date-format="YYYY-MM-DD"
|
time-format="HH:mm:ss"
|
style="margin-left: 8px;"
|
@change="handleDateChange"
|
/>
|
</div>
|
|
</div>
|
<div class="filter-actions">
|
<el-button type="primary" @click="queryData">
|
<el-icon><Search /></el-icon>
|
查询
|
</el-button>
|
<el-button @click="resetQuery">
|
<el-icon><Refresh /></el-icon>
|
重置
|
</el-button>
|
</div>
|
</div>
|
|
<!-- 规则表格 -->
|
<div class="table-section">
|
<el-table :data="ruleList" stripe style="width: 100%">
|
<el-table-column prop="id" label="序号" width="80" align="center" />
|
<el-table-column prop="pointsName" label="名称" align="ceter">
|
<template #default="{ row }">
|
{{ row.pointsName}}{{ row.updatedAt}}V{{ row.version }}
|
</template>
|
</el-table-column>
|
|
<el-table-column prop="effectiveStart" label="开始生效时间" align="center" />
|
<el-table-column prop="modifierName" label="修改人" align="center" />
|
|
<el-table-column label="操作" align="center" fixed="right">
|
<template #default="{ row }">
|
<el-button type="primary" size="small" @click="editRule(row)">查看</el-button>
|
<el-button type="primary" size="small" @click="editRule(row)">编辑</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<!-- 分页 -->
|
<div class="pagination-section">
|
<div class="pagination-info">
|
共{{ total }}条
|
</div>
|
<el-pagination
|
v-model:current-page="queryParams.pageNum"
|
v-model:page-size="queryParams.pageSize"
|
:page-sizes="[10, 20, 50, 100]"
|
:total="total"
|
layout="sizes, prev, pager, next, jumper"
|
@size-change="handleSizeChange"
|
@current-change="handleCurrentChange"
|
/>
|
</div>
|
</div>
|
</el-card>
|
</div>
|
</template>
|
|
<script setup lang="ts">
|
import { ref, reactive, onMounted } from 'vue'
|
import { dayjs, ElMessage } from 'element-plus'
|
import { Search, Refresh } from '@element-plus/icons-vue'
|
import pointsApi from '@/api/pointsApi'
|
import type { PointsRule, PointsQueryParams } from '@/types/points'
|
// 导入路由钩子
|
import { useRouter } from 'vue-router'
|
|
// 查询参数
|
const queryParams = reactive<PointsQueryParams>({
|
// ruleType: '',
|
// category: '',
|
// status: '',
|
dateRange: '',
|
pageNum: 1,
|
pageSize: 10,
|
})
|
|
// 规则列表
|
const ruleList = ref<PointsRule[]>([])
|
|
// 总数
|
const total = ref(0)
|
|
// 页面加载时获取数据
|
onMounted(() => {
|
queryData()
|
})
|
|
// 查询数据
|
const queryData = async () => {
|
try {
|
const res = await pointsApi.getPointsRules(queryParams)
|
// 模拟分页数据
|
ruleList.value = res.data.list || []
|
total.value = ruleList.value.length
|
} catch (error) {
|
ElMessage.error('获取积分规则失败')
|
console.error('获取积分规则失败:', error)
|
}
|
}
|
|
// 重置查询
|
const resetQuery = () => {
|
Object.keys(queryParams).forEach(key => {
|
queryParams[key as keyof PointsQueryParams] = '' as any
|
})
|
queryParams.pageNum = 1
|
queryParams.pageSize = 10
|
queryData()
|
}
|
|
// 处理分页大小变化
|
const handleSizeChange = (size: number) => {
|
queryParams.pageSize = size
|
queryData()
|
}
|
|
// 处理当前页码变化
|
const handleCurrentChange = (current: number) => {
|
queryParams.pageNum = current
|
queryData()
|
}
|
|
// 获取规则类型标签
|
const getRuleTypeLabel = (type: string) => {
|
const typeMap: Record<string, string> = {
|
acquisition: '获取',
|
consumption: '消耗',
|
conversion: '转换',
|
}
|
return typeMap[type] || type
|
}
|
|
// 获取分类标签
|
const getCategoryLabel = (category: string) => {
|
const categoryMap: Record<string, string> = {
|
resource_contribution: '资源贡献',
|
resource_transaction: '资源交易',
|
resource_dissemination: '资源传播',
|
user_participation: '用户参与',
|
other: '其他',
|
}
|
return categoryMap[category] || category
|
}
|
|
// 处理状态变化
|
const handleStatusChange = async (row: PointsRule) => {
|
try {
|
await pointsApi.savePointsRules({
|
id: row.id,
|
status: row.status
|
})
|
ElMessage.success('状态更新成功')
|
} catch (error) {
|
ElMessage.error('状态更新失败')
|
// 恢复原来的状态
|
row.status = row.status === 1 ? 0 : 1
|
console.error('更新规则状态失败:', error)
|
}
|
}
|
|
// 处理日期变化
|
const handleDateChange = (dates: [string, string] | null) => {
|
if (dates) {
|
queryParams.effectiveStartTime = dates[0]
|
queryParams.effectiveEndTime = dates[1]
|
} else {
|
queryParams.effectiveStartTime = ''
|
queryParams.effectiveEndTime = ''
|
}
|
}
|
|
// 创建路由实例
|
const router = useRouter()
|
|
// 编辑规则
|
const editRule = (row: PointsRule) => {
|
// 跳转到规则设置界面,并传入规则id
|
router.push({
|
path: '/points/settings',
|
query: { ruleId: row.id }
|
})
|
}
|
</script>
|
|
<style scoped lang="scss">
|
.points-rule-list {
|
padding: 20px;
|
|
.page-title {
|
font-size: 18px;
|
font-weight: bold;
|
margin-bottom: 20px;
|
color: #333;
|
}
|
|
.rule-list-card {
|
.filter-section {
|
margin-bottom: 20px;
|
display: flex;
|
gap: 20px;
|
.filter-row {
|
display: flex;
|
flex-wrap: wrap;
|
gap: 16px;
|
margin-bottom: 16px;
|
|
.filter-item {
|
display: flex;
|
align-items: center;
|
margin-bottom: 8px;
|
|
.filter-label {
|
margin-right: 8px;
|
color: #606266;
|
}
|
|
.el-select {
|
width: 180px;
|
}
|
}
|
}
|
|
.filter-actions {
|
display: flex;
|
justify-content: flex-end;
|
gap: 10px;
|
}
|
}
|
|
.table-section {
|
.pagination-section {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-top: 16px;
|
padding: 10px 0;
|
|
.pagination-info {
|
color: #606266;
|
}
|
}
|
}
|
}
|
}
|
</style>
|