fix:进度条
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 4m44s

This commit is contained in:
sexygoat
2026-04-30 17:01:00 +08:00
parent 78a41513bd
commit 81155fd8e4
12 changed files with 457 additions and 178 deletions

View File

@@ -2,11 +2,9 @@
* 资产信息格式化工具函数
*/
import type { Ref } from 'vue'
type TagType = 'primary' | 'success' | 'warning' | 'info' | 'danger'
export function useAssetFormatters(deviceRealtime?: Ref<any>) {
export function useAssetFormatters() {
// 格式化数据大小MB 转 GB/MB
const formatDataSize = (mb: number) => {
if (mb >= 1024) {
@@ -145,57 +143,27 @@ export function useAssetFormatters(deviceRealtime?: Ref<any>) {
return map[status] || 'info'
}
const parseSignalValue = (value: unknown) => {
if (value === null || value === undefined || value === '') return null
const parsed = Number(value)
return Number.isNaN(parsed) ? null : parsed
// 获取设备信号综合判断文案
const getSignalQualityText = (quality?: string | null) => {
return quality?.trim() || '暂无数据'
}
const clamp = (value: number, min: number, max: number) => {
return Math.min(Math.max(value, min), max)
}
const calculateSignalScore = () => {
if (!deviceRealtime?.value) return null
const rsrp = parseSignalValue(deviceRealtime.value.rsrp)
const rsrq = parseSignalValue(deviceRealtime.value.rsrq)
const sinr = parseSignalValue(deviceRealtime.value.sinr)
// RSRP、RSRQ 必须是负数SINR 允许 0 或负值
if (rsrp === null || rsrq === null || sinr === null) return null
if (rsrp >= 0 || rsrq >= 0) return null
const rsrpScore = clamp((rsrp + 120) * 2, 0, 100)
const rsrqScore = clamp((rsrq + 20) * 5, 0, 100)
const sinrScore = clamp(sinr * 5, 0, 100)
return rsrpScore * 0.5 + sinrScore * 0.3 + rsrqScore * 0.2
}
// 计算信号强度等级:基于 RSRP、RSRQ、SINR 的综合评分RSSI 不参与
const calculateSignalStrength = () => {
const score = calculateSignalScore()
if (score === null) return '-'
if (score >= 85) return '极好'
if (score >= 70) return '良好'
if (score >= 50) return '一般'
if (score >= 30) return '较差'
return '很差'
}
// 获取信号强度标签类型
const getSignalStrengthType = (): TagType => {
const strength = calculateSignalStrength()
// 获取设备信号综合判断标签类型
const getSignalQualityType = (quality?: string | null): TagType => {
const normalizedQuality = getSignalQualityText(quality)
const map: Record<string, TagType> = {
: 'success',
: 'success',
: 'warning',
: 'danger',
: 'danger'
: 'success',
: 'success',
: 'warning',
: 'danger',
: 'info'
}
return map[strength] || 'info'
return map[normalizedQuality] || 'info'
}
// 获取设备弱信号原因文案
const getSignalBadReasonText = (reason?: string | null) => {
return reason?.trim() || '暂时无法判断'
}
// 获取切卡模式名称
@@ -242,6 +210,31 @@ export function useAssetFormatters(deviceRealtime?: Ref<any>) {
return '#f56c6c'
}
// 格式化进度百分比文本
const formatProgressPercentage = (percentage: number): string => {
if (!Number.isFinite(percentage)) return '0%'
const normalizedPercentage = Math.min(Math.max(percentage, 0), 100)
if (Number.isInteger(normalizedPercentage)) return `${normalizedPercentage}%`
return `${normalizedPercentage.toFixed(2).replace(/\.?0+$/, '')}%`
}
// 计算断点位置百分比(用于虚流量停机阈值标记)
const getBreakpointPercentage = (breakpoint: number, total: number): number => {
if (!total || total <= 0) return 0
const percentage = (breakpoint / total) * 100
return Math.min(Math.max(Math.round(percentage * 100) / 100, 0), 100)
}
// 生成断点标记样式,避免圆点在进度条两端溢出
const getBreakpointMarkerStyle = (breakpoint: number, total: number, markerSize: number = 8) => {
const percentage = getBreakpointPercentage(breakpoint, total)
const halfMarkerSize = markerSize / 2
return {
left: `clamp(${halfMarkerSize}px, ${percentage}%, calc(100% - ${halfMarkerSize}px))`
}
}
return {
formatDataSize,
formatAmount,
@@ -256,12 +249,16 @@ export function useAssetFormatters(deviceRealtime?: Ref<any>) {
getOnlineStatusType,
getWalletStatusType,
getPackageStatusTagType,
calculateSignalStrength,
getSignalStrengthType,
getSignalQualityText,
getSignalQualityType,
getSignalBadReasonText,
getSwitchModeName,
getTransactionTypeTag,
getPaymentStatusType,
getUsageProgress,
getProgressColorByPercentage
getProgressColorByPercentage,
formatProgressPercentage,
getBreakpointPercentage,
getBreakpointMarkerStyle
}
}