fix:流量
All checks were successful
构建并部署前端到生产环境 / build-and-deploy (push) Successful in 52s

This commit is contained in:
sexygoat
2026-04-27 18:30:26 +08:00
parent 5de611d28f
commit e121fca8ca
2 changed files with 52 additions and 39 deletions

View File

@@ -39,12 +39,23 @@
</template>
<script setup>
import { ref, computed, watch } from 'vue';
import { assetApi } from '@/api/index.js';
import { useUserStore } from '@/store/index.js';
import {
ref,
computed,
watch
} from 'vue';
import {
assetApi
} from '@/api/index.js';
import {
useUserStore
} from '@/store/index.js';
const props = defineProps({
identifier: { type: String, default: '' }
identifier: {
type: String,
default: ''
}
});
const emit = defineEmits(['packageLoaded']);
@@ -59,7 +70,10 @@
// 格式化流量数据MB 转 GB
const formatTraffic = (mb) => {
if (!mb || mb === 0) {
return { value: '0.00', unit: 'MB' };
return {
value: '0.00',
unit: 'MB'
};
}
if (mb >= 1024) {
@@ -102,24 +116,19 @@
if (!identifier) return;
try {
const data = await assetApi.getPackageHistory(identifier, 1, 10, { status: 1 });
const data = await assetApi.getInfo(identifier);
if (data.items && data.items.length > 0) {
// 只有一个生效中的套餐
const activePackage = data.items[0];
if (activePackage.enable_virtual_data) {
usedMB.value = activePackage.virtual_used_mb || 0;
if (data.current_package_usage_id) {
if (data.enable_virtual_data) {
usedMB.value = data.virtual_used_mb || 0;
totalMB.value = data.virtual_total_mb || 0;
} else {
usedMB.value = activePackage.data_usage_mb || 0;
usedMB.value = data.real_used_mb || 0;
totalMB.value = data.real_total_mb || 0;
}
totalMB.value = activePackage.data_limit_mb || 0;
remainMB.value = totalMB.value - usedMB.value;
// 将套餐信息(包括到期时间)传递给父组件
emit('packageLoaded', activePackage);
remainMB.value = Math.max(totalMB.value - usedMB.value, 0);
emit('packageLoaded', data);
} else {
// 没有生效中的套餐
usedMB.value = 0;
totalMB.value = 0;
remainMB.value = 0;
@@ -135,7 +144,9 @@ if (activePackage.enable_virtual_data) {
if (newVal) {
loadPackageData();
}
}, { immediate: true });
}, {
immediate: true
});
</script>
<style scoped lang="scss">
@@ -144,14 +155,23 @@ if (activePackage.enable_virtual_data) {
display: flex;
align-items: baseline;
gap: 4rpx;
.title { font-size: 35rpx; font-weight: 700; margin-right: 5rpx; }
.title {
font-size: 35rpx;
font-weight: 700;
margin-right: 5rpx;
}
}
.traffic-stats {
background: var(--gray-100);
border-radius: var(--radius-small);
padding: 20rpx;
margin-top: 16rpx;
.stat-item { flex: 1; }
.stat-item {
flex: 1;
}
}
}
</style>
</style>