2026-04-20 20:21:02 +08:00
|
|
|
<template>
|
|
|
|
|
<BaseDialog
|
|
|
|
|
:show="show"
|
|
|
|
|
:title="t('admin.channelMonitor.form.selectKeyTitle')"
|
2026-04-21 01:42:58 +08:00
|
|
|
width="wide"
|
2026-04-20 20:21:02 +08:00
|
|
|
@close="$emit('close')"
|
|
|
|
|
>
|
|
|
|
|
<div class="space-y-3">
|
|
|
|
|
<p class="text-xs text-gray-500 dark:text-gray-400">
|
|
|
|
|
{{ t('admin.channelMonitor.form.selectKeyHint') }}
|
|
|
|
|
</p>
|
2026-04-21 01:42:58 +08:00
|
|
|
|
|
|
|
|
<div class="relative">
|
|
|
|
|
<input
|
|
|
|
|
v-model="search"
|
|
|
|
|
type="text"
|
|
|
|
|
class="input pl-9"
|
|
|
|
|
:placeholder="t('keys.searchPlaceholder')"
|
|
|
|
|
/>
|
|
|
|
|
<svg class="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
|
|
|
<circle cx="11" cy="11" r="8" /><path d="m21 21-4.35-4.35" />
|
|
|
|
|
</svg>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-04-20 20:21:02 +08:00
|
|
|
<div v-if="loading" class="py-6 text-center text-sm text-gray-500">
|
|
|
|
|
{{ t('common.loading') }}
|
|
|
|
|
</div>
|
2026-04-21 01:42:58 +08:00
|
|
|
<div v-else-if="filteredKeys.length === 0" class="py-6 text-center text-sm text-gray-500">
|
2026-04-20 20:21:02 +08:00
|
|
|
{{ t('admin.channelMonitor.form.noActiveKey') }}
|
|
|
|
|
</div>
|
2026-04-21 01:42:58 +08:00
|
|
|
<div v-else class="max-h-96 overflow-auto rounded-lg border border-gray-200 dark:border-dark-600">
|
|
|
|
|
<table class="w-full text-sm">
|
|
|
|
|
<thead class="bg-gray-50 dark:bg-dark-800 sticky top-0 z-10">
|
|
|
|
|
<tr class="text-left text-xs font-medium uppercase tracking-wider text-gray-500 dark:text-gray-400">
|
|
|
|
|
<th class="px-3 py-2">{{ t('common.name') }}</th>
|
|
|
|
|
<th class="px-3 py-2">{{ t('keys.apiKey') }}</th>
|
|
|
|
|
<th class="px-3 py-2">{{ t('keys.group') }}</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody class="divide-y divide-gray-200 dark:divide-dark-700">
|
|
|
|
|
<tr
|
|
|
|
|
v-for="k in filteredKeys"
|
|
|
|
|
:key="k.id"
|
|
|
|
|
class="cursor-pointer hover:bg-gray-50 dark:hover:bg-dark-700"
|
|
|
|
|
@click="$emit('pick', k)"
|
|
|
|
|
>
|
|
|
|
|
<td class="px-3 py-2 font-medium text-gray-900 dark:text-white">{{ k.name }}</td>
|
|
|
|
|
<td class="px-3 py-2 font-mono text-xs text-gray-500 dark:text-gray-400">{{ maskApiKey(k.key) }}</td>
|
|
|
|
|
<td class="px-3 py-2">
|
|
|
|
|
<span v-if="k.group" class="inline-flex items-center rounded-md bg-gray-100 px-2 py-0.5 text-xs text-gray-700 dark:bg-dark-700 dark:text-gray-300">
|
|
|
|
|
{{ k.group.name }}
|
|
|
|
|
</span>
|
|
|
|
|
<span v-else class="text-xs text-gray-400">—</span>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
2026-04-20 20:21:02 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<div class="flex justify-end">
|
|
|
|
|
<button @click="$emit('close')" class="btn btn-secondary">
|
|
|
|
|
{{ t('common.cancel') }}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</BaseDialog>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2026-04-21 01:42:58 +08:00
|
|
|
import { computed, ref, watch } from 'vue'
|
2026-04-20 20:21:02 +08:00
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
|
import type { ApiKey } from '@/types'
|
2026-04-21 01:42:58 +08:00
|
|
|
import type { Provider } from '@/api/admin/channelMonitor'
|
2026-04-20 20:21:02 +08:00
|
|
|
import BaseDialog from '@/components/common/BaseDialog.vue'
|
2026-04-21 01:42:58 +08:00
|
|
|
import { maskApiKey } from '@/utils/maskApiKey'
|
2026-04-20 20:21:02 +08:00
|
|
|
|
2026-04-21 01:42:58 +08:00
|
|
|
const props = defineProps<{
|
2026-04-20 20:21:02 +08:00
|
|
|
show: boolean
|
|
|
|
|
loading: boolean
|
|
|
|
|
keys: ApiKey[]
|
2026-04-21 01:42:58 +08:00
|
|
|
provider: Provider
|
2026-04-20 20:21:02 +08:00
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
defineEmits<{
|
|
|
|
|
(e: 'close'): void
|
|
|
|
|
(e: 'pick', key: ApiKey): void
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
2026-04-21 01:42:58 +08:00
|
|
|
const search = ref('')
|
|
|
|
|
|
|
|
|
|
watch(() => props.show, (shown) => {
|
|
|
|
|
if (!shown) search.value = ''
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const filteredKeys = computed<ApiKey[]>(() => {
|
|
|
|
|
const q = search.value.trim().toLowerCase()
|
|
|
|
|
return props.keys.filter((k) => {
|
|
|
|
|
if (k.group?.platform !== props.provider) return false
|
|
|
|
|
if (!q) return true
|
|
|
|
|
return (
|
|
|
|
|
k.name.toLowerCase().includes(q) ||
|
|
|
|
|
k.key.toLowerCase().includes(q) ||
|
|
|
|
|
(k.group?.name || '').toLowerCase().includes(q)
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
})
|
2026-04-20 20:21:02 +08:00
|
|
|
</script>
|