fix:优化当前的项目
This commit is contained in:
@@ -72,18 +72,28 @@ function renderModels(me) {
|
||||
list.forEach((m) => {
|
||||
const opt = document.createElement("option");
|
||||
opt.value = String(m.id);
|
||||
const imageModel = (m.image_model || "").trim();
|
||||
opt.textContent = imageModel ? `${m.model_name} (${m.model} / 图:${imageModel})` : `${m.model_name} (${m.model})`;
|
||||
opt.textContent = `${m.model_name} (${m.model})`;
|
||||
if ((active && m.id === active) || m.active) opt.selected = true;
|
||||
sel.appendChild(opt);
|
||||
});
|
||||
}
|
||||
|
||||
function renderVip(me) {
|
||||
const vip = me && me.vip ? me.vip : {};
|
||||
const enabledSelect = $("vipEnabledSelect");
|
||||
const tokenBalance = $("vipTokenBalance");
|
||||
const totalConsumed = $("vipTotalConsumed");
|
||||
if (enabledSelect) enabledSelect.value = vip.vip_enabled ? "1" : "0";
|
||||
if (tokenBalance) tokenBalance.value = String(Number(vip.token_balance || 0));
|
||||
if (totalConsumed) totalConsumed.value = String(Number(vip.total_consumed_tokens || 0));
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
const me = await authMe();
|
||||
if (!me) return;
|
||||
renderAccounts(me);
|
||||
renderModels(me);
|
||||
renderVip(me);
|
||||
}
|
||||
|
||||
const accountSelect = $("accountSelect");
|
||||
@@ -95,6 +105,8 @@ const deleteAccountBtn = $("deleteAccountBtn");
|
||||
const modelSelect = $("modelSelect");
|
||||
const saveModelBtn = $("saveModelBtn");
|
||||
const deleteModelBtn = $("deleteModelBtn");
|
||||
const saveVipBtn = $("saveVipBtn");
|
||||
const vipRechargeBtn = $("vipRechargeBtn");
|
||||
|
||||
if (accountSelect) {
|
||||
accountSelect.addEventListener("change", async () => {
|
||||
@@ -121,7 +133,7 @@ if (deleteWechatBtn) {
|
||||
setStatus("请先选择要删除的公众号", true);
|
||||
return;
|
||||
}
|
||||
const sure = window.confirm("确定删除当前公众号绑定吗?删除后不可恢复。");
|
||||
const sure = await window.uiConfirm("确定删除当前公众号绑定吗?删除后不可恢复。", "删除公众号");
|
||||
if (!sure) return;
|
||||
setLoading(deleteWechatBtn, true, "删除当前公众号", "删除中...");
|
||||
try {
|
||||
@@ -195,7 +207,7 @@ if (saveModelBtn) {
|
||||
api_key: ($("apiKey") && $("apiKey").value.trim()) || "",
|
||||
base_url: ($("baseUrl") && $("baseUrl").value.trim()) || "",
|
||||
model: ($("modelValue") && $("modelValue").value.trim()) || "",
|
||||
image_model: ($("imageModelValue") && $("imageModelValue").value.trim()) || "",
|
||||
image_model: "",
|
||||
timeout_sec: Number((($("timeoutSec") && $("timeoutSec").value) || "120").trim()),
|
||||
max_output_tokens: Number((($("maxOutputTokens") && $("maxOutputTokens").value) || "8192").trim()),
|
||||
max_retries: Number((($("maxRetries") && $("maxRetries").value) || "0").trim()),
|
||||
@@ -207,7 +219,6 @@ if (saveModelBtn) {
|
||||
setStatus("模型配置已保存并设为当前。");
|
||||
if ($("apiKey")) $("apiKey").value = "";
|
||||
if ($("modelName")) $("modelName").value = "";
|
||||
if ($("imageModelValue")) $("imageModelValue").value = "";
|
||||
await refresh();
|
||||
} catch (e) {
|
||||
setStatus(e.message || "模型保存失败", true);
|
||||
@@ -224,7 +235,7 @@ if (deleteModelBtn) {
|
||||
setStatus("请先选择要删除的模型", true);
|
||||
return;
|
||||
}
|
||||
const sure = window.confirm("确定删除当前模型配置吗?删除后不可恢复。");
|
||||
const sure = await window.uiConfirm("确定删除当前模型配置吗?删除后不可恢复。", "删除模型");
|
||||
if (!sure) return;
|
||||
setLoading(deleteModelBtn, true, "删除当前模型", "删除中...");
|
||||
try {
|
||||
@@ -243,6 +254,61 @@ if (deleteModelBtn) {
|
||||
});
|
||||
}
|
||||
|
||||
if (saveVipBtn) {
|
||||
saveVipBtn.addEventListener("click", async () => {
|
||||
setLoading(saveVipBtn, true, "保存 VIP 设置", "保存中...");
|
||||
try {
|
||||
const enabled = (($("vipEnabledSelect") && $("vipEnabledSelect").value) || "0") === "1";
|
||||
const out = await postJSON("/api/auth/vip/toggle", { enabled });
|
||||
if (!out.ok) {
|
||||
setStatus(out.detail || "VIP 设置保存失败", true);
|
||||
return;
|
||||
}
|
||||
setStatus("VIP 设置已更新。");
|
||||
await refresh();
|
||||
} catch (e) {
|
||||
setStatus(e.message || "VIP 设置保存失败", true);
|
||||
} finally {
|
||||
setLoading(saveVipBtn, false, "保存 VIP 设置", "保存中...");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (vipRechargeBtn) {
|
||||
vipRechargeBtn.addEventListener("click", async () => {
|
||||
setLoading(vipRechargeBtn, true, "充值 Token", "创建订单中...");
|
||||
try {
|
||||
const tokens = Number((($("vipRechargeTokens") && $("vipRechargeTokens").value) || "0").trim());
|
||||
if (!Number.isFinite(tokens) || tokens <= 0) {
|
||||
setStatus("请输入正确的充值数量", true);
|
||||
return;
|
||||
}
|
||||
const out = await postJSON("/api/pay/wechat/", {
|
||||
tokens: Math.round(tokens),
|
||||
amount_cny: Number((((Number(tokens) / 10000) * 9.9) || 9.9).toFixed(2)),
|
||||
channel: "wechat",
|
||||
});
|
||||
if (!out.ok) {
|
||||
setStatus(out.detail || "充值失败", true);
|
||||
return;
|
||||
}
|
||||
if (out.pay_url) {
|
||||
window.open(out.pay_url, "_blank", "noopener");
|
||||
setStatus("订单已创建,请在新窗口完成支付。");
|
||||
} else {
|
||||
setStatus("订单已创建,但未获取到支付链接,请联系管理员配置购物系统。", true);
|
||||
}
|
||||
window.setTimeout(() => {
|
||||
window.location.href = "/billing";
|
||||
}, 400);
|
||||
} catch (e) {
|
||||
setStatus(e.message || "充值失败", true);
|
||||
} finally {
|
||||
setLoading(vipRechargeBtn, false, "充值 Token", "创建订单中...");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (logoutBtn) {
|
||||
logoutBtn.addEventListener("click", async () => {
|
||||
setLoading(logoutBtn, true, "退出登录", "退出中...");
|
||||
@@ -292,9 +358,14 @@ if (deleteAccountBtn) {
|
||||
setStatus("请输入注销校验重置码", true);
|
||||
return;
|
||||
}
|
||||
const sure = window.confirm("确定注销账户吗?将清空此账号所有业务数据,操作不可恢复。");
|
||||
const sure = await window.uiConfirm("确定注销账户吗?将清空此账号所有业务数据,操作不可恢复。", "注销账户");
|
||||
if (!sure) return;
|
||||
const confirmText = window.prompt("为防止误删,请输入「注销账户」后确认:", "");
|
||||
const confirmText = await window.uiPrompt(
|
||||
"为防止误删,请输入「注销账户」后确认:",
|
||||
"二次确认",
|
||||
"",
|
||||
"请输入:注销账户",
|
||||
);
|
||||
if ((confirmText || "").trim() !== "注销账户") {
|
||||
setStatus("二次确认未通过,已取消注销。", true);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user