Просмотр исходного кода

fix(tasks): 任务列表标题列支持排序,孩子ID改为显示用户名

Sisyphus 1 месяц назад
Родитель
Сommit
cd54ba9005

+ 29 - 3
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/AdminController.java

@@ -264,12 +264,12 @@ public class AdminController {
 
     // 任务管理
     @PostMapping("/tasks")
-    public Result<Page<Task>> getTasks(@RequestBody Map<String, Object> params) {
+    public Result<Map<String, Object>> getTasks(@RequestBody Map<String, Object> params) {
         int page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
         int size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 10;
         String status = (String) params.get("status");
         Long familyId = params.get("familyId") != null ? ((Number) params.get("familyId")).longValue() : null;
-        
+
         Page<Task> pageParam = new Page<>(page, size);
         LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>();
         if (status != null && !status.isEmpty()) {
@@ -281,7 +281,33 @@ public class AdminController {
         wrapper.orderByDesc(Task::getCreatedAt);
         SortUtil.applySort(wrapper);
         Page<Task> result = taskMapper.selectPage(pageParam, wrapper);
-        return Result.success(result);
+
+        // 为每条任务填充执行者名称
+        java.util.List<Map<String, Object>> records = new java.util.ArrayList<>();
+        for (Task t : result.getRecords()) {
+            Map<String, Object> item = new java.util.HashMap<>();
+            org.springframework.beans.BeanUtils.copyProperties(t, item);
+            // 根据 executorType 查昵称
+            String executorType = t.getExecutorType();
+            Long executorId = t.getExecutorId();
+            if ("child".equals(executorType) && executorId != null) {
+                FamilyMember fm = familyMemberMapper.selectById(executorId);
+                item.put("executorName", fm != null ? fm.getNickname() : "未知成员");
+            } else if ("parent".equals(executorType) && executorId != null) {
+                User u = userMapper.selectById(executorId);
+                item.put("executorName", u != null ? u.getNickname() : "未知用户");
+            } else {
+                item.put("executorName", "");
+            }
+            records.add(item);
+        }
+
+        Map<String, Object> resultMap = new java.util.HashMap<>();
+        resultMap.put("records", records);
+        resultMap.put("total", result.getTotal());
+        resultMap.put("current", result.getCurrent());
+        resultMap.put("size", result.getSize());
+        return Result.success(resultMap);
     }
 
     @PostMapping("/tasks/stats")

+ 7 - 2
cfc-web/src/views/Tasks.vue

@@ -96,7 +96,7 @@
       <!-- 任务列表 -->
       <el-table :data="tableData" border v-loading="loading" style="width: 100%" :max-height="tableHeight">
         <el-table-column prop="id" label="ID" width="80"></el-table-column>
-        <el-table-column prop="title" label="任务名称" min-width="200"></el-table-column>
+        <el-table-column prop="title" label="任务名称" min-width="200" :class-name="sortClass('title')" @click.native="onSortClick('title')"></el-table-column>
         <el-table-column prop="points" label="积分" width="80">
           <template slot-scope="scope">
             <el-tag type="success">{{ scope.row.points }}</el-tag>
@@ -122,7 +122,7 @@
             </el-tag>
           </template>
         </el-table-column>
-        <el-table-column prop="childId" label="孩子ID" width="80"></el-table-column>
+        <el-table-column prop="executorName" label="用户" width="100"></el-table-column>
         <el-table-column prop="createdAt" label="创建时间" width="180">
           <template slot-scope="scope">
             {{ formatDate(scope.row.createdAt) }}
@@ -147,9 +147,12 @@
 
 <script>
 import { getTasksList, getTaskStats, getFamilyList } from '@/api/admin'
+import SortMixin from '@/mixins/SortMixin'
 
 export default {
+  mixins: [SortMixin],
   name: 'Tasks',
+  sortableColumns: { title: '任务名称' },
   computed: {
     tableHeight() {
       return window.innerHeight - 340
@@ -158,6 +161,7 @@ export default {
   data() {
     return {
       loading: false,
+      sortState: [],
       tableData: [],
       stats: {
         total: 0,
@@ -199,6 +203,7 @@ export default {
           status: this.searchForm.status,
           familyId: this.searchForm.familyId || undefined
         }
+        this.applySortToParams(params)
         const res = await getTasksList(params)
         this.tableData = res.data.records || res.data || []
         this.pagination.total = res.data.total || this.tableData.length