feat:0666账号密码自动登录刷新Token

This commit is contained in:
2026-11-03 12:13:39 +08:00
parent 4dbec33dbd
commit f69cdc6d8e
12 changed files with 741 additions and 11 deletions
+26
View File
@@ -31,6 +31,7 @@ export default function PlatformRock() {
const [upstreamStock, setUpstreamStock] = useState<number | null>(null)
const [loadingStats, setLoadingStats] = useState(false)
const [testingConn, setTestingConn] = useState(false)
const [testingLogin, setTestingLogin] = useState(false)
const [savingConfig, setSavingConfig] = useState(false)
const [autoPurchaseEnabled, setAutoPurchaseEnabled] = useState(false)
const [togglingAutoPurchase, setTogglingAutoPurchase] = useState(false)
@@ -81,6 +82,7 @@ export default function PlatformRock() {
auto_delivery_enabled: cfg.auto_delivery_enabled,
base_url: cfg.base_url,
bearer_token: cfg.bearer_token,
login_username: cfg.login_username,
min_points_warning: cfg.min_points_warning,
token_warning_stock: cfg.token_warning_stock,
using_warn_days: cfg.using_warn_days ?? 3,
@@ -188,10 +190,29 @@ export default function PlatformRock() {
}
}
// 测试上游账号密码登录(只验证,不保存 token)
const handleTestLogin = async () => {
const username = form.getFieldValue('login_username') as string | undefined
const password = form.getFieldValue('login_password') as string | undefined
setTestingLogin(true)
try {
const res = await rockApi.testLogin({ username, password })
message.success(`登录成功:${res.username}(${res.role}),积分 ${res.points}`)
} catch (e) {
message.error('测试登录失败: ' + (e instanceof Error ? e.message : '未知错误'))
} finally {
setTestingLogin(false)
}
}
// 保存策略配置
const handleSaveConfig = async () => {
try {
const values = await form.validateFields()
// 密码留空表示不修改,避免每次保存都清空已保存的密文
if (!values.login_password) {
delete values.login_password
}
setSavingConfig(true)
const updated = await rockApi.updateConfig(values)
setConfig(updated)
@@ -369,6 +390,11 @@ export default function PlatformRock() {
autoPurchaseEnabled={autoPurchaseEnabled}
autoPurchaseCoolingSeconds={stats?.auto_purchase_cooldown_seconds ?? 0}
nextAutoPurchaseAt={stats?.next_auto_purchase_at}
loginPasswordSet={config?.login_password_set}
lastTokenRefreshAt={config?.last_token_refresh_at}
lastTokenError={config?.last_token_error}
testingLogin={testingLogin}
onTestLogin={handleTestLogin}
togglingAutoPurchase={togglingAutoPurchase}
testingConn={testingConn}
savingConfig={savingConfig}