Files
DecomEval/web/src/features/admin/SettingsView.vue
T

100 lines
4.2 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.
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { NButton, NIcon, NInputNumber, NRadio, NRadioGroup, NTooltip, useDialog } from "naive-ui";
import { HelpCircleOutline } from "@vicons/ionicons5";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
import { useToast } from "../../shared/toast";
const toast = useToast();
const dialog = useDialog();
const mode = ref("local");
const seconds = ref(300);
const concurrency = ref(4);
const saving = ref(false);
const loaded = ref(false);
function askMode(next: string) {
if (next === mode.value) return;
const toPlatform = next === "nqi";
dialog.warning({
title: "更换登录方式",
content: toPlatform
? "换成大数据平台账号后,登录页会显示图形验证码,登录失败会换一张。管理员仍只校验本系统密码。"
: "换成自有账号后,登录页不再显示验证码。",
positiveText: "更换",
negativeText: "取消",
onPositiveClick: () => { mode.value = next; },
});
}
async function load() {
try {
const result = await api<{ loginMode: string; credentialRefreshSeconds: number; workerConcurrency: number }>("/api/admin/settings");
mode.value = result.loginMode;
seconds.value = result.credentialRefreshSeconds;
concurrency.value = result.workerConcurrency;
loaded.value = true;
} catch (error) {
toast.error(error instanceof Error ? error.message : "设置没有获取到");
}
}
async function save() {
if (saving.value || !loaded.value) return;
saving.value = true;
try {
await api("/api/admin/settings", {
method: "PUT",
body: JSON.stringify({ loginMode: mode.value, credentialRefreshSeconds: seconds.value, workerConcurrency: concurrency.value }),
});
toast.success("已保存");
} catch (error) {
toast.error(error instanceof Error ? error.message : "保存失败");
} finally {
saving.value = false;
}
}
onMounted(load);
</script>
<template>
<Shell>
<section class="page admin-page">
<form class="settings-form" @submit.prevent="save">
<header class="page-head">
<h2>设置</h2>
<n-button type="primary" attr-type="submit" :loading="saving" :disabled="!loaded">保存</n-button>
</header>
<div class="admin-scroll">
<p v-if="!loaded" class="admin-status">正在获取</p>
<div v-else class="settings-fields">
<div class="form-row">
<label for="login-mode">登录方式<n-tooltip><template #trigger><n-icon class="hint-mark" :size="16"><HelpCircleOutline /></n-icon></template>自有账号登录不显示验证码。大数据平台登录会显示图形验证码,失败后换一张。管理员始终只校验本系统密码。</n-tooltip></label>
<n-radio-group id="login-mode" :value="mode" @update:value="askMode">
<n-radio value="local">自有账号</n-radio>
<n-radio value="nqi">大数据平台账号</n-radio>
</n-radio-group>
</div>
<div class="form-row">
<label for="refresh-seconds">凭证刷新间隔<n-tooltip><template #trigger><n-icon class="hint-mark" :size="16"><HelpCircleOutline /></n-icon></template>账号池里的平台凭证按这个间隔刷新。</n-tooltip></label>
<div class="setting-control">
<n-input-number id="refresh-seconds" v-model:value="seconds" button-placement="both" :min="60" :max="86400" :precision="0" />
<span class="setting-unit">秒</span>
</div>
</div>
<div class="form-row">
<label for="worker-concurrency">同时运行的任务数<n-tooltip><template #trigger><n-icon class="hint-mark" :size="16"><HelpCircleOutline /></n-icon></template>采集和导出共用。调大后马上多领任务。调小后不打断正在运行的任务。</n-tooltip></label>
<div class="setting-control">
<n-input-number id="worker-concurrency" v-model:value="concurrency" button-placement="both" :min="1" :max="32" :precision="0" />
<span class="setting-unit">个</span>
</div>
</div>
</div>
</div>
</form>
</section>
</Shell>
</template>