feat: 前端支持平台子路径,托管时从平台登录进入

This commit is contained in:
2026-11-03 12:30:24 +08:00
parent c38e649904
commit 5d4b86c558
17 changed files with 271 additions and 53 deletions
+13 -4
View File
@@ -4,6 +4,7 @@ import { NButton, NIcon, NInputNumber, NRadio, NRadioGroup, NTooltip, useDialog
import { HelpCircleOutline } from "@vicons/ionicons5";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
import { hosted } from "../../shared/installState";
import { useToast } from "../../shared/toast";
const toast = useToast();
@@ -13,15 +14,23 @@ const seconds = ref(300);
const concurrency = ref(4);
const saving = ref(false);
const loaded = ref(false);
const modeHint = hosted
? "自有账号由平台管理,用户用平台账号直接进入。大数据平台登录会显示图形验证码,失败后换一张。管理员始终从平台进入。"
: "自有账号登录不显示验证码。大数据平台登录会显示图形验证码,失败后换一张。管理员始终只校验本系统密码。";
function askMode(next: string) {
if (next === mode.value) return;
const toPlatform = next === "nqi";
const content = hosted
? toPlatform
? "换成大数据平台账号后,用户在登录页用大数据平台账号登录,会显示图形验证码。管理员仍从平台进入。"
: "换成自有账号后,用户用平台账号直接进入,账号由平台管理。"
: toPlatform
? "换成大数据平台账号后,登录页会显示图形验证码,登录失败会换一张。管理员仍只校验本系统密码。"
: "换成自有账号后,登录页不再显示验证码。";
dialog.warning({
title: "更换登录方式",
content: toPlatform
? "换成大数据平台账号后,登录页会显示图形验证码,登录失败会换一张。管理员仍只校验本系统密码。"
: "换成自有账号后,登录页不再显示验证码。",
content,
positiveText: "更换",
negativeText: "取消",
onPositiveClick: () => { mode.value = next; },
@@ -72,7 +81,7 @@ onMounted(load);
<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>
<label for="login-mode">登录方式<n-tooltip><template #trigger><n-icon class="hint-mark" :size="16"><HelpCircleOutline /></n-icon></template>{{ modeHint }}</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>
+2 -4
View File
@@ -4,7 +4,7 @@ import { NButton, NDropdown, NIcon, NInput, NModal, NSelect, useDialog } from "n
import type { DropdownOption } from "naive-ui";
import { EllipsisVerticalOutline } from "@vicons/ionicons5";
import Shell from "../../shell/Shell.vue";
import { api } from "../../shared/http";
import { api, sessionInfo } from "../../shared/http";
import { useToast } from "../../shared/toast";
interface User { id: number; username: string; role: string }
@@ -19,9 +19,7 @@ const pwdShow = ref(false);
const pwdUser = ref<User | null>(null);
const pwdNext = ref("");
const pwdAgain = ref("");
const actorId = sessionStorage.getItem("decom-id") || "";
const actorKind = sessionStorage.getItem("decom-kind") || "";
const actorName = sessionStorage.getItem("decom-name") || "";
const { id: actorId, kind: actorKind, name: actorName } = sessionInfo();
function canReset(user: User) {
if (user.role === "user") return true;
+24
View File
@@ -0,0 +1,24 @@
<script setup lang="ts">
import { NButton } from "naive-ui";
import { platformHome } from "../../shared/base";
import { goPlatformLogin } from "../../shared/platform";
import ThemeButton from "../../shell/ThemeButton.vue";
</script>
<template>
<div class="gate">
<ThemeButton placement="left" />
<section class="gate-card" aria-labelledby="denied-title">
<div class="gate-brand">
<div class="brand-mark" aria-hidden="true">D</div>
<h1>DecomEval</h1>
</div>
<h2 id="denied-title" class="gate-title">无权使用</h2>
<p class="gate-text">当前平台账号没有使用 DecomEval 的权限。请联系平台管理员开通,或换一个有权限的账号登录。</p>
<div class="gate-actions">
<n-button @click="goPlatformLogin()">重新登录</n-button>
<n-button type="primary" tag="a" :href="platformHome">返回平台</n-button>
</div>
</section>
</div>
</template>
+9 -4
View File
@@ -2,16 +2,20 @@
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { NButton, NInput, NModal, NSpin } from "naive-ui";
import { platformLoginUrl } from "../../shared/base";
import { api, saveSession } from "../../shared/http";
import { hosted } from "../../shared/installState";
import { useToast } from "../../shared/toast";
import ThemeButton from "../../shell/ThemeButton.vue";
import "./login-gate.css";
const BROKEN_CAPTCHA = "data:,";
const props = defineProps<{ purpose?: "login" | "pool" }>();
const emit = defineEmits<{ done: [] }>();
const route = useRoute();
const router = useRouter();
const toast = useToast();
const adminLoginUrl = platformLoginUrl();
const mode = ref("local");
const username = ref("");
const password = ref("");
@@ -19,13 +23,13 @@ const captcha = ref("");
const captchaUrl = ref("");
const captchaLoading = ref(false);
const captchaBroken = ref(false);
const captchaSrc = computed(() => captchaBroken.value || !captchaUrl.value ? "/__captcha_broken__" : captchaUrl.value);
const captchaSrc = computed(() => captchaBroken.value || !captchaUrl.value ? BROKEN_CAPTCHA : captchaUrl.value);
function markCaptchaBroken(event: Event) {
const img = event.target as HTMLImageElement;
if (captchaBroken.value) return;
captchaBroken.value = true;
img.src = "/__captcha_broken__";
img.src = BROKEN_CAPTCHA;
}
const sessionId = ref("");
const smsCode = ref("");
@@ -331,7 +335,7 @@ async function finishNqi() {
<n-input :input-props="{ id: 'pool-captcha', autocomplete: 'off' }" v-model:value="captcha" @keyup.enter="submitLogin" />
<button type="button" class="lv-captcha-box" title="点击刷新" @click="refreshCaptcha">
<n-spin v-if="captchaLoading" size="small" />
<img v-else :src="captchaSrc" alt="验证码" @error="markCaptchaBroken" />
<img v-else :src="captchaSrc" :class="{ broken: captchaSrc === BROKEN_CAPTCHA }" alt="验证码" @error="markCaptchaBroken" />
</button>
</div>
<n-button class="lv-go" type="primary" attr-type="submit" :loading="busy">添加</n-button>
@@ -365,12 +369,13 @@ async function finishNqi() {
<input id="login-captcha" v-model="captcha" placeholder="captcha" autocomplete="off" @keyup.enter="submitLogin" />
<button type="button" class="lv-captcha-box" title="点击刷新" @click="refreshCaptcha">
<n-spin v-if="captchaLoading" size="small" />
<img v-else :src="captchaSrc" alt="验证码" @error="markCaptchaBroken" />
<img v-else :src="captchaSrc" :class="{ broken: captchaSrc === BROKEN_CAPTCHA }" alt="验证码" @error="markCaptchaBroken" />
</button>
</div>
</template>
<button class="lv-go" type="submit" :disabled="busy">{{ busy ? "登录中" : "登录" }}</button>
</form>
<a v-if="hosted && mode === 'nqi'" class="lv-admin" :href="adminLoginUrl">管理员登录</a>
</section>
<n-modal v-model:show="smsRequired" :mask-closable="false" :auto-focus="false">
<div class="lv-sms-sheet" role="dialog" aria-modal="true" aria-labelledby="sms-title">
+15
View File
@@ -197,6 +197,21 @@ html[data-theme="dark"] .gate.lv-tower {
}
.gate.lv-tower .lv-go:hover { filter: brightness(1.12); }
.gate.lv-tower .lv-go:disabled { opacity: 0.6; cursor: default; filter: none; }
.gate.lv-tower .lv-admin {
display: block;
width: fit-content;
margin: 18px 0 0 auto;
color: var(--muted-line);
font-size: 12px;
letter-spacing: 0.08em;
text-decoration: none;
}
.gate.lv-tower .lv-admin:hover,
.gate.lv-tower .lv-admin:focus-visible {
color: var(--ink-line);
text-decoration: underline;
text-underline-offset: 3px;
}
@media (max-width: 720px) {
.gate.lv-tower { grid-template-columns: 28px 1fr; }
+6 -4
View File
@@ -3,7 +3,7 @@ import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { NButton, NInput } from "naive-ui";
import { api } from "../../shared/http";
import { markInstalled } from "../../shared/installState";
import { hosted, markInstalled } from "../../shared/installState";
import { useToast } from "../../shared/toast";
import ThemeButton from "../../shell/ThemeButton.vue";
@@ -76,9 +76,11 @@ async function submit() {
<div class="form-row"><label>数据库名</label><n-input v-model:value="database" /></div>
<div class="form-row"><label>用户</label><n-input v-model:value="username" /></div>
<div class="form-row"><label>密码</label><n-input v-model:value="password" type="password" show-password-on="click" /></div>
<p class="form-section">管理员</p>
<div class="form-row"><label>账号</label><n-input v-model:value="adminUsername" /></div>
<div class="form-row"><label>密码</label><n-input v-model:value="adminPassword" type="password" show-password-on="click" /></div>
<template v-if="!hosted">
<p class="form-section">管理员</p>
<div class="form-row"><label>账号</label><n-input v-model:value="adminUsername" /></div>
<div class="form-row"><label>密码</label><n-input v-model:value="adminPassword" type="password" show-password-on="click" /></div>
</template>
<n-button class="gate-submit" type="primary" :loading="busy" @click="submit">完成安装</n-button>
</section>
</div>
+2 -1
View File
@@ -2,6 +2,7 @@
import { onMounted, onUnmounted, ref } from "vue";
import { NButton, NDatePicker, NInput, NModal, NSelect } from "naive-ui";
import Shell from "../../shell/Shell.vue";
import { appUrl } from "../../shared/base";
import { api, token } from "../../shared/http";
import { useToast } from "../../shared/toast";
@@ -116,7 +117,7 @@ async function submit() {
async function download(row: Task) {
try {
const response = await fetch(`/api/tasks/${row.id}/file`, { headers: { Authorization: `Bearer ${token()}` } });
const response = await fetch(appUrl(`/api/tasks/${row.id}/file`), { headers: { Authorization: `Bearer ${token()}` } });
if (!response.ok) {
toast.error("结果还不能下载,请等状态变成可下载");
return;