admin-model.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const USER_STATUS_META = {
  2. pending_email: { label: '待验证邮箱', color: 'gold' },
  3. pending_review: { label: '待管理员审核', color: 'blue' },
  4. active: { label: '正常', color: 'green' },
  5. disabled: { label: '已禁用', color: 'red' }
  6. };
  7. const MERGE_SUMMARY_ITEMS = [
  8. ['domains', '域名'],
  9. ['dnsCredentials', 'DNS 凭据'],
  10. ['apiTokens', 'API 密钥'],
  11. ['inboundMailboxes', '收信邮箱'],
  12. ['inboundMessages', '入站邮件'],
  13. ['sendEvents', '发送记录'],
  14. ['smtpCredential', 'SMTP 凭据']
  15. ];
  16. export function adminUserStatusMeta(status) {
  17. return USER_STATUS_META[status] || { label: String(status || '未知'), color: 'default' };
  18. }
  19. export function buildMergeConfirmationText(sourceUser, targetUser) {
  20. return `MERGE ${sourceUser?.username || sourceUser?.id || ''} INTO ${targetUser?.username || targetUser?.id || ''}`;
  21. }
  22. export function mergePreviewSummary(preview) {
  23. const counts = preview?.selectedCounts || {};
  24. return MERGE_SUMMARY_ITEMS.map(([key, label]) => ({
  25. key,
  26. label,
  27. count: Number(counts[key] || 0)
  28. }));
  29. }
  30. export function serializeSystemEmailPayload(values) {
  31. const payload = compactObject({
  32. host: values?.host,
  33. port: values?.port === '' || values?.port == null ? undefined : Number(values.port),
  34. secure: values?.secure,
  35. username: values?.username,
  36. password: values?.password,
  37. fromEmail: values?.fromEmail
  38. });
  39. if (typeof payload.password === 'string' && payload.password.trim() === '') {
  40. delete payload.password;
  41. }
  42. return payload;
  43. }
  44. export function serializeAuditFilters(filters) {
  45. const params = new URLSearchParams();
  46. for (const [key, value] of Object.entries(filters || {})) {
  47. if (value === '' || value == null) {
  48. continue;
  49. }
  50. params.set(key, String(value));
  51. }
  52. return params.toString();
  53. }
  54. function compactObject(values) {
  55. return Object.fromEntries(
  56. Object.entries(values).filter(([, value]) => value !== '' && value != null)
  57. );
  58. }