feat: 新增 Vue 工具箱供对比
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>MarketGrid 工具箱</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/src/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+1752
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "marketgrid-web",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build",
|
||||
"preview": "vite preview --host 127.0.0.1 --port 5173 --strictPort"
|
||||
},
|
||||
"dependencies": {
|
||||
"naive-ui": "2.45.3",
|
||||
"vue": "3.5.44",
|
||||
"vue-router": "5.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "6.0.10",
|
||||
"vite": "8.3.4"
|
||||
}
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
<script setup>
|
||||
import { dateZhCN, zhCN } from 'naive-ui'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const names = new Set(['home', 'market', 'buildings', 'tasks', 'results'])
|
||||
const menuOptions = [
|
||||
{
|
||||
type: 'group',
|
||||
label: '工具',
|
||||
key: 'tools',
|
||||
children: [
|
||||
{ label: '工具箱首页', key: 'home' },
|
||||
{ label: '市场网格出图', key: 'market' },
|
||||
{ label: '楼宇数据查询', key: 'buildings' },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
label: '工作记录',
|
||||
key: 'records',
|
||||
children: [
|
||||
{ label: '任务中心', key: 'tasks' },
|
||||
{ label: '成果浏览', key: 'results' },
|
||||
],
|
||||
},
|
||||
]
|
||||
const themeOverrides = {
|
||||
common: {
|
||||
primaryColor: '#1F6F8B',
|
||||
primaryColorHover: '#2B86A4',
|
||||
primaryColorPressed: '#18596F',
|
||||
primaryColorSuppl: '#1F6F8B',
|
||||
borderRadius: '6px',
|
||||
fontSize: '13px',
|
||||
fontSizeMedium: '13px',
|
||||
heightMedium: '32px',
|
||||
fontFamily: '"Segoe UI", "Microsoft YaHei", sans-serif',
|
||||
},
|
||||
Form: {
|
||||
blankHeightMedium: '8px',
|
||||
feedbackHeightMedium: '14px',
|
||||
labelFontSizeLeftMedium: '13px',
|
||||
labelPaddingHorizontal: '0 8px 0 0',
|
||||
},
|
||||
Menu: {
|
||||
itemHeight: '34px',
|
||||
},
|
||||
}
|
||||
|
||||
function go(key) {
|
||||
if (names.has(key)) router.push({ name: key })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-config-provider :locale="zhCN" :date-locale="dateZhCN" :theme-overrides="themeOverrides">
|
||||
<n-layout has-sider class="shell">
|
||||
<n-layout-sider bordered :width="216" content-style="display:flex;flex-direction:column;">
|
||||
<div class="brand">
|
||||
<strong>MarketGrid</strong>
|
||||
<span>空间数据工具箱</span>
|
||||
</div>
|
||||
<n-menu :value="route.name" :options="menuOptions" :indent="16" @update:value="go" />
|
||||
</n-layout-sider>
|
||||
<div class="main-column">
|
||||
<header class="topbar">
|
||||
<h1>{{ route.meta.title }}</h1>
|
||||
<div id="page-actions"></div>
|
||||
</header>
|
||||
<div class="page-body">
|
||||
<router-view />
|
||||
</div>
|
||||
</div>
|
||||
</n-layout>
|
||||
</n-config-provider>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.shell { height: 100vh; overflow: hidden; }
|
||||
.main-column { flex: 1; min-width: 0; height: 100vh; display: flex; flex-direction: column; }
|
||||
.brand { padding: 12px 16px 2px; }
|
||||
.brand strong { display: block; font-size: 18px; }
|
||||
.brand span { display: block; margin-top: 2px; color: #66788a; font-size: 12px; }
|
||||
.topbar {
|
||||
flex: none;
|
||||
height: 48px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 0 16px;
|
||||
background: #fff;
|
||||
border-bottom: 1px solid #e4ebf1;
|
||||
z-index: 2;
|
||||
}
|
||||
.topbar h1 { margin: 0; font-size: 16px; font-weight: 600; }
|
||||
.page-body { flex: 1; min-height: 0; overflow: auto; padding: 12px 16px 16px; background: #f5f7f9; }
|
||||
</style>
|
||||
@@ -0,0 +1,75 @@
|
||||
export class ApiError extends Error {}
|
||||
|
||||
function errorMessage(data) {
|
||||
const detail = data && data.detail
|
||||
if (typeof detail === 'string' && detail) return detail
|
||||
if (Array.isArray(detail)) {
|
||||
const text = detail.map((item) => item.msg || '').filter(Boolean).join(';')
|
||||
if (text) return text
|
||||
}
|
||||
return '请求失败'
|
||||
}
|
||||
|
||||
export async function request(path, options = {}) {
|
||||
const headers = { ...(options.headers || {}) }
|
||||
if (options.body && !(options.body instanceof FormData) && !headers['Content-Type']) {
|
||||
headers['Content-Type'] = 'application/json'
|
||||
}
|
||||
let response
|
||||
try {
|
||||
response = await fetch(path, { ...options, headers })
|
||||
} catch {
|
||||
throw new ApiError('无法连接接口。请确认已运行 start-web。')
|
||||
}
|
||||
const text = await response.text()
|
||||
let data = null
|
||||
if (text) {
|
||||
try {
|
||||
data = JSON.parse(text)
|
||||
} catch {
|
||||
data = { detail: text }
|
||||
}
|
||||
}
|
||||
if (!response.ok) throw new ApiError(errorMessage(data))
|
||||
return data
|
||||
}
|
||||
|
||||
export function getJSON(path) {
|
||||
return request(path)
|
||||
}
|
||||
|
||||
export function postJSON(path, body) {
|
||||
return request(path, { method: 'POST', body: JSON.stringify(body) })
|
||||
}
|
||||
|
||||
export function del(path) {
|
||||
return request(path, { method: 'DELETE' })
|
||||
}
|
||||
|
||||
export function uploadFile(file) {
|
||||
const body = new FormData()
|
||||
body.append('file', file)
|
||||
return request('/api/imports', { method: 'POST', body })
|
||||
}
|
||||
|
||||
export function statFile(path) {
|
||||
return getJSON(`/api/files/stat?path=${encodeURIComponent(path)}`)
|
||||
}
|
||||
|
||||
export function downloadHref(taskId, name) {
|
||||
return `/api/results/${encodeURIComponent(taskId)}/files/${encodeURIComponent(name)}`
|
||||
}
|
||||
|
||||
export function formatTime(ts) {
|
||||
if (!ts) return ''
|
||||
const date = new Date(ts * 1000)
|
||||
const pad = (value) => String(value).padStart(2, '0')
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
|
||||
}
|
||||
|
||||
export function formatMb(bytes, digits = 2) {
|
||||
return `${(bytes / 1024 / 1024).toLocaleString('zh-CN', {
|
||||
minimumFractionDigits: digits,
|
||||
maximumFractionDigits: digits,
|
||||
})} MB`
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import { statFile, uploadFile, formatMb } from '../api'
|
||||
|
||||
const props = defineProps({
|
||||
label: { type: String, required: true },
|
||||
extension: { type: String, required: true },
|
||||
hint: { type: String, default: '' },
|
||||
modelValue: { type: String, default: '' },
|
||||
})
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
|
||||
const mode = ref('path')
|
||||
const savedPath = ref(props.modelValue || '')
|
||||
const status = ref('')
|
||||
const busy = ref(false)
|
||||
let ticket = 0
|
||||
let timer = 0
|
||||
|
||||
watch(() => props.modelValue, (value) => {
|
||||
if (mode.value === 'path' && value) savedPath.value = value
|
||||
clearTimeout(timer)
|
||||
timer = setTimeout(() => refresh(value), value ? 250 : 0)
|
||||
}, { immediate: true })
|
||||
|
||||
function setMode(next) {
|
||||
mode.value = next
|
||||
if (next === 'upload') emit('update:modelValue', '')
|
||||
else emit('update:modelValue', savedPath.value)
|
||||
}
|
||||
|
||||
async function refresh(path) {
|
||||
const current = ++ticket
|
||||
if (!path) {
|
||||
status.value = mode.value === 'upload' ? `请选择 .${props.extension} 文件` : '文件不存在'
|
||||
return
|
||||
}
|
||||
try {
|
||||
const info = await statFile(path)
|
||||
if (current !== ticket) return
|
||||
status.value = info.exists ? `已就绪 · ${formatMb(info.size, 1)}` : '文件不存在'
|
||||
} catch {
|
||||
if (current === ticket) status.value = '文件不存在'
|
||||
}
|
||||
}
|
||||
|
||||
async function customRequest({ file, onFinish, onError, onProgress }) {
|
||||
if (!file.file) {
|
||||
onError()
|
||||
return
|
||||
}
|
||||
busy.value = true
|
||||
status.value = '正在导入…'
|
||||
try {
|
||||
onProgress({ percent: 30 })
|
||||
const result = await uploadFile(file.file)
|
||||
savedPath.value = result.path
|
||||
emit('update:modelValue', result.path)
|
||||
onProgress({ percent: 100 })
|
||||
onFinish()
|
||||
} catch (error) {
|
||||
status.value = error.message || '导入失败'
|
||||
onError()
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="file-field panel">
|
||||
<div class="file-title">
|
||||
<n-tooltip v-if="hint">
|
||||
<template #trigger>
|
||||
<span class="hint">{{ label }}</span>
|
||||
</template>
|
||||
{{ hint }}
|
||||
</n-tooltip>
|
||||
<span v-else>{{ label }}</span>
|
||||
</div>
|
||||
<n-radio-group :value="mode" size="small" @update:value="setMode">
|
||||
<n-radio-button value="path">本地路径</n-radio-button>
|
||||
<n-radio-button value="upload">拖拽上传</n-radio-button>
|
||||
</n-radio-group>
|
||||
<n-input
|
||||
v-if="mode === 'path'"
|
||||
:value="modelValue"
|
||||
placeholder="文件路径"
|
||||
clearable
|
||||
@update:value="emit('update:modelValue', ($event || '').trim())"
|
||||
/>
|
||||
<n-upload
|
||||
v-else
|
||||
:accept="`.${extension}`"
|
||||
:max="1"
|
||||
:show-file-list="false"
|
||||
:custom-request="customRequest"
|
||||
:disabled="busy"
|
||||
>
|
||||
<n-button size="small" :loading="busy">选择 .{{ extension }} 文件</n-button>
|
||||
</n-upload>
|
||||
<p class="muted">{{ status }}</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.file-field { display: flex; flex-direction: column; gap: 8px; }
|
||||
.file-title { font-weight: 600; }
|
||||
.hint { border-bottom: 1px dashed #b7c2cc; cursor: help; }
|
||||
</style>
|
||||
@@ -0,0 +1,143 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { del, formatTime, getJSON, postJSON } from '../api'
|
||||
|
||||
const props = defineProps({
|
||||
task: { type: Object, required: true },
|
||||
logOpen: { type: Boolean, default: false },
|
||||
})
|
||||
const emit = defineEmits(['changed'])
|
||||
|
||||
const error = ref('')
|
||||
const confirming = ref(false)
|
||||
const removing = ref(false)
|
||||
const log = ref('')
|
||||
const logError = ref('')
|
||||
const expanded = ref(props.logOpen)
|
||||
let ticket = 0
|
||||
|
||||
const percent = computed(() => {
|
||||
if (!props.task.total) return 0
|
||||
return Math.min(100, Math.round((props.task.done || 0) / props.task.total * 100))
|
||||
})
|
||||
const countText = computed(() => {
|
||||
const counts = props.task.counts
|
||||
if (!counts || typeof counts !== 'object') return ''
|
||||
return Object.entries(counts).map(([key, value]) => `${key} ${value}`).join(',')
|
||||
})
|
||||
|
||||
watch(() => [props.task.message, props.task.done, props.task.status], () => {
|
||||
if (expanded.value) loadLog()
|
||||
})
|
||||
|
||||
function onExpand(names) {
|
||||
expanded.value = names.includes('log')
|
||||
if (expanded.value) loadLog()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (props.logOpen) loadLog()
|
||||
})
|
||||
|
||||
async function loadLog() {
|
||||
const current = ++ticket
|
||||
try {
|
||||
const data = await getJSON(`/api/tasks/${encodeURIComponent(props.task.id)}/log`)
|
||||
if (current === ticket) {
|
||||
log.value = data.text || ''
|
||||
logError.value = ''
|
||||
}
|
||||
} catch (reason) {
|
||||
if (current === ticket) logError.value = reason.message
|
||||
}
|
||||
}
|
||||
|
||||
async function stop() {
|
||||
error.value = ''
|
||||
try {
|
||||
await postJSON(`/api/tasks/${encodeURIComponent(props.task.id)}/stop`, {})
|
||||
emit('changed')
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
}
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
removing.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
await del(`/api/tasks/${encodeURIComponent(props.task.id)}`)
|
||||
confirming.value = false
|
||||
emit('changed')
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
} finally {
|
||||
removing.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<article class="task-card panel">
|
||||
<header>
|
||||
<strong>{{ task.kind_label }} · {{ task.status_label }}</strong>
|
||||
<span>{{ task.id }} · {{ formatTime(task.created) }}</span>
|
||||
</header>
|
||||
<p class="message">{{ task.message }}</p>
|
||||
<n-alert v-if="error" type="error">{{ error }}</n-alert>
|
||||
<n-progress v-if="task.total" type="line" :percentage="percent" :show-indicator="false" />
|
||||
<p v-if="task.total" class="muted">{{ task.done }} / {{ task.total }}</p>
|
||||
<p v-else-if="task.done" class="muted">已处理 {{ task.done }} 条</p>
|
||||
<p v-if="countText" class="muted">{{ countText }}</p>
|
||||
<n-alert v-if="task.active && task.stop_requested" type="info">正在停止,请稍候。</n-alert>
|
||||
<div class="actions">
|
||||
<n-button v-if="task.active && !task.stop_requested" size="small" @click="stop">停止任务</n-button>
|
||||
<n-button v-if="!task.active" size="small" @click="confirming = true">删除任务</n-button>
|
||||
</div>
|
||||
<p class="muted">成果目录:{{ task.output }}</p>
|
||||
<n-collapse :default-expanded-names="logOpen ? ['log'] : []" @update:expanded-names="onExpand">
|
||||
<n-collapse-item title="运行日志" name="log">
|
||||
<n-alert v-if="logError" type="error">{{ logError }}</n-alert>
|
||||
<div class="log-box"><pre>{{ log || '等待任务输出……' }}</pre></div>
|
||||
</n-collapse-item>
|
||||
</n-collapse>
|
||||
<n-modal
|
||||
v-model:show="confirming"
|
||||
preset="card"
|
||||
title="删除任务"
|
||||
style="width: 420px"
|
||||
:segmented="{ content: true, footer: 'soft' }"
|
||||
:content-style="{ maxHeight: '180px', overflow: 'auto' }"
|
||||
>
|
||||
<p>将删除该任务记录及其成果目录,不可恢复。</p>
|
||||
<template #footer>
|
||||
<n-space justify="end">
|
||||
<n-button @click="confirming = false">取消</n-button>
|
||||
<n-button type="primary" :loading="removing" @click="remove">确认删除</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-modal>
|
||||
</article>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.task-card { display: flex; flex-direction: column; gap: 6px; }
|
||||
header { display: flex; flex-direction: column; gap: 2px; }
|
||||
header span, .message { margin: 0; }
|
||||
.message { white-space: pre-wrap; }
|
||||
.actions { display: flex; gap: 8px; }
|
||||
.log-box {
|
||||
max-height: 180px;
|
||||
overflow: auto;
|
||||
background: #f7f9fb;
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
}
|
||||
pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
font-family: Consolas, "Microsoft YaHei", monospace;
|
||||
font-size: 12px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,24 @@
|
||||
import { createApp } from 'vue'
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import naive from 'naive-ui'
|
||||
import App from './App.vue'
|
||||
import './styles.css'
|
||||
import Home from './views/Home.vue'
|
||||
import Market from './views/Market.vue'
|
||||
import Buildings from './views/Buildings.vue'
|
||||
import Tasks from './views/Tasks.vue'
|
||||
import Results from './views/Results.vue'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{ path: '/', name: 'home', component: Home, meta: { title: '工具箱首页' } },
|
||||
{ path: '/market', name: 'market', component: Market, meta: { title: '市场网格出图' } },
|
||||
{ path: '/buildings', name: 'buildings', component: Buildings, meta: { title: '楼宇数据查询' } },
|
||||
{ path: '/tasks', name: 'tasks', component: Tasks, meta: { title: '任务中心' } },
|
||||
{ path: '/results', name: 'results', component: Results, meta: { title: '成果浏览' } },
|
||||
{ path: '/:pathMatch(.*)*', redirect: '/' },
|
||||
],
|
||||
})
|
||||
|
||||
createApp(App).use(router).use(naive).mount('#app')
|
||||
@@ -0,0 +1,64 @@
|
||||
html, body, #app {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
color: #1f2a33;
|
||||
background: #f5f7f9;
|
||||
font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
|
||||
}
|
||||
|
||||
.page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
max-width: 1120px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
margin: 4px 0 0;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.two-col,
|
||||
.three-col,
|
||||
.metrics {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.two-col { grid-template-columns: 1fr 1fr; }
|
||||
.three-col,
|
||||
.metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
|
||||
|
||||
.panel {
|
||||
border: 1px solid #e4ebf1;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
padding: 10px 12px;
|
||||
}
|
||||
|
||||
.muted {
|
||||
margin: 0;
|
||||
color: #66788a;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.scroll-box {
|
||||
max-height: 280px;
|
||||
overflow: auto;
|
||||
border: 1px solid #e4ebf1;
|
||||
border-radius: 6px;
|
||||
padding: 6px 10px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.two-col,
|
||||
.three-col,
|
||||
.metrics { grid-template-columns: 1fr; }
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<script setup>
|
||||
import { onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||
import FileField from '../components/FileField.vue'
|
||||
import TaskCard from '../components/TaskCard.vue'
|
||||
import { getJSON, postJSON } from '../api'
|
||||
|
||||
const draft = reactive({
|
||||
ready: false,
|
||||
path: '',
|
||||
extension: 'csv',
|
||||
url: '',
|
||||
cookies: '',
|
||||
referer: '',
|
||||
start: 1,
|
||||
limit: 1000,
|
||||
concurrency: 8,
|
||||
encoding: 'gbk',
|
||||
timeout: 30,
|
||||
retries: 2,
|
||||
interval: 0.2,
|
||||
lastTaskId: '',
|
||||
})
|
||||
const error = ref('')
|
||||
const success = ref('')
|
||||
const submitting = ref(false)
|
||||
const lastTask = ref(null)
|
||||
let pollTimer = 0
|
||||
const encodings = [
|
||||
{ label: 'gbk', value: 'gbk' },
|
||||
{ label: 'utf-8-sig', value: 'utf-8-sig' },
|
||||
]
|
||||
|
||||
async function ensureDefaults() {
|
||||
if (draft.ready) return
|
||||
const [catalog, connection] = await Promise.all([
|
||||
getJSON('/api/catalog'),
|
||||
getJSON('/api/connection'),
|
||||
])
|
||||
if (!draft.path) draft.path = catalog.building_csv.path
|
||||
draft.extension = catalog.building_csv.extension || 'csv'
|
||||
draft.url = connection.URL || ''
|
||||
draft.cookies = connection.COOKIES || ''
|
||||
draft.referer = connection.REFERER || ''
|
||||
draft.ready = true
|
||||
}
|
||||
|
||||
async function refreshTask() {
|
||||
if (!draft.lastTaskId) return
|
||||
try {
|
||||
lastTask.value = await getJSON(`/api/tasks/${encodeURIComponent(draft.lastTaskId)}`)
|
||||
} catch {
|
||||
// 轮询失败时保留上一帧。
|
||||
}
|
||||
}
|
||||
|
||||
function numbersReady() {
|
||||
return [draft.start, draft.limit, draft.concurrency, draft.timeout, draft.retries, draft.interval]
|
||||
.every((value) => typeof value === 'number')
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
error.value = ''
|
||||
success.value = ''
|
||||
if (!draft.path) {
|
||||
error.value = '请先导入楼宇轮廓文件。'
|
||||
return
|
||||
}
|
||||
if (!numbersReady()) {
|
||||
error.value = '请填写完整参数。'
|
||||
return
|
||||
}
|
||||
const url = draft.url.trim()
|
||||
const cookies = draft.cookies.trim()
|
||||
const urlOk = url.startsWith('http://') || url.startsWith('https://')
|
||||
if ((url || cookies) && (!urlOk || !cookies)) {
|
||||
error.value = '服务地址和登录信息需同时填写,且地址以 http(s):// 开头。'
|
||||
return
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
const result = await postJSON('/api/tasks', {
|
||||
kind: 'buildings',
|
||||
params: {
|
||||
INPUT_CSV: draft.path,
|
||||
INPUT_ENCODING: draft.encoding,
|
||||
START_ROW: draft.start,
|
||||
LIMIT: draft.limit || null,
|
||||
CONCURRENCY: draft.concurrency,
|
||||
TIMEOUT: draft.timeout,
|
||||
MAX_RETRIES: draft.retries,
|
||||
REQUEST_INTERVAL: draft.interval,
|
||||
},
|
||||
credentials: { URL: url, COOKIES: cookies, REFERER: draft.referer.trim() },
|
||||
})
|
||||
draft.lastTaskId = result.id
|
||||
success.value = '任务已启动,可在任务中心查看进度。'
|
||||
await refreshTask()
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await ensureDefaults()
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
}
|
||||
await refreshTask()
|
||||
pollTimer = setInterval(refreshTask, 2000)
|
||||
})
|
||||
|
||||
onUnmounted(() => clearInterval(pollTimer))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<teleport to="#page-actions">
|
||||
<n-button type="primary" :loading="submitting" :disabled="!draft.ready" @click="submit">开始查询</n-button>
|
||||
</teleport>
|
||||
<p class="muted">按楼宇轮廓(WKT)查询:先计算落在轮廓内部的点,再按该点查询。</p>
|
||||
<n-alert v-if="error" type="error">{{ error }}</n-alert>
|
||||
<n-alert v-if="success" type="success">{{ success }}</n-alert>
|
||||
<FileField v-model="draft.path" label="楼宇轮廓清单" :extension="draft.extension" hint="默认 source/NRBuildPolygon.csv" />
|
||||
<n-form label-placement="left" label-width="168" @submit.prevent="submit">
|
||||
<n-form-item label-placement="top">
|
||||
<template #label>
|
||||
<n-tooltip>
|
||||
<template #trigger><span class="tip">连接信息</span></template>
|
||||
默认显示脚本内配置或上次保存值。开始查询时写入本机,不进入任务记录。
|
||||
</n-tooltip>
|
||||
</template>
|
||||
<div class="stack">
|
||||
<n-form-item label="服务地址" :show-feedback="false">
|
||||
<n-input v-model:value="draft.url" clearable placeholder="https://...wfs?..." />
|
||||
</n-form-item>
|
||||
<n-form-item label="登录信息(Cookies)" :show-feedback="false">
|
||||
<n-input v-model:value="draft.cookies" type="password" show-password-on="click" clearable placeholder="CASTGC=..." />
|
||||
</n-form-item>
|
||||
<n-form-item label="来源页(可留空)" :show-feedback="false">
|
||||
<n-input v-model:value="draft.referer" clearable placeholder="可留空" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</n-form-item>
|
||||
<div class="three-col">
|
||||
<n-form-item label="起始行">
|
||||
<n-input-number v-model:value="draft.start" :min="1" :precision="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<template #label>
|
||||
<n-tooltip><template #trigger><span class="tip">查询数量</span></template>0 表示全部</n-tooltip>
|
||||
</template>
|
||||
<n-input-number v-model:value="draft.limit" :min="0" :precision="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="并发数">
|
||||
<n-input-number v-model:value="draft.concurrency" :min="1" :max="32" :precision="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
<n-form-item>
|
||||
<template #label>
|
||||
<n-tooltip>
|
||||
<template #trigger><span class="tip">文件编码</span></template>
|
||||
按内容自动识别,识别不出时按此项
|
||||
</n-tooltip>
|
||||
</template>
|
||||
<n-select v-model:value="draft.encoding" :options="encodings" />
|
||||
</n-form-item>
|
||||
<n-collapse>
|
||||
<n-collapse-item title="高级参数" name="advanced">
|
||||
<div class="three-col">
|
||||
<n-form-item label="超时(秒)">
|
||||
<n-input-number v-model:value="draft.timeout" :min="1" :max="300" :precision="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="失败重试">
|
||||
<n-input-number v-model:value="draft.retries" :min="0" :max="10" :precision="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="请求间隔(秒)">
|
||||
<n-input-number v-model:value="draft.interval" :min="0" :max="60" :step="0.1" style="width: 100%" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</n-collapse-item>
|
||||
</n-collapse>
|
||||
</n-form>
|
||||
<TaskCard v-if="lastTask" :task="lastTask" log-open @changed="refreshTask" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.stack { display: flex; flex-direction: column; gap: 8px; width: 100%; }
|
||||
.tip { border-bottom: 1px dashed #b7c2cc; cursor: help; }
|
||||
</style>
|
||||
@@ -0,0 +1,75 @@
|
||||
<script setup>
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { getJSON } from '../api'
|
||||
|
||||
const router = useRouter()
|
||||
const error = ref('')
|
||||
const loading = ref(false)
|
||||
const home = ref({ running: 0, tasks: 0, archives: 0, sources: [] })
|
||||
const columns = [
|
||||
{ title: '数据源', key: 'label', width: 140 },
|
||||
{ title: '状态', key: 'status', width: 90 },
|
||||
{ title: '文件', key: 'file', ellipsis: { tooltip: true } },
|
||||
{ title: '大小 MB', key: 'size_mb', width: 100 },
|
||||
]
|
||||
|
||||
async function load() {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
home.value = await getJSON('/api/home')
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<teleport to="#page-actions">
|
||||
<n-button :loading="loading" @click="load">刷新</n-button>
|
||||
</teleport>
|
||||
<n-alert type="info">
|
||||
这是供对比的 Vue 界面,Streamlit 仍从 start-ui.cmd 进入。几何编辑和规则引擎是后续能力,当前未提供。
|
||||
</n-alert>
|
||||
<n-alert v-if="error" type="error">{{ error }}</n-alert>
|
||||
<div class="metrics">
|
||||
<div class="panel metric"><span>正在运行</span><strong>{{ home.running }}</strong></div>
|
||||
<div class="panel metric"><span>任务记录</span><strong>{{ home.tasks }}</strong></div>
|
||||
<div class="panel metric"><span>成果包</span><strong>{{ home.archives }}</strong></div>
|
||||
</div>
|
||||
<h2 class="section-title">选择工具</h2>
|
||||
<div class="two-col">
|
||||
<div class="panel tool">
|
||||
<strong>市场网格出图</strong>
|
||||
<p class="muted">按市场生成信号图和成果包。</p>
|
||||
<n-button type="primary" @click="router.push({ name: 'market' })">开始出图</n-button>
|
||||
</div>
|
||||
<div class="panel tool">
|
||||
<strong>楼宇数据查询</strong>
|
||||
<p class="muted">按坐标批量查询楼宇信息。</p>
|
||||
<n-button type="primary" @click="router.push({ name: 'buildings' })">开始查询</n-button>
|
||||
</div>
|
||||
</div>
|
||||
<h2 class="section-title">默认数据源</h2>
|
||||
<n-data-table
|
||||
size="small"
|
||||
:columns="columns"
|
||||
:data="home.sources"
|
||||
:bordered="true"
|
||||
:max-height="320"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.tool { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
|
||||
.metric { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
|
||||
.metric span { color: #66788a; }
|
||||
.metric strong { font-size: 22px; line-height: 1; }
|
||||
</style>
|
||||
@@ -0,0 +1,252 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, onUnmounted, reactive, ref, watch } from 'vue'
|
||||
import FileField from '../components/FileField.vue'
|
||||
import TaskCard from '../components/TaskCard.vue'
|
||||
import { getJSON, postJSON } from '../api'
|
||||
|
||||
const hints = {
|
||||
MARKET_GPKG: '市场边界,默认 source/GridMap.gpkg',
|
||||
GRID_5G_GPKG: '大文件请填本地路径,不要上传',
|
||||
BUILDING_INFO_GPKG: '建筑信息',
|
||||
AOI_CSV: 'AOI 报表',
|
||||
GIS_PROJECT_SOURCE: 'QGIS 工程模板',
|
||||
NR_BUILDINGS_DATA_CSV: '楼宇查询结果。开始生成时如有需要会整理边界图层',
|
||||
}
|
||||
const draft = reactive({
|
||||
ready: false,
|
||||
paths: {},
|
||||
allMarkets: true,
|
||||
chosen: [],
|
||||
maxWorkers: 4,
|
||||
scale: 5,
|
||||
summary: true,
|
||||
maxRaster: 25,
|
||||
summaryRaster: 100,
|
||||
clipMode: 'intersects',
|
||||
padding: 0.05,
|
||||
lastTaskId: '',
|
||||
})
|
||||
const sources = ref([])
|
||||
const nr = ref(null)
|
||||
const options = ref([])
|
||||
const marketError = ref('')
|
||||
const error = ref('')
|
||||
const success = ref('')
|
||||
const submitting = ref(false)
|
||||
const loadingMarkets = ref(false)
|
||||
const lastTask = ref(null)
|
||||
let marketTicket = 0
|
||||
let marketTimer = 0
|
||||
let pollTimer = 0
|
||||
|
||||
const fileItems = computed(() => {
|
||||
const items = sources.value.map((item) => ({ ...item, hint: hints[item.key] || '' }))
|
||||
if (nr.value) items.push({ ...nr.value, hint: hints[nr.value.key] || '' })
|
||||
return items
|
||||
})
|
||||
const canStart = computed(() => draft.ready && options.value.length > 0 && !submitting.value)
|
||||
const clipOptions = [
|
||||
{ label: '与市场相交', value: 'intersects' },
|
||||
{ label: '中心点在市场内', value: 'center' },
|
||||
]
|
||||
|
||||
async function ensureCatalog() {
|
||||
const data = await getJSON('/api/catalog')
|
||||
sources.value = data.sources
|
||||
nr.value = data.nr_csv
|
||||
if (!draft.ready) {
|
||||
for (const item of data.sources) draft.paths[item.key] = item.path
|
||||
draft.paths[data.nr_csv.key] = data.nr_csv.path
|
||||
draft.ready = true
|
||||
}
|
||||
}
|
||||
|
||||
async function loadMarkets(path) {
|
||||
const current = ++marketTicket
|
||||
loadingMarkets.value = true
|
||||
try {
|
||||
if (!path) {
|
||||
options.value = []
|
||||
marketError.value = '请先导入可用的市场边界。'
|
||||
return
|
||||
}
|
||||
const data = await getJSON(`/api/markets?path=${encodeURIComponent(path)}`)
|
||||
if (current !== marketTicket) return
|
||||
options.value = data.options || []
|
||||
draft.chosen = draft.chosen.filter((id) => options.value.some((item) => item.id === id))
|
||||
marketError.value = options.value.length ? '' : '请先导入可用的市场边界。'
|
||||
} catch (reason) {
|
||||
if (current !== marketTicket) return
|
||||
options.value = []
|
||||
marketError.value = reason.message
|
||||
} finally {
|
||||
if (current === marketTicket) loadingMarkets.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshTask() {
|
||||
if (!draft.lastTaskId) return
|
||||
try {
|
||||
lastTask.value = await getJSON(`/api/tasks/${encodeURIComponent(draft.lastTaskId)}`)
|
||||
} catch {
|
||||
// 轮询失败时保留上一帧。
|
||||
}
|
||||
}
|
||||
|
||||
function numbersReady() {
|
||||
return [draft.maxWorkers, draft.scale, draft.maxRaster, draft.summaryRaster, draft.padding]
|
||||
.every((value) => typeof value === 'number')
|
||||
}
|
||||
|
||||
async function submit() {
|
||||
error.value = ''
|
||||
success.value = ''
|
||||
if (!canStart.value) return
|
||||
if (!numbersReady()) {
|
||||
error.value = '请填写完整参数。'
|
||||
return
|
||||
}
|
||||
const ids = draft.allMarkets ? options.value.map((item) => item.id) : [...draft.chosen]
|
||||
if (!ids.length) {
|
||||
error.value = '请至少选择一个市场网格。'
|
||||
return
|
||||
}
|
||||
for (const item of fileItems.value) {
|
||||
if (!draft.paths[item.key]) {
|
||||
error.value = '请完成所需数据的导入。'
|
||||
return
|
||||
}
|
||||
}
|
||||
submitting.value = true
|
||||
try {
|
||||
const result = await postJSON('/api/tasks', {
|
||||
kind: 'market',
|
||||
params: {
|
||||
...draft.paths,
|
||||
SELECTED_MARKET_IDS: ids,
|
||||
MAX_WORKERS: draft.maxWorkers,
|
||||
SCALE: draft.scale,
|
||||
SUMMARY_OUTPUT_ENABLED: draft.summary,
|
||||
MAX_RASTER_PIXELS: Math.round(draft.maxRaster * 1_000_000),
|
||||
SUMMARY_MAX_RASTER_PIXELS: Math.round(draft.summaryRaster * 1_000_000),
|
||||
CLIP_MODE: draft.clipMode,
|
||||
PROJECT_EXTENT_PADDING_RATIO: draft.padding,
|
||||
},
|
||||
})
|
||||
draft.lastTaskId = result.id
|
||||
success.value = '任务已启动,可在任务中心查看进度。'
|
||||
await refreshTask()
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => draft.paths.MARKET_GPKG, (path) => {
|
||||
clearTimeout(marketTimer)
|
||||
marketTimer = setTimeout(() => loadMarkets(path), 300)
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await ensureCatalog()
|
||||
await loadMarkets(draft.paths.MARKET_GPKG)
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
}
|
||||
await refreshTask()
|
||||
pollTimer = setInterval(refreshTask, 2000)
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
clearInterval(pollTimer)
|
||||
clearTimeout(marketTimer)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<teleport to="#page-actions">
|
||||
<n-button type="primary" :disabled="!canStart" :loading="submitting" @click="submit">开始生成</n-button>
|
||||
</teleport>
|
||||
<n-alert v-if="error" type="error">{{ error }}</n-alert>
|
||||
<n-alert v-if="success" type="success">{{ success }}</n-alert>
|
||||
<h2 class="section-title">1 · 导入数据</h2>
|
||||
<div class="two-col">
|
||||
<FileField
|
||||
v-for="item in fileItems"
|
||||
:key="item.key"
|
||||
v-model="draft.paths[item.key]"
|
||||
:label="item.label"
|
||||
:extension="item.extension"
|
||||
:hint="item.hint"
|
||||
/>
|
||||
</div>
|
||||
<h2 class="section-title">2 · 选择市场与参数</h2>
|
||||
<n-alert v-if="marketError" type="warning">{{ marketError }}</n-alert>
|
||||
<n-spin :show="loadingMarkets" size="small">
|
||||
<div class="panel market-box">
|
||||
<n-tooltip>
|
||||
<template #trigger>
|
||||
<n-checkbox v-model:checked="draft.allMarkets" :disabled="!options.length">处理全部市场</n-checkbox>
|
||||
</template>
|
||||
取消后可在下方指定市场
|
||||
</n-tooltip>
|
||||
<div v-if="options.length && !draft.allMarkets" class="scroll-box">
|
||||
<n-checkbox-group v-model:value="draft.chosen">
|
||||
<div v-for="item in options" :key="item.id" class="pick">
|
||||
<n-checkbox :value="item.id" :label="`${item.id} · ${item.name}`" />
|
||||
</div>
|
||||
</n-checkbox-group>
|
||||
</div>
|
||||
<p v-else-if="options.length" class="muted">将处理全部 {{ options.length }} 个市场</p>
|
||||
<p v-else class="muted">请先导入可用的市场边界。</p>
|
||||
</div>
|
||||
</n-spin>
|
||||
<n-form label-placement="left" label-width="176" @submit.prevent="submit">
|
||||
<div class="three-col">
|
||||
<n-form-item>
|
||||
<template #label>
|
||||
<n-tooltip><template #trigger><span class="tip">并行进程数</span></template>1 到 16,默认 4</n-tooltip>
|
||||
</template>
|
||||
<n-input-number v-model:value="draft.maxWorkers" :min="1" :max="16" :precision="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item>
|
||||
<template #label>
|
||||
<n-tooltip><template #trigger><span class="tip">分辨率倍数</span></template>放大查看更清晰,默认 5</n-tooltip>
|
||||
</template>
|
||||
<n-input-number v-model:value="draft.scale" :min="0.1" :max="20" :step="0.5" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="全量汇总包">
|
||||
<n-checkbox v-model:checked="draft.summary">生成全量汇总包</n-checkbox>
|
||||
</n-form-item>
|
||||
</div>
|
||||
<n-collapse>
|
||||
<n-collapse-item title="更多参数" name="more">
|
||||
<div class="two-col">
|
||||
<n-form-item label="单市场像元上限(百万)">
|
||||
<n-input-number v-model:value="draft.maxRaster" :min="1" :max="100" :precision="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="汇总像元上限(百万)">
|
||||
<n-input-number v-model:value="draft.summaryRaster" :min="1" :max="200" :precision="0" style="width: 100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="网格纳入方式">
|
||||
<n-select v-model:value="draft.clipMode" :options="clipOptions" />
|
||||
</n-form-item>
|
||||
<n-form-item label="地图留白比例">
|
||||
<n-input-number v-model:value="draft.padding" :min="0" :max="1" :step="0.01" style="width: 100%" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
</n-collapse-item>
|
||||
</n-collapse>
|
||||
</n-form>
|
||||
<TaskCard v-if="lastTask" :task="lastTask" log-open @changed="refreshTask" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.market-box { display: flex; flex-direction: column; gap: 8px; }
|
||||
.pick { padding: 2px 0; }
|
||||
.tip { border-bottom: 1px dashed #b7c2cc; cursor: help; }
|
||||
</style>
|
||||
@@ -0,0 +1,124 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { downloadHref, formatMb, getJSON, postJSON } from '../api'
|
||||
|
||||
const tasks = ref([])
|
||||
const selectedId = ref(null)
|
||||
const directory = ref('')
|
||||
const files = ref([])
|
||||
const error = ref('')
|
||||
const notice = ref('')
|
||||
const opening = ref(false)
|
||||
|
||||
const options = computed(() => tasks.value.map((task) => ({ label: task.label, value: task.id })))
|
||||
|
||||
async function loadTasks() {
|
||||
error.value = ''
|
||||
try {
|
||||
const data = await getJSON('/api/results')
|
||||
tasks.value = data.tasks || []
|
||||
if (!tasks.value.length) {
|
||||
selectedId.value = null
|
||||
files.value = []
|
||||
directory.value = ''
|
||||
return
|
||||
}
|
||||
if (!tasks.value.some((task) => task.id === selectedId.value)) selectedId.value = tasks.value[0].id
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFiles(id) {
|
||||
notice.value = ''
|
||||
if (!id) {
|
||||
files.value = []
|
||||
directory.value = ''
|
||||
return
|
||||
}
|
||||
try {
|
||||
const data = await getJSON(`/api/results/${encodeURIComponent(id)}/files`)
|
||||
directory.value = data.directory || ''
|
||||
files.value = data.files || []
|
||||
error.value = ''
|
||||
} catch (reason) {
|
||||
files.value = []
|
||||
error.value = reason.message
|
||||
}
|
||||
}
|
||||
|
||||
async function openDirectory() {
|
||||
if (!selectedId.value) return
|
||||
opening.value = true
|
||||
notice.value = ''
|
||||
try {
|
||||
await postJSON(`/api/results/${encodeURIComponent(selectedId.value)}/open`, {})
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
} finally {
|
||||
opening.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function showLarge(file) {
|
||||
notice.value = `${file.name}(${formatMb(file.size)})较大,请从本地目录复制:${directory.value}`
|
||||
}
|
||||
|
||||
watch(selectedId, loadFiles)
|
||||
onMounted(loadTasks)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<teleport to="#page-actions">
|
||||
<n-button :disabled="!selectedId" :loading="opening" @click="openDirectory">打开目录</n-button>
|
||||
</teleport>
|
||||
<n-alert v-if="error" type="error">{{ error }}</n-alert>
|
||||
<n-alert v-if="notice" type="info">{{ notice }}</n-alert>
|
||||
<n-empty v-if="!tasks.length" description="暂无成果。完成出图或查询后会显示在这里。" />
|
||||
<template v-else>
|
||||
<n-form label-placement="left" label-width="88">
|
||||
<n-form-item label="成果清单">
|
||||
<n-select v-model:value="selectedId" :options="options" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
<p class="muted">{{ directory }}</p>
|
||||
<n-empty v-if="!files.length" description="该任务暂无文件。" />
|
||||
<div v-else class="file-list">
|
||||
<div v-for="file in files" :key="file.name" class="file-row">
|
||||
<span class="file-name" :title="file.name">{{ file.name }}</span>
|
||||
<span class="muted size">{{ formatMb(file.size) }}</span>
|
||||
<a v-if="!file.too_large" class="download" :href="downloadHref(selectedId, file.name)" :download="file.name">下载</a>
|
||||
<n-button v-else text type="primary" @click="showLarge(file)">从本地目录复制</n-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.file-list {
|
||||
max-height: 420px;
|
||||
overflow: auto;
|
||||
border: 1px solid #e4ebf1;
|
||||
border-radius: 8px;
|
||||
background: #fff;
|
||||
}
|
||||
.file-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) 110px 128px;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
padding: 7px 10px;
|
||||
border-bottom: 1px solid #f0f3f6;
|
||||
}
|
||||
.file-row:last-child { border-bottom: 0; }
|
||||
.file-name {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-family: Consolas, "Microsoft YaHei", monospace;
|
||||
}
|
||||
.size { text-align: right; }
|
||||
.download { justify-self: end; color: #1f6f8b; }
|
||||
</style>
|
||||
@@ -0,0 +1,86 @@
|
||||
<script setup>
|
||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||
import TaskCard from '../components/TaskCard.vue'
|
||||
import { getJSON, postJSON } from '../api'
|
||||
|
||||
const tasks = ref([])
|
||||
const error = ref('')
|
||||
const success = ref('')
|
||||
const confirming = ref(false)
|
||||
const clearing = ref(false)
|
||||
let pollTimer = 0
|
||||
|
||||
const finishedCount = computed(() => tasks.value.filter((task) => !task.active).length)
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const data = await getJSON('/api/tasks')
|
||||
tasks.value = data.tasks || []
|
||||
error.value = ''
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
}
|
||||
}
|
||||
|
||||
async function clearAll() {
|
||||
clearing.value = true
|
||||
error.value = ''
|
||||
try {
|
||||
const result = await postJSON('/api/tasks/clear', {})
|
||||
success.value = result.message
|
||||
confirming.value = false
|
||||
await load()
|
||||
} catch (reason) {
|
||||
error.value = reason.message
|
||||
} finally {
|
||||
clearing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
load()
|
||||
pollTimer = setInterval(load, 2000)
|
||||
})
|
||||
onUnmounted(() => clearInterval(pollTimer))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="page">
|
||||
<teleport to="#page-actions">
|
||||
<n-button :disabled="!finishedCount || confirming" @click="confirming = true">清空全部任务</n-button>
|
||||
</teleport>
|
||||
<n-alert v-if="error" type="error">{{ error }}</n-alert>
|
||||
<n-alert v-if="success" type="success">{{ success }}</n-alert>
|
||||
<n-empty v-if="!tasks.length" description="暂无任务。" />
|
||||
<div v-else class="task-list">
|
||||
<TaskCard v-for="task in tasks" :key="task.id" :task="task" @changed="load" />
|
||||
</div>
|
||||
<n-modal
|
||||
v-model:show="confirming"
|
||||
preset="card"
|
||||
title="清空全部任务"
|
||||
style="width: 440px"
|
||||
:segmented="{ content: true, footer: 'soft' }"
|
||||
:content-style="{ maxHeight: '200px', overflow: 'auto' }"
|
||||
>
|
||||
<p>将删除 {{ finishedCount }} 个已结束任务的记录和成果目录,不可恢复。运行中的任务不会删除。</p>
|
||||
<template #footer>
|
||||
<n-space justify="end">
|
||||
<n-button @click="confirming = false">取消</n-button>
|
||||
<n-button type="primary" :loading="clearing" @click="clearAll">确认清空</n-button>
|
||||
</n-space>
|
||||
</template>
|
||||
</n-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.task-list {
|
||||
max-height: calc(100vh - 150px);
|
||||
overflow: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding-right: 2px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,22 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue()],
|
||||
server: {
|
||||
host: '127.0.0.1',
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: 'http://127.0.0.1:8765',
|
||||
changeOrigin: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
preview: {
|
||||
host: '127.0.0.1',
|
||||
port: 5173,
|
||||
strictPort: true,
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user