diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index ed9fe09b..2d964d8c 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -512,6 +512,7 @@ "创建新的兑换码": "Create a new redemption code", "未找到所请求的页面": "The requested page was not found", "过期时间格式错误!": "Expiration time format error!", + "过期时间不能早于当前时间!": "Expiration time cannot be earlier than the current time!", "请输入过期时间,格式为 yyyy-MM-dd HH:mm:ss,-1 表示无限制": "Please enter the expiration time, the format is yyyy-MM-dd HH:mm:ss, -1 means no limit", "此项可选,为一个 JSON 文本,键为用户请求的模型名称,值为要替换的模型名称,例如:": "This is optional, it's a JSON text, the key is the model name requested by the user, and the value is the model name to be replaced, for example:", "此项可选,输入镜像站地址,格式为:": "This is optional, enter the mirror site address, the format is:", diff --git a/web/src/pages/Token/EditToken.js b/web/src/pages/Token/EditToken.js index fb8badf7..c2ab5a98 100644 --- a/web/src/pages/Token/EditToken.js +++ b/web/src/pages/Token/EditToken.js @@ -345,7 +345,23 @@ const EditToken = (props) => { label={t('过期时间')} type='dateTime' placeholder={t('请选择过期时间')} - rules={[{ required: true, message: t('请选择过期时间') }]} + rules={[ + { required: true, message: t('请选择过期时间') }, + { + validator: (rule, value) => { + // 允许 -1 表示永不过期,也允许空值在必填校验时被拦截 + if (value === -1 || !value) return Promise.resolve(); + const time = Date.parse(value); + if (isNaN(time)) { + return Promise.reject(t('过期时间格式错误!')); + } + if (time <= Date.now()) { + return Promise.reject(t('过期时间不能早于当前时间!')); + } + return Promise.resolve(); + }, + }, + ]} showClear style={{ width: '100%' }} />