Compare commits
14 Commits
0c28031e81
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 968a6f8d22 | |||
| 735989f0ae | |||
| 0d378b9f35 | |||
| 809cc5fd81 | |||
| 69efff3cb4 | |||
| 7e735cdf72 | |||
| 69473320b3 | |||
| d585a6baaa | |||
| 0e273111a2 | |||
| d0a1c3dce5 | |||
| d299db0ab2 | |||
| 80a0e7eeb6 | |||
| d5b4cc7b77 | |||
| 5e69e5a841 |
@@ -0,0 +1,20 @@
|
||||
.venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.git/
|
||||
.gitignore
|
||||
.claude/
|
||||
.playwright-mcp/
|
||||
.trae/
|
||||
node_modules/
|
||||
web/frontend/node_modules/
|
||||
data/
|
||||
docs/
|
||||
tests/
|
||||
*.md
|
||||
!README.md
|
||||
release/
|
||||
dist/
|
||||
build/
|
||||
*.spec
|
||||
*.exe
|
||||
@@ -0,0 +1,29 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install system dependencies (tkinter needed by app/core processing)
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
gcc \
|
||||
python3-tk \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install Python dependencies
|
||||
COPY web/backend/requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy project files
|
||||
COPY app/ ./app/
|
||||
COPY config/ ./config/
|
||||
COPY config.ini ./
|
||||
COPY templates/ ./templates/
|
||||
COPY web/ ./web/
|
||||
|
||||
# Create data directories
|
||||
RUN mkdir -p data/input data/output data/result data/temp
|
||||
|
||||
# Expose port
|
||||
EXPOSE 18889
|
||||
|
||||
# Run
|
||||
CMD ["python", "-m", "uvicorn", "web.backend.main:app", "--host", "0.0.0.0", "--port", "18889"]
|
||||
@@ -0,0 +1,19 @@
|
||||
# Build stage
|
||||
FROM node:20-alpine AS build
|
||||
|
||||
WORKDIR /app
|
||||
COPY web/frontend/package.json web/frontend/package-lock.json* ./
|
||||
RUN npm install
|
||||
COPY web/frontend/ .
|
||||
# Override outDir for Docker build (vite config uses ../backend/static for local dev)
|
||||
RUN npx vite build --outDir ./dist
|
||||
|
||||
# Production stage
|
||||
FROM nginx:alpine
|
||||
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 18888
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -57,6 +57,43 @@ cd web && python -m uvicorn backend.main:app --host 0.0.0.0 --port 8000
|
||||
|
||||
**默认账号:** `admin` / `admin123`(首次登录后建议修改密码)
|
||||
|
||||
### Docker 部署 (生产环境)
|
||||
|
||||
**环境要求:** Docker + Docker Compose
|
||||
|
||||
```bash
|
||||
# 1. 克隆代码
|
||||
git clone https://gitea.94kan.cn/houhuan/orc-order-v2.git
|
||||
cd orc-order-v2
|
||||
|
||||
# 2. 配置环境变量(百度 OCR API 密钥、Gitea Token 等)
|
||||
cp .env.example .env # 若无 .env.example,手动创建 .env
|
||||
# 编辑 .env 填入:
|
||||
# BAIDU_OCR_API_KEY=xxx
|
||||
# BAIDU_OCR_SECRET_KEY=xxx
|
||||
# GITEA_TOKEN=xxx
|
||||
|
||||
# 3. 构建并启动
|
||||
docker-compose up -d --build
|
||||
|
||||
# 4. 访问
|
||||
# 前端: http://服务器IP:18888
|
||||
# 后端 API: http://服务器IP:18889
|
||||
# 默认账号: admin / admin123(首次登录后建议修改密码)
|
||||
|
||||
# 常用命令
|
||||
docker-compose logs -f # 查看日志
|
||||
docker-compose restart # 重启服务
|
||||
docker-compose down # 停止服务
|
||||
docker-compose up -d --build # 重新构建并启动
|
||||
```
|
||||
|
||||
**端口说明:**
|
||||
- `18888` — 前端 (Nginx),对外访问入口
|
||||
- `18889` — 后端 API (FastAPI),前端自动代理,无需直接访问
|
||||
|
||||
**数据持久化:** `data/` 目录挂载到宿主机,SQLite 数据库、上传文件、处理结果不会因容器重建而丢失。
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
|
||||
@@ -22,7 +22,7 @@ DEFAULT_CONFIG = {
|
||||
'result_folder': 'data/result',
|
||||
'temp_folder': 'data/temp',
|
||||
'template_folder': 'templates',
|
||||
'template_file': '银豹-采购单模板.xls',
|
||||
'template_file': 'templates/银豹-采购单模板.xls',
|
||||
'processed_record': 'data/processed_files.json',
|
||||
'data_dir': 'data',
|
||||
'product_db': 'data/product_cache.db'
|
||||
|
||||
@@ -104,8 +104,8 @@ class ConfigManager:
|
||||
logger.info(f"已创建默认配置文件: {self.config_file}")
|
||||
|
||||
def save_config(self) -> None:
|
||||
"""保存配置到文件(API 密钥不写入文件)"""
|
||||
# 保存前临时清空 API 密钥,避免写入文件
|
||||
"""保存配置到文件(API 密钥不写入文件,Gitea token 需要持久化)"""
|
||||
# 保存前临时清空 API 密钥,避免写入文件(这些从 .env 读取)
|
||||
saved_keys = {}
|
||||
for option in ('api_key', 'secret_key'):
|
||||
try:
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ input_folder = data/input
|
||||
output_folder = data/output
|
||||
temp_folder = data/temp
|
||||
template_folder = templates
|
||||
template_file = templates\银豹-采购单模板.xls
|
||||
template_file = templates/银豹-采购单模板.xls
|
||||
processed_record = data/processed_files.json
|
||||
data_dir = data
|
||||
product_db = data/product_cache.db
|
||||
@@ -40,7 +40,7 @@ version = 2026.05.05.0239
|
||||
base_url = https://gitea.94kan.cn
|
||||
owner = houhuan
|
||||
repo = yixuan-sync-data
|
||||
token = 50b61e43a141d606ae2529cd1755bc666d800e08
|
||||
token =
|
||||
|
||||
[WebAuth]
|
||||
username = admin
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ output_folder = data/output
|
||||
result_folder = data/result
|
||||
temp_folder = data/temp
|
||||
template_folder = templates
|
||||
template_file = 银豹-采购单模板.xls
|
||||
template_file = templates/银豹-采购单模板.xls
|
||||
processed_record = data/processed_files.json
|
||||
data_dir = data
|
||||
product_db = data/product_cache.db
|
||||
@@ -37,5 +37,5 @@ item_data = 商品资料.xlsx
|
||||
base_url = https://gitea.94kan.cn
|
||||
owner = houhuan
|
||||
repo = yixuan-sync-data
|
||||
token =
|
||||
token = 50b61e43a141d606ae2529cd1755bc666d800e08
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
services:
|
||||
backend:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.backend
|
||||
container_name: yixuan-backend
|
||||
ports:
|
||||
- "18889:18889"
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
- ./config.ini:/app/config.ini:ro
|
||||
- ./config:/app/config:ro
|
||||
- ./templates:/app/templates:ro
|
||||
env_file:
|
||||
- .env
|
||||
restart: unless-stopped
|
||||
|
||||
frontend:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile.frontend
|
||||
container_name: yixuan-frontend
|
||||
ports:
|
||||
- "18888:18888"
|
||||
depends_on:
|
||||
- backend
|
||||
restart: unless-stopped
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
server {
|
||||
listen 18888;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml;
|
||||
gzip_min_length 1000;
|
||||
|
||||
# API proxy to backend
|
||||
location /api/ {
|
||||
proxy_pass http://backend:18889;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# WebSocket proxy to backend
|
||||
location /ws/ {
|
||||
proxy_pass http://backend:18889;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
# Vue Router history mode - serve index.html for all routes
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# Cache static assets
|
||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
# Web backend dependencies
|
||||
fastapi>=0.104.0
|
||||
uvicorn[standard]>=0.24.0
|
||||
python-jose[cryptography]>=3.3.0
|
||||
bcrypt>=4.0.0
|
||||
python-multipart>=0.0.6
|
||||
httpx>=0.25.0
|
||||
werkzeug>=3.0.0
|
||||
|
||||
# Core app dependencies (needed by processing endpoints)
|
||||
pandas>=1.3.0
|
||||
openpyxl>=3.0.0
|
||||
xlrd>=2.0.0,<2.1.0
|
||||
xlwt>=1.3.0
|
||||
xlutils>=2.0.0
|
||||
numpy>=1.19.0
|
||||
requests>=2.25.0
|
||||
python-dotenv>=1.0.0
|
||||
configparser>=5.0.0
|
||||
@@ -64,6 +64,11 @@ async def get_config(
|
||||
return result
|
||||
|
||||
|
||||
def _is_masked(key: str, value: str) -> bool:
|
||||
"""Check if a value looks like a masked sensitive field (contains asterisks)."""
|
||||
return any(s in key.lower() for s in _SENSITIVE_KEYS) and '*' in value
|
||||
|
||||
|
||||
@router.put("")
|
||||
async def update_config(
|
||||
body: ConfigUpdate,
|
||||
@@ -72,6 +77,9 @@ async def update_config(
|
||||
if body.section not in _ALLOWED_SECTIONS:
|
||||
raise HTTPException(403, f"不允许修改配置节: {body.section}")
|
||||
|
||||
if _is_masked(body.key, body.value):
|
||||
raise HTTPException(400, "敏感字段不能直接提交掩码值,请先清除输入框再输入真实值")
|
||||
|
||||
cfg = _get_config()
|
||||
try:
|
||||
cfg.update(body.section, body.key, body.value)
|
||||
@@ -88,11 +96,19 @@ async def bulk_update_config(
|
||||
):
|
||||
cfg = _get_config()
|
||||
updated = []
|
||||
skipped = []
|
||||
for item in body.updates:
|
||||
if item.section not in _ALLOWED_SECTIONS:
|
||||
continue
|
||||
# Skip masked sensitive values to prevent destroying real credentials
|
||||
if _is_masked(item.key, item.value):
|
||||
skipped.append(f"[{item.section}] {item.key}")
|
||||
continue
|
||||
cfg.update(item.section, item.key, item.value)
|
||||
updated.append(f"[{item.section}] {item.key}")
|
||||
|
||||
cfg.save_config()
|
||||
return {"message": f"已更新 {len(updated)} 项", "updated": updated}
|
||||
msg = f"已更新 {len(updated)} 项"
|
||||
if skipped:
|
||||
msg += f",跳过 {len(skipped)} 项掩码值"
|
||||
return {"message": msg, "updated": updated, "skipped": skipped}
|
||||
|
||||
@@ -169,6 +169,10 @@ async def delete_file(
|
||||
return {"message": f"已删除 {filename}"}
|
||||
|
||||
|
||||
class BatchDeleteRequest(BaseModel):
|
||||
files: list[dict]
|
||||
|
||||
|
||||
@router.post("/batch-delete")
|
||||
async def batch_delete_files(
|
||||
req: BatchDeleteRequest,
|
||||
@@ -252,10 +256,6 @@ class RelationDeleteRequest(BaseModel):
|
||||
ids: List[int]
|
||||
|
||||
|
||||
class BatchDeleteRequest(BaseModel):
|
||||
files: list[dict]
|
||||
|
||||
|
||||
def _cleanup_relation_for_deleted_file(directory: str, filename: str):
|
||||
"""Clean up relation table when a file is deleted."""
|
||||
import sqlite3
|
||||
|
||||
@@ -78,6 +78,7 @@ async def sync_status(
|
||||
):
|
||||
try:
|
||||
from app.config.settings import ConfigManager
|
||||
import httpx as _httpx
|
||||
cfg = ConfigManager()
|
||||
base_url = cfg.get("Gitea", "base_url", fallback="").strip()
|
||||
owner = cfg.get("Gitea", "owner", fallback="").strip()
|
||||
@@ -85,6 +86,22 @@ async def sync_status(
|
||||
token = cfg.get("Gitea", "token", fallback="").strip()
|
||||
enabled = bool(base_url and owner and repo and token)
|
||||
repo_url = f"{base_url}/{owner}/{repo}" if enabled else ""
|
||||
return {"enabled": enabled, "repo_url": repo_url}
|
||||
except Exception:
|
||||
return {"enabled": False, "repo_url": ""}
|
||||
|
||||
connected = False
|
||||
error = ""
|
||||
if enabled:
|
||||
try:
|
||||
async with _httpx.AsyncClient(timeout=10) as client:
|
||||
resp = await client.get(
|
||||
f"{base_url}/api/v1/repos/{owner}/{repo}",
|
||||
headers={"Authorization": f"token {token}"},
|
||||
)
|
||||
connected = resp.status_code == 200
|
||||
if not connected:
|
||||
error = f"Gitea 返回 {resp.status_code}"
|
||||
except Exception as e:
|
||||
error = str(e)
|
||||
|
||||
return {"enabled": enabled, "connected": connected, "repo_url": repo_url, "error": error}
|
||||
except Exception as e:
|
||||
return {"enabled": False, "connected": False, "repo_url": "", "error": str(e)}
|
||||
|
||||
@@ -112,6 +112,29 @@ async def get_task(
|
||||
return task
|
||||
|
||||
|
||||
@router.delete("/{task_id}")
|
||||
async def delete_task(
|
||||
task_id: str,
|
||||
current_user: dict = Depends(get_current_user),
|
||||
):
|
||||
"""Delete a single task by ID."""
|
||||
loop = asyncio.get_event_loop()
|
||||
deleted = await loop.run_in_executor(None, lambda: db_schema.delete_task(task_id))
|
||||
if not deleted:
|
||||
raise HTTPException(status_code=404, detail="任务不存在")
|
||||
return {"message": "已删除"}
|
||||
|
||||
|
||||
@router.delete("")
|
||||
async def clear_all_tasks(
|
||||
current_user: dict = Depends(get_current_user),
|
||||
):
|
||||
"""Clear all task history records."""
|
||||
loop = asyncio.get_event_loop()
|
||||
count = await loop.run_in_executor(None, db_schema.clear_task_history)
|
||||
return {"message": f"已清除 {count} 条记录", "count": count}
|
||||
|
||||
|
||||
@router.post("/{task_id}/retry")
|
||||
async def retry_task(
|
||||
task_id: str,
|
||||
|
||||
@@ -333,6 +333,28 @@ def query_task_stats() -> dict:
|
||||
conn.close()
|
||||
|
||||
|
||||
def delete_task(task_id: str) -> bool:
|
||||
"""Delete a single task by ID. Returns True if deleted."""
|
||||
conn = sqlite3.connect(_db_path)
|
||||
try:
|
||||
cur = conn.execute("DELETE FROM task_history WHERE id = ?", (task_id,))
|
||||
conn.commit()
|
||||
return cur.rowcount > 0
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def clear_task_history() -> int:
|
||||
"""Delete all task history records. Returns number of deleted rows."""
|
||||
conn = sqlite3.connect(_db_path)
|
||||
try:
|
||||
cur = conn.execute("DELETE FROM task_history")
|
||||
conn.commit()
|
||||
return cur.rowcount
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Query functions — File metadata
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -39,13 +39,22 @@
|
||||
v-for="(value, key) in config[activeTab]"
|
||||
:key="key"
|
||||
class="field-row"
|
||||
:class="{ edited: edited[activeTab]?.[key] !== undefined && edited[activeTab][key] !== value }"
|
||||
:class="{ edited: isEdited(activeTab, key, value) }"
|
||||
>
|
||||
<label class="field-label">
|
||||
{{ key }}
|
||||
<span v-if="edited[activeTab]?.[key] !== undefined && edited[activeTab][key] !== value" class="edited-dot"></span>
|
||||
<span v-if="isEdited(activeTab, key, value)" class="edited-dot"></span>
|
||||
</label>
|
||||
<el-input
|
||||
v-if="isSensitive(key)"
|
||||
:model-value="edited[activeTab]?.[key] ?? ''"
|
||||
@update:model-value="setEditedValue(activeTab, key, $event)"
|
||||
placeholder="已设置,留空保持不变"
|
||||
size="small"
|
||||
show-password
|
||||
/>
|
||||
<el-input
|
||||
v-else
|
||||
:model-value="getEditedValue(activeTab, key, value)"
|
||||
@update:model-value="setEditedValue(activeTab, key, $event)"
|
||||
size="small"
|
||||
@@ -80,6 +89,19 @@ const sectionLabels: Record<string, string> = {
|
||||
WebAuth: 'Web 认证',
|
||||
}
|
||||
|
||||
const SENSITIVE_KEYS = new Set(['api_key', 'secret_key', 'token', 'password', 'api_secret', 'access_key'])
|
||||
|
||||
function isSensitive(key: string): boolean {
|
||||
return SENSITIVE_KEYS.has(key.toLowerCase())
|
||||
}
|
||||
|
||||
function isEdited(section: string, key: string, original: string): boolean {
|
||||
const val = edited[section]?.[key]
|
||||
if (val === undefined) return false
|
||||
if (isSensitive(key)) return val !== ''
|
||||
return val !== original
|
||||
}
|
||||
|
||||
async function loadConfig() {
|
||||
loading.value = true
|
||||
try {
|
||||
@@ -109,6 +131,10 @@ async function saveAll() {
|
||||
const updates: { section: string; key: string; value: string }[] = []
|
||||
for (const [section, keys] of Object.entries(edited)) {
|
||||
for (const [key, value] of Object.entries(keys)) {
|
||||
// Skip empty sensitive fields (user left placeholder unchanged)
|
||||
if (isSensitive(key) && !value) continue
|
||||
// Skip masked values that somehow got through
|
||||
if (isSensitive(key) && value.includes('*')) continue
|
||||
updates.push({ section, key, value })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,6 +183,18 @@
|
||||
<span class="action-desc">处理Excel生成采购单</span>
|
||||
</div>
|
||||
</button>
|
||||
<button class="action-btn action-btn-danger" @click="clearAll" :disabled="processing">
|
||||
<div class="action-icon danger">
|
||||
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
|
||||
<polyline points="3,6 5,6 21,6"/>
|
||||
<path d="M19,6v14a2,2,0,0,1-2,2H7a2,2,0,0,1-2-2V6M8,6V4a2,2,0,0,1,2-2h4a2,2,0,0,1,2,2V6"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="action-info">
|
||||
<span class="action-name">清除全部</span>
|
||||
<span class="action-desc">删除所有文件和处理记录</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -192,7 +204,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, nextTick, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Refresh, Document, Grid } from '@element-plus/icons-vue'
|
||||
import { useProcessingStore } from '../stores/processing'
|
||||
import api from '../api'
|
||||
@@ -402,6 +414,33 @@ const runPipeline = () => doAction('/processing/pipeline')
|
||||
const runOcr = () => doAction('/processing/ocr-batch')
|
||||
const runExcel = () => doAction('/processing/excel')
|
||||
|
||||
async function clearAll(): Promise<void> {
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
'将删除 input、output、result 目录下所有文件,并清除全部处理记录。此操作不可撤销,是否继续?',
|
||||
'清除全部数据',
|
||||
{ type: 'warning', confirmButtonText: '确认清除', cancelButtonText: '取消' }
|
||||
)
|
||||
} catch { return }
|
||||
|
||||
processing.value = true
|
||||
try {
|
||||
await Promise.all([
|
||||
api.post('/files/clear/input'),
|
||||
api.post('/files/clear/output'),
|
||||
api.post('/files/clear/result'),
|
||||
api.delete('/tasks'),
|
||||
api.post('/files/relations/sync'),
|
||||
])
|
||||
ElMessage.success('已清除所有文件和处理记录')
|
||||
refreshStats()
|
||||
} catch (err: any) {
|
||||
ElMessage.error(err.response?.data?.detail || '清除失败')
|
||||
} finally {
|
||||
processing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-refresh stats when any task completes or fails
|
||||
watch(
|
||||
() => visibleTasks.value.map(t => t.status),
|
||||
@@ -674,6 +713,16 @@ onMounted(() => {
|
||||
color: #525252;
|
||||
}
|
||||
|
||||
.action-icon.danger {
|
||||
background: rgba(239,68,68,0.08);
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.action-btn-danger:hover:not(:disabled) {
|
||||
border-color: #fca5a5;
|
||||
background: #fef2f2;
|
||||
}
|
||||
|
||||
.action-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
@@ -46,10 +46,6 @@
|
||||
<el-icon><Timer /></el-icon>
|
||||
<template #title>任务历史</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/logs">
|
||||
<el-icon><Notebook /></el-icon>
|
||||
<template #title>日志中心</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/memory">
|
||||
<el-icon><Memo /></el-icon>
|
||||
<template #title>记忆库</template>
|
||||
@@ -177,10 +173,6 @@
|
||||
<el-icon><Timer /></el-icon>
|
||||
<template #title>任务历史</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/logs">
|
||||
<el-icon><Notebook /></el-icon>
|
||||
<template #title>日志中心</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="/memory">
|
||||
<el-icon><Memo /></el-icon>
|
||||
<template #title>记忆库</template>
|
||||
@@ -226,7 +218,7 @@ import { ref, computed, reactive, onMounted, onUnmounted, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||||
import {
|
||||
HomeFilled, Memo, Connection, Setting, Cloudy, Timer, Notebook, FolderOpened,
|
||||
HomeFilled, Memo, Connection, Setting, Cloudy, Timer, FolderOpened,
|
||||
ArrowDown, Lock, SwitchButton, DArrowLeft, DArrowRight, Menu as MenuIcon
|
||||
} from '@element-plus/icons-vue'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
@@ -303,7 +295,6 @@ const pageTitles: Record<string, string> = {
|
||||
'/files/tables': '表格处理',
|
||||
'/files/images': '图片处理',
|
||||
'/tasks': '任务历史',
|
||||
'/logs': '日志中心',
|
||||
'/memory': '记忆库',
|
||||
'/barcodes': '条码映射',
|
||||
'/config': '系统配置',
|
||||
|
||||
@@ -10,16 +10,24 @@
|
||||
<!-- Enabled state -->
|
||||
<div v-if="syncStatus.enabled" class="sync-enabled">
|
||||
<!-- Connection info -->
|
||||
<div class="connection-card">
|
||||
<div class="connection-card" :class="{ 'connection-error': !syncStatus.connected }">
|
||||
<div class="connection-icon">
|
||||
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="var(--success)" stroke-width="1.5">
|
||||
<svg v-if="syncStatus.connected" width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="var(--success)" stroke-width="1.5">
|
||||
<path d="M22 11.08V12a10 10 0 11-5.93-9.14"/>
|
||||
<polyline points="22 4 12 14.01 9 11.01"/>
|
||||
</svg>
|
||||
<svg v-else width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="var(--danger)" stroke-width="1.5">
|
||||
<circle cx="12" cy="12" r="10"/>
|
||||
<line x1="15" y1="9" x2="9" y2="15"/>
|
||||
<line x1="9" y1="9" x2="15" y2="15"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="connection-info">
|
||||
<span class="connection-status">已连接</span>
|
||||
<span class="connection-status" :class="{ 'status-error': !syncStatus.connected }">
|
||||
{{ syncStatus.connected ? '已连接' : '连接失败' }}
|
||||
</span>
|
||||
<span class="connection-url">{{ syncStatus.repo_url }}</span>
|
||||
<span v-if="syncStatus.error" class="connection-error-msg">{{ syncStatus.error }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -96,7 +104,7 @@ import api from '../api'
|
||||
const processingStore = useProcessingStore()
|
||||
|
||||
const syncing = ref(false)
|
||||
const syncStatus = ref({ enabled: false, repo_url: '' })
|
||||
const syncStatus = ref({ enabled: false, connected: false, repo_url: '', error: '' })
|
||||
|
||||
const currentTask = computed(() => {
|
||||
if (processingStore.taskSource === 'sync') return processingStore.currentTask
|
||||
@@ -214,6 +222,10 @@ onMounted(checkStatus)
|
||||
color: var(--success);
|
||||
}
|
||||
|
||||
.connection-status.status-error {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.connection-url {
|
||||
display: block;
|
||||
font-size: 13px;
|
||||
@@ -222,6 +234,18 @@ onMounted(checkStatus)
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.connection-error {
|
||||
background: rgba(239,68,68,0.05);
|
||||
border-color: rgba(239,68,68,0.15);
|
||||
}
|
||||
|
||||
.connection-error-msg {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
color: var(--danger);
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
/* ── Sync actions ── */
|
||||
.sync-actions {
|
||||
display: grid;
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
<template #prefix><el-icon><Search /></el-icon></template>
|
||||
</el-input>
|
||||
<el-button size="small" @click="loadData" :icon="Refresh">刷新</el-button>
|
||||
<el-button size="small" type="danger" @click="clearAllTasks">清除全部</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -88,10 +89,11 @@
|
||||
<span class="time-cell">{{ formatTime(row.created_at) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140" fixed="right">
|
||||
<el-table-column label="操作" width="180" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link size="small" @click="showDetail(row)">详情</el-button>
|
||||
<el-button v-if="row.status === 'failed'" type="warning" link size="small" @click="retryTask(row)">重试</el-button>
|
||||
<el-button type="danger" link size="small" @click="deleteTask(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@@ -137,7 +139,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted, onUnmounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Timer, CircleCheck, CircleClose, Loading, Search, Refresh } from '@element-plus/icons-vue'
|
||||
import api from '../api'
|
||||
import { useDebounce } from '../composables/useDebounce'
|
||||
@@ -214,6 +216,30 @@ async function copyPath(text: string) {
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteTask(row: any) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除任务 #${row.id}?`, '确认删除')
|
||||
await api.delete(`/tasks/${row.id}`)
|
||||
ElMessage.success('已删除')
|
||||
loadData()
|
||||
loadStats()
|
||||
} catch (err: any) {
|
||||
if (err !== 'cancel') ElMessage.error(err.response?.data?.detail || '删除失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function clearAllTasks() {
|
||||
try {
|
||||
await ElMessageBox.confirm('确定清除所有任务历史记录?此操作不可撤销。', '确认清除', { type: 'warning' })
|
||||
await api.delete('/tasks')
|
||||
ElMessage.success('已清除所有任务历史')
|
||||
loadData()
|
||||
loadStats()
|
||||
} catch (err: any) {
|
||||
if (err !== 'cancel') ElMessage.error(err.response?.data?.detail || '清除失败')
|
||||
}
|
||||
}
|
||||
|
||||
async function retryTask(row: any) {
|
||||
try {
|
||||
await api.post(`/tasks/${row.id}/retry`)
|
||||
|
||||
@@ -81,10 +81,11 @@
|
||||
<span class="time-text">{{ fmtTime(row.created_at) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="320" fixed="right">
|
||||
<el-table-column label="操作" width="370" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="previewFile(row)">预览</el-button>
|
||||
<el-button link type="primary" size="small" @click="showDetail(row)">详情</el-button>
|
||||
<el-button link type="primary" size="small" @click="downloadFile(row)">下载</el-button>
|
||||
<el-button link type="primary" size="small" @click="pipelineFile(row)">生成采购单</el-button>
|
||||
<el-button link type="primary" size="small" @click="ocrFile(row)">仅OCR</el-button>
|
||||
<el-button link type="danger" size="small" @click="deleteFile(row)">删除</el-button>
|
||||
|
||||
@@ -78,10 +78,11 @@
|
||||
<span class="time-text">{{ fmtTime(row.created_at) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="280" fixed="right">
|
||||
<el-table-column label="操作" width="320" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="primary" size="small" @click="previewFile(row)">预览</el-button>
|
||||
<el-button link type="primary" size="small" @click="showDetail(row)">详情</el-button>
|
||||
<el-button link type="primary" size="small" @click="downloadFile(row)">下载</el-button>
|
||||
<el-button link type="primary" size="small" @click="processFile(row)">处理</el-button>
|
||||
<el-button link type="danger" size="small" @click="deleteFile(row)">删除</el-button>
|
||||
</template>
|
||||
@@ -210,6 +211,15 @@ async function processFile(row: any) {
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadFile(row: any) {
|
||||
const token = localStorage.getItem('token')
|
||||
if (row.output_excel) {
|
||||
window.open(`/api/files/download/output/${encodeURIComponent(row.output_excel)}?token=${token}`, '_blank')
|
||||
} else if (row.result_purchase) {
|
||||
window.open(`/api/files/download/result/${encodeURIComponent(row.result_purchase)}?token=${token}`, '_blank')
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteFile(row: any) {
|
||||
try {
|
||||
await ElMessageBox.confirm(`确定删除 ${row.output_excel}?`, '确认')
|
||||
|
||||
Reference in New Issue
Block a user