feat: 完成登录与栅格下载桌面端
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { darkTheme, NConfigProvider, NMessageProvider, zhCN, dateZhCN } from "naive-ui";
|
||||
import LoginView from "./features/auth/LoginView.vue";
|
||||
import Shell from "./shell/Shell.vue";
|
||||
import type { UserInfo } from "./features/auth/api";
|
||||
import { isDark, themeOverrides } from "./shared/theme";
|
||||
|
||||
const user = ref<UserInfo | null>(null);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-config-provider :locale="zhCN" :date-locale="dateZhCN" :theme="isDark ? darkTheme : null" :theme-overrides="themeOverrides">
|
||||
<n-message-provider>
|
||||
<LoginView v-if="!user" @success="user = $event" />
|
||||
<Shell v-else :user="user" @logout="user = null" />
|
||||
</n-message-provider>
|
||||
</n-config-provider>
|
||||
</template>
|
||||
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
|
||||
|
After Width: | Height: | Size: 496 B |
@@ -0,0 +1,178 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { NAlert, NButton, NIcon, NInput, NSpin, NTooltip } from "naive-ui";
|
||||
import { HelpCircleOutline, MoonOutline, SunnyOutline } from "@vicons/ionicons5";
|
||||
import { ApiError } from "../../shared/http";
|
||||
import { loadCaptcha, login, refreshCaptcha, sendSms, type UserInfo } from "./api";
|
||||
import { isDark, toggleTheme } from "../../shared/theme";
|
||||
|
||||
const emit = defineEmits<{ success: [user: UserInfo] }>();
|
||||
|
||||
const ready = ref(false);
|
||||
const offline = ref("");
|
||||
const sessionId = ref("");
|
||||
const captchaUrl = ref("");
|
||||
const username = ref("");
|
||||
const password = ref("");
|
||||
const captcha = ref("");
|
||||
const smsCode = ref("");
|
||||
const smsRequired = ref(false);
|
||||
const sending = ref(false);
|
||||
const submitting = ref(false);
|
||||
const errorText = ref("");
|
||||
const smsHint = ref("");
|
||||
const countdown = ref(0);
|
||||
let timer = 0;
|
||||
|
||||
onMounted(() => {
|
||||
void connect();
|
||||
});
|
||||
|
||||
async function connect() {
|
||||
offline.value = "";
|
||||
ready.value = false;
|
||||
for (let attempt = 0; attempt < 20; attempt += 1) {
|
||||
try {
|
||||
const result = await loadCaptcha();
|
||||
sessionId.value = result.sessionId;
|
||||
captchaUrl.value = result.captcha;
|
||||
ready.value = true;
|
||||
return;
|
||||
} catch (error) {
|
||||
const failedLocally = !(error instanceof ApiError) || error.status === 0;
|
||||
offline.value = error instanceof ApiError ? error.message : "连接失败";
|
||||
if (!failedLocally) {
|
||||
ready.value = true;
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => window.setTimeout(resolve, 500));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function reloadCaptcha() {
|
||||
errorText.value = "";
|
||||
try {
|
||||
if (!sessionId.value) {
|
||||
await connect();
|
||||
return;
|
||||
}
|
||||
const result = await refreshCaptcha(sessionId.value);
|
||||
captchaUrl.value = result.captcha;
|
||||
captcha.value = "";
|
||||
} catch (error) {
|
||||
errorText.value = error instanceof ApiError ? error.message : "验证码刷新失败";
|
||||
await connect();
|
||||
}
|
||||
}
|
||||
|
||||
async function requestSms() {
|
||||
if (!sessionId.value || countdown.value > 0) return;
|
||||
sending.value = true;
|
||||
smsHint.value = "";
|
||||
try {
|
||||
const result = await sendSms(sessionId.value);
|
||||
smsHint.value = result.message || "短信已发送";
|
||||
countdown.value = 60;
|
||||
timer = window.setInterval(() => {
|
||||
countdown.value -= 1;
|
||||
if (countdown.value <= 0) window.clearInterval(timer);
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
errorText.value = error instanceof ApiError ? error.message : "短信发送失败";
|
||||
} finally {
|
||||
sending.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
errorText.value = "";
|
||||
submitting.value = true;
|
||||
try {
|
||||
const result = await login({
|
||||
sessionId: sessionId.value,
|
||||
username: username.value.trim(),
|
||||
password: password.value,
|
||||
captcha: captcha.value.trim(),
|
||||
smsCode: smsCode.value.trim(),
|
||||
});
|
||||
if (result.status === "sms_required") {
|
||||
smsRequired.value = true;
|
||||
smsHint.value = result.message || "请获取并填写短信验证码";
|
||||
return;
|
||||
}
|
||||
if (result.user) emit("success", result.user);
|
||||
} catch (error) {
|
||||
errorText.value = error instanceof ApiError ? error.message : "登录失败";
|
||||
smsRequired.value = false;
|
||||
await reloadCaptcha();
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="gate">
|
||||
<n-button class="theme-switch" quaternary circle :aria-label="isDark ? '切换到日间' : '切换到夜间'" @click="toggleTheme">
|
||||
<template #icon><n-icon><MoonOutline v-if="!isDark" /><SunnyOutline v-else /></n-icon></template>
|
||||
</n-button>
|
||||
<section class="gate-card">
|
||||
<div class="brand">
|
||||
<div class="brand-mark" aria-hidden="true">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
|
||||
<path d="M4 16.5 12 4l8 12.5" stroke="currentColor" stroke-width="1.8" />
|
||||
<path d="M7.2 16.5h9.6M9.2 13.2h5.6" stroke="currentColor" stroke-width="1.8" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h1>NqiTools</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<n-spin :show="!ready && !offline">
|
||||
<n-alert v-if="!ready" type="warning" style="margin-bottom: 12px">连接失败,正在重试。</n-alert>
|
||||
<n-alert v-else-if="offline" type="warning" style="margin-bottom: 12px">{{ offline }}</n-alert>
|
||||
<n-alert v-if="errorText" type="error" style="margin-bottom: 12px">{{ errorText }}</n-alert>
|
||||
<form @submit.prevent="submit">
|
||||
<div class="form-row">
|
||||
<label for="username">账号</label>
|
||||
<n-input id="username" v-model:value="username" placeholder="账号" autocomplete="username" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="password">密码</label>
|
||||
<n-input id="password" v-model:value="password" type="password" show-password-on="click" placeholder="密码" autocomplete="current-password" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="captcha">
|
||||
验证码
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
点击图片刷新。
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<div class="captcha-line">
|
||||
<n-input id="captcha" v-model:value="captcha" placeholder="验证码" />
|
||||
<img v-if="captchaUrl" :src="captchaUrl" alt="验证码" title="点击刷新" @click="reloadCaptcha" />
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="smsRequired" class="form-row">
|
||||
<label for="sms">短信</label>
|
||||
<div class="captcha-line">
|
||||
<n-input id="sms" v-model:value="smsCode" placeholder="短信验证码" />
|
||||
<n-button :disabled="sending || countdown > 0" @click="requestSms">
|
||||
{{ countdown > 0 ? `${countdown}s` : "获取短信" }}
|
||||
</n-button>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="smsHint" class="file-name" style="margin: 0 0 8px 96px">{{ smsHint }}</p>
|
||||
<div class="gate-actions">
|
||||
<n-button type="primary" attr-type="submit" :loading="submitting" :disabled="!ready">登录</n-button>
|
||||
</div>
|
||||
</form>
|
||||
</n-spin>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,43 @@
|
||||
import { api } from "../../shared/http";
|
||||
|
||||
export interface UserInfo {
|
||||
loginId: string;
|
||||
userName: string;
|
||||
cityName: string;
|
||||
orgName: string;
|
||||
}
|
||||
|
||||
export function loadCaptcha() {
|
||||
return api<{ sessionId: string; captcha: string }>("/api/auth/captcha", { method: "POST" });
|
||||
}
|
||||
|
||||
export function refreshCaptcha(sessionId: string) {
|
||||
return api<{ sessionId: string; captcha: string }>("/api/auth/captcha/refresh", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ sessionId }),
|
||||
});
|
||||
}
|
||||
|
||||
export function sendSms(sessionId: string) {
|
||||
return api<{ message: string }>("/api/auth/sms", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ sessionId }),
|
||||
});
|
||||
}
|
||||
|
||||
export function login(body: {
|
||||
sessionId: string;
|
||||
username: string;
|
||||
password: string;
|
||||
captcha: string;
|
||||
smsCode?: string;
|
||||
}) {
|
||||
return api<{ status: string; message?: string; user?: UserInfo }>("/api/auth/login", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
return api<{ ok: boolean }>("/api/auth/logout", { method: "POST" });
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import { NButton, NEmpty, NIcon, NProgress, NTag, useMessage } from "naive-ui";
|
||||
import { FolderOpenOutline, PlayOutline, StopCircleOutline } from "@vicons/ionicons5";
|
||||
import { ApiError, openLocal } from "../../shared/http";
|
||||
import { cancelJob, loadJobs, resumeJob, type DownloadJob } from "./api";
|
||||
|
||||
const props = defineProps<{ focusId: string }>();
|
||||
const message = useMessage();
|
||||
const jobs = ref<DownloadJob[]>([]);
|
||||
const tab = ref<"active" | "done">("active");
|
||||
let timer = 0;
|
||||
|
||||
const activeJobs = computed(() => jobs.value.filter((job) => job.status !== "done"));
|
||||
const doneJobs = computed(() => jobs.value.filter((job) => job.status === "done"));
|
||||
const visible = computed(() => (tab.value === "active" ? activeJobs.value : doneJobs.value));
|
||||
|
||||
const statusText: Record<string, string> = {
|
||||
queued: "等待中",
|
||||
running: "下载中",
|
||||
cancelled: "已停止",
|
||||
error: "出错",
|
||||
done_with_errors: "部分失败",
|
||||
done: "已完成",
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
void refresh();
|
||||
timer = window.setInterval(() => void refresh(), 1000);
|
||||
});
|
||||
|
||||
onUnmounted(() => window.clearInterval(timer));
|
||||
|
||||
async function refresh() {
|
||||
try {
|
||||
const result = await loadJobs();
|
||||
jobs.value = result.jobs;
|
||||
} catch (error) {
|
||||
if (error instanceof ApiError && error.status !== 0) message.error(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
function percent(job: DownloadJob) {
|
||||
if (!job.total) return 0;
|
||||
return Math.min(100, Math.round((job.completed / job.total) * 100));
|
||||
}
|
||||
|
||||
async function stop(job: DownloadJob) {
|
||||
try {
|
||||
await cancelJob(job.id);
|
||||
await refresh();
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "停止失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function resume(job: DownloadJob) {
|
||||
try {
|
||||
await resumeJob(job.id);
|
||||
tab.value = "active";
|
||||
await refresh();
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "继续失败");
|
||||
}
|
||||
}
|
||||
|
||||
async function openFile(job: DownloadJob) {
|
||||
const opened = await openLocal(job.csvPath).catch(() => false);
|
||||
if (!opened) message.info(job.csvPath);
|
||||
}
|
||||
|
||||
async function openDir(job: DownloadJob) {
|
||||
const index = Math.max(job.csvPath.lastIndexOf("\\"), job.csvPath.lastIndexOf("/"));
|
||||
const folder = index > 0 ? job.csvPath.slice(0, index) : job.csvPath;
|
||||
const opened = await openLocal(folder).catch(() => false);
|
||||
if (!opened) message.info(folder);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<h2>下载管理</h2>
|
||||
</div>
|
||||
</header>
|
||||
<div class="tabs">
|
||||
<button class="tab" :class="{ on: tab === 'active' }" type="button" @click="tab = 'active'">
|
||||
正在下载<em>{{ activeJobs.length }}</em>
|
||||
</button>
|
||||
<button class="tab" :class="{ on: tab === 'done' }" type="button" @click="tab = 'done'">
|
||||
已完成<em>{{ doneJobs.length }}</em>
|
||||
</button>
|
||||
</div>
|
||||
<div class="task-list">
|
||||
<article
|
||||
v-for="job in visible"
|
||||
:key="job.id"
|
||||
class="task"
|
||||
:class="{ focus: job.id === props.focusId }"
|
||||
>
|
||||
<div class="task-top">
|
||||
<div>
|
||||
<h3>{{ job.name }}</h3>
|
||||
<div class="sub">{{ job.completed }}/{{ job.total }} 个栅格 · 已写入 {{ job.writtenRows }} 行</div>
|
||||
</div>
|
||||
<div class="task-actions">
|
||||
<n-tag size="small" :type="job.status === 'running' ? 'info' : job.status === 'done' ? 'success' : 'warning'">
|
||||
{{ statusText[job.status] || job.status }}
|
||||
</n-tag>
|
||||
<n-button v-if="job.status === 'running' || job.status === 'queued'" size="small" @click="stop(job)">
|
||||
<template #icon><n-icon><StopCircleOutline /></n-icon></template>
|
||||
停止
|
||||
</n-button>
|
||||
<n-button v-else-if="job.status !== 'done'" size="small" type="primary" secondary @click="resume(job)">
|
||||
<template #icon><n-icon><PlayOutline /></n-icon></template>
|
||||
继续
|
||||
</n-button>
|
||||
<n-button size="small" quaternary @click="openFile(job)">打开</n-button>
|
||||
<n-button size="small" quaternary @click="openDir(job)">
|
||||
<template #icon><n-icon><FolderOpenOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</div>
|
||||
</div>
|
||||
<n-progress
|
||||
style="margin-top: 10px"
|
||||
:percentage="percent(job)"
|
||||
:show-indicator="true"
|
||||
:processing="job.status === 'running'"
|
||||
/>
|
||||
<div class="task-foot">
|
||||
<span class="sub">{{ job.message }}</span>
|
||||
<span class="sub">失败 {{ job.failed }}</span>
|
||||
</div>
|
||||
<ul v-if="job.failures?.length" class="fail-list">
|
||||
<li v-for="item in job.failures.slice(0, 3)" :key="item.id">{{ item.id }}:{{ item.message }}</li>
|
||||
</ul>
|
||||
</article>
|
||||
<n-empty v-if="visible.length === 0" class="empty" :description="tab === 'active' ? '没有正在下载的任务' : '还没有完成的任务'" />
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,197 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, watch } from "vue";
|
||||
import {
|
||||
NButton,
|
||||
NCheckbox,
|
||||
NCheckboxGroup,
|
||||
NIcon,
|
||||
NInput,
|
||||
NInputNumber,
|
||||
NSelect,
|
||||
NTooltip,
|
||||
useMessage,
|
||||
} from "naive-ui";
|
||||
import { FolderOpenOutline, HelpCircleOutline } from "@vicons/ionicons5";
|
||||
import { ApiError, chooseDirectory } from "../../shared/http";
|
||||
import { createJob, loadMeta, type Meta } from "./api";
|
||||
|
||||
const emit = defineEmits<{ started: [id: string] }>();
|
||||
const message = useMessage();
|
||||
|
||||
const meta = ref<Meta | null>(null);
|
||||
const network = ref("NR");
|
||||
const cityCode = ref("JM");
|
||||
const month = ref(previousMonth());
|
||||
const concurrency = ref(8);
|
||||
const groups = ref<string[]>([]);
|
||||
const outputDir = ref("");
|
||||
const file = ref<File | null>(null);
|
||||
const submitting = ref(false);
|
||||
|
||||
const networkOptions = [
|
||||
{ label: "5G", value: "NR" },
|
||||
{ label: "4G", value: "LTE" },
|
||||
];
|
||||
|
||||
function previousMonth() {
|
||||
const date = new Date();
|
||||
date.setDate(1);
|
||||
date.setMonth(date.getMonth() - 1);
|
||||
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
meta.value = await loadMeta();
|
||||
syncGroups();
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "读取下载项目失败");
|
||||
}
|
||||
});
|
||||
|
||||
watch(network, syncGroups);
|
||||
|
||||
function syncGroups() {
|
||||
groups.value = (meta.value?.groups[network.value] || []).map((item) => item.id);
|
||||
}
|
||||
|
||||
function onFile(event: Event) {
|
||||
const input = event.target as HTMLInputElement;
|
||||
file.value = input.files?.[0] ?? null;
|
||||
}
|
||||
|
||||
async function pickDir() {
|
||||
const selected = await chooseDirectory();
|
||||
if (selected) outputDir.value = selected;
|
||||
}
|
||||
|
||||
async function start() {
|
||||
if (!file.value) {
|
||||
message.warning("请先选择栅格 ID 表");
|
||||
return;
|
||||
}
|
||||
if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(month.value)) {
|
||||
message.warning("月份格式应为 YYYY-MM");
|
||||
return;
|
||||
}
|
||||
const form = new FormData();
|
||||
form.append("file", file.value);
|
||||
form.append("network", network.value);
|
||||
form.append("city_code", cityCode.value);
|
||||
form.append("month", month.value);
|
||||
form.append("groups", JSON.stringify(groups.value));
|
||||
form.append("concurrency", String(concurrency.value || 8));
|
||||
form.append("output_dir", outputDir.value.trim());
|
||||
submitting.value = true;
|
||||
try {
|
||||
const job = await createJob(form);
|
||||
message.success("已开始下载");
|
||||
emit("started", job.id);
|
||||
} catch (error) {
|
||||
message.error(error instanceof ApiError ? error.message : "创建下载失败");
|
||||
} finally {
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<div class="page-scroll">
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<h2>栅格下载</h2>
|
||||
</div>
|
||||
<div class="head-actions">
|
||||
<n-button type="primary" :loading="submitting" @click="start">开始下载</n-button>
|
||||
</div>
|
||||
</header>
|
||||
<div class="panel">
|
||||
<div class="form-row">
|
||||
<label>网络</label>
|
||||
<n-select v-model:value="network" :options="networkOptions" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>地市</label>
|
||||
<n-select
|
||||
v-model:value="cityCode"
|
||||
:options="(meta?.cities || []).map((city) => ({ label: city.name, value: city.code }))"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>
|
||||
月份
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
例如 2026-09。
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<n-input v-model:value="month" placeholder="YYYY-MM" />
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>
|
||||
并发
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
同时下载的栅格数量。
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<n-input-number v-model:value="concurrency" :min="1" :max="32" />
|
||||
</div>
|
||||
<div class="form-row" style="align-items: start">
|
||||
<label>
|
||||
项目
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
选择要导出的指标。
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<n-checkbox-group v-model:value="groups">
|
||||
<div v-for="item in meta?.groups[network] || []" :key="item.id" style="margin-bottom: 6px">
|
||||
<n-checkbox :value="item.id">{{ item.label }}</n-checkbox>
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="14" style="margin-left: 4px"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
{{ item.columns.join("、") }}
|
||||
</n-tooltip>
|
||||
</div>
|
||||
</n-checkbox-group>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>
|
||||
区域表
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-icon class="hint" :size="15"><HelpCircleOutline /></n-icon>
|
||||
</template>
|
||||
支持 CSV、TXT、XLSX。
|
||||
</n-tooltip>
|
||||
</label>
|
||||
<div class="captcha-line">
|
||||
<label class="n-button n-button--default-type" style="padding: 0 12px; line-height: 32px; border: 1px solid #d5e0ea; border-radius: 6px; cursor: pointer">
|
||||
选择文件
|
||||
<input type="file" accept=".csv,.txt,.xlsx" hidden @change="onFile" />
|
||||
</label>
|
||||
<span class="file-name">{{ file?.name || "尚未选择" }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label>保存到</label>
|
||||
<div class="captcha-line">
|
||||
<n-input v-model:value="outputDir" placeholder="默认目录" />
|
||||
<n-button @click="pickDir">
|
||||
<template #icon><n-icon><FolderOpenOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -0,0 +1,51 @@
|
||||
import { api } from "../../shared/http";
|
||||
|
||||
export interface GroupOption {
|
||||
id: string;
|
||||
label: string;
|
||||
columns: string[];
|
||||
}
|
||||
|
||||
export interface Meta {
|
||||
networks: { value: string; label: string }[];
|
||||
cities: { name: string; code: string }[];
|
||||
groups: Record<string, GroupOption[]>;
|
||||
fixed: { grid: string[]; cell: Record<string, string[]> };
|
||||
}
|
||||
|
||||
export interface DownloadJob {
|
||||
id: string;
|
||||
name: string;
|
||||
status: string;
|
||||
message: string;
|
||||
network: string;
|
||||
cityName: string;
|
||||
month: string;
|
||||
total: number;
|
||||
completed: number;
|
||||
failed: number;
|
||||
writtenRows: number;
|
||||
csvPath: string;
|
||||
failures: { id: string; message: string }[];
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export function loadMeta() {
|
||||
return api<Meta>("/api/download/meta");
|
||||
}
|
||||
|
||||
export function loadJobs() {
|
||||
return api<{ jobs: DownloadJob[] }>("/api/download/jobs");
|
||||
}
|
||||
|
||||
export function createJob(form: FormData) {
|
||||
return api<DownloadJob>("/api/download/jobs", { method: "POST", body: form });
|
||||
}
|
||||
|
||||
export function cancelJob(id: string) {
|
||||
return api<DownloadJob>(`/api/download/jobs/${id}/cancel`, { method: "POST" });
|
||||
}
|
||||
|
||||
export function resumeJob(id: string) {
|
||||
return api<DownloadJob>(`/api/download/jobs/${id}/resume`, { method: "POST" });
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { createApp } from "vue";
|
||||
import App from "./App.vue";
|
||||
import "./styles.css";
|
||||
|
||||
createApp(App).mount("#app");
|
||||
@@ -0,0 +1,49 @@
|
||||
export const API_BASE = import.meta.env.DEV ? "" : "http://127.0.0.1:8765";
|
||||
|
||||
export class ApiError extends Error {
|
||||
status: number;
|
||||
|
||||
constructor(status: number, message: string) {
|
||||
super(message);
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
export async function api<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
let response: Response;
|
||||
try {
|
||||
const headers = new Headers(init?.headers);
|
||||
if (init?.body && !(init.body instanceof FormData) && !headers.has("Content-Type")) {
|
||||
headers.set("Content-Type", "application/json");
|
||||
}
|
||||
response = await fetch(`${API_BASE}${path}`, { ...init, headers });
|
||||
} catch {
|
||||
throw new ApiError(0, "连接失败");
|
||||
}
|
||||
const text = await response.text();
|
||||
const data = text ? JSON.parse(text) : null;
|
||||
if (!response.ok) {
|
||||
const detail = data?.detail;
|
||||
const message = typeof detail === "string" ? detail : "请求失败";
|
||||
throw new ApiError(response.status, message);
|
||||
}
|
||||
return data as T;
|
||||
}
|
||||
|
||||
export function health() {
|
||||
return api<{ ok: boolean }>("/api/health");
|
||||
}
|
||||
|
||||
export async function openLocal(path: string) {
|
||||
if (!("__TAURI_INTERNALS__" in window)) return false;
|
||||
const { openPath } = await import("@tauri-apps/plugin-opener");
|
||||
await openPath(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function chooseDirectory() {
|
||||
if (!("__TAURI_INTERNALS__" in window)) return null;
|
||||
const { open } = await import("@tauri-apps/plugin-dialog");
|
||||
const selected = await open({ directory: true, multiple: false });
|
||||
return typeof selected === "string" ? selected : null;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { ref, watch } from "vue";
|
||||
|
||||
const stored = localStorage.getItem("nqi-theme");
|
||||
export const isDark = ref(stored === "dark");
|
||||
|
||||
watch(isDark, (value) => {
|
||||
localStorage.setItem("nqi-theme", value ? "dark" : "light");
|
||||
document.documentElement.dataset.theme = value ? "dark" : "light";
|
||||
}, { immediate: true });
|
||||
|
||||
export function toggleTheme() {
|
||||
isDark.value = !isDark.value;
|
||||
}
|
||||
|
||||
export const themeOverrides = {
|
||||
common: {
|
||||
primaryColor: "#2563eb",
|
||||
primaryColorHover: "#1d4ed8",
|
||||
primaryColorPressed: "#1e40af",
|
||||
primaryColorSuppl: "#2563eb",
|
||||
borderRadius: "6px",
|
||||
fontFamily: '"Segoe UI", "Microsoft YaHei", sans-serif',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { NButton, NIcon, NLayoutSider, NMenu } from "naive-ui";
|
||||
import { LogOutOutline, MoonOutline, PersonOutline, SunnyOutline } from "@vicons/ionicons5";
|
||||
import { logout, type UserInfo } from "../features/auth/api";
|
||||
import { isDark, toggleTheme } from "../shared/theme";
|
||||
import { navGroups, type PageKey } from "./navigation";
|
||||
import GridDownloadView from "../features/download/GridDownloadView.vue";
|
||||
import DownloadManagerView from "../features/download/DownloadManagerView.vue";
|
||||
|
||||
const props = defineProps<{ user: UserInfo }>();
|
||||
const emit = defineEmits<{ logout: [] }>();
|
||||
|
||||
const page = ref<PageKey>("grid");
|
||||
const focusId = ref("");
|
||||
|
||||
function onMenu(key: string) {
|
||||
if (key === "grid" || key === "tasks") page.value = key;
|
||||
}
|
||||
|
||||
function onStarted(id: string) {
|
||||
focusId.value = id;
|
||||
page.value = "tasks";
|
||||
}
|
||||
|
||||
async function signOut() {
|
||||
try {
|
||||
await logout();
|
||||
} finally {
|
||||
emit("logout");
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="shell">
|
||||
<aside class="sider">
|
||||
<div class="sider-title">NqiTools</div>
|
||||
<n-layout-sider :native-scrollbar="false" :width="220" style="background: transparent; flex: 1">
|
||||
<n-menu :value="page" :options="navGroups" @update:value="onMenu" />
|
||||
</n-layout-sider>
|
||||
<div class="sider-user">
|
||||
<n-icon :size="18"><PersonOutline /></n-icon>
|
||||
<div class="who">
|
||||
<strong>{{ props.user.userName || props.user.loginId }}</strong>
|
||||
<span>{{ props.user.cityName || "已登录" }}</span>
|
||||
</div>
|
||||
<n-button quaternary circle size="small" :aria-label="isDark ? '切换到日间' : '切换到夜间'" @click="toggleTheme">
|
||||
<template #icon><n-icon><MoonOutline v-if="!isDark" /><SunnyOutline v-else /></n-icon></template>
|
||||
</n-button>
|
||||
<n-button quaternary circle size="small" aria-label="退出" @click="signOut">
|
||||
<template #icon><n-icon><LogOutOutline /></n-icon></template>
|
||||
</n-button>
|
||||
</div>
|
||||
</aside>
|
||||
<main class="content">
|
||||
<GridDownloadView v-if="page === 'grid'" @started="onStarted" />
|
||||
<DownloadManagerView v-else :focus-id="focusId" />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,22 @@
|
||||
import type { Component } from "vue";
|
||||
import { h } from "vue";
|
||||
import { NIcon } from "naive-ui";
|
||||
import { CloudDownloadOutline, ListOutline } from "@vicons/ionicons5";
|
||||
|
||||
function renderIcon(icon: Component) {
|
||||
return () => h(NIcon, null, { default: () => h(icon) });
|
||||
}
|
||||
|
||||
export type PageKey = "grid" | "tasks";
|
||||
|
||||
export const navGroups = [
|
||||
{
|
||||
type: "group" as const,
|
||||
label: "下载",
|
||||
key: "download",
|
||||
children: [
|
||||
{ label: "栅格下载", key: "grid" as const, icon: renderIcon(CloudDownloadOutline) },
|
||||
{ label: "下载管理", key: "tasks" as const, icon: renderIcon(ListOutline) },
|
||||
],
|
||||
},
|
||||
];
|
||||
@@ -0,0 +1,357 @@
|
||||
:root {
|
||||
color: var(--ink);
|
||||
background: var(--bg);
|
||||
font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
|
||||
font-size: 14px;
|
||||
--bg: #f3f4f6;
|
||||
--panel: #ffffff;
|
||||
--ink: #111827;
|
||||
--muted: #6b7280;
|
||||
--line: #e5e7eb;
|
||||
--accent: #2563eb;
|
||||
--accent-soft: #eff6ff;
|
||||
--sidebar: #ffffff;
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] {
|
||||
--bg: #0f172a;
|
||||
--panel: #1e293b;
|
||||
--ink: #f8fafc;
|
||||
--muted: #94a3b8;
|
||||
--line: #334155;
|
||||
--accent: #60a5fa;
|
||||
--accent-soft: #1e3a8a;
|
||||
--sidebar: #111827;
|
||||
}
|
||||
|
||||
::selection {
|
||||
background: var(--accent-soft);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
margin: 0;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
button,
|
||||
input,
|
||||
select {
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.gate {
|
||||
position: relative;
|
||||
min-height: 100%;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 32px 16px;
|
||||
background: var(--bg);
|
||||
}
|
||||
|
||||
.theme-switch {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
}
|
||||
|
||||
.gate-card {
|
||||
width: min(440px, 100%);
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
|
||||
padding: 28px 28px 22px;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
align-items: center;
|
||||
margin-bottom: 22px;
|
||||
}
|
||||
|
||||
.brand-mark {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 10px;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.brand h1 {
|
||||
margin: 0;
|
||||
font-size: 20px;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.brand p,
|
||||
.file-name,
|
||||
.hint,
|
||||
.task .sub,
|
||||
.empty {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.form-row {
|
||||
display: grid;
|
||||
grid-template-columns: 84px minmax(0, 1fr);
|
||||
gap: 8px 12px;
|
||||
align-items: center;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.brand p {
|
||||
margin: 2px 0 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.captcha-line {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.form-row label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.captcha-line img {
|
||||
width: 112px;
|
||||
height: 36px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
background: var(--bg);
|
||||
cursor: pointer;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.gate-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.shell {
|
||||
height: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: 220px minmax(0, 1fr);
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.sider {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--sidebar);
|
||||
border-right: 1px solid var(--line);
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.sider-title {
|
||||
padding: 18px 16px 8px;
|
||||
font-weight: 650;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.sider-user {
|
||||
margin-top: auto;
|
||||
padding: 12px;
|
||||
border-top: 1px solid var(--line);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.sider-user .who {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.sider-user strong,
|
||||
.sider-user span {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.sider-user span {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.content {
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.page {
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.page-scroll {
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.page-head {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 14px 20px;
|
||||
background: var(--bg);
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.page-head h2 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.page-head p {
|
||||
margin: 2px 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.head-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.panel,
|
||||
.task {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.panel {
|
||||
margin: 16px 20px 24px;
|
||||
border-radius: 10px;
|
||||
padding: 16px 16px 8px;
|
||||
}
|
||||
|
||||
.hint {
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
padding: 12px 20px 0;
|
||||
}
|
||||
|
||||
.file-name {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tab {
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--muted);
|
||||
border-bottom: 2px solid transparent;
|
||||
padding: 8px 2px;
|
||||
margin-right: 16px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.tab.on {
|
||||
color: var(--accent);
|
||||
border-bottom-color: var(--accent);
|
||||
font-weight: 650;
|
||||
}
|
||||
|
||||
.tab em {
|
||||
font-style: normal;
|
||||
margin-left: 6px;
|
||||
color: var(--accent);
|
||||
background: var(--accent-soft);
|
||||
border-radius: 99px;
|
||||
padding: 0 7px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.task-list {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
padding: 12px 20px 24px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.task {
|
||||
border-radius: 10px;
|
||||
padding: 12px 14px;
|
||||
}
|
||||
|
||||
.task.focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
|
||||
}
|
||||
|
||||
.task-top,
|
||||
.task-foot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.task h3 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.empty {
|
||||
margin: 48px auto;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.task-actions {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.fail-list {
|
||||
margin: 8px 0 0;
|
||||
padding-left: 18px;
|
||||
color: #9a4d16;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.task .sub {
|
||||
margin-top: 2px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.empty {
|
||||
margin: 48px auto;
|
||||
text-align: center;
|
||||
}
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/// <reference types="vite/client" />
|
||||
|
||||
declare module "*.vue" {
|
||||
import type { DefineComponent } from "vue";
|
||||
const component: DefineComponent<{}, {}, any>;
|
||||
export default component;
|
||||
}
|
||||
Reference in New Issue
Block a user