You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

110 lines
7.7 KiB

import { defineComponent, ref, reactive, computed, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrRenderStyle, ssrRenderList, ssrRenderAttr, ssrIncludeBooleanAttr, ssrLooseContain, ssrLooseEqual, ssrInterpolate } from 'vue/server-renderer';
import { u as useApi } from './useApi-DMQewX5_.mjs';
import { u as useToast } from './useToast-CS21XT61.mjs';
import './auth-QFkCoU1C.mjs';
import 'pinia';
import './server.mjs';
import '../nitro/nitro.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'unhead/server';
import 'devalue';
import 'unhead/utils';
import 'perfect-debounce';
import './useLoading-D4zrSa2m.mjs';
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "globalconfig",
__ssrInlineRender: true,
setup(__props) {
const REGIONS = [
{ value: 1, label: "中国" },
{ value: 2, label: "美国" },
{ value: 3, label: "东亚" },
{ value: 4, label: "东南亚" },
{ value: 5, label: "南亚" },
{ value: 6, label: "中东" },
{ value: 7, label: "欧洲" },
{ value: 8, label: "俄罗斯" },
{ value: 9, label: "非洲" },
{ value: 10, label: "南美" },
{ value: 11, label: "北美" },
{ value: 12, label: "大洋洲" },
{ value: 13, label: "巴西" },
{ value: 14, label: "印度" }
];
useApi();
useToast();
const view = ref("list");
const items = ref([]);
const loading = ref(false);
const submitting = ref(false);
const isEditing = ref(false);
const filterRegion = ref(1);
const keyword = ref("");
const form = reactive({ id: 0, region: 1, group: "", key: "", value: "", description: "" });
const filteredRows = computed(() => {
const kw = keyword.value.trim().toLowerCase();
if (!kw) return items.value;
return items.value.filter((c) => ((c.group || "") + (c.key || "")).toLowerCase().includes(kw));
});
const groupedRows = computed(() => {
const groups = {};
filteredRows.value.forEach((c) => {
const g = c.group || "";
(groups[g] = groups[g] || []).push(c);
});
const names = Object.keys(groups).sort((a, b) => {
if (a === "") return -1;
if (b === "") return 1;
return a < b ? -1 : 1;
});
return names.map((g) => ({ key: g, label: g || "未分组", items: groups[g] }));
});
return (_ctx, _push, _parent, _attrs) => {
_push(`<div${ssrRenderAttrs(_attrs)}><div style="${ssrRenderStyle(view.value === "list" ? null : { display: "none" })}"><div class="flex items-center justify-between mb-5"><div><h2 class="text-lg font-semibold text-slate-800">全局环境配置</h2><p class="text-xs text-slate-400 mt-1">全局第三方服务配置(AI / 翻译等),按区域分组,所有应用共享。修改后各服务约 10 分钟内自动同步。</p></div><button class="btn btn-primary btn-sm text-white">+ 新增配置</button></div><div class="flex items-center gap-3 mb-4"><span class="text-sm text-slate-500">区域</span><select class="select select-bordered select-sm"><!--[-->`);
ssrRenderList(REGIONS, (r) => {
_push(`<option${ssrRenderAttr("value", r.value)}${ssrIncludeBooleanAttr(Array.isArray(filterRegion.value) ? ssrLooseContain(filterRegion.value, r.value) : ssrLooseEqual(filterRegion.value, r.value)) ? " selected" : ""}>${ssrInterpolate(r.label)}</option>`);
});
_push(`<!--]--></select><input${ssrRenderAttr("value", keyword.value)} class="input input-bordered input-sm w-48" placeholder="按分组/键搜索"></div><div class="bg-white rounded-xl shadow-sm border border-slate-100"><div class="overflow-x-auto"><table class="table"><thead><tr><th>键</th><th>值</th><th>描述</th><th class="text-right">操作</th></tr></thead><tbody>`);
if (loading.value) {
_push(`<tr><td colspan="4" class="text-center py-8"><span class="loading loading-spinner loading-sm"></span></td></tr>`);
} else if (!filteredRows.value.length) {
_push(`<tr><td colspan="4" class="text-center text-slate-400 py-8">暂无配置</td></tr>`);
} else {
_push(`<!---->`);
}
_push(`<!--[-->`);
ssrRenderList(groupedRows.value, (grp) => {
_push(`<!--[--><tr class="bg-slate-100/80"><td colspan="4" class="py-2"><span class="font-semibold text-slate-600 text-sm">▸ ${ssrInterpolate(grp.label)}</span><span class="text-xs text-slate-400 ml-2">${ssrInterpolate(grp.items.length)} 项</span></td></tr><!--[-->`);
ssrRenderList(grp.items, (c) => {
_push(`<tr class="hover"><td class="font-mono text-sm font-medium">${ssrInterpolate(c.key || "")}</td><td class="text-sm text-slate-500 max-w-xs truncate"${ssrRenderAttr("title", c.value || "")}>${ssrInterpolate(c.value || "")}</td><td class="text-sm text-slate-400">${ssrInterpolate(c.description || "")}</td><td class="text-right"><div class="inline-flex gap-1"><button class="btn btn-ghost btn-xs">编辑</button><button class="btn btn-ghost btn-xs text-red-500">删除</button></div></td></tr>`);
});
_push(`<!--]--><!--]-->`);
});
_push(`<!--]--></tbody></table></div></div></div><div style="${ssrRenderStyle(view.value === "form" ? null : { display: "none" })}"><div class="flex items-center gap-3 mb-5"><button class="btn btn-ghost btn-sm">← 返回列表</button><h2 class="text-lg font-semibold text-slate-800">${ssrInterpolate(isEditing.value ? "编辑配置" : "新增配置")}</h2></div><div class="bg-white rounded-xl shadow-sm border border-slate-100 p-6 max-w-2xl"><form><div class="grid grid-cols-2 gap-4"><div class="form-control mb-4"><label class="label"><span class="label-text font-medium">区域 *</span></label><select class="select select-bordered w-full"><!--[-->`);
ssrRenderList(REGIONS, (r) => {
_push(`<option${ssrRenderAttr("value", r.value)}${ssrIncludeBooleanAttr(Array.isArray(form.region) ? ssrLooseContain(form.region, r.value) : ssrLooseEqual(form.region, r.value)) ? " selected" : ""}>${ssrInterpolate(r.label)}</option>`);
});
_push(`<!--]--></select></div><div class="form-control mb-4"><label class="label"><span class="label-text font-medium">分组 (group)</span></label><input${ssrRenderAttr("value", form.group)} type="text" class="input input-bordered w-full" placeholder="如 ai / translate / asr"></div></div><div class="form-control mb-4"><label class="label"><span class="label-text font-medium">键 (key) *</span></label><input${ssrRenderAttr("value", form.key)} type="text" class="input input-bordered w-full" required placeholder="如 openai_api_key"></div><div class="form-control mb-4"><label class="label"><span class="label-text font-medium">值 (value)</span></label><textarea class="textarea textarea-bordered w-full font-mono text-sm" rows="3">${ssrInterpolate(form.value)}</textarea></div><div class="form-control mb-6"><label class="label"><span class="label-text font-medium">描述</span></label><input${ssrRenderAttr("value", form.description)} type="text" class="input input-bordered w-full"></div><div class="flex gap-3"><button type="button" class="btn btn-ghost">取消</button><button type="submit" class="btn btn-primary text-white"${ssrIncludeBooleanAttr(submitting.value) ? " disabled" : ""}>保存</button></div></form></div></div></div>`);
};
}
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
const ssrContext = useSSRContext();
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/globalconfig.vue");
return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
export { _sfc_main as default };
//# sourceMappingURL=globalconfig-B_Ujsbj7.mjs.map