feat: add IM admin management

This commit is contained in:
richjohnrambo
2026-08-21 01:06:19 +08:00
parent 331a55751d
commit a2abaef3a6
290 changed files with 19917 additions and 337 deletions
@@ -0,0 +1,89 @@
<template>
<n-modal v-model:show="showModal" preset="dialog" :title="isBatch ? '批量生成邀请码' : '生成邀请码'">
<n-form ref="formRef" :model="formValue" :rules="rules" label-placement="left" :label-width="90">
<n-form-item v-if="isBatch" label="生成数量" path="quantity">
<n-input-number v-model:value="formValue.quantity" :min="1" :max="1000" />
</n-form-item>
<n-form-item label="到期时间" path="expiresAt">
<n-date-picker v-model:value="formValue.expiresAt" type="datetime" clearable />
</n-form-item>
<n-form-item label="备注" path="remark">
<n-input v-model:value="formValue.remark" type="textarea" maxlength="255" show-count />
</n-form-item>
</n-form>
<template #action>
<n-space justify="end">
<n-button @click="closeModal">取消</n-button>
<n-button type="primary" :loading="loading" @click="submit">确认</n-button>
</n-space>
</template>
</n-modal>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { useMessage } from 'naive-ui';
import { BatchCreate, Create } from '@/api/im/registrationInvite';
import { localRfc3339 } from './model';
const emit = defineEmits(['reload']);
const message = useMessage();
const showModal = ref(false);
const loading = ref(false);
const formRef = ref();
const tenantId = ref(0);
const isBatch = ref(false);
const formValue = reactive({
quantity: 100,
expiresAt: Date.now() + 7 * 24 * 3600 * 1000,
remark: '',
idempotencyKey: '',
});
const rules = {
quantity: { required: true, type: 'number', min: 1, max: 1000, message: '数量必须在1到1000之间' },
expiresAt: { required: true, type: 'number', message: '请选择到期时间' },
};
function openModal(id: number, batch = false) {
tenantId.value = id;
isBatch.value = batch;
formValue.quantity = 100;
formValue.expiresAt = Date.now() + 7 * 24 * 3600 * 1000;
formValue.remark = '';
formValue.idempotencyKey = crypto.randomUUID();
showModal.value = true;
}
function closeModal() {
showModal.value = false;
}
async function submit() {
await formRef.value?.validate();
loading.value = true;
try {
const params = {
tenantId: tenantId.value,
expiresAt: localRfc3339(formValue.expiresAt),
remark: formValue.remark,
idempotencyKey: formValue.idempotencyKey,
};
if (isBatch.value) {
await BatchCreate({ ...params, quantity: formValue.quantity });
} else {
await Create(params);
}
message.success('生成成功');
closeModal();
emit('reload');
} catch (error: any) {
message.error(error.toString());
} finally {
loading.value = false;
}
}
defineExpose({ openModal });
</script>