Files
OpenMaopaoya/frontend-uni/src/pages/channels/index.vue
T

39 lines
1.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view style="padding:14px">
<button class="btn primary" @click="adding = true">+ 添加渠道</button>
<view v-if="adding" class="glass">
<input v-model="f.name" placeholder="渠道名" />
<input v-model="f.base_url" placeholder="Base URL (OpenAI兼容)" />
<input v-model="f.api_key" password placeholder="API Key" />
<view class="row"><button class="btn primary" @click="save">保存</button>
<button class="btn" @click="adding = false">取消</button></view>
</view>
<view v-for="c in chans" :key="c.id" class="glass">
<view class="row spread"><text style="font-weight:600">{{ c.name }}</text>
<text class="tag">{{ c.visibility }}</text></view>
<view class="hint">{{ c.base_url }}</view>
<view class="row" style="margin-top:6px">
<button class="btn small" @click="test(c)">测试</button>
<button class="btn small danger" @click="del(c)">删</button>
</view>
</view>
</view>
</template>
<script setup>
import { ref } from "vue";
import { api, toast } from "../../utils/api";
const chans = ref([]), adding = ref(false);
const f = ref({ name: "", base_url: "", api_key: "" });
async function load() { chans.value = (await api("/channels")).channels; }
load();
async function save() {
await api("/channels", { method: "POST", body: { ...f.value, models: {}, visibility: "admin" } });
adding.value = false; load(); toast("已保存");
}
async function test(c) {
try { const d = await api(`/channels/${c.id}/test`); toast(d.ok ? "✅ 通" : "❌ " + d.message); }
catch (e) { toast(e.message); }
}
async function del(c) { await api(`/channels/${c.id}`, { method: "DELETE" }); load(); }
</script>