seatonwan9
2025-09-02 83d5b2be8fdf0ac0b59cacf6b344c8815ab4d040
src/views/pointsManage/personal/index.vue
@@ -58,11 +58,11 @@
              <span class="filter-label">数据类目:</span>
              <el-select v-model="queryParams.dataCategory" placeholder="全部" clearable>
                <el-option label="全部" value="" />
                <el-option
                  v-for="category in categoryList"
                  :key="category"
                  :label="getCategoryLabel(category)"
                  :value="category"
                <el-option
                  v-for="category in categoryList"
                  :key="category"
                  :label="getCategoryLabel(category)"
                  :value="category"
                />
              </el-select>
            </div>
@@ -103,7 +103,7 @@
        <!-- 流水表格 -->
        <div class="table-section">
          <el-table :data="flowList" stripe style="width: 100%">
          <el-table :data="flowList" stripe style="width: 100%" :height="440">
            <el-table-column prop="id" label="序号" width="80" align="center" />
            <el-table-column prop="dataCategory" label="数据类目" width="120">
              <template #default="{ row }">
@@ -145,18 +145,23 @@
<script setup lang="ts">
import { ref, reactive, onMounted, computed } from 'vue'
import { dayjs, ElMessage } from 'element-plus'
import {
  ArrowLeft,
  Refresh,
  Setting,
  Close,
  Money,
  Plus,
  Minus,
  Search
import {
  ArrowLeft,
  Refresh,
  Setting,
  Close,
  Money,
  Plus,
  Minus,
  Search
} 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>({
@@ -168,7 +173,7 @@
// 查询参数
const queryParams = reactive<PointsQueryParams>({
  userId: '1',
  userId: '',
  dataCategory: '',
  dataType: '',
  pageNum: 1,
@@ -208,7 +213,13 @@
// 获取积分统计
const getPointsStats = async () => {
  try {
    const userId = 1;
    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
@@ -233,6 +244,13 @@
// 获取积分流水
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 || []
@@ -300,7 +318,26 @@
  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()
@@ -332,7 +369,7 @@
        cursor: pointer;
        color: #409eff;
        font-size: 18px;
        &:hover {
          color: #66b1ff;
        }
@@ -354,7 +391,7 @@
          cursor: pointer;
          color: #909399;
          font-size: 16px;
          &:hover {
            color: #409eff;
          }
@@ -548,7 +585,7 @@
        :deep(.el-select),
        :deep(.el-date-picker) {
          width: 100%;
          @media (min-width: 768px) {
            width: auto;
            min-width: 120px;