feat: add tenant-aware IM management console

This commit is contained in:
richjohnrambo
2026-08-19 00:31:09 +08:00
parent 642b7ec5da
commit 89ba6bcff8
126 changed files with 11941 additions and 339 deletions
@@ -0,0 +1,144 @@
import { computed, ref } from 'vue';
import { FormSchema } from '@/components/Form';
import { defRangeShortcuts } from '@/utils/dateUtil';
import { useDictStore } from '@/store/modules/dict';
import { List as TenantList } from '@/api/imTenant';
const dict = useDictStore();
export const tenantOptions = ref<any[]>([]);
export class State {
public id = '';
public tenantId = '';
public tenantName = '';
public batchId = '';
public code = '';
public status = '';
public expiresAt = '';
public usageCount = 0;
public lastUsedAt = '';
public createdBy = '';
public remark = '';
public createdAt = '';
}
export const statusOptions = [
{ label: '有效', value: 'active', type: 'success' },
{ label: '已过期', value: 'expired', type: 'warning' },
{ label: '已撤销', value: 'revoked', type: 'error' },
];
export const schemas = ref<FormSchema[]>([
{
field: 'tenantId',
component: 'NSelect',
label: '租户',
componentProps: {
clearable: true,
options: computed(() => tenantOptions.value),
placeholder: '请选择租户',
},
},
{
field: 'inviteCode',
component: 'NInput',
label: '邀请码',
componentProps: {
placeholder: '完整5位,区分大小写',
maxlength: 5,
},
},
{
field: 'status',
component: 'NSelect',
label: '状态',
componentProps: {
clearable: true,
options: statusOptions,
placeholder: '请选择状态',
},
},
{
field: 'batchId',
component: 'NInput',
label: '批次ID',
componentProps: {
placeholder: '请输入批次ID',
},
},
{
field: 'createdBy',
component: 'NInput',
label: '创建人',
componentProps: {
placeholder: '请输入创建人ID',
},
},
{
field: 'createdAt',
component: 'NDatePicker',
label: '创建时间',
componentProps: {
type: 'datetimerange',
clearable: true,
shortcuts: defRangeShortcuts(),
},
},
{
field: 'expiresAt',
component: 'NDatePicker',
label: '到期时间',
componentProps: {
type: 'datetimerange',
clearable: true,
shortcuts: defRangeShortcuts(),
},
},
]);
export const columns = [
{ title: 'ID', key: 'id', align: 'left', width: 150 },
{ title: '租户', key: 'tenantName', align: 'left', width: 160 },
{ title: '邀请码', key: 'code', align: 'left', width: 120 },
{ title: '状态', key: 'status', align: 'left', width: 110 },
{ title: '批次ID', key: 'batchId', align: 'left', width: 150 },
{ title: '到期时间', key: 'expiresAt', align: 'left', width: 190 },
{ title: '累计使用次数', key: 'usageCount', align: 'left', width: 130 },
{ title: '最后使用时间', key: 'lastUsedAt', align: 'left', width: 190 },
{ title: '创建人', key: 'createdBy', align: 'left', width: 110 },
{ title: '创建时间', key: 'createdAt', align: 'left', width: 190 },
{ title: '备注', key: 'remark', align: 'left', width: 220 },
];
export function loadOptions() {
dict.loadOptions(['sys_switch']);
}
export async function loadTenantOptions() {
const res = await TenantList({ page: 1, perPage: 20, state: 1 });
tenantOptions.value = (res?.list || []).map((item) => ({
label: `${item.name}(${item.code})`,
value: item.id,
}));
return tenantOptions.value;
}
export function statusLabel(status: string) {
return statusOptions.find((item) => item.value === status)?.label || status;
}
export function localRfc3339(value: number | null) {
if (!value) {
return '';
}
const date = new Date(value);
const pad = (n: number) => `${n}`.padStart(2, '0');
const offset = -date.getTimezoneOffset();
const sign = offset >= 0 ? '+' : '-';
const hours = pad(Math.floor(Math.abs(offset) / 60));
const minutes = pad(Math.abs(offset) % 60);
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(
date.getHours()
)}:${pad(date.getMinutes())}:${pad(date.getSeconds())}${sign}${hours}:${minutes}`;
}