mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-22 21:27:11 +08:00
- 新增共享六语言词典、前端 i18n 运行时与语言设置入口 - 推进连接、驱动、数据网格、查询、AI、Redis、表设计等模块文案本地化 - 补充 raw 边界、SQL/驱动/更新场景测试与 i18n 扫描工具
109 lines
3.3 KiB
TypeScript
109 lines
3.3 KiB
TypeScript
import React from 'react';
|
|
import { Checkbox, Input, Modal, Typography } from 'antd';
|
|
import { useI18n } from '../i18n/provider';
|
|
|
|
const { Text } = Typography;
|
|
|
|
type ConnectionPackagePasswordModalMode = 'import' | 'export';
|
|
|
|
export interface ConnectionPackagePasswordModalProps {
|
|
open: boolean;
|
|
title: string;
|
|
mode?: ConnectionPackagePasswordModalMode;
|
|
includeSecrets?: boolean;
|
|
useFilePassword?: boolean;
|
|
password: string;
|
|
error?: string;
|
|
confirmLoading?: boolean;
|
|
confirmText?: string;
|
|
cancelText?: string;
|
|
onIncludeSecretsChange?: (value: boolean) => void;
|
|
onUseFilePasswordChange?: (value: boolean) => void;
|
|
onPasswordChange: (value: string) => void;
|
|
onConfirm: () => void;
|
|
onCancel: () => void;
|
|
}
|
|
|
|
export default function ConnectionPackagePasswordModal({
|
|
open,
|
|
title,
|
|
mode = 'import',
|
|
includeSecrets = true,
|
|
useFilePassword = false,
|
|
password,
|
|
error,
|
|
confirmLoading,
|
|
confirmText,
|
|
cancelText,
|
|
onIncludeSecretsChange,
|
|
onUseFilePasswordChange,
|
|
onPasswordChange,
|
|
onConfirm,
|
|
onCancel,
|
|
}: ConnectionPackagePasswordModalProps) {
|
|
const { t } = useI18n();
|
|
const isExportMode = mode === 'export';
|
|
const showFilePasswordInput = isExportMode ? useFilePassword : true;
|
|
const resolvedConfirmText = confirmText ?? t('common.confirm');
|
|
const resolvedCancelText = cancelText ?? t('common.cancel');
|
|
const placeholder = isExportMode
|
|
? t('app.connection_package.dialog.file_password_placeholder')
|
|
: t('app.connection_package.dialog.restore_password_placeholder');
|
|
const helperText = !includeSecrets
|
|
? t('app.connection_package.dialog.help.exclude_passwords')
|
|
: (useFilePassword
|
|
? t('app.connection_package.dialog.help.share_file_password_separately')
|
|
: t('app.connection_package.dialog.help.encrypted_passwords_recommend_file_password'));
|
|
|
|
return (
|
|
<Modal
|
|
open={open}
|
|
title={title}
|
|
okText={resolvedConfirmText}
|
|
cancelText={resolvedCancelText}
|
|
confirmLoading={confirmLoading}
|
|
onOk={onConfirm}
|
|
onCancel={onCancel}
|
|
destroyOnHidden={false}
|
|
maskClosable={false}
|
|
>
|
|
{isExportMode ? (
|
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
|
|
<Checkbox
|
|
checked={includeSecrets}
|
|
onChange={(event) => onIncludeSecretsChange?.(event.target.checked)}
|
|
>
|
|
{t('app.connection_package.dialog.option.include_passwords')}
|
|
</Checkbox>
|
|
<Checkbox
|
|
checked={useFilePassword}
|
|
disabled={!includeSecrets}
|
|
onChange={(event) => onUseFilePasswordChange?.(event.target.checked)}
|
|
>
|
|
{t('app.connection_package.dialog.option.use_file_password')}
|
|
</Checkbox>
|
|
</div>
|
|
) : null}
|
|
{showFilePasswordInput ? (
|
|
<Input.Password
|
|
autoFocus
|
|
value={password}
|
|
placeholder={placeholder}
|
|
disabled={isExportMode && !useFilePassword}
|
|
onChange={(event) => onPasswordChange(event.target.value)}
|
|
/>
|
|
) : null}
|
|
{isExportMode ? (
|
|
<Text type={useFilePassword ? 'warning' : 'secondary'} style={{ display: 'block', marginTop: 8 }}>
|
|
{helperText}
|
|
</Text>
|
|
) : null}
|
|
{error ? (
|
|
<Text type="danger" style={{ display: 'block', marginTop: 8 }}>
|
|
{error}
|
|
</Text>
|
|
) : null}
|
|
</Modal>
|
|
);
|
|
}
|