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)
|
}
|