|
|
@@ -1,6 +1,17 @@
|
|
|
<template>
|
|
|
<!-- 保持模板结构不变 -->
|
|
|
<div>
|
|
|
+ <el-row>
|
|
|
+ <el-tooltip content="测试模式不会直接运行程序,只会输出日志信息">
|
|
|
+ <el-switch
|
|
|
+ v-model="dryRun"
|
|
|
+ size="large"
|
|
|
+ active-text="测试模式"
|
|
|
+ inactive-text="工作模式"
|
|
|
+ />
|
|
|
+ </el-tooltip>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
<el-row :gutter="16" justify="center">
|
|
|
<el-col :span="8">
|
|
|
<el-card shadow="hover">
|
|
|
@@ -38,12 +49,6 @@
|
|
|
>
|
|
|
提交单个搜索任务
|
|
|
</el-button>
|
|
|
- <el-button
|
|
|
- :disabled="!workerStatus.search || loadingStates.search"
|
|
|
- @click="sendRequest('search', 'submit', true)"
|
|
|
- >
|
|
|
- 仅测试
|
|
|
- </el-button>
|
|
|
</el-row>
|
|
|
</el-space>
|
|
|
</el-card>
|
|
|
@@ -89,7 +94,7 @@ import { ref, computed, onMounted, onUnmounted } from 'vue'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import { useProxyStore } from '../stores/proxyStore'
|
|
|
|
|
|
-const backendBaseUrl = import.meta.env.VITE_API_BASE_URL || ''
|
|
|
+const backendBaseUrl = (import.meta as any).env.VITE_API_BASE_URL || ''
|
|
|
const store = useProxyStore()
|
|
|
const workers = ref<Array<any>>([])
|
|
|
const keywordInput = ref('')
|
|
|
@@ -103,6 +108,7 @@ const loadingStates = ref({
|
|
|
crawl: false,
|
|
|
convert: false
|
|
|
})
|
|
|
+const dryRun = ref(false)
|
|
|
let pollTimer: number | null = null
|
|
|
|
|
|
const workerStatus = computed(() => {
|
|
|
@@ -161,7 +167,7 @@ function stopPolling() {
|
|
|
onMounted(() => startPolling())
|
|
|
onUnmounted(() => stopPolling())
|
|
|
|
|
|
-const sendRequest = async (workerName: string, action: string, dryRun: boolean = false) => {
|
|
|
+const sendRequest = async (workerName: string, action: string) => {
|
|
|
const loadingKey = workerName as keyof typeof loadingStates.value
|
|
|
loadingStates.value[loadingKey] = true
|
|
|
|
|
|
@@ -176,15 +182,15 @@ const sendRequest = async (workerName: string, action: string, dryRun: boolean =
|
|
|
action: action,
|
|
|
select_proxy: store.selectedProxy,
|
|
|
data: {
|
|
|
- ...(workerName === 'search' && keywordInput.value ? {
|
|
|
- keyword: keywordInput.value.trim(),
|
|
|
+ ...(workerName === 'search' ? {
|
|
|
+ keyword: keywordInput.value.trim() || '',
|
|
|
config: {
|
|
|
max_result_items: 200,
|
|
|
skip_existing: true,
|
|
|
browser_config: {},
|
|
|
- dry_run: dryRun
|
|
|
+ dry_run: dryRun.value
|
|
|
}
|
|
|
- } : {}),
|
|
|
+ }: {}),
|
|
|
...(workerName === 'crawl' ? {
|
|
|
overwrite: false,
|
|
|
proxy_pool_url: store.selectedProxy
|
|
|
@@ -204,9 +210,46 @@ const sendRequest = async (workerName: string, action: string, dryRun: boolean =
|
|
|
|
|
|
// 直接刷新状态而不是尝试局部更新
|
|
|
await fetchWorkerStatus()
|
|
|
- ElMessage.success(`${action === 'start' ? '启动' : '停止'}${workerName}成功`)
|
|
|
+ // 操作类型中文映射
|
|
|
+ const actionMap: Record<string, string> = {
|
|
|
+ start: '启动',
|
|
|
+ stop: '停止',
|
|
|
+ submit_all: '提交所有任务',
|
|
|
+ clean: '清空任务',
|
|
|
+ submit: '提交搜索'
|
|
|
+ }
|
|
|
+
|
|
|
+ // 模块名称中文映射
|
|
|
+ const workerNameMap: Record<string, string> = {
|
|
|
+ search: '浏览器搜索',
|
|
|
+ crawl: '提取结果页',
|
|
|
+ convert: '文档转换'
|
|
|
+ }
|
|
|
+
|
|
|
+ const actionName = actionMap[action] || '操作'
|
|
|
+ const moduleName = workerNameMap[workerName] || '任务'
|
|
|
+
|
|
|
+ ElMessage.success(`${actionName}${moduleName}成功`)
|
|
|
} catch (error) {
|
|
|
- ElMessage.error(`操作失败: ${error instanceof Error ? error.message : '未知错误'}`)
|
|
|
+ // 错误提示中文映射
|
|
|
+ const errorActionMap: Record<string, string> = {
|
|
|
+ start: '启动',
|
|
|
+ stop: '停止',
|
|
|
+ submit_all: '提交所有',
|
|
|
+ clean: '清空',
|
|
|
+ submit: '提交'
|
|
|
+ }
|
|
|
+
|
|
|
+ const errorModuleMap: Record<string, string> = {
|
|
|
+ search: '搜索任务',
|
|
|
+ crawl: '提取任务',
|
|
|
+ convert: '转换任务'
|
|
|
+ }
|
|
|
+
|
|
|
+ const actionName = errorActionMap[action] || '操作'
|
|
|
+ const moduleName = errorModuleMap[workerName] || '任务'
|
|
|
+
|
|
|
+ ElMessage.error(`${actionName}${moduleName}失败: ${error instanceof Error ? error.message : '未知错误'}`)
|
|
|
console.error('API请求错误:', error)
|
|
|
} finally {
|
|
|
loadingStates.value[loadingKey] = false
|