feat: 添加租户创建功能,支持设置管理员及有效期,新增订单统计接口
This commit is contained in:
@@ -49,6 +49,10 @@
|
||||
|
||||
核心对象:`dto.TenantItem`
|
||||
|
||||
- 创建租户并关联租户管理员(新增)
|
||||
- 表单字段:`code`、`name`、`admin_user_id`、`duration(7/30/90/180/365 天)`
|
||||
- API:`POST /super/v1/tenants`(`dto.TenantCreateForm`)
|
||||
- 行为:创建 `tenants` 记录,并创建 `tenant_users` 关系,角色为 `tenant_admin`
|
||||
- 租户列表(筛选/分页/排序)
|
||||
- 过滤:`name`、`status`
|
||||
- 排序:`asc/desc`
|
||||
@@ -87,4 +91,3 @@
|
||||
- **swagger 不一致**:`dto.TenantStatusUpdateForm.status` / `dto.UserStatusUpdateForm.status` 在 swagger 里额外出现 `normal/disabled` enum,但 `consts.*Status` 与列表筛选 enum 为 `pending_verify/verified/banned`;前端应以 `/statuses` 接口返回为准,并推动后端修正 swagger。
|
||||
- **分页 items 结构疑似不完整**:列表接口 swagger 中 `items` 被标成单个 object(`$ref dto.TenantItem`/`dto.UserItem`),实际应为数组;当前前端服务层已做兼容(`normalizeItems`),但建议后端修正 swagger。
|
||||
- **租户/用户详情与更多运维能力缺失**:目前没有用户详情、租户详情、角色管理、密码重置等超管常见能力;如需要可扩展接口与页面。
|
||||
|
||||
|
||||
2
frontend/superadmin/dist/index.html
vendored
2
frontend/superadmin/dist/index.html
vendored
@@ -7,7 +7,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Sakai Vue</title>
|
||||
<link href="https://fonts.cdnfonts.com/css/lato" rel="stylesheet">
|
||||
<script type="module" crossorigin src="./assets/index-BB3R-ZJM.js"></script>
|
||||
<script type="module" crossorigin src="./assets/index-Brwtp57n.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="./assets/index-Ba8sjR1v.css">
|
||||
</head>
|
||||
|
||||
|
||||
8
frontend/superadmin/src/service/OrderService.js
Normal file
8
frontend/superadmin/src/service/OrderService.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import { requestJson } from './apiClient';
|
||||
|
||||
export const OrderService = {
|
||||
async getOrderStatistics() {
|
||||
return requestJson('/super/v1/orders/statistics');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -22,6 +22,17 @@ export const TenantService = {
|
||||
items: normalizeItems(data?.items)
|
||||
};
|
||||
},
|
||||
async createTenant({ code, name, admin_user_id, duration } = {}) {
|
||||
return requestJson('/super/v1/tenants', {
|
||||
method: 'POST',
|
||||
body: {
|
||||
code,
|
||||
name,
|
||||
admin_user_id,
|
||||
duration
|
||||
}
|
||||
});
|
||||
},
|
||||
async renewTenantExpire({ tenantID, duration }) {
|
||||
return requestJson(`/super/v1/tenants/${tenantID}`, {
|
||||
method: 'PATCH',
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup>
|
||||
import StatisticsStrip from '@/components/StatisticsStrip.vue';
|
||||
import { OrderService } from '@/service/OrderService';
|
||||
import { TenantService } from '@/service/TenantService';
|
||||
import { UserService } from '@/service/UserService';
|
||||
import { useToast } from 'primevue/usetoast';
|
||||
@@ -13,6 +14,15 @@ const tenantLoading = ref(false);
|
||||
const statistics = ref([]);
|
||||
const statisticsLoading = ref(false);
|
||||
|
||||
const orderStats = ref(null);
|
||||
const orderStatsLoading = ref(false);
|
||||
|
||||
function formatCny(amountInCents) {
|
||||
const amount = Number(amountInCents) / 100;
|
||||
if (!Number.isFinite(amount)) return '-';
|
||||
return new Intl.NumberFormat('zh-CN', { style: 'currency', currency: 'CNY' }).format(amount);
|
||||
}
|
||||
|
||||
const statisticsItems = computed(() => {
|
||||
const total = (statistics.value || []).reduce((sum, row) => sum + (Number(row?.count) || 0), 0);
|
||||
const statusIcon = (status) => {
|
||||
@@ -59,6 +69,26 @@ const tenantItems = computed(() => [
|
||||
}
|
||||
]);
|
||||
|
||||
const orderItems = computed(() => {
|
||||
const byStatus = new Map((orderStats.value?.by_status || []).map((row) => [row?.status, row]));
|
||||
const getCount = (status) => byStatus.get(status)?.count ?? 0;
|
||||
|
||||
const totalCount = orderStats.value?.total_count ?? 0;
|
||||
const totalAmountPaidSum = orderStats.value?.total_amount_paid_sum ?? 0;
|
||||
const refundingCount = getCount('refunding');
|
||||
const refundedCount = getCount('refunded');
|
||||
const refundRequestedCount = refundingCount + refundedCount;
|
||||
|
||||
return [
|
||||
{ key: 'orders-total', label: '订单总数:', value: orderStatsLoading.value ? '-' : totalCount, icon: 'pi-shopping-cart' },
|
||||
{ key: 'orders-paid', label: '已支付:', value: orderStatsLoading.value ? '-' : getCount('paid'), icon: 'pi-check-circle' },
|
||||
{ key: 'orders-refunding', label: '退款中:', value: orderStatsLoading.value ? '-' : refundingCount, icon: 'pi-spin pi-spinner' },
|
||||
{ key: 'orders-refund-requested', label: '退款申请:', value: orderStatsLoading.value ? '-' : refundRequestedCount, icon: 'pi-undo' },
|
||||
{ key: 'orders-refunded', label: '已退款:', value: orderStatsLoading.value ? '-' : getCount('refunded'), icon: 'pi-undo' },
|
||||
{ key: 'orders-amount', label: '实付总额:', value: orderStatsLoading.value ? '-' : formatCny(totalAmountPaidSum), icon: 'pi-wallet' }
|
||||
];
|
||||
});
|
||||
|
||||
async function loadTenantTotal() {
|
||||
tenantLoading.value = true;
|
||||
try {
|
||||
@@ -82,15 +112,28 @@ async function loadStatistics() {
|
||||
}
|
||||
}
|
||||
|
||||
async function loadOrderStatistics() {
|
||||
orderStatsLoading.value = true;
|
||||
try {
|
||||
orderStats.value = await OrderService.getOrderStatistics();
|
||||
} catch (error) {
|
||||
toast.add({ severity: 'error', summary: '加载失败', detail: error?.message || '无法加载订单统计信息', life: 4000 });
|
||||
} finally {
|
||||
orderStatsLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadTenantTotal();
|
||||
loadStatistics();
|
||||
loadOrderStatistics();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<StatisticsStrip :items="tenantItems" containerClass="card mb-4" />
|
||||
<StatisticsStrip :items="orderItems" containerClass="card mb-4" />
|
||||
<StatisticsStrip :items="statisticsItems" containerClass="card mb-4" />
|
||||
|
||||
<div class="card">
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<script setup>
|
||||
import { TenantService } from '@/service/TenantService';
|
||||
import { UserService } from '@/service/UserService';
|
||||
import SearchField from '@/components/SearchField.vue';
|
||||
import SearchPanel from '@/components/SearchPanel.vue';
|
||||
import { useToast } from 'primevue/usetoast';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
const toast = useToast();
|
||||
|
||||
@@ -19,6 +20,17 @@ const status = ref('');
|
||||
const sortField = ref('id');
|
||||
const sortOrder = ref(-1);
|
||||
|
||||
const createDialogVisible = ref(false);
|
||||
const creating = ref(false);
|
||||
const createCode = ref('');
|
||||
const createName = ref('');
|
||||
const createDuration = ref(365);
|
||||
const createAdminUserID = ref(null);
|
||||
|
||||
const adminSearchUsername = ref('');
|
||||
const adminSearchLoading = ref(false);
|
||||
const adminSearchResults = ref([]);
|
||||
|
||||
function formatDate(value) {
|
||||
if (!value) return '-';
|
||||
const date = new Date(value);
|
||||
@@ -123,6 +135,63 @@ const durationOptions = [
|
||||
{ label: '365 天', value: 365 }
|
||||
];
|
||||
|
||||
const canCreateTenant = computed(() => {
|
||||
return Boolean(createCode.value?.trim()) && Boolean(createName.value?.trim()) && Number(createAdminUserID.value) > 0 && Number(createDuration.value) > 0;
|
||||
});
|
||||
|
||||
function openCreateDialog() {
|
||||
createCode.value = '';
|
||||
createName.value = '';
|
||||
createDuration.value = 365;
|
||||
createAdminUserID.value = null;
|
||||
adminSearchUsername.value = '';
|
||||
adminSearchResults.value = [];
|
||||
createDialogVisible.value = true;
|
||||
}
|
||||
|
||||
async function searchAdminUsers() {
|
||||
const keyword = String(adminSearchUsername.value || '').trim();
|
||||
if (!keyword) {
|
||||
adminSearchResults.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
adminSearchLoading.value = true;
|
||||
try {
|
||||
const result = await UserService.listUsers({ page: 1, limit: 10, username: keyword });
|
||||
adminSearchResults.value = result?.items || [];
|
||||
} catch (error) {
|
||||
toast.add({ severity: 'error', summary: '搜索失败', detail: error?.message || '无法搜索用户', life: 4000 });
|
||||
} finally {
|
||||
adminSearchLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function pickAdmin(user) {
|
||||
createAdminUserID.value = user?.id ?? null;
|
||||
}
|
||||
|
||||
async function confirmCreateTenant() {
|
||||
if (!canCreateTenant.value) return;
|
||||
|
||||
creating.value = true;
|
||||
try {
|
||||
await TenantService.createTenant({
|
||||
code: createCode.value.trim(),
|
||||
name: createName.value.trim(),
|
||||
admin_user_id: Number(createAdminUserID.value),
|
||||
duration: Number(createDuration.value)
|
||||
});
|
||||
toast.add({ severity: 'success', summary: '创建成功', detail: `租户:${createName.value.trim()}`, life: 3000 });
|
||||
createDialogVisible.value = false;
|
||||
await loadTenants();
|
||||
} catch (error) {
|
||||
toast.add({ severity: 'error', summary: '创建失败', detail: error?.message || '无法创建租户', life: 4000 });
|
||||
} finally {
|
||||
creating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function openRenewDialog(item) {
|
||||
renewTenant.value = item;
|
||||
renewDuration.value = 30;
|
||||
@@ -209,6 +278,7 @@ onMounted(() => {
|
||||
<div class="card">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h4 class="m-0">租户列表</h4>
|
||||
<Button label="创建租户" icon="pi pi-plus" @click="openCreateDialog" />
|
||||
</div>
|
||||
|
||||
<SearchPanel :loading="loading" @search="onSearch" @reset="onReset">
|
||||
@@ -318,5 +388,61 @@ onMounted(() => {
|
||||
<Button label="确认" icon="pi pi-check" @click="confirmUpdateTenantStatus" :loading="tenantStatusUpdating" :disabled="!tenantStatusValue" />
|
||||
</template>
|
||||
</Dialog>
|
||||
|
||||
<Dialog v-model:visible="createDialogVisible" :modal="true" :style="{ width: '720px' }">
|
||||
<template #header>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-medium">创建租户</span>
|
||||
<span class="text-muted-color">并关联租户管理员</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="grid grid-cols-12 gap-4">
|
||||
<div class="col-span-12 md:col-span-6">
|
||||
<label class="block font-medium mb-2">租户 Code</label>
|
||||
<InputText v-model="createCode" placeholder="例如:acme" class="w-full" :disabled="creating" />
|
||||
<small class="text-muted-color">用于 URL 标识(建议小写字母/数字),创建后不建议修改</small>
|
||||
</div>
|
||||
<div class="col-span-12 md:col-span-6">
|
||||
<label class="block font-medium mb-2">租户名称</label>
|
||||
<InputText v-model="createName" placeholder="例如:ACME 工作室" class="w-full" :disabled="creating" />
|
||||
</div>
|
||||
<div class="col-span-12 md:col-span-6">
|
||||
<label class="block font-medium mb-2">有效期</label>
|
||||
<Select v-model="createDuration" :options="durationOptions" optionLabel="label" optionValue="value" placeholder="选择有效期" fluid :disabled="creating" />
|
||||
</div>
|
||||
<div class="col-span-12 md:col-span-6">
|
||||
<label class="block font-medium mb-2">租户管理员 UserID</label>
|
||||
<InputNumber v-model="createAdminUserID" :min="1" placeholder="输入用户ID" class="w-full" :disabled="creating" />
|
||||
<small class="text-muted-color">下方可通过用户名搜索并一键填入</small>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Divider />
|
||||
|
||||
<div class="flex items-end gap-2">
|
||||
<div class="flex-1">
|
||||
<label class="block font-medium mb-2">按用户名搜索管理员</label>
|
||||
<InputText v-model="adminSearchUsername" placeholder="输入用户名关键字" class="w-full" :disabled="creating" @keyup.enter="searchAdminUsers" />
|
||||
</div>
|
||||
<Button label="搜索" icon="pi pi-search" :loading="adminSearchLoading" :disabled="creating" @click="searchAdminUsers" />
|
||||
</div>
|
||||
|
||||
<DataTable :value="adminSearchResults" dataKey="id" size="small" :loading="adminSearchLoading" scrollable scrollHeight="220px">
|
||||
<Column field="id" header="ID" style="width: 7rem" />
|
||||
<Column field="username" header="用户名" />
|
||||
<Column field="status_description" header="状态" style="width: 10rem" />
|
||||
<Column header="操作" style="width: 8rem">
|
||||
<template #body="{ data }">
|
||||
<Button label="设为管理员" size="small" severity="secondary" @click="pickAdmin(data)" />
|
||||
</template>
|
||||
</Column>
|
||||
</DataTable>
|
||||
</div>
|
||||
<template #footer>
|
||||
<Button label="取消" icon="pi pi-times" text @click="createDialogVisible = false" :disabled="creating" />
|
||||
<Button label="确认创建" icon="pi pi-check" @click="confirmCreateTenant" :loading="creating" :disabled="!canCreateTenant" />
|
||||
</template>
|
||||
</Dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -13,6 +13,7 @@ export default defineConfig({
|
||||
noDiscovery: true
|
||||
},
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
proxy: {
|
||||
'/super/v1': {
|
||||
target: 'http://localhost:8080',
|
||||
|
||||
Reference in New Issue
Block a user