352 lines
10 KiB
Vue
352 lines
10 KiB
Vue
<template>
|
||
<div class="container-box storage-page">
|
||
<div class="header-bar">
|
||
<h2>存储空间</h2>
|
||
<div class="header-actions">
|
||
<el-button @click="loadOrders"><el-icon><Refresh /></el-icon>刷新订单</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<el-alert
|
||
type="info"
|
||
:closable="false"
|
||
show-icon
|
||
class="tips"
|
||
title="查看并调整各租户的附件空间。租户实际可用空间 = max(基础额度, 已生效扩容套餐容量)。扩容套餐的维护在「基础设置 → 存储套餐」。"
|
||
/>
|
||
|
||
<div class="panel">
|
||
<div class="panel-head">
|
||
<h3>租户存储额度</h3>
|
||
<span class="tip">输入租户 ID 查询用量,可直接调整基础额度</span>
|
||
</div>
|
||
<div class="query-bar">
|
||
<el-input
|
||
v-model="tidInput"
|
||
type="number"
|
||
placeholder="请输入租户 ID"
|
||
clearable
|
||
style="width: 220px"
|
||
@keyup.enter="queryTenant"
|
||
/>
|
||
<el-button type="primary" @click="queryTenant">查询</el-button>
|
||
</div>
|
||
|
||
<div v-if="tenantLoading" v-loading="tenantLoading" class="tenant-placeholder"></div>
|
||
|
||
<template v-else-if="info && info.tid">
|
||
<div class="usage-row">
|
||
<span class="used">{{ formatSize(info.used_bytes) }}</span>
|
||
<span class="total">/ {{ formatSize(info.quota_bytes) }}</span>
|
||
<el-tag size="small" type="info" effect="plain">已用 {{ info.used_percent || 0 }}%</el-tag>
|
||
</div>
|
||
<el-progress
|
||
:percentage="progressPercent"
|
||
:status="progressStatus"
|
||
:stroke-width="10"
|
||
:format="() => `${progressPercent}%`"
|
||
/>
|
||
<div class="usage-foot">
|
||
<span>基础额度 {{ info.base_quota_mb }} MB</span>
|
||
<span v-if="info.package_quota_mb">· 套餐 {{ info.package_name }} {{ formatCapacity(info.package_quota_mb) }}(剩 {{ info.days_remaining }} 天)</span>
|
||
<span>· 剩余 {{ formatSize(info.remaining_bytes) }}</span>
|
||
</div>
|
||
|
||
<div class="quota-edit">
|
||
<span class="label">调整基础额度</span>
|
||
<el-input-number v-model="quotaInput" :min="0" :max="1024 * 1024" :step="100" controls-position="right" />
|
||
<span class="unit">MB(0 = 恢复默认 {{ 500 }}MB)</span>
|
||
<el-button type="primary" :loading="quotaSaving" @click="saveQuota">保存</el-button>
|
||
</div>
|
||
</template>
|
||
|
||
<el-empty v-else description="请输入租户 ID 查询存储用量" />
|
||
</div>
|
||
|
||
<div class="panel">
|
||
<div class="panel-head">
|
||
<h3>存储购买订单</h3>
|
||
<div class="order-filter">
|
||
<el-select v-model="orderStatus" placeholder="状态" clearable style="width: 130px" @change="loadOrders">
|
||
<el-option label="待支付" value="pending" />
|
||
<el-option label="已支付" value="paid" />
|
||
<el-option label="已取消" value="cancelled" />
|
||
<el-option label="已替换" value="replaced" />
|
||
</el-select>
|
||
</div>
|
||
</div>
|
||
<el-table :data="orders" v-loading="ordersLoading" size="small" border stripe>
|
||
<el-table-column prop="order_no" label="订单号" min-width="180" show-overflow-tooltip />
|
||
<el-table-column prop="tid" label="租户ID" width="90" align="center" />
|
||
<el-table-column prop="package_name" label="套餐" min-width="120" />
|
||
<el-table-column label="容量" width="100" align="center">
|
||
<template #default="{ row }">{{ formatCapacity(row.capacity_mb) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="金额" width="100" align="center">
|
||
<template #default="{ row }">¥{{ Number(row.amount || 0).toFixed(2) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="状态" width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag size="small" :type="orderStatusType(row.status)">{{ orderStatusText(row.status) }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="有效期" min-width="190" align="center">
|
||
<template #default="{ row }">
|
||
<span v-if="row.start_time && row.end_time">{{ formatDate(row.start_time) }} ~ {{ formatDate(row.end_time) }}</span>
|
||
<span v-else>-</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="create_time" label="下单时间" min-width="160" align="center">
|
||
<template #default="{ row }">{{ formatDate(row.create_time) }}</template>
|
||
</el-table-column>
|
||
<template #empty><el-empty description="暂无存储订单" /></template>
|
||
</el-table>
|
||
<div class="pagination-bar">
|
||
<el-pagination
|
||
:current-page="orderPage"
|
||
:page-size="orderPageSize"
|
||
:total="orderTotal"
|
||
@current-change="handleOrderPage"
|
||
layout="total, prev, pager, next"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, ref } from "vue";
|
||
import { ElMessage } from "element-plus";
|
||
import { Refresh } from "@element-plus/icons-vue";
|
||
import {
|
||
getTenantStorageInfo,
|
||
getStorageOrders,
|
||
updateTenantStorageQuota,
|
||
} from "@/api/storage";
|
||
|
||
const tidInput = ref<string>("");
|
||
const tenantLoading = ref(false);
|
||
const info = ref<Record<string, any>>({});
|
||
const quotaInput = ref<number>(500);
|
||
const quotaSaving = ref(false);
|
||
|
||
const orders = ref<any[]>([]);
|
||
const ordersLoading = ref(false);
|
||
const orderStatus = ref("");
|
||
const orderPage = ref(1);
|
||
const orderPageSize = ref(10);
|
||
const orderTotal = ref(0);
|
||
|
||
const progressPercent = computed(() => {
|
||
const p = Number(info.value.used_percent) || 0;
|
||
return Math.min(100, Math.max(0, Math.round(p * 10) / 10));
|
||
});
|
||
|
||
const progressStatus = computed(() => {
|
||
const p = progressPercent.value;
|
||
if (p >= 95) return "exception";
|
||
if (p >= 80) return "warning";
|
||
return "";
|
||
});
|
||
|
||
const formatSize = (bytes: any) => {
|
||
const n = Number(bytes) || 0;
|
||
if (n >= 1024 ** 3) return `${(n / 1024 ** 3).toFixed(2)} GB`;
|
||
if (n >= 1024 ** 2) return `${(n / 1024 ** 2).toFixed(1)} MB`;
|
||
if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`;
|
||
return `${n} B`;
|
||
};
|
||
|
||
const formatCapacity = (mb: any) => {
|
||
const n = Number(mb) || 0;
|
||
return n >= 1024 ? `${(n / 1024).toFixed(n % 1024 === 0 ? 0 : 1)} GB` : `${n} MB`;
|
||
};
|
||
|
||
const formatDate = (value: any) => {
|
||
if (!value) return "-";
|
||
const d = new Date(value);
|
||
if (Number.isNaN(d.getTime())) return String(value).slice(0, 19).replace("T", " ");
|
||
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
||
};
|
||
|
||
const orderStatusText = (s: string) =>
|
||
({ pending: "待支付", paid: "已支付", cancelled: "已取消", replaced: "已替换" }[s] || s);
|
||
const orderStatusType = (s: string) =>
|
||
({ pending: "warning", paid: "success", cancelled: "info", replaced: "info" }[s] || "info");
|
||
|
||
const queryTenant = async () => {
|
||
const tid = Number(tidInput.value || 0);
|
||
if (!tid || tid <= 0) {
|
||
ElMessage.warning("请输入有效的租户 ID");
|
||
return;
|
||
}
|
||
tenantLoading.value = true;
|
||
try {
|
||
const res = await getTenantStorageInfo(tid);
|
||
if (res?.code === 200) {
|
||
info.value = res.data || {};
|
||
quotaInput.value = Number(info.value.base_quota_mb || 500);
|
||
} else {
|
||
info.value = {};
|
||
ElMessage.error(res?.msg || "查询失败");
|
||
}
|
||
} catch (e: any) {
|
||
info.value = {};
|
||
ElMessage.error(e?.message || "查询失败");
|
||
} finally {
|
||
tenantLoading.value = false;
|
||
}
|
||
};
|
||
|
||
const saveQuota = async () => {
|
||
const tid = Number(info.value.tid || 0);
|
||
if (!tid) return;
|
||
quotaSaving.value = true;
|
||
try {
|
||
const res = await updateTenantStorageQuota(tid, Number(quotaInput.value || 0));
|
||
if (res?.code === 200) {
|
||
info.value = res.data || info.value;
|
||
ElMessage.success("基础额度已更新");
|
||
} else {
|
||
ElMessage.error(res?.msg || "保存失败");
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || "保存失败");
|
||
} finally {
|
||
quotaSaving.value = false;
|
||
}
|
||
};
|
||
|
||
const loadOrders = async () => {
|
||
ordersLoading.value = true;
|
||
try {
|
||
const res = await getStorageOrders({
|
||
page: orderPage.value,
|
||
pageSize: orderPageSize.value,
|
||
status: orderStatus.value || undefined,
|
||
});
|
||
if (res?.code === 200) {
|
||
orders.value = res.data?.list || [];
|
||
orderTotal.value = Number(res.data?.total || 0);
|
||
}
|
||
} catch {
|
||
orders.value = [];
|
||
} finally {
|
||
ordersLoading.value = false;
|
||
}
|
||
};
|
||
|
||
const handleOrderPage = (val: number) => {
|
||
orderPage.value = val;
|
||
loadOrders();
|
||
};
|
||
|
||
onMounted(() => {
|
||
loadOrders();
|
||
});
|
||
</script>
|
||
|
||
<style scoped lang="less">
|
||
.storage-page {
|
||
.tips {
|
||
margin-bottom: 16px;
|
||
}
|
||
|
||
.panel {
|
||
padding: 18px 20px;
|
||
margin-bottom: 18px;
|
||
border: 1px solid var(--el-border-color-lighter);
|
||
border-radius: 12px;
|
||
background: var(--el-bg-color);
|
||
}
|
||
|
||
.panel-head {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 16px;
|
||
|
||
h3 {
|
||
margin: 0;
|
||
font-size: 16px;
|
||
font-weight: 600;
|
||
color: var(--el-text-color-primary);
|
||
}
|
||
|
||
.tip {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
}
|
||
|
||
.query-bar {
|
||
display: flex;
|
||
gap: 10px;
|
||
margin-bottom: 18px;
|
||
}
|
||
|
||
.tenant-placeholder {
|
||
min-height: 60px;
|
||
}
|
||
|
||
.usage-row {
|
||
display: flex;
|
||
align-items: baseline;
|
||
gap: 8px;
|
||
margin-bottom: 10px;
|
||
|
||
.used {
|
||
font-size: 26px;
|
||
font-weight: 700;
|
||
color: var(--el-text-color-primary);
|
||
}
|
||
|
||
.total {
|
||
font-size: 14px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
}
|
||
|
||
.usage-foot {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 6px;
|
||
margin-top: 10px;
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
.quota-edit {
|
||
display: flex;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
gap: 10px;
|
||
margin-top: 20px;
|
||
padding-top: 18px;
|
||
border-top: 1px solid var(--el-border-color-lighter);
|
||
|
||
.label {
|
||
font-size: 14px;
|
||
font-weight: 600;
|
||
color: var(--el-text-color-primary);
|
||
}
|
||
|
||
.unit {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
}
|
||
|
||
.order-filter {
|
||
display: flex;
|
||
gap: 10px;
|
||
}
|
||
|
||
.pagination-bar {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
margin-top: 14px;
|
||
}
|
||
}
|
||
</style>
|