feat: 优化 OAuth 账号导入流程
This commit is contained in:
@@ -16,6 +16,8 @@ import type {
|
||||
TempUnschedulableStatus,
|
||||
AdminDataPayload,
|
||||
AdminDataImportResult,
|
||||
CodexSessionImportRequest,
|
||||
CodexSessionImportResult,
|
||||
CheckMixedChannelRequest,
|
||||
CheckMixedChannelResponse
|
||||
} from '@/types'
|
||||
@@ -547,6 +549,11 @@ export async function importData(payload: {
|
||||
return data
|
||||
}
|
||||
|
||||
export async function importCodexSession(payload: CodexSessionImportRequest): Promise<CodexSessionImportResult> {
|
||||
const { data } = await apiClient.post<CodexSessionImportResult>('/admin/accounts/import/codex-session', payload)
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Antigravity default model mapping from backend
|
||||
* @returns Default model mapping (from -> to)
|
||||
@@ -663,6 +670,7 @@ export const accountsAPI = {
|
||||
syncFromCrs,
|
||||
exportData,
|
||||
importData,
|
||||
importCodexSession,
|
||||
getAntigravityDefaultModelMapping,
|
||||
batchClearError,
|
||||
batchRefresh,
|
||||
|
||||
@@ -2765,6 +2765,7 @@
|
||||
:show-mobile-refresh-token-option="form.platform === 'openai'"
|
||||
:show-session-token-option="false"
|
||||
:show-access-token-option="false"
|
||||
:show-codex-session-import-option="form.platform === 'openai'"
|
||||
:platform="form.platform"
|
||||
:show-project-id="geminiOAuthType === 'code_assist'"
|
||||
@generate-url="handleGenerateUrl"
|
||||
@@ -2772,6 +2773,7 @@
|
||||
@validate-refresh-token="handleValidateRefreshToken"
|
||||
@validate-mobile-refresh-token="handleOpenAIValidateMobileRT"
|
||||
@validate-session-token="handleValidateSessionToken"
|
||||
@import-codex-session="handleOpenAIImportCodexSession"
|
||||
/>
|
||||
|
||||
</div>
|
||||
@@ -3119,6 +3121,7 @@ import type {
|
||||
AccountType,
|
||||
CheckMixedChannelResponse,
|
||||
CreateAccountRequest,
|
||||
CodexSessionImportMessage,
|
||||
OpenAICompactMode
|
||||
} from '@/types'
|
||||
import BaseDialog from '@/components/common/BaseDialog.vue'
|
||||
@@ -3152,6 +3155,7 @@ interface OAuthFlowExposed {
|
||||
sessionKey: string
|
||||
refreshToken: string
|
||||
sessionToken: string
|
||||
codexSession: string
|
||||
inputMethod: AuthInputMethod
|
||||
reset: () => void
|
||||
}
|
||||
@@ -4631,6 +4635,113 @@ const handleOpenAIExchange = async (authCode: string) => {
|
||||
// OpenAI Mobile RT client_id
|
||||
const OPENAI_MOBILE_RT_CLIENT_ID = 'app_LlGpXReQgckcGGUo2JrYvtJK'
|
||||
|
||||
const buildOpenAICodexImportCredentialExtras = (): Record<string, unknown> | null => {
|
||||
const credentials: Record<string, unknown> = {}
|
||||
if (!isOpenAIModelRestrictionDisabled.value) {
|
||||
const modelMapping = buildModelMappingObject(modelRestrictionMode.value, allowedModels.value, modelMappings.value)
|
||||
if (modelMapping) {
|
||||
credentials.model_mapping = modelMapping
|
||||
}
|
||||
}
|
||||
|
||||
const compactModelMapping = buildOpenAICompactModelMapping()
|
||||
if (compactModelMapping) {
|
||||
credentials.compact_model_mapping = compactModelMapping
|
||||
}
|
||||
|
||||
if (!applyTempUnschedConfig(credentials)) {
|
||||
return null
|
||||
}
|
||||
return credentials
|
||||
}
|
||||
|
||||
const formatCodexImportMessages = (messages?: CodexSessionImportMessage[]) => {
|
||||
return (messages || [])
|
||||
.map((item) => {
|
||||
const name = item.name ? ` ${item.name}` : ''
|
||||
return `#${item.index}${name}: ${item.message}`
|
||||
})
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
const handleOpenAIImportCodexSession = async (content: string) => {
|
||||
const oauthClient = openaiOAuth
|
||||
const trimmed = content.trim()
|
||||
if (!trimmed) {
|
||||
oauthClient.error.value = t('admin.accounts.oauth.openai.codexSessionEmpty')
|
||||
return
|
||||
}
|
||||
|
||||
const credentialExtras = buildOpenAICodexImportCredentialExtras()
|
||||
if (credentialExtras === null) {
|
||||
return
|
||||
}
|
||||
|
||||
oauthClient.loading.value = true
|
||||
oauthClient.error.value = ''
|
||||
|
||||
try {
|
||||
const extra = buildOpenAIExtra()
|
||||
const result = await adminAPI.accounts.importCodexSession({
|
||||
content: trimmed,
|
||||
name: form.name,
|
||||
notes: form.notes || null,
|
||||
proxy_id: form.proxy_id,
|
||||
concurrency: form.concurrency,
|
||||
load_factor: form.load_factor ?? undefined,
|
||||
priority: form.priority,
|
||||
rate_multiplier: form.rate_multiplier,
|
||||
group_ids: form.group_ids,
|
||||
expires_at: form.expires_at,
|
||||
auto_pause_on_expired: autoPauseOnExpired.value,
|
||||
credential_extras: Object.keys(credentialExtras).length > 0 ? credentialExtras : undefined,
|
||||
extra,
|
||||
update_existing: true
|
||||
})
|
||||
|
||||
const successCount = result.created + result.updated
|
||||
const params = {
|
||||
created: result.created,
|
||||
updated: result.updated,
|
||||
skipped: result.skipped,
|
||||
failed: result.failed
|
||||
}
|
||||
|
||||
if (successCount > 0 && result.failed === 0) {
|
||||
appStore.showSuccess(t('admin.accounts.oauth.openai.codexSessionImportSuccess', params))
|
||||
emit('created')
|
||||
handleClose()
|
||||
return
|
||||
}
|
||||
|
||||
const errorText = formatCodexImportMessages(result.errors)
|
||||
const warningText = formatCodexImportMessages(result.warnings)
|
||||
oauthClient.error.value = [errorText, warningText].filter(Boolean).join('\n')
|
||||
|
||||
if (result.failed === 0) {
|
||||
appStore.showWarning(t('admin.accounts.oauth.openai.codexSessionImportSuccess', params))
|
||||
return
|
||||
}
|
||||
|
||||
if (successCount > 0) {
|
||||
appStore.showWarning(t('admin.accounts.oauth.openai.codexSessionImportPartial', params))
|
||||
emit('created')
|
||||
return
|
||||
}
|
||||
|
||||
appStore.showError(t('admin.accounts.oauth.openai.codexSessionImportFailed'))
|
||||
} catch (error: any) {
|
||||
oauthClient.error.value =
|
||||
error.response?.data?.detail ||
|
||||
error.response?.data?.message ||
|
||||
error.message ||
|
||||
t('admin.accounts.oauth.openai.codexSessionImportFailed')
|
||||
appStore.showError(oauthClient.error.value)
|
||||
} finally {
|
||||
oauthClient.loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// OpenAI RT 批量验证和创建(共享逻辑)
|
||||
const handleOpenAIBatchRT = async (refreshTokenInput: string, clientId?: string) => {
|
||||
const oauthClient = openaiOAuth
|
||||
|
||||
@@ -81,6 +81,17 @@
|
||||
t('admin.accounts.oauth.openai.accessTokenAuth', '手动输入 AT')
|
||||
}}</span>
|
||||
</label>
|
||||
<label v-if="showCodexSessionImportOption" class="flex cursor-pointer items-center gap-2">
|
||||
<input
|
||||
v-model="inputMethod"
|
||||
type="radio"
|
||||
value="codex_session"
|
||||
class="text-blue-600 focus:ring-blue-500"
|
||||
/>
|
||||
<span class="text-sm text-blue-900 dark:text-blue-200">{{
|
||||
t('admin.accounts.oauth.openai.codexSessionAuth')
|
||||
}}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -168,6 +179,85 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Codex JSON / AT 批量输入 -->
|
||||
<div v-if="inputMethod === 'codex_session'" class="space-y-4">
|
||||
<div
|
||||
class="rounded-lg border border-blue-300 bg-white/80 p-4 dark:border-blue-600 dark:bg-gray-800/80"
|
||||
>
|
||||
<p class="mb-3 text-sm text-blue-700 dark:text-blue-300">
|
||||
{{ t('admin.accounts.oauth.openai.codexSessionDesc') }}
|
||||
</p>
|
||||
|
||||
<div class="mb-4">
|
||||
<label
|
||||
class="mb-2 flex items-center gap-2 text-sm font-semibold text-gray-700 dark:text-gray-300"
|
||||
>
|
||||
<Icon name="key" size="sm" class="text-blue-500" />
|
||||
{{ t('admin.accounts.oauth.openai.codexSessionInputLabel') }}
|
||||
<span
|
||||
v-if="parsedCodexSessionCount > 1"
|
||||
class="rounded-full bg-blue-500 px-2 py-0.5 text-xs text-white"
|
||||
>
|
||||
{{ t('admin.accounts.oauth.keysCount', { count: parsedCodexSessionCount }) }}
|
||||
</span>
|
||||
</label>
|
||||
<textarea
|
||||
v-model="codexSessionInput"
|
||||
rows="8"
|
||||
class="input w-full resize-y font-mono text-sm"
|
||||
:placeholder="t('admin.accounts.oauth.openai.codexSessionPlaceholder')"
|
||||
spellcheck="false"
|
||||
></textarea>
|
||||
<p class="mt-1 text-xs text-blue-600 dark:text-blue-400">
|
||||
{{ t('admin.accounts.oauth.openai.codexSessionHint') }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="error"
|
||||
class="mb-4 rounded-lg border border-red-200 bg-red-50 p-3 dark:border-red-700 dark:bg-red-900/30"
|
||||
>
|
||||
<p class="whitespace-pre-line text-sm text-red-600 dark:text-red-400">
|
||||
{{ error }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary w-full"
|
||||
:disabled="loading || !codexSessionInput.trim()"
|
||||
@click="handleImportCodexSession"
|
||||
>
|
||||
<svg
|
||||
v-if="loading"
|
||||
class="-ml-1 mr-2 h-4 w-4 animate-spin"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<circle
|
||||
class="opacity-25"
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
stroke="currentColor"
|
||||
stroke-width="4"
|
||||
></circle>
|
||||
<path
|
||||
class="opacity-75"
|
||||
fill="currentColor"
|
||||
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
||||
></path>
|
||||
</svg>
|
||||
<Icon v-else name="sparkles" size="sm" class="mr-2" />
|
||||
{{
|
||||
loading
|
||||
? t('admin.accounts.oauth.openai.validating')
|
||||
: t('admin.accounts.oauth.openai.codexSessionImportAndCreate')
|
||||
}}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Cookie Auto-Auth Form -->
|
||||
<div v-if="inputMethod === 'cookie'" class="space-y-4">
|
||||
<div
|
||||
@@ -561,6 +651,7 @@ interface Props {
|
||||
showMobileRefreshTokenOption?: boolean // Whether to show mobile refresh token option (OpenAI only)
|
||||
showSessionTokenOption?: boolean
|
||||
showAccessTokenOption?: boolean
|
||||
showCodexSessionImportOption?: boolean
|
||||
platform?: AccountPlatform // Platform type for different UI/text
|
||||
showProjectId?: boolean // New prop to control project ID visibility
|
||||
}
|
||||
@@ -579,6 +670,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
showMobileRefreshTokenOption: false,
|
||||
showSessionTokenOption: false,
|
||||
showAccessTokenOption: false,
|
||||
showCodexSessionImportOption: false,
|
||||
platform: 'anthropic',
|
||||
showProjectId: true
|
||||
})
|
||||
@@ -591,6 +683,7 @@ const emit = defineEmits<{
|
||||
'validate-mobile-refresh-token': [refreshToken: string]
|
||||
'validate-session-token': [sessionToken: string]
|
||||
'import-access-token': [accessToken: string]
|
||||
'import-codex-session': [content: string]
|
||||
'update:inputMethod': [method: AuthInputMethod]
|
||||
}>()
|
||||
|
||||
@@ -630,12 +723,13 @@ const authCodeInput = ref('')
|
||||
const sessionKeyInput = ref('')
|
||||
const refreshTokenInput = ref('')
|
||||
const sessionTokenInput = ref('')
|
||||
const codexSessionInput = ref('')
|
||||
const showHelpDialog = ref(false)
|
||||
const oauthState = ref('')
|
||||
const projectId = ref('')
|
||||
|
||||
// Computed: show method selection when either cookie or refresh token option is enabled
|
||||
const showMethodSelection = computed(() => props.showCookieOption || props.showRefreshTokenOption || props.showMobileRefreshTokenOption || props.showSessionTokenOption || props.showAccessTokenOption)
|
||||
const showMethodSelection = computed(() => props.showCookieOption || props.showRefreshTokenOption || props.showMobileRefreshTokenOption || props.showSessionTokenOption || props.showAccessTokenOption || props.showCodexSessionImportOption)
|
||||
|
||||
// Clipboard
|
||||
const { copied, copyToClipboard } = useClipboard()
|
||||
@@ -656,6 +750,16 @@ const parsedRefreshTokenCount = computed(() => {
|
||||
.filter((rt) => rt).length
|
||||
})
|
||||
|
||||
const parsedCodexSessionCount = computed(() => {
|
||||
const trimmed = codexSessionInput.value.trim()
|
||||
if (!trimmed) return 0
|
||||
if (trimmed.startsWith('{') || trimmed.startsWith('[')) return 1
|
||||
return trimmed
|
||||
.split('\n')
|
||||
.map((item) => item.trim())
|
||||
.filter((item) => item).length
|
||||
})
|
||||
|
||||
// Watchers
|
||||
watch(inputMethod, (newVal) => {
|
||||
emit('update:inputMethod', newVal)
|
||||
@@ -727,6 +831,12 @@ const handleValidateRefreshToken = () => {
|
||||
}
|
||||
}
|
||||
|
||||
const handleImportCodexSession = () => {
|
||||
if (codexSessionInput.value.trim()) {
|
||||
emit('import-codex-session', codexSessionInput.value.trim())
|
||||
}
|
||||
}
|
||||
|
||||
// Expose methods and state
|
||||
defineExpose({
|
||||
authCode: authCodeInput,
|
||||
@@ -735,6 +845,7 @@ defineExpose({
|
||||
sessionKey: sessionKeyInput,
|
||||
refreshToken: refreshTokenInput,
|
||||
sessionToken: sessionTokenInput,
|
||||
codexSession: codexSessionInput,
|
||||
inputMethod,
|
||||
reset: () => {
|
||||
authCodeInput.value = ''
|
||||
@@ -743,6 +854,7 @@ defineExpose({
|
||||
sessionKeyInput.value = ''
|
||||
refreshTokenInput.value = ''
|
||||
sessionTokenInput.value = ''
|
||||
codexSessionInput.value = ''
|
||||
inputMethod.value = 'manual'
|
||||
showHelpDialog.value = false
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<Icon name="refresh" size="md" :class="[loading ? 'animate-spin' : '']" />
|
||||
</button>
|
||||
<slot name="after"></slot>
|
||||
<button @click="$emit('sync')" class="btn btn-secondary">{{ t('admin.accounts.syncFromCrs') }}</button>
|
||||
<slot name="beforeCreate"></slot>
|
||||
<button @click="$emit('create')" class="btn btn-primary">{{ t('admin.accounts.createAccount') }}</button>
|
||||
<slot name="afterCreate"></slot>
|
||||
@@ -17,7 +16,7 @@ import { useI18n } from 'vue-i18n'
|
||||
import Icon from '@/components/icons/Icon.vue'
|
||||
|
||||
defineProps(['loading'])
|
||||
defineEmits(['refresh', 'sync', 'create'])
|
||||
defineEmits(['refresh', 'create'])
|
||||
|
||||
const { t } = useI18n()
|
||||
</script>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useAppStore } from '@/stores/app'
|
||||
import { adminAPI } from '@/api/admin'
|
||||
|
||||
export type AddMethod = 'oauth' | 'setup-token'
|
||||
export type AuthInputMethod = 'manual' | 'cookie' | 'refresh_token' | 'mobile_refresh_token' | 'session_token' | 'access_token'
|
||||
export type AuthInputMethod = 'manual' | 'cookie' | 'refresh_token' | 'mobile_refresh_token' | 'session_token' | 'access_token' | 'codex_session'
|
||||
|
||||
export interface OAuthState {
|
||||
authUrl: string
|
||||
|
||||
@@ -2777,6 +2777,11 @@ export default {
|
||||
dataExportSelected: 'Export Selected',
|
||||
dataExportIncludeProxies: 'Include proxies linked to the exported accounts',
|
||||
dataImport: 'Import',
|
||||
moreActions: 'More Actions',
|
||||
dataActions: 'Data',
|
||||
toolActions: 'Tools',
|
||||
viewColumns: 'Columns',
|
||||
selectedCount: '{count} selected',
|
||||
dataExportConfirmMessage: 'The exported data contains sensitive account and proxy information. Store it securely.',
|
||||
dataExportConfirm: 'Confirm Export',
|
||||
dataExported: 'Data exported successfully',
|
||||
@@ -3470,6 +3475,16 @@ export default {
|
||||
refreshTokenAuth: 'Manual RT Input',
|
||||
refreshTokenDesc: 'Enter your existing OpenAI Refresh Token(s). Supports batch input (one per line). The system will automatically validate and create accounts.',
|
||||
refreshTokenPlaceholder: 'Paste your OpenAI Refresh Token...\nSupports multiple, one per line',
|
||||
codexSessionAuth: 'Codex JSON / AT Batch Input',
|
||||
codexSessionDesc: 'Paste Codex JSON or an accessToken. Accounts use the step 1 settings.',
|
||||
codexSessionInputLabel: 'Codex JSON or accessToken',
|
||||
codexSessionPlaceholder: 'Multiple lines supported, one token or JSON per line',
|
||||
codexSessionHint: 'sessionToken will not be saved as refresh_token. Without refresh_token, the account expires with the accessToken expiry; import is rejected if the expiry cannot be parsed and step 1 has no expiration.',
|
||||
codexSessionImportAndCreate: 'Import & Create Account',
|
||||
codexSessionEmpty: 'Please enter Codex JSON or accessToken',
|
||||
codexSessionImportFailed: 'Failed to import Codex account',
|
||||
codexSessionImportSuccess: 'Import completed: created {created}, updated {updated}, skipped {skipped}',
|
||||
codexSessionImportPartial: 'Partial success: created {created}, updated {updated}, skipped {skipped}, failed {failed}',
|
||||
sessionTokenAuth: 'Manual ST Input',
|
||||
sessionTokenDesc: 'Enter your existing Session Token(s). Supports batch input (one per line). The system will automatically validate and create accounts.',
|
||||
sessionTokenPlaceholder: 'Paste your Session Token...\nSupports multiple, one per line',
|
||||
|
||||
@@ -2853,6 +2853,11 @@ export default {
|
||||
dataExportSelected: '导出选中',
|
||||
dataExportIncludeProxies: '导出代理(导出账号关联的代理)',
|
||||
dataImport: '导入',
|
||||
moreActions: '更多操作',
|
||||
dataActions: '数据操作',
|
||||
toolActions: '工具',
|
||||
viewColumns: '列显示',
|
||||
selectedCount: '已选 {count}',
|
||||
dataExportConfirmMessage: '导出的数据包含账号与代理的敏感信息,请妥善保存。',
|
||||
dataExportConfirm: '确认导出',
|
||||
dataExported: '数据导出成功',
|
||||
@@ -3605,6 +3610,16 @@ export default {
|
||||
refreshTokenAuth: '手动输入 RT',
|
||||
refreshTokenDesc: '输入您已有的 OpenAI Refresh Token,支持批量输入(每行一个),系统将自动验证并创建账号。',
|
||||
refreshTokenPlaceholder: '粘贴您的 OpenAI Refresh Token...\n支持多个,每行一个',
|
||||
codexSessionAuth: 'Codex JSON / AT 批量输入',
|
||||
codexSessionDesc: '粘贴 Codex JSON 或 accessToken,按第一步配置创建账号。',
|
||||
codexSessionInputLabel: 'Codex JSON 或 accessToken',
|
||||
codexSessionPlaceholder: '支持多行,每行一个 token 或 JSON',
|
||||
codexSessionHint: 'sessionToken 不会作为 refresh_token 保存;未包含 refresh_token 时会按 accessToken 过期时间设置账号过期,无法解析且第一步未设置过期时间时会拒绝导入。',
|
||||
codexSessionImportAndCreate: '导入并创建账号',
|
||||
codexSessionEmpty: '请输入 Codex JSON 或 accessToken',
|
||||
codexSessionImportFailed: 'Codex 账号导入失败',
|
||||
codexSessionImportSuccess: '导入完成:新增 {created},更新 {updated},跳过 {skipped}',
|
||||
codexSessionImportPartial: '部分成功:新增 {created},更新 {updated},跳过 {skipped},失败 {failed}',
|
||||
sessionTokenAuth: '手动输入 ST',
|
||||
sessionTokenDesc: '输入您已有的 Session Token,支持批量输入(每行一个),系统将自动验证并创建账号。',
|
||||
sessionTokenPlaceholder: '粘贴您的 Session Token...\n支持多个,每行一个',
|
||||
|
||||
@@ -1105,6 +1105,51 @@ export interface AdminDataImportResult {
|
||||
errors?: AdminDataImportError[]
|
||||
}
|
||||
|
||||
export interface CodexSessionImportRequest {
|
||||
content?: string
|
||||
contents?: string[]
|
||||
name?: string
|
||||
notes?: string | null
|
||||
group_ids?: number[]
|
||||
proxy_id?: number | null
|
||||
concurrency?: number
|
||||
priority?: number
|
||||
rate_multiplier?: number
|
||||
load_factor?: number | null
|
||||
expires_at?: number | null
|
||||
auto_pause_on_expired?: boolean
|
||||
credential_extras?: Record<string, unknown>
|
||||
extra?: Record<string, unknown>
|
||||
update_existing?: boolean
|
||||
skip_default_group_bind?: boolean
|
||||
confirm_mixed_channel_risk?: boolean
|
||||
}
|
||||
|
||||
export interface CodexSessionImportMessage {
|
||||
index: number
|
||||
name?: string
|
||||
message: string
|
||||
}
|
||||
|
||||
export interface CodexSessionImportItem {
|
||||
index: number
|
||||
name?: string
|
||||
action: 'created' | 'updated' | 'skipped' | 'failed'
|
||||
account_id?: number
|
||||
message?: string
|
||||
}
|
||||
|
||||
export interface CodexSessionImportResult {
|
||||
total: number
|
||||
created: number
|
||||
updated: number
|
||||
skipped: number
|
||||
failed: number
|
||||
items?: CodexSessionImportItem[]
|
||||
warnings?: CodexSessionImportMessage[]
|
||||
errors?: CodexSessionImportMessage[]
|
||||
}
|
||||
|
||||
// ==================== Usage & Redeem Types ====================
|
||||
|
||||
export type RedeemCodeType = 'balance' | 'concurrency' | 'subscription' | 'invitation'
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
<AccountTableActions
|
||||
:loading="loading"
|
||||
@refresh="handleManualRefresh"
|
||||
@sync="showSync = true"
|
||||
@create="showCreate = true"
|
||||
>
|
||||
<template #after>
|
||||
@@ -23,7 +22,7 @@
|
||||
<button
|
||||
@click="
|
||||
showAutoRefreshDropdown = !showAutoRefreshDropdown;
|
||||
showColumnDropdown = false
|
||||
showAccountToolsDropdown = false
|
||||
"
|
||||
class="btn btn-secondary px-2 md:px-3"
|
||||
:title="t('admin.accounts.autoRefresh')"
|
||||
@@ -63,68 +62,100 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Error Passthrough Rules -->
|
||||
<button
|
||||
@click="showErrorPassthrough = true"
|
||||
class="btn btn-secondary"
|
||||
:title="t('admin.errorPassthrough.title')"
|
||||
>
|
||||
<Icon name="shield" size="md" class="mr-1.5" />
|
||||
<span class="hidden md:inline">{{ t('admin.errorPassthrough.title') }}</span>
|
||||
</button>
|
||||
|
||||
<!-- TLS Fingerprint Profiles -->
|
||||
<button
|
||||
@click="showTLSFingerprintProfiles = true"
|
||||
class="btn btn-secondary"
|
||||
:title="t('admin.tlsFingerprintProfiles.title')"
|
||||
>
|
||||
<Icon name="lock" size="md" class="mr-1.5" />
|
||||
<span class="hidden md:inline">{{ t('admin.tlsFingerprintProfiles.title') }}</span>
|
||||
</button>
|
||||
|
||||
<!-- Column Settings Dropdown -->
|
||||
<div class="relative" ref="columnDropdownRef">
|
||||
<!-- More Tools Dropdown -->
|
||||
<div class="relative" ref="accountToolsDropdownRef">
|
||||
<button
|
||||
@click="
|
||||
showColumnDropdown = !showColumnDropdown;
|
||||
showAccountToolsDropdown = !showAccountToolsDropdown;
|
||||
showAutoRefreshDropdown = false
|
||||
"
|
||||
class="btn btn-secondary px-2 md:px-3"
|
||||
:title="t('admin.users.columnSettings')"
|
||||
:title="t('admin.accounts.moreActions')"
|
||||
>
|
||||
<svg class="h-4 w-4 md:mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="1.5">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" d="M9 4.5v15m6-15v15m-10.875 0h15.75c.621 0 1.125-.504 1.125-1.125V5.625c0-.621-.504-1.125-1.125-1.125H4.125C3.504 4.5 3 5.004 3 5.625v12.75c0 .621.504 1.125 1.125 1.125z" />
|
||||
</svg>
|
||||
<span class="hidden md:inline">{{ t('admin.users.columnSettings') }}</span>
|
||||
<Icon name="more" size="sm" class="md:mr-1.5" />
|
||||
<span class="hidden md:inline">{{ t('admin.accounts.moreActions') }}</span>
|
||||
<Icon name="chevronDown" size="xs" class="ml-1 hidden md:inline" />
|
||||
</button>
|
||||
<!-- Dropdown menu -->
|
||||
<div
|
||||
v-if="showColumnDropdown"
|
||||
class="absolute right-0 z-50 mt-2 w-48 origin-top-right rounded-lg border border-gray-200 bg-white shadow-lg dark:border-gray-700 dark:bg-gray-800"
|
||||
v-if="showAccountToolsDropdown"
|
||||
class="absolute right-0 z-50 mt-2 w-[min(20rem,calc(100vw-2rem))] origin-top-right overflow-hidden rounded-lg border border-gray-200 bg-white shadow-xl dark:border-gray-700 dark:bg-gray-800"
|
||||
>
|
||||
<div class="max-h-80 overflow-y-auto p-2">
|
||||
<button
|
||||
v-for="col in toggleableColumns"
|
||||
:key="col.key"
|
||||
@click="toggleColumn(col.key)"
|
||||
class="flex w-full items-center justify-between rounded-md px-3 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-gray-700"
|
||||
>
|
||||
<span>{{ col.label }}</span>
|
||||
<Icon v-if="isColumnVisible(col.key)" name="check" size="sm" class="text-primary-500" />
|
||||
<div class="max-h-[70vh] overflow-y-auto p-2">
|
||||
<div class="px-2 py-2">
|
||||
<div class="text-xs font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
|
||||
{{ t('admin.accounts.dataActions') }}
|
||||
</div>
|
||||
</div>
|
||||
<button class="account-tools-menu-item" @click="openSyncFromCrs">
|
||||
<span class="account-tools-menu-icon bg-blue-50 text-blue-600 dark:bg-blue-900/30 dark:text-blue-300">
|
||||
<Icon name="sync" size="sm" />
|
||||
</span>
|
||||
<span class="flex-1 text-left">{{ t('admin.accounts.syncFromCrs') }}</span>
|
||||
</button>
|
||||
<button class="account-tools-menu-item" @click="openImportData">
|
||||
<span class="account-tools-menu-icon bg-emerald-50 text-emerald-600 dark:bg-emerald-900/30 dark:text-emerald-300">
|
||||
<Icon name="upload" size="sm" />
|
||||
</span>
|
||||
<span class="flex-1 text-left">{{ t('admin.accounts.dataImport') }}</span>
|
||||
</button>
|
||||
<button class="account-tools-menu-item" @click="openExportDataDialogFromMenu">
|
||||
<span class="account-tools-menu-icon bg-violet-50 text-violet-600 dark:bg-violet-900/30 dark:text-violet-300">
|
||||
<Icon name="download" size="sm" />
|
||||
</span>
|
||||
<span class="flex-1 text-left">
|
||||
{{ selIds.length ? t('admin.accounts.dataExportSelected') : t('admin.accounts.dataExport') }}
|
||||
</span>
|
||||
<span
|
||||
v-if="selIds.length"
|
||||
class="rounded-full bg-primary-100 px-2 py-0.5 text-xs font-medium text-primary-700 dark:bg-primary-900/40 dark:text-primary-300"
|
||||
>
|
||||
{{ t('admin.accounts.selectedCount', { count: selIds.length }) }}
|
||||
</span>
|
||||
</button>
|
||||
|
||||
<div class="my-2 border-t border-gray-100 dark:border-gray-700"></div>
|
||||
<div class="px-2 py-2">
|
||||
<div class="text-xs font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
|
||||
{{ t('admin.accounts.toolActions') }}
|
||||
</div>
|
||||
</div>
|
||||
<button class="account-tools-menu-item" @click="openErrorPassthrough">
|
||||
<span class="account-tools-menu-icon bg-amber-50 text-amber-600 dark:bg-amber-900/30 dark:text-amber-300">
|
||||
<Icon name="shield" size="sm" />
|
||||
</span>
|
||||
<span class="flex-1 text-left">{{ t('admin.errorPassthrough.title') }}</span>
|
||||
</button>
|
||||
<button class="account-tools-menu-item" @click="openTLSFingerprintProfiles">
|
||||
<span class="account-tools-menu-icon bg-slate-100 text-slate-600 dark:bg-slate-700 dark:text-slate-200">
|
||||
<Icon name="lock" size="sm" />
|
||||
</span>
|
||||
<span class="flex-1 text-left">{{ t('admin.tlsFingerprintProfiles.title') }}</span>
|
||||
</button>
|
||||
|
||||
<div class="my-2 border-t border-gray-100 dark:border-gray-700"></div>
|
||||
<div class="px-2 py-2">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<span class="text-xs font-semibold uppercase tracking-wide text-gray-400 dark:text-gray-500">
|
||||
{{ t('admin.accounts.viewColumns') }}
|
||||
</span>
|
||||
<Icon name="grid" size="sm" class="text-gray-400" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-1">
|
||||
<button
|
||||
v-for="col in toggleableColumns"
|
||||
:key="col.key"
|
||||
@click="toggleColumn(col.key)"
|
||||
class="flex w-full items-center justify-between rounded-md px-3 py-2 text-sm text-gray-700 transition-colors hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-gray-700"
|
||||
>
|
||||
<span class="truncate">{{ col.label }}</span>
|
||||
<Icon v-if="isColumnVisible(col.key)" name="check" size="sm" class="text-primary-500" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #beforeCreate>
|
||||
<button @click="showImportData = true" class="btn btn-secondary">
|
||||
{{ t('admin.accounts.dataImport') }}
|
||||
</button>
|
||||
<button @click="openExportDataDialog" class="btn btn-secondary">
|
||||
{{ selIds.length ? t('admin.accounts.dataExportSelected') : t('admin.accounts.dataExport') }}
|
||||
</button>
|
||||
</template>
|
||||
</AccountTableActions>
|
||||
</div>
|
||||
<div
|
||||
@@ -457,9 +488,9 @@ const togglingSchedulable = ref<number | null>(null)
|
||||
const menu = reactive<{show:boolean, acc:Account|null, pos:{top:number, left:number}|null}>({ show: false, acc: null, pos: null })
|
||||
const exportingData = ref(false)
|
||||
|
||||
// Column settings
|
||||
const showColumnDropdown = ref(false)
|
||||
const columnDropdownRef = ref<HTMLElement | null>(null)
|
||||
// Account tools dropdown
|
||||
const showAccountToolsDropdown = ref(false)
|
||||
const accountToolsDropdownRef = ref<HTMLElement | null>(null)
|
||||
const hiddenColumns = reactive<Set<string>>(new Set())
|
||||
const DEFAULT_HIDDEN_COLUMNS = ['today_stats', 'proxy', 'notes', 'priority', 'rate_multiplier']
|
||||
const HIDDEN_COLUMNS_KEY = 'account-hidden-columns'
|
||||
@@ -820,7 +851,8 @@ const isAnyModalOpen = computed(() => {
|
||||
showTest.value ||
|
||||
showStats.value ||
|
||||
showSchedulePanel.value ||
|
||||
showErrorPassthrough.value
|
||||
showErrorPassthrough.value ||
|
||||
showTLSFingerprintProfiles.value
|
||||
)
|
||||
})
|
||||
|
||||
@@ -931,6 +963,35 @@ const handleManualRefresh = async () => {
|
||||
usageManualRefreshToken.value += 1
|
||||
}
|
||||
|
||||
const closeAccountToolsDropdown = () => {
|
||||
showAccountToolsDropdown.value = false
|
||||
}
|
||||
|
||||
const openSyncFromCrs = () => {
|
||||
closeAccountToolsDropdown()
|
||||
showSync.value = true
|
||||
}
|
||||
|
||||
const openImportData = () => {
|
||||
closeAccountToolsDropdown()
|
||||
showImportData.value = true
|
||||
}
|
||||
|
||||
const openExportDataDialogFromMenu = () => {
|
||||
closeAccountToolsDropdown()
|
||||
openExportDataDialog()
|
||||
}
|
||||
|
||||
const openErrorPassthrough = () => {
|
||||
closeAccountToolsDropdown()
|
||||
showErrorPassthrough.value = true
|
||||
}
|
||||
|
||||
const openTLSFingerprintProfiles = () => {
|
||||
closeAccountToolsDropdown()
|
||||
showTLSFingerprintProfiles.value = true
|
||||
}
|
||||
|
||||
const syncPendingListChanges = async () => {
|
||||
hasPendingListSync.value = false
|
||||
await load()
|
||||
@@ -944,7 +1005,7 @@ const { pause: pauseAutoRefresh, resume: resumeAutoRefresh } = useIntervalFn(
|
||||
if (document.hidden) return
|
||||
if (loading.value || autoRefreshFetching.value) return
|
||||
if (isAnyModalOpen.value) return
|
||||
if (menu.show) return
|
||||
if (menu.show || showAccountToolsDropdown.value || showAutoRefreshDropdown.value) return
|
||||
if (inAutoRefreshSilentWindow()) {
|
||||
autoRefreshCountdown.value = Math.max(
|
||||
0,
|
||||
@@ -1572,11 +1633,11 @@ const handleScroll = () => {
|
||||
menu.show = false
|
||||
}
|
||||
|
||||
// 点击外部关闭列设置下拉菜单
|
||||
// 点击外部关闭顶部下拉菜单
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
const target = event.target as HTMLElement
|
||||
if (columnDropdownRef.value && !columnDropdownRef.value.contains(target)) {
|
||||
showColumnDropdown.value = false
|
||||
if (accountToolsDropdownRef.value && !accountToolsDropdownRef.value.contains(target)) {
|
||||
showAccountToolsDropdown.value = false
|
||||
}
|
||||
if (autoRefreshDropdownRef.value && !autoRefreshDropdownRef.value.contains(target)) {
|
||||
showAutoRefreshDropdown.value = false
|
||||
@@ -1608,3 +1669,13 @@ onUnmounted(() => {
|
||||
document.removeEventListener('click', handleClickOutside)
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.account-tools-menu-item {
|
||||
@apply flex w-full items-center gap-3 rounded-md px-3 py-2 text-sm text-gray-700 transition-colors hover:bg-gray-100 dark:text-gray-200 dark:hover:bg-gray-700;
|
||||
}
|
||||
|
||||
.account-tools-menu-icon {
|
||||
@apply inline-flex h-8 w-8 flex-shrink-0 items-center justify-center rounded-md;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user