feat: AI生图额度按上游真实配额展示——下拉标注CF 173张/日与Pollinations按Key余额、文案双上游联动、已授权显示共享池剩余、tooltip官方出处
This commit is contained in:
1 parent
b4e5d6ac6d
commit
eefdc07786
3 files changed
+159
-38
No files matched your search
@@ -138,27 +138,49 @@ const EXAMPLES = [
|
||||
|
||||
const canGen = computed(() => !!prompt.value.trim());
|
||||
|
||||
// ---------- 内置免费额度(每日次数,服务端统计;北京时间 0 点重置) ----------
|
||||
const quota = ref<{ authorized: boolean; limit: number; used: number; remaining: number } | null>(null);
|
||||
// ---------- 内置免费额度(机器每日次数 + 上游真实免费池;北京时间 0 点重置) ----------
|
||||
const quota = ref<{
|
||||
authorized: boolean; limit: number; used: number; remaining: number;
|
||||
upstream?: string; upstream_daily?: number | null; upstream_used?: number | null;
|
||||
upstream_remaining?: number | null; upstream_note?: string; cf_daily?: number;
|
||||
} | null>(null);
|
||||
const quotaText = computed(() => {
|
||||
const q = quota.value;
|
||||
if (!q) return '内置免费 · 有每日次数限制';
|
||||
if (q.authorized) return '已授权 · 不限次数';
|
||||
if (q.remaining <= 0) return `内置免费 · 每日${q.limit}次 · 今日已用完`;
|
||||
return `内置免费 · 每日${q.limit}次 · 今日剩${q.remaining}次`;
|
||||
if (!q.authorized && q.remaining <= 0) return `内置免费 · 每日${q.limit}次 · 今日已用完`;
|
||||
const me = q.authorized ? '已授权' : `免费${q.limit}次·剩${q.remaining}`;
|
||||
if (q.upstream === 'pollinations') return `${me} · Pollinations按Key余额`;
|
||||
if (q.upstream === 'cloudflare') {
|
||||
if ((q.upstream_remaining ?? 1) <= 0) return 'CF免费池已用完 · 08:00重置';
|
||||
return `${me} · CF池剩${q.upstream_remaining}/${q.upstream_daily}张`;
|
||||
}
|
||||
return q.authorized ? '已授权' : `内置免费 · 每日${q.limit}次 · 今日剩${q.remaining}次`;
|
||||
});
|
||||
const quotaOut = computed(() => !!quota.value && !quota.value.authorized && quota.value.remaining <= 0);
|
||||
const quotaOut = computed(() => {
|
||||
const q = quota.value;
|
||||
if (!q) return false;
|
||||
if (q.upstream === 'cloudflare' && (q.upstream_remaining ?? 1) <= 0) return true;
|
||||
return !q.authorized && q.remaining <= 0;
|
||||
});
|
||||
const quotaTip = computed(() => quota.value?.upstream_note || '内置免费额度说明');
|
||||
// 模型下拉后缀:把各上游的真实免费配额实际写出来
|
||||
function upSuffix(id: string) {
|
||||
if (id.startsWith('pollinations')) return '(按Key余额)';
|
||||
return `(CF ${quota.value?.cf_daily ?? 173}张/日)`;
|
||||
}
|
||||
async function loadQuota() {
|
||||
try {
|
||||
const res = await fetch('/relay/ai/quota', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ machine: getMachineId() }),
|
||||
body: JSON.stringify({ machine: getMachineId(), model: model.value }),
|
||||
});
|
||||
const j = await res.json();
|
||||
if (j.code === 200 && j.data) quota.value = j.data;
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
// 切换模型 → 上游不同,额度说明跟着换
|
||||
watch(model, () => loadQuota());
|
||||
|
||||
onMounted(async () => {
|
||||
loadProvider();
|
||||
@@ -243,10 +265,10 @@ async function generate() {
|
||||
<div class="gen-ctrl">
|
||||
<!-- 模型 -->
|
||||
<div class="gen-sec">
|
||||
<div class="gen-h">模型 <span class="gen-quota" :class="{ out: quotaOut }">{{ quotaText }}</span></div>
|
||||
<div class="gen-h" :title="quotaTip">模型 <span class="gen-quota" :class="{ out: quotaOut }">{{ quotaText }}</span></div>
|
||||
<select v-model="model" class="gen-model-sel">
|
||||
<optgroup label="站内免费模型">
|
||||
<option v-for="m in models.filter(x => !x.custom)" :key="m.id" :value="m.id">{{ m.id }}</option>
|
||||
<option v-for="m in models.filter(x => !x.custom)" :key="m.id" :value="m.id">{{ m.id }}{{ upSuffix(m.id) }}</option>
|
||||
</optgroup>
|
||||
<optgroup v-if="models.some(x => x.custom)" label="我的模型">
|
||||
<option v-for="m in models.filter(x => x.custom)" :key="m.id" :value="m.id">{{ m.id }}(我的)</option>
|
||||
|
||||
Reference in new issue
Block a user