Blame view

antis-ncc-admin/src/components/workbench/flow-counts.js 1.37 KB
e1dcb3a0   “wangming”   1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  import { FlowBeforeList } from '@/api/workFlow/FlowBefore'
  import { FlowDelegateList } from '@/api/workFlow/FlowDelegate'
  
  function extractTotal(res) {
    const data = (res && res.data) || {}
    const p = data.pagination || {}
    if (p.total !== undefined && p.total !== null) return Number(p.total) || 0
    if (p.Total !== undefined && p.Total !== null) return Number(p.Total) || 0
    if (Array.isArray(data.list)) return data.list.length
    return 0
  }
  
  /**
   * 工作台待办真实数量:
   * - 待我审核:FlowBefore category=1
   * - 已办事宜:FlowBefore category=2
   * - 流程委托:FlowDelegate 列表
   * (Dashboard/FlowTodoCount 后端目前是空实现,不能用)
   */
  export async function fetchFlowWorkbenchCounts() {
    const query = { currentPage: 1, pageSize: 1, sort: 'desc', sidx: '' }
    const [todoRes, doneRes, entrustRes] = await Promise.all([
      FlowBeforeList(1, query).catch(() => null),
      FlowBeforeList(2, query).catch(() => null),
      FlowDelegateList(query).catch(() => null)
    ])
    return {
      toBeReviewed: extractTotal(todoRes),
      flowDone: extractTotal(doneRes),
      entrust: extractTotal(entrustRes)
    }
  }
  
  /** 待办事项列表(最近 N 条) */
  export async function fetchFlowTodoList(pageSize = 8) {
    const res = await FlowBeforeList(1, {
      currentPage: 1,
      pageSize,
      sort: 'desc',
      sidx: ''
    })
    return ((res.data && res.data.list) || [])
  }