| | |
| | | <span class="filter-label">数据类目:</span> |
| | | <el-select v-model="queryParams.dataCategory" placeholder="全部" clearable> |
| | | <el-option label="全部" value="" /> |
| | | <el-option label="资源贡献" value="resource_contribution" /> |
| | | <el-option label="资源交易" value="resource_transaction" /> |
| | | <el-option label="资源传播" value="resource_dissemination" /> |
| | | <el-option label="用户参与" value="user_participation" /> |
| | | <el-option label="积分转换" value="points_conversion" /> |
| | | <el-option label="其他" value="other" /> |
| | | <el-option |
| | | v-for="category in categoryList" |
| | | :key="category" |
| | | :label="getCategoryLabel(category)" |
| | | :value="category" |
| | | /> |
| | | </el-select> |
| | | </div> |
| | | <div class="filter-item"> |
| | | <span class="filter-label">时间:</span> |
| | | <el-date-picker |
| | | v-model="dateRange" |
| | | type="daterange" |
| | | type="datetimerange" |
| | | range-separator="至" |
| | | start-placeholder="开始日期" |
| | | end-placeholder="结束日期" |
| | | format="YYYY-MM-DD" |
| | | value-format="YYYY-MM-DD" |
| | | format="YYYY-MM-DD HH:mm:ss" |
| | | date-format="YYYY-MM-DD" |
| | | time-format="HH:mm:ss" |
| | | @change="handleDateChange" |
| | | /> |
| | | </div> |
| | |
| | | <span class="filter-label">数据类型:</span> |
| | | <el-select v-model="queryParams.dataType" placeholder="全部" clearable> |
| | | <el-option label="全部" value="" /> |
| | | <el-option label="获取" value="earned" /> |
| | | <el-option label="消耗" value="consumed" /> |
| | | <el-option label="转换" value="converted" /> |
| | | <el-option label="获取" value="0" /> |
| | | <el-option label="消耗" value="1" /> |
| | | </el-select> |
| | | </div> |
| | | </div> |
| | |
| | | <span>{{ getCategoryLabel(row.dataCategory) }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="name" label="名称" min-width="300" show-overflow-tooltip /> |
| | | <el-table-column prop="flowTime" label="时间" width="180" align="center" /> |
| | | <el-table-column prop="points" label="积分" width="100" align="center"> |
| | | <el-table-column prop="name" label="名称" show-overflow-tooltip /> |
| | | <el-table-column prop="flowTime" label="时间" align="center" /> |
| | | <el-table-column prop="points" label="积分" align="center"> |
| | | <template #default="{ row }"> |
| | | <span :class="row.points > 0 ? 'points-earned' : 'points-consumed'"> |
| | | {{ row.points > 0 ? '+' : '' }}{{ row.points }} |
| | |
| | | |
| | | <script setup lang="ts"> |
| | | import { ref, reactive, onMounted, computed } from 'vue' |
| | | import { ElMessage } from 'element-plus' |
| | | import { dayjs, ElMessage } from 'element-plus' |
| | | import { |
| | | ArrowLeft, |
| | | Refresh, |
| | |
| | | } from '@element-plus/icons-vue' |
| | | import pointsApi from '@/api/pointsApi' |
| | | import type { PointsStats, PointsFlow, PointsQueryParams } from '@/types/points' |
| | | import { useUserInfo } from '@/stores/modules/userInfo' |
| | | import { queryUserDetail } from '@/api/userInfo' |
| | | |
| | | // 获取用户信息 store |
| | | const userStore = useUserInfo() |
| | | |
| | | // 积分统计 |
| | | const stats = ref<PointsStats>({ |
| | | balance: 20000, |
| | | totalEarned: 10000, |
| | | totalConsumed: 200, |
| | | balance: 0, |
| | | totalEarned: 0, |
| | | totalConsumed: 0, |
| | | totalConverted: 0, |
| | | }) |
| | | |
| | | // 查询参数 |
| | | const queryParams = reactive<PointsQueryParams>({ |
| | | userId: '', |
| | | dataCategory: '', |
| | | dataType: '', |
| | | startTime: '', |
| | | endTime: '', |
| | | pageNum: 1, |
| | | pageSize: 10, |
| | | }) |
| | |
| | | |
| | | // 总数 |
| | | const total = ref(0) |
| | | |
| | | // 数据类目列表 |
| | | const categoryList = ref<string[]>([]) |
| | | |
| | | // 格式化数字 |
| | | const formatNumber = (num: number) => { |
| | |
| | | // 获取积分统计 |
| | | const getPointsStats = async () => { |
| | | try { |
| | | const res = await pointsApi.getPersonalPointsStats() |
| | | const userId = userStore.getUserId || userStore.getUserInfo?.userId |
| | | if (!userId) { |
| | | console.error('无法获取用户ID') |
| | | return |
| | | } |
| | | // 更新查询参数中的 userId |
| | | queryParams.userId = userId.toString() |
| | | const res = await pointsApi.getPersonalPointsStats(userId) |
| | | if (res.code === 200 && res.data) { |
| | | stats.value = res.data |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | // 获取数据类目列表 |
| | | const getCategoryList = async () => { |
| | | try { |
| | | const res = await pointsApi.getPointsFlowCategories() |
| | | if (res.code === 200 && res.data) { |
| | | categoryList.value = res.data |
| | | } |
| | | } catch (error) { |
| | | console.error('获取数据类目失败:', error) |
| | | } |
| | | } |
| | | |
| | | // 获取积分流水 |
| | | const getPointsFlow = async () => { |
| | | try { |
| | | const userId = userStore.getUserId || userStore.getUserInfo?.userId |
| | | if (!userId) { |
| | | console.error('无法获取用户ID') |
| | | return |
| | | } |
| | | // 更新查询参数中的 userId |
| | | queryParams.userId = userId.toString() |
| | | const res = await pointsApi.getPersonalPointsFlow(queryParams) |
| | | if (res.code === 200) { |
| | | flowList.value = res.data.list || [] |
| | |
| | | const resetQuery = () => { |
| | | queryParams.dataCategory = '' |
| | | queryParams.dataType = '' |
| | | queryParams.startTime = '' |
| | | queryParams.endTime = '' |
| | | queryParams.flowStartTime = '' |
| | | queryParams.flowEndTime = '' |
| | | dateRange.value = null |
| | | queryParams.pageNum = 1 |
| | | queryData() |
| | |
| | | // 处理日期变化 |
| | | const handleDateChange = (dates: [string, string] | null) => { |
| | | if (dates) { |
| | | queryParams.startTime = dates[0] |
| | | queryParams.endTime = dates[1] |
| | | queryParams.flowStartTime = dayjs(dates[0]).format('YYYY-MM-DD HH:mm:ss'); |
| | | queryParams.flowEndTime = dayjs(dates[1]).format('YYYY-MM-DD HH:mm:ss'); |
| | | } else { |
| | | queryParams.startTime = '' |
| | | queryParams.endTime = '' |
| | | queryParams.flowStartTime = '' |
| | | queryParams.flowEndTime = '' |
| | | } |
| | | } |
| | | |
| | |
| | | ElMessage.info('关闭全部功能') |
| | | } |
| | | |
| | | onMounted(() => { |
| | | onMounted(async () => { |
| | | // 页面挂载时,检查 userStore 是否已有用户信息 |
| | | let userId = userStore.getUserId || userStore.getUserInfo?.userId |
| | | if (!userId) { |
| | | try { |
| | | const res: any = await queryUserDetail() |
| | | if (res?.code === 200 && res.data) { |
| | | userStore.updateUserDetail(res.data) |
| | | userId = res.data.userId || res.data.id |
| | | } else { |
| | | ElMessage.error(res?.msg || '无法获取用户信息,请先登录') |
| | | return |
| | | } |
| | | } catch (e) { |
| | | console.error('获取用户详情失败:', e) |
| | | ElMessage.error('获取用户信息失败,请稍后重试') |
| | | return |
| | | } |
| | | } |
| | | |
| | | getPointsStats() |
| | | getPointsFlow() |
| | | getCategoryList() |
| | | }) |
| | | </script> |
| | | |