- Implemented TenantDetail.vue to display tenant information, manage tenant status, and handle tenant renewals. - Added user management features in UserDetail.vue, including user status updates and role management. - Integrated data loading for tenant users and orders in TenantDetail.vue. - Included search and pagination functionalities for owned and joined tenants in UserDetail.vue. - Enhanced user experience with toast notifications for success and error messages.
95 lines
2.8 KiB
JavaScript
95 lines
2.8 KiB
JavaScript
import { requestJson } from './apiClient';
|
|
|
|
function normalizeItems(items) {
|
|
if (Array.isArray(items)) return items;
|
|
if (items && typeof items === 'object') return [items];
|
|
return [];
|
|
}
|
|
|
|
export const TenantService = {
|
|
async listTenants({
|
|
page,
|
|
limit,
|
|
id,
|
|
user_id,
|
|
name,
|
|
code,
|
|
status,
|
|
expired_at_from,
|
|
expired_at_to,
|
|
created_at_from,
|
|
created_at_to,
|
|
sortField,
|
|
sortOrder
|
|
} = {}) {
|
|
const iso = (d) => {
|
|
if (!d) return undefined;
|
|
const date = d instanceof Date ? d : new Date(d);
|
|
if (Number.isNaN(date.getTime())) return undefined;
|
|
return date.toISOString();
|
|
};
|
|
|
|
const query = {
|
|
page,
|
|
limit,
|
|
id,
|
|
user_id,
|
|
name,
|
|
code,
|
|
status,
|
|
expired_at_from: iso(expired_at_from),
|
|
expired_at_to: iso(expired_at_to),
|
|
created_at_from: iso(created_at_from),
|
|
created_at_to: iso(created_at_to)
|
|
};
|
|
if (sortField && sortOrder) {
|
|
if (sortOrder === 1) query.asc = sortField;
|
|
if (sortOrder === -1) query.desc = sortField;
|
|
}
|
|
|
|
const data = await requestJson('/super/v1/tenants', { query });
|
|
return {
|
|
page: data?.page ?? page ?? 1,
|
|
limit: data?.limit ?? limit ?? 10,
|
|
total: data?.total ?? 0,
|
|
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 listTenantUsers(tenantID, { page, limit, user_id, username, role, status } = {}) {
|
|
return requestJson(`/super/v1/tenants/${tenantID}/users`, {
|
|
query: { page, limit, user_id, username, role, status }
|
|
});
|
|
},
|
|
async renewTenantExpire({ tenantID, duration }) {
|
|
return requestJson(`/super/v1/tenants/${tenantID}`, {
|
|
method: 'PATCH',
|
|
body: { duration }
|
|
});
|
|
},
|
|
async getTenantStatuses() {
|
|
const data = await requestJson('/super/v1/tenants/statuses');
|
|
return Array.isArray(data) ? data : [];
|
|
},
|
|
async updateTenantStatus({ tenantID, status }) {
|
|
return requestJson(`/super/v1/tenants/${tenantID}/status`, {
|
|
method: 'PATCH',
|
|
body: { status }
|
|
});
|
|
},
|
|
async getTenantDetail(tenantID) {
|
|
if (!tenantID) throw new Error('tenantID is required');
|
|
return requestJson(`/super/v1/tenants/${tenantID}`);
|
|
}
|
|
};
|