feat: 支持托管到Metrix应用包并移除授权与平台模式
- 新增 scripts/package_metrix.py 打包应用包(user_auth=metrix、admin_auth=none、数据目录 /data) - 托管模式只认平台代理身份,停用应用登录与改密码,新增 /api/session - 后端按 X-Forwarded-Prefix 注入 <base href>,前端改为相对路径构建并按 basePath 请求 - 托管时隐藏登录页、退出按钮和修改密码页,顶栏显示 Metrix 用户名 - 移除授权到期校验、激活码和连点品牌图标打开的授权延期窗口 - 移除 Metrix 平台数据源/仓库模式及相关配置、接口、设置页和 requests 依赖 - 新增托管鉴权与 base href 注入测试,更新使用与开发文档
This commit is contained in:
+2
-1
@@ -1,8 +1,10 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<base href="/" />
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<title>CapacityReport</title>
|
||||
</head>
|
||||
<body>
|
||||
@@ -10,4 +12,3 @@
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">
|
||||
<defs>
|
||||
<linearGradient id="g" x1="0" y1="0" x2="1" y2="1">
|
||||
<stop offset="0" stop-color="#0052D9"/>
|
||||
<stop offset="1" stop-color="#618DFF"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<rect width="32" height="32" rx="7" fill="url(#g)"/>
|
||||
<rect x="7.5" y="17" width="4" height="7.5" rx="1.2" fill="#fff" fill-opacity=".72"/>
|
||||
<rect x="14" y="12" width="4" height="12.5" rx="1.2" fill="#fff" fill-opacity=".86"/>
|
||||
<rect x="20.5" y="7.5" width="4" height="17" rx="1.2" fill="#fff"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 558 B |
+13
-60
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<LoginView v-if="!token" :loading="loginLoading" @login="handleLogin" />
|
||||
<n-layout v-else has-sider class="app-layout">
|
||||
<LoginView v-if="session.ready && !session.hosted && !token" :loading="loginLoading" @login="handleLogin" />
|
||||
<n-layout v-else-if="session.ready" has-sider class="app-layout">
|
||||
<n-layout-sider
|
||||
class="app-sider"
|
||||
collapse-mode="width"
|
||||
@@ -11,17 +11,7 @@
|
||||
@update:collapsed="handleSidebarCollapsed"
|
||||
>
|
||||
<div class="brand">
|
||||
<div
|
||||
class="brand-mark"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
title="CapacityReport"
|
||||
@click="handleBrandMarkClick"
|
||||
@keydown.enter.prevent="handleBrandMarkClick"
|
||||
@keydown.space.prevent="handleBrandMarkClick"
|
||||
>
|
||||
📊
|
||||
</div>
|
||||
<div class="brand-mark" aria-hidden="true">📊</div>
|
||||
<div class="brand-text">CapacityReport</div>
|
||||
</div>
|
||||
<n-menu
|
||||
@@ -98,7 +88,11 @@
|
||||
<button class="theme-toggle" type="button" :title="themeToggleTitle" @click="toggleTheme">
|
||||
<n-icon><component :is="themeToggleIcon" /></n-icon>
|
||||
</button>
|
||||
<n-button tertiary circle title="退出登录" class="logout-button" @click="logout">
|
||||
<span v-if="session.hosted" class="header-user" :title="session.userName">
|
||||
<n-icon><PersonCircleOutline /></n-icon>
|
||||
<span>{{ session.userName }}</span>
|
||||
</span>
|
||||
<n-button v-else tertiary circle title="退出登录" class="logout-button" @click="logout">
|
||||
<template #icon>
|
||||
<n-icon><LogOutOutline /></n-icon>
|
||||
</template>
|
||||
@@ -111,8 +105,6 @@
|
||||
</n-layout-content>
|
||||
</n-layout>
|
||||
</n-layout>
|
||||
|
||||
<LicenseActivationModal v-if="licenseModalVisible" v-model:show="licenseModalVisible" @metrix-changed="onMetrixChanged" />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -126,31 +118,28 @@ import {
|
||||
FileTrayFullOutline,
|
||||
LogOutOutline,
|
||||
MoonOutline,
|
||||
PersonCircleOutline,
|
||||
ServerOutline,
|
||||
SettingsOutline,
|
||||
StatsChartOutline,
|
||||
SunnyOutline
|
||||
} from '@vicons/ionicons5';
|
||||
|
||||
import { apiGet, apiPost, clearToken, getToken, setToken, setUnauthorizedHandler } from './api/client';
|
||||
import type { AppConfig, LoginResponse } from './types';
|
||||
import { apiPost, clearToken, getToken, setToken, setUnauthorizedHandler } from './api/client';
|
||||
import type { LoginResponse } from './types';
|
||||
import { pageHeader, resetPageHeader, resolveHeaderValue, type PageHeaderAction } from './composables/pageHeader';
|
||||
import { metrixEnabled } from './composables/metrixEnabled';
|
||||
import { loadSession, session } from './composables/session';
|
||||
import { themeName, toggleAppTheme } from './composables/theme';
|
||||
|
||||
const LoginView = defineAsyncComponent(() => import('./components/LoginView.vue'));
|
||||
const LicenseActivationModal = defineAsyncComponent(() => import('./components/LicenseActivationModal.vue'));
|
||||
const message = useMessage();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const token = ref(getToken());
|
||||
const loginLoading = ref(false);
|
||||
const sidebarCollapsed = ref(localStorage.getItem('sidebarCollapsed') === 'true');
|
||||
const licenseModalVisible = ref(false);
|
||||
const brandClickCount = ref(0);
|
||||
const menuKeys = ['workflow', 'dashboard', 'history', 'database', 'script', 'settings'] as const;
|
||||
type MenuKey = (typeof menuKeys)[number];
|
||||
let brandClickResetTimer: number | undefined;
|
||||
|
||||
const menuOptions: MenuOption[] = [
|
||||
{ label: '数据处理', key: 'workflow', icon: renderIcon(CloudUploadOutline) },
|
||||
@@ -175,17 +164,12 @@ const themeToggleTitle = computed(() => (themeName.value === 'dark' ? '切换到
|
||||
onMounted(() => {
|
||||
window.addEventListener('dragover', preventWindowFileDrop, { capture: true });
|
||||
window.addEventListener('drop', preventWindowFileDrop, { capture: true });
|
||||
if (token.value) {
|
||||
void loadMetrixEnabled();
|
||||
}
|
||||
void loadSession();
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('dragover', preventWindowFileDrop, { capture: true });
|
||||
window.removeEventListener('drop', preventWindowFileDrop, { capture: true });
|
||||
if (brandClickResetTimer !== undefined) {
|
||||
window.clearTimeout(brandClickResetTimer);
|
||||
}
|
||||
});
|
||||
|
||||
watch(
|
||||
@@ -204,7 +188,6 @@ async function handleLogin(payload: { username: string; password: string }) {
|
||||
setToken(result.token);
|
||||
token.value = result.token;
|
||||
message.success('登录成功');
|
||||
void loadMetrixEnabled();
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '登录失败');
|
||||
} finally {
|
||||
@@ -233,36 +216,6 @@ function handleMenuChange(key: string | number) {
|
||||
void router.push({ name: key });
|
||||
}
|
||||
|
||||
function onMetrixChanged(enabled: boolean) {
|
||||
metrixEnabled.value = enabled;
|
||||
}
|
||||
|
||||
async function loadMetrixEnabled() {
|
||||
try {
|
||||
const config = await apiGet<AppConfig>('/api/config/full');
|
||||
metrixEnabled.value = config.metrix_enabled ?? false;
|
||||
} catch {
|
||||
metrixEnabled.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleBrandMarkClick() {
|
||||
brandClickCount.value += 1;
|
||||
if (brandClickResetTimer !== undefined) {
|
||||
window.clearTimeout(brandClickResetTimer);
|
||||
}
|
||||
|
||||
if (brandClickCount.value >= 8) {
|
||||
brandClickCount.value = 0;
|
||||
licenseModalVisible.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
brandClickResetTimer = window.setTimeout(() => {
|
||||
brandClickCount.value = 0;
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
function isMenuKey(value: unknown): value is MenuKey {
|
||||
return typeof value === 'string' && menuKeys.includes(value as MenuKey);
|
||||
}
|
||||
|
||||
+22
-25
@@ -1,3 +1,4 @@
|
||||
import { appUrl } from '../base';
|
||||
import type { ApiError, ApiErrorDetail } from '../types';
|
||||
|
||||
const TOKEN_KEY = 'capacity_report_token';
|
||||
@@ -7,6 +8,7 @@ const API_FETCH_RETRIES = 8;
|
||||
const API_FETCH_RETRY_DELAY_MS = 500;
|
||||
const TAURI_HTTP_ERROR_PREFIX = 'CAPAREPORT_HTTP_ERROR:';
|
||||
let onUnauthorized: (() => void) | null = null;
|
||||
let hostedMode = false;
|
||||
let cachedTauriInvoke: TauriInvoke | null = null;
|
||||
|
||||
type TauriInvoke = <T>(command: string, args?: Record<string, unknown>) => Promise<T>;
|
||||
@@ -66,6 +68,19 @@ export function setUnauthorizedHandler(handler: () => void): void {
|
||||
onUnauthorized = handler;
|
||||
}
|
||||
|
||||
export function setHostedMode(value: boolean): void {
|
||||
hostedMode = value;
|
||||
}
|
||||
|
||||
function unauthorizedError(status: number): ApiRequestError {
|
||||
if (!hostedMode) {
|
||||
clearToken();
|
||||
}
|
||||
onUnauthorized?.();
|
||||
const text = hostedMode ? '访问已失效,请刷新页面后重试' : '登录已过期,请重新登录';
|
||||
return new ApiRequestError(text, status, { code: 'UNAUTHORIZED', message: text });
|
||||
}
|
||||
|
||||
export async function apiGet<T>(url: string): Promise<T> {
|
||||
return request<T>(url, { method: 'GET' });
|
||||
}
|
||||
@@ -92,12 +107,7 @@ export async function request<T>(url: string, init: RequestInit = {}): Promise<T
|
||||
throw new ApiRequestError(error.message, response.status, error.detail);
|
||||
}
|
||||
|
||||
clearToken();
|
||||
onUnauthorized?.();
|
||||
throw new ApiRequestError('登录已过期,请重新登录', response.status, {
|
||||
code: 'UNAUTHORIZED',
|
||||
message: '登录已过期,请重新登录'
|
||||
});
|
||||
throw unauthorizedError(response.status);
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -130,14 +140,7 @@ export function upload<T>(
|
||||
|
||||
xhr.addEventListener('load', () => {
|
||||
if (xhr.status === 401) {
|
||||
clearToken();
|
||||
onUnauthorized?.();
|
||||
reject(
|
||||
new ApiRequestError('登录已过期,请重新登录', xhr.status, {
|
||||
code: 'UNAUTHORIZED',
|
||||
message: '登录已过期,请重新登录'
|
||||
})
|
||||
);
|
||||
reject(unauthorizedError(xhr.status));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -203,12 +206,7 @@ export async function downloadGet(url: string, fallbackFilename: string): Promis
|
||||
|
||||
const response = await fetchWithRetry(apiUrl(url), { headers });
|
||||
if (response.status === 401) {
|
||||
clearToken();
|
||||
onUnauthorized?.();
|
||||
throw new ApiRequestError('登录已过期,请重新登录', response.status, {
|
||||
code: 'UNAUTHORIZED',
|
||||
message: '登录已过期,请重新登录'
|
||||
});
|
||||
throw unauthorizedError(response.status);
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -358,16 +356,15 @@ function parseFilename(disposition: string | null): string {
|
||||
}
|
||||
|
||||
export function apiUrl(url: string): string {
|
||||
if (!API_BASE || /^https?:\/\//i.test(url)) {
|
||||
if (/^https?:\/\//i.test(url)) {
|
||||
return url;
|
||||
}
|
||||
if (!API_BASE) {
|
||||
return appUrl(url);
|
||||
}
|
||||
return `${API_BASE}${url.startsWith('/') ? url : `/${url}`}`;
|
||||
}
|
||||
|
||||
export function getApiBaseUrl(): string {
|
||||
return API_BASE || window.location.origin;
|
||||
}
|
||||
|
||||
function resolveApiBase(): string {
|
||||
const configured = (import.meta.env.VITE_API_BASE || '').replace(/\/$/, '');
|
||||
if (configured) {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
function computeBasePath(): string {
|
||||
const path = new URL(document.baseURI).pathname;
|
||||
return path.endsWith('/') ? path : path.slice(0, path.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
/** 站点所在路径:直接访问时是 "/",托管到 Metrix 时类似 "/apps/capacityreport/"。 */
|
||||
export const basePath = computeBasePath();
|
||||
|
||||
export function appUrl(path: string): string {
|
||||
return basePath + path.replace(/^\/+/, '');
|
||||
}
|
||||
@@ -528,9 +528,7 @@ async function testConnection() {
|
||||
async function loadDatabaseSourceOptions() {
|
||||
try {
|
||||
const config = await apiGet<AppConfig>('/api/config');
|
||||
const mainName = config.warehouse_type === 'metrix'
|
||||
? (config.metrix.target_database || 'Metrix')
|
||||
: (config.mysql.dbname || '主数据库');
|
||||
const mainName = config.mysql.dbname || '主数据库';
|
||||
const cellName = config.cell_data?.mysql?.dbname || 'CellData';
|
||||
databaseSourceOptions.value = [
|
||||
{ label: `主数据库:${mainName}`, value: 'main', title: '主数据库', databaseName: mainName },
|
||||
|
||||
@@ -231,32 +231,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<n-modal
|
||||
v-model:show="licenseModalVisible"
|
||||
preset="card"
|
||||
title="授权已过期"
|
||||
:mask-closable="!activationLoading"
|
||||
:style="{ width: '420px', maxWidth: 'calc(100vw - 32px)' }"
|
||||
>
|
||||
<div class="license-dialog-body">
|
||||
<p class="license-dialog-text">{{ licenseErrorMessage }}</p>
|
||||
<div class="license-key-label">key: {{ activationKeyLabel }}</div>
|
||||
<n-input
|
||||
v-model:value="activationCode"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 3, maxRows: 5 }"
|
||||
placeholder="请输入激活码"
|
||||
:disabled="activationLoading"
|
||||
/>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="license-dialog-footer">
|
||||
<n-button :disabled="activationLoading" @click="licenseModalVisible = false">取消</n-button>
|
||||
<n-button type="primary" :loading="activationLoading" @click="submitActivation">激活</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
|
||||
<n-modal
|
||||
v-model:show="capacityHelpVisible"
|
||||
preset="card"
|
||||
@@ -328,8 +302,8 @@ import {
|
||||
TrashOutline
|
||||
} from '@vicons/ionicons5';
|
||||
|
||||
import { ApiRequestError, apiGet, apiPost, upload } from '../api/client';
|
||||
import type { ActiveTask, ApiErrorDetail, CellDataResult, LicenseStatus, TaskStatus } from '../types';
|
||||
import { apiGet, apiPost, upload } from '../api/client';
|
||||
import type { ActiveTask, CellDataResult, TaskStatus } from '../types';
|
||||
import { toColoredLogLines } from '../composables/logLines';
|
||||
|
||||
type FileStatus = 'pending' | 'uploading' | 'uploaded' | 'error';
|
||||
@@ -372,17 +346,10 @@ const taskStatus = ref<TaskStatus | null>(null);
|
||||
const activeTask = ref<ActiveTask | null>(null);
|
||||
const keepLatestLog = ref(true);
|
||||
const logContainer = ref<HTMLElement | null>(null);
|
||||
const licenseModalVisible = ref(false);
|
||||
const activationCode = ref('');
|
||||
const activationLoading = ref(false);
|
||||
const activationKeyLabel = ref('2026/12/30');
|
||||
const licenseErrorMessage = ref('当前数据日期已超过授权到期日期,请输入激活码延长 30 天。');
|
||||
const taskMode = ref<'local' | 'remote' | 'cell_data' | 'unknown'>('unknown');
|
||||
let activationRetry: (() => Promise<void>) | null = null;
|
||||
let timer: number | undefined;
|
||||
|
||||
const stageLabels: Record<string, string> = {
|
||||
license: '授权校验中...',
|
||||
cell_data: '更新 CellData...',
|
||||
locating: '定位数据中...',
|
||||
downloading: '远程下载中...',
|
||||
@@ -711,9 +678,7 @@ async function uploadAndStart() {
|
||||
item.status = 'error';
|
||||
}
|
||||
});
|
||||
if (!handleApiLicenseError(error)) {
|
||||
message.error(error instanceof Error ? error.message : '上传或启动任务失败');
|
||||
}
|
||||
message.error(error instanceof Error ? error.message : '上传或启动任务失败');
|
||||
} finally {
|
||||
working.value = false;
|
||||
}
|
||||
@@ -743,9 +708,7 @@ async function startRemoteProcessing() {
|
||||
taskMode.value = 'remote';
|
||||
startPolling(result.task_id);
|
||||
} catch (error) {
|
||||
if (!handleApiLicenseError(error)) {
|
||||
message.error(error instanceof Error ? error.message : '启动远程自动化任务失败');
|
||||
}
|
||||
message.error(error instanceof Error ? error.message : '启动远程自动化任务失败');
|
||||
} finally {
|
||||
remoteStarting.value = false;
|
||||
}
|
||||
@@ -825,7 +788,7 @@ async function startUploadedTask(taskId: string) {
|
||||
taskStatus.value = {
|
||||
task_id: taskId,
|
||||
status: 'processing',
|
||||
stage: 'license',
|
||||
stage: 'processing',
|
||||
logs: ['任务已提交,等待处理日志...']
|
||||
};
|
||||
startPolling(taskId);
|
||||
@@ -876,9 +839,6 @@ async function poll(taskId: string) {
|
||||
if (['completed', 'failed'].includes(taskStatus.value.status)) {
|
||||
stopPolling();
|
||||
await checkActiveTask();
|
||||
if (taskStatus.value.status === 'failed') {
|
||||
handleTaskLicenseError(taskStatus.value);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
stopPolling();
|
||||
@@ -886,86 +846,6 @@ async function poll(taskId: string) {
|
||||
}
|
||||
}
|
||||
|
||||
function handleTaskLicenseError(status: TaskStatus): boolean {
|
||||
const detail = status.error_detail || parseLicenseDetail(status.error || '');
|
||||
if (detail?.code !== 'LICENSE_EXPIRED') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const taskId = status.task_id;
|
||||
const retry =
|
||||
taskMode.value === 'local'
|
||||
? () => startUploadedTask(taskId)
|
||||
: taskMode.value === 'remote'
|
||||
? () => startRemoteProcessing()
|
||||
: null;
|
||||
openLicenseModal(detail, retry);
|
||||
return true;
|
||||
}
|
||||
|
||||
function handleApiLicenseError(error: unknown): boolean {
|
||||
if (!(error instanceof ApiRequestError) || error.code !== 'LICENSE_EXPIRED') {
|
||||
return false;
|
||||
}
|
||||
|
||||
openLicenseModal(error.detail);
|
||||
return true;
|
||||
}
|
||||
|
||||
function openLicenseModal(detail?: ApiErrorDetail, retry?: (() => Promise<void>) | null) {
|
||||
activationKeyLabel.value = detail?.key_label || activationKeyLabel.value;
|
||||
licenseErrorMessage.value =
|
||||
detail?.message || '当前数据日期已超过授权到期日期,请输入激活码延长 30 天。';
|
||||
activationCode.value = '';
|
||||
activationRetry = retry || null;
|
||||
licenseModalVisible.value = true;
|
||||
}
|
||||
|
||||
async function submitActivation() {
|
||||
const code = activationCode.value.trim();
|
||||
if (!code) {
|
||||
message.warning('请输入激活码');
|
||||
return;
|
||||
}
|
||||
|
||||
activationLoading.value = true;
|
||||
try {
|
||||
const result = await apiPost<LicenseStatus>('/api/license/activate', { code });
|
||||
activationKeyLabel.value = result.key_label;
|
||||
licenseModalVisible.value = false;
|
||||
message.success(`激活成功,到期日期: ${result.expires_on}`);
|
||||
if (activationRetry) {
|
||||
const retry = activationRetry;
|
||||
activationRetry = null;
|
||||
await retry();
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof ApiRequestError && error.detail?.key_label) {
|
||||
activationKeyLabel.value = error.detail.key_label;
|
||||
}
|
||||
message.error(error instanceof Error ? error.message : '激活失败');
|
||||
} finally {
|
||||
activationLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function parseLicenseDetail(text: string): ApiErrorDetail | null {
|
||||
if (!text.includes('授权已过期')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const expiresMatch = text.match(/到期日期\s+(\d{4}-\d{2}-\d{2})/);
|
||||
const currentMatch = text.match(/数据日期\s+(\d{4}-\d{2}-\d{2})/);
|
||||
const expiresOn = expiresMatch?.[1];
|
||||
return {
|
||||
code: 'LICENSE_EXPIRED',
|
||||
message: text,
|
||||
expires_on: expiresOn,
|
||||
current_date: currentMatch?.[1],
|
||||
key_label: expiresOn ? expiresOn.replace(/-/g, '/') : activationKeyLabel.value
|
||||
};
|
||||
}
|
||||
|
||||
function stageText(stage?: string | null): string {
|
||||
if (!stage) return '处理中...';
|
||||
return stageLabels[stage] || '处理中...';
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
<template>
|
||||
<n-modal
|
||||
v-model:show="visible"
|
||||
preset="card"
|
||||
title="授权延期"
|
||||
:mask-closable="!activationLoading"
|
||||
:style="{ width: '420px', maxWidth: 'calc(100vw - 32px)' }"
|
||||
>
|
||||
<div class="license-dialog-body">
|
||||
<p class="license-dialog-text">{{ licenseMessage }}</p>
|
||||
<div class="license-key-label">key: {{ activationKeyLabel }}</div>
|
||||
<n-input
|
||||
v-model:value="activationCode"
|
||||
type="textarea"
|
||||
:autosize="{ minRows: 3, maxRows: 5 }"
|
||||
placeholder="请输入激活码"
|
||||
:disabled="activationLoading"
|
||||
/>
|
||||
<div class="license-metrix-toggle">
|
||||
<n-switch :value="metrixEnabled" :loading="savingMetrix" size="small" @update:value="toggleMetrix" />
|
||||
<span class="license-metrix-label">启用 Metrix 平台</span>
|
||||
</div>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="license-dialog-footer">
|
||||
<n-button :disabled="activationLoading" @click="visible = false">取消</n-button>
|
||||
<n-button type="primary" :loading="activationLoading" @click="submitActivation">激活</n-button>
|
||||
</div>
|
||||
</template>
|
||||
</n-modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useMessage } from 'naive-ui';
|
||||
|
||||
import { apiGet, apiPost } from '../api/client';
|
||||
import type { AppConfig, LicenseStatus } from '../types';
|
||||
|
||||
const visible = defineModel<boolean>('show', { required: true });
|
||||
const emit = defineEmits<{ metrixChanged: [enabled: boolean] }>();
|
||||
const message = useMessage();
|
||||
const activationCode = ref('');
|
||||
const activationLoading = ref(false);
|
||||
const activationKeyLabel = ref('2026/12/30');
|
||||
const licenseMessage = ref('输入激活码可将授权到期日期延长 30 天。');
|
||||
const metrixEnabled = ref(false);
|
||||
const savingMetrix = ref(false);
|
||||
|
||||
onMounted(() => {
|
||||
void loadLicenseStatus();
|
||||
void loadMetrixEnabled();
|
||||
});
|
||||
|
||||
async function loadLicenseStatus() {
|
||||
try {
|
||||
const status = await apiGet<LicenseStatus>('/api/license/status');
|
||||
activationKeyLabel.value = status.key_label;
|
||||
licenseMessage.value = `当前授权到期日期:${status.expires_on}。输入激活码可延长 30 天。`;
|
||||
activationCode.value = '';
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '获取授权状态失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMetrixEnabled() {
|
||||
try {
|
||||
const config = await apiGet<AppConfig>('/api/config/full');
|
||||
metrixEnabled.value = config.metrix_enabled ?? false;
|
||||
} catch {
|
||||
metrixEnabled.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleMetrix(target: boolean) {
|
||||
if (target === metrixEnabled.value) return;
|
||||
savingMetrix.value = true;
|
||||
try {
|
||||
await apiPost('/api/config/metrix-enabled', { enabled: target });
|
||||
metrixEnabled.value = target;
|
||||
emit('metrixChanged', target);
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '保存失败');
|
||||
} finally {
|
||||
savingMetrix.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function submitActivation() {
|
||||
const code = activationCode.value.trim();
|
||||
if (!code) {
|
||||
message.warning('请输入激活码');
|
||||
return;
|
||||
}
|
||||
|
||||
activationLoading.value = true;
|
||||
try {
|
||||
const result = await apiPost<LicenseStatus>('/api/license/activate', { code });
|
||||
activationKeyLabel.value = result.key_label;
|
||||
licenseMessage.value = `当前授权到期日期:${result.expires_on}。输入激活码可继续延长 30 天。`;
|
||||
activationCode.value = '';
|
||||
message.success(`激活成功,到期日期: ${result.expires_on}`);
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '激活失败');
|
||||
} finally {
|
||||
activationLoading.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.license-metrix-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 16px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--n-border-color, #e0e0e6);
|
||||
}
|
||||
.license-metrix-label {
|
||||
font-size: 13px;
|
||||
color: var(--n-text-color-3, #999);
|
||||
}
|
||||
</style>
|
||||
@@ -4,77 +4,6 @@
|
||||
|
||||
<n-card size="small" class="work-card settings-tabs-card">
|
||||
<n-tabs type="line" animated class="settings-tabs">
|
||||
<n-tab-pane v-if="metrixEnabledRef" name="backend" tab="数据源 / 仓库">
|
||||
<div class="settings-database-panel">
|
||||
<div class="settings-database-stack">
|
||||
<n-card title="后端类型" size="small" class="work-card">
|
||||
<n-form label-placement="top">
|
||||
<n-form-item label="数据源">
|
||||
<n-radio-group v-model:value="sourceType">
|
||||
<n-radio-button value="external">外部储存</n-radio-button>
|
||||
<n-radio-button value="metrix">Metrix 储存平台</n-radio-button>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
<n-form-item label="数据仓库">
|
||||
<n-radio-group v-model:value="warehouseType">
|
||||
<n-radio-button value="mysql">MySQL</n-radio-button>
|
||||
<n-radio-button value="metrix">Metrix 数据库平台</n-radio-button>
|
||||
</n-radio-group>
|
||||
</n-form-item>
|
||||
<p class="form-hint">数据源和数据仓库可独立选择;CellData 单独配置。</p>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<n-space justify="end">
|
||||
<n-button type="primary" :loading="savingBackend" @click="saveBackend">保存类型</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-card>
|
||||
|
||||
<n-card title="Metrix 连接(存储平台 / 数据库平台)" size="small" class="work-card">
|
||||
<n-form label-placement="top">
|
||||
<n-form-item label="平台地址 (api_base)">
|
||||
<n-input v-model:value="metrixForm.base_url" placeholder="http://host.docker.internal:8000" />
|
||||
</n-form-item>
|
||||
<n-form-item label="API Token">
|
||||
<n-input v-model:value="metrixForm.token" type="password" show-password-on="click" placeholder="mtx_..." />
|
||||
</n-form-item>
|
||||
<n-grid :cols="12" :x-gap="12">
|
||||
<n-gi :span="6">
|
||||
<n-form-item label="储存连接 ID">
|
||||
<n-input v-model:value="metrixForm.storage_id" placeholder="stg_..." />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi :span="6">
|
||||
<n-form-item label="数据库连接 ID">
|
||||
<n-input v-model:value="metrixForm.database_conn_id" placeholder="db_..." />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
<n-grid :cols="12" :x-gap="12">
|
||||
<n-gi :span="8">
|
||||
<n-form-item label="目标库/Schema">
|
||||
<n-input v-model:value="metrixForm.target_database" placeholder="连接已指定库时可空" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
<n-gi :span="4">
|
||||
<n-form-item label="最近 N 天回退">
|
||||
<n-input-number v-model:value="metrixForm.recent_days" class="full-width" :min="1" :precision="0" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
<p class="form-hint">填写 Metrix 平台连接信息。</p>
|
||||
</n-form>
|
||||
<template #footer>
|
||||
<n-space justify="end">
|
||||
<n-button type="primary" :loading="savingMetrix" @click="saveMetrix">保存连接</n-button>
|
||||
<n-button :loading="testingRemote" @click="testRemote">测试储存</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-card>
|
||||
</div>
|
||||
</div>
|
||||
</n-tab-pane>
|
||||
|
||||
<n-tab-pane name="database" tab="数据库">
|
||||
<div class="settings-database-panel">
|
||||
<div class="settings-database-stack">
|
||||
@@ -608,7 +537,7 @@
|
||||
</div>
|
||||
</n-tab-pane>
|
||||
|
||||
<n-tab-pane name="security" tab="修改密码">
|
||||
<n-tab-pane v-if="!session.hosted" name="security" tab="修改密码">
|
||||
<div class="settings-security-panel">
|
||||
<n-card title="修改登录密码" size="small" class="work-card">
|
||||
<n-form label-placement="top">
|
||||
@@ -813,14 +742,13 @@ import type {
|
||||
DataDirectoryMapping,
|
||||
DataMappingsConfig,
|
||||
HistoryRetentionConfig,
|
||||
MetrixConfig,
|
||||
RemoteAutoSchedulerConfig,
|
||||
RemoteDataConfig,
|
||||
RemoteSchedulerStatus
|
||||
} from '../types';
|
||||
import { showDownloadCompleteDialog } from '../composables/downloadFeedback';
|
||||
import { metrixEnabled as metrixEnabledRef } from '../composables/metrixEnabled';
|
||||
import { resetPageHeader, setPageHeader } from '../composables/pageHeader';
|
||||
import { session } from '../composables/session';
|
||||
|
||||
interface ExtractFieldConfig {
|
||||
Field: string;
|
||||
@@ -881,10 +809,6 @@ const savingCellDataMysql = ref(false);
|
||||
const savingCellDataRemote = ref(false);
|
||||
const savingCellDataSettings = ref(false);
|
||||
const validatingCellDataSettings = ref(false);
|
||||
const savingBackend = ref(false);
|
||||
const savingMetrix = ref(false);
|
||||
const sourceType = ref<'external' | 'metrix'>('external');
|
||||
const warehouseType = ref<'mysql' | 'metrix'>('mysql');
|
||||
const savingDirectoryMappings = ref(false);
|
||||
const savingHistoryRetention = ref(false);
|
||||
const savingSheetFilter = ref(false);
|
||||
@@ -969,15 +893,6 @@ const cellDataRegexForm = reactive({
|
||||
file_time_regex: '(?P<timestamp>\\\\d{14})(?=\\\\.zip$)'
|
||||
});
|
||||
|
||||
const metrixForm = reactive<MetrixConfig>({
|
||||
base_url: 'http://host.docker.internal:8000',
|
||||
token: '',
|
||||
storage_id: '',
|
||||
database_conn_id: '',
|
||||
target_database: '',
|
||||
recent_days: 7
|
||||
});
|
||||
|
||||
const dataMappingsForm = reactive<DataMappingsConfig>({
|
||||
directories: [
|
||||
{ path: '4G', table: '4G_UD', ready_rule: 'daily' },
|
||||
@@ -1121,16 +1036,6 @@ async function loadConfig() {
|
||||
try {
|
||||
const config = await apiGet<AppConfig>('/api/config/full');
|
||||
configUpdate.value = config.update;
|
||||
sourceType.value = (config.source_type === 'metrix' ? 'metrix' : 'external') as 'external' | 'metrix';
|
||||
warehouseType.value = config.warehouse_type || 'mysql';
|
||||
if (config.metrix) {
|
||||
metrixForm.base_url = config.metrix.base_url || '';
|
||||
metrixForm.token = config.metrix.token || '';
|
||||
metrixForm.storage_id = config.metrix.storage_id || '';
|
||||
metrixForm.database_conn_id = config.metrix.database_conn_id || '';
|
||||
metrixForm.target_database = config.metrix.target_database || '';
|
||||
metrixForm.recent_days = Number(config.metrix.recent_days) || 7;
|
||||
}
|
||||
Object.assign(dataMappingsForm, normalizeDataMappingsConfig(config.data_mappings));
|
||||
mysqlForm.host = config.mysql.host;
|
||||
mysqlForm.port = config.mysql.port;
|
||||
@@ -1178,42 +1083,6 @@ function updateCellDataRemoteProtocol(value: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function saveBackend() {
|
||||
savingBackend.value = true;
|
||||
try {
|
||||
const result = await apiPost<ApiMessage>('/api/config/backend', {
|
||||
source_type: sourceType.value,
|
||||
warehouse_type: warehouseType.value
|
||||
});
|
||||
configUpdate.value = result.update || configUpdate.value;
|
||||
message.success(result.message || '后端类型已保存');
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '保存后端类型失败');
|
||||
} finally {
|
||||
savingBackend.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveMetrix() {
|
||||
if (!metrixForm.base_url) {
|
||||
message.warning('请填写平台地址');
|
||||
return;
|
||||
}
|
||||
savingMetrix.value = true;
|
||||
try {
|
||||
const result = await apiPost<ApiMessage>('/api/config/metrix', {
|
||||
...metrixForm,
|
||||
recent_days: Math.max(Number(metrixForm.recent_days) || 7, 1)
|
||||
});
|
||||
configUpdate.value = result.update || configUpdate.value;
|
||||
message.success(result.message || 'Metrix 连接已保存');
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '保存 Metrix 连接失败');
|
||||
} finally {
|
||||
savingMetrix.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveMysql() {
|
||||
if (!mysqlForm.host || !mysqlForm.user || !mysqlForm.dbname) {
|
||||
message.warning('请填写完整数据库配置');
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
export const metrixEnabled = ref(false);
|
||||
@@ -0,0 +1,24 @@
|
||||
import { reactive } from 'vue';
|
||||
|
||||
import { apiGet, setHostedMode } from '../api/client';
|
||||
import type { SessionInfo } from '../types';
|
||||
|
||||
export const session = reactive({
|
||||
ready: false,
|
||||
hosted: false,
|
||||
userName: ''
|
||||
});
|
||||
|
||||
export async function loadSession(): Promise<void> {
|
||||
try {
|
||||
const info = await apiGet<SessionInfo>('/api/session');
|
||||
session.hosted = Boolean(info.hosted);
|
||||
session.userName = info.user?.name || '';
|
||||
} catch {
|
||||
session.hosted = false;
|
||||
session.userName = '';
|
||||
} finally {
|
||||
setHostedMode(session.hosted);
|
||||
session.ready = true;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import { basePath } from './base';
|
||||
|
||||
const FileWorkflow = () => import('./components/FileWorkflow.vue');
|
||||
const CapacityDashboard = () => import('./components/CapacityDashboard.vue');
|
||||
const HistoryPanel = () => import('./components/HistoryPanel.vue');
|
||||
@@ -19,6 +21,6 @@ export const routes: RouteRecordRaw[] = [
|
||||
];
|
||||
|
||||
export const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
history: createWebHistory(basePath),
|
||||
routes
|
||||
});
|
||||
|
||||
+20
-29
@@ -388,6 +388,26 @@ select {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.header-user {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
gap: 6px;
|
||||
max-width: 180px;
|
||||
height: 32px;
|
||||
padding: 0 10px;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: 13px;
|
||||
border: 1px solid var(--td-border-color);
|
||||
border-radius: var(--td-radius-default);
|
||||
}
|
||||
|
||||
.header-user span {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.content {
|
||||
height: calc(100vh - 64px);
|
||||
min-width: 0;
|
||||
@@ -653,35 +673,6 @@ select {
|
||||
border-radius: var(--td-radius-small);
|
||||
}
|
||||
|
||||
.license-dialog-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.license-dialog-text {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.license-key-label {
|
||||
padding: 8px 10px;
|
||||
color: var(--td-brand-color);
|
||||
font-family: Consolas, "Courier New", monospace;
|
||||
font-size: 13px;
|
||||
background: var(--td-brand-color-light);
|
||||
border: 1px solid var(--td-brand-color-focus);
|
||||
border-radius: var(--td-radius-default);
|
||||
}
|
||||
|
||||
.license-dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.file-list {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
+6
-23
@@ -13,18 +13,15 @@ export interface ApiError {
|
||||
export interface ApiErrorDetail {
|
||||
code?: string;
|
||||
message?: string;
|
||||
expires_on?: string;
|
||||
current_date?: string;
|
||||
key_label?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface LicenseStatus {
|
||||
success: boolean;
|
||||
expires_on: string;
|
||||
key_label: string;
|
||||
current_date?: string | null;
|
||||
zip_count?: number;
|
||||
export interface SessionInfo {
|
||||
hosted: boolean;
|
||||
user?: {
|
||||
name: string;
|
||||
role: 'admin' | 'user';
|
||||
} | null;
|
||||
}
|
||||
|
||||
export interface CellDataResult {
|
||||
@@ -41,7 +38,6 @@ export interface TaskStatus {
|
||||
logs: string[];
|
||||
elapsed_time?: number;
|
||||
error?: string;
|
||||
error_detail?: ApiErrorDetail;
|
||||
result?: CellDataResult;
|
||||
}
|
||||
|
||||
@@ -96,9 +92,6 @@ export interface CacheSize {
|
||||
|
||||
export interface AppConfig {
|
||||
update: string;
|
||||
metrix_enabled: boolean;
|
||||
source_type: 'external' | 'metrix';
|
||||
warehouse_type: 'mysql' | 'metrix';
|
||||
mysql: {
|
||||
host: string;
|
||||
port: number;
|
||||
@@ -106,7 +99,6 @@ export interface AppConfig {
|
||||
passwd?: string;
|
||||
dbname: string;
|
||||
};
|
||||
metrix: MetrixConfig;
|
||||
data_mappings: DataMappingsConfig;
|
||||
remote_data: RemoteDataConfig;
|
||||
cell_data: CellDataConfig;
|
||||
@@ -115,15 +107,6 @@ export interface AppConfig {
|
||||
extract_fields: Array<Record<string, unknown>>;
|
||||
}
|
||||
|
||||
export interface MetrixConfig {
|
||||
base_url: string;
|
||||
token?: string;
|
||||
storage_id: string;
|
||||
database_conn_id: string;
|
||||
target_database: string;
|
||||
recent_days: number;
|
||||
}
|
||||
|
||||
export interface DataDirectoryMapping {
|
||||
path: string;
|
||||
table: string;
|
||||
|
||||
@@ -5,6 +5,8 @@ import Components from 'unplugin-vue-components/vite';
|
||||
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
|
||||
|
||||
export default defineConfig({
|
||||
// 相对路径资源:托管到 Metrix 时由后端注入 <base href="/apps/<slug>/">。
|
||||
base: './',
|
||||
plugins: [
|
||||
vue(),
|
||||
AutoImport({
|
||||
|
||||
Reference in New Issue
Block a user