yeg
2026-08-26 9f48020dfd3e29d1c0049a3da9df3203c40bc264
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import type { GroupStatus } from '@/stores/batteryGroups'
import { request, type ApiResponse } from './request'
 
export interface BatteryGroupListParams {
  pageNum: number
  pageSize: number
  groupId?: number
  groupName?: string
  model?: string
  status?: string
  createBy?: string
  beginCreateTime?: string
  endCreateTime?: string
}
 
interface BatteryGroupDto {
  groupId: number
  groupName: string | null
  model: string | null
  purpose: string | null
  status: string | null
  createBy: string | null
  createTime: string | null
  batteryCount: number | null
}
 
interface BatteryGroupListResponse extends ApiResponse {
  total: number
  rows: BatteryGroupDto[]
}
 
export interface BatteryGroupListItem {
  id: number
  name: string
  model: string
  purpose: string
  batteryCount: number
  createdAt: string
  status: GroupStatus
  creator: string
}
 
export interface BatteryGroupListResult {
  total: number
  rows: BatteryGroupListItem[]
}
 
interface BatteryGroupCreatorResponse extends ApiResponse {
  data: BatteryGroupCreatorDto[]
}
 
interface BatteryGroupCreatorDto {
  userName: string | null
  nickName: string | null
}
 
export interface BatteryGroupCreatorOption {
  label: string
  value: string
}
 
function mapBatteryGroup(item: BatteryGroupDto): BatteryGroupListItem {
  return {
    id: item.groupId,
    name: item.groupName || '-',
    model: item.model || '-',
    purpose: item.purpose || '-',
    batteryCount: Number(item.batteryCount) || 0,
    createdAt: item.createTime || '-',
    status: item.status === '1' ? '禁用' : '启用',
    creator: item.createBy || '-',
  }
}
 
export async function getBatteryGroupList(params: BatteryGroupListParams): Promise<BatteryGroupListResult> {
  const searchParams = new URLSearchParams()
  Object.entries(params).forEach(([key, value]) => {
    if (value === undefined || value === '') return
    searchParams.set(key, String(value))
  })
 
  const result = await request<BatteryGroupListResponse>(`/system/batteryGroup/list?${searchParams.toString()}`)
  return {
    total: Number(result.total) || 0,
    rows: (result.rows || []).map(mapBatteryGroup),
  }
}
 
export async function getBatteryGroupCreatorOptions(): Promise<BatteryGroupCreatorOption[]> {
  const result = await request<BatteryGroupCreatorResponse>('/system/batteryGroup/creatorOptions')
  return (result.data || [])
    .map(item => {
      const value = item.userName?.trim() || ''
      const name = item.nickName?.trim() || value
      return { label: name === value ? name : `${name}(${value})`, value }
    })
    .filter(item => item.value)
}