Commit 27122a78 by liucan

feat:任务执行记录新增根据任务名称查询

parent ea172f23
import axios from "axios"; import axios from 'axios'
import { ElMessage } from "element-plus"; import { ElMessage } from 'element-plus'
import { getToken, removeToken } from "@/utils/auth"; import { getToken, removeToken } from '@/utils/auth'
// 创建axios实例 // 创建axios实例
const instance = axios.create({ const instance = axios.create({
baseURL: import.meta.env.VITE_APP_BASE_API || "", baseURL: import.meta.env.VITE_APP_BASE_API || '',
timeout: 10000, // 毫秒 timeout: 10000, // 毫秒
headers: { headers: {
"Content-Type": "application/zip; charset=utf-8", 'Content-Type': 'application/zip; charset=utf-8'
}, }
}); })
// 请求拦截器 // 请求拦截器
instance.interceptors.request.use( instance.interceptors.request.use(
(config) => { (config) => {
const token = getToken(); const token = getToken()
if (token) { if (token) {
// 保持与原项目相同的Token头设置 // 保持与原项目相同的Token头设置
config.headers["Token"] = token; config.headers['Token'] = token
} }
return config; return config
}, },
(err) => { (err) => {
console.log("请求出错"); console.log('请求出错')
return Promise.reject(err); return Promise.reject(err)
} }
); )
// 响应拦截器 // 响应拦截器
instance.interceptors.response.use( instance.interceptors.response.use(
(res) => { (res) => {
let result = res.data; let result = res.data
if (typeof res.data === "string") { if (typeof res.data === 'string') {
try { try {
result = JSON.parse(res.data); result = JSON.parse(res.data)
} catch (e) { } catch (e) {
// 不是JSON格式,保持原样 // 不是JSON格式,保持原样
} }
} else { } else {
// 4000 token无效或者过期 // 4000 token无效或者过期
if (result.code === 4000) { if (result.code === 4000) {
removeToken(); removeToken()
window.location.reload(); window.location.reload()
} }
if (result.code === 0) { if (result.code === 0) {
result.ok = true; result.ok = true
} else { } else {
result.ok = false; result.ok = false
ElMessage.error(result.msg || "请求失败"); ElMessage.error(result.msg || '请求失败')
} }
} }
return result; return result
}, },
(err) => { (err) => {
ElMessage.error("网络请求出错, 请检查网络"); ElMessage.error('网络请求出错, 请检查网络')
return Promise.reject(err); return Promise.reject(err)
} }
); )
// HTTP 请求方法常量 // HTTP 请求方法常量
export const GET = "get"; export const GET = 'get'
export const POST = "post"; export const POST = 'post'
export const PUT = "put"; export const PUT = 'put'
export const DELETE = "delete"; export const DELETE = 'delete'
// 请求函数类型 // 请求函数类型
export interface RequestConfig { export interface RequestConfig {
url: string; url: string
method: "get" | "post" | "put" | "delete"; method: 'get' | 'post' | 'put' | 'delete'
params?: any; params?: any
data?: any; data?: any
headers?: Record<string, string>; headers?: Record<string, string>
} }
export interface ApiResponse<T = any> { export interface ApiResponse<T = any> {
code: number; code: number
data: T; data: T
message: string; message: string
} }
export interface QueryParams { export interface QueryParams {
page?: number; page?: number
size?: number; size?: number
project?: string; project?: string
spider?: string; spider?: string
scrapydServerId?: string; scrapydServerId?: string
order_prop?: string; order_prop?: string
order_type?: string; order_type?: string
status?: any; status?: any
job?: any; job?: any
} }
// 请求函数 // 请求函数
export const request = (config: RequestConfig) => { export const request = (config: RequestConfig) => {
return instance(config); return instance(config)
}; }
export interface UserQueryParams { export interface UserQueryParams {
page?: number; page?: number
size?: number; size?: number
username?: string; username?: string
nickname?: string; nickname?: string
password?: string; password?: string
role?: number; role?: number
status?: any; status?: any
id?: number; id?: number
ids?: any; ids?: any
scrapydServerId?: string; scrapydServerId?: string
project?: string; project?: string
spiders?: any; spiders?: any
times?: any; times?: any
job_id?: string; job_id?: string
scrapyd_server_id?: string; scrapyd_server_id?: string
schedule_type?: string; schedule_type?: string
spider?: string; spider?: string
cron?: string; cron?: string
options?: string; options?: string
sat_name?: string; sat_name?: string
ntc_id?: string; ntc_id?: string
filters?: any; filters?: any
norad_cat_id?: string; norad_cat_id?: string
object_name?: string; object_name?: string
name?: string; name?: string
spacecraft?: string; spacecraft?: string
station?: string; station?: string
interval?: number[]; interval?: number[]
schedule_job_id?: string
} }
...@@ -22,6 +22,17 @@ ...@@ -22,6 +22,17 @@
</el-config-provider> </el-config-provider>
</div> </div>
<div class="spider w-[300px] flex items-center"> <div class="spider w-[300px] flex items-center">
<span style="color: white" class="w-[100px]">任务名称:</span>
<el-select v-model="jobname" placeholder="请选择任务名称">
<el-option
v-for="item in jobNameOptions"
:key="item.value"
:label="item.label"
:value="item.value"
></el-option>
</el-select>
</div>
<div class="spider w-[300px] flex items-center">
<span style="color: white" class="w-[100px]">所属爬虫:</span> <span style="color: white" class="w-[100px]">所属爬虫:</span>
<el-select v-model="spidername" placeholder="请选择爬虫"> <el-select v-model="spidername" placeholder="请选择爬虫">
<el-option <el-option
...@@ -99,7 +110,7 @@ import { ref, onMounted } from 'vue' ...@@ -99,7 +110,7 @@ import { ref, onMounted } from 'vue'
import Pagination from '@/components/pagination/index.vue' import Pagination from '@/components/pagination/index.vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { getSpiderTaskRecord } from '@/api/spiderTask.ts' import { getSpiderTaskList, getSpiderTaskRecord } from '@/api/spiderTask.ts'
import MenuTitle from '@/components/MenuTitle.vue' import MenuTitle from '@/components/MenuTitle.vue'
import TableSearch from '@/components/TableSearch.vue' import TableSearch from '@/components/TableSearch.vue'
//时间处理库 //时间处理库
...@@ -157,6 +168,9 @@ const spideOptions = [ ...@@ -157,6 +168,9 @@ const spideOptions = [
} }
] ]
// 任务名称下拉框选项
const jobNameOptions = ref<Array<{ label: string; value: string }>>([])
//表单loading标记 //表单loading标记
const tableLoading = ref(false) const tableLoading = ref(false)
...@@ -164,9 +178,27 @@ const tableLoading = ref(false) ...@@ -164,9 +178,27 @@ const tableLoading = ref(false)
const resetQuery = () => { const resetQuery = () => {
timeValue.value = [] timeValue.value = []
spidername.value = '' spidername.value = ''
jobname.value = ''
getData() getData()
} }
// 任务列表
const taskList = ref([])
// 获取任务列表
const getTaskList = async () => {
const res = await getSpiderTaskList({})
taskList.value = res.data
jobNameOptions.value = taskList.value
.filter((task: any) => task.id)
.map((task: any) => ({
label: task.kwargs.spider,
value: task.id
}))
console.log(taskList.value)
}
// 获取任务执行记录列表 // 获取任务执行记录列表
const getData = async () => { const getData = async () => {
let resTime: any[] = [] let resTime: any[] = []
...@@ -186,6 +218,7 @@ const getData = async () => { ...@@ -186,6 +218,7 @@ const getData = async () => {
} }
const spidername = ref('') const spidername = ref('')
const jobname = ref('')
//查询数据的方法 //查询数据的方法
const searchData = async () => { const searchData = async () => {
...@@ -202,6 +235,7 @@ const searchData = async () => { ...@@ -202,6 +235,7 @@ const searchData = async () => {
size: pageObj.value.pageSize, size: pageObj.value.pageSize,
status: 'total', status: 'total',
spider: spidername.value, spider: spidername.value,
schedule_job_id: jobname.value,
times: resTime times: resTime
}) })
pageObj.value.total = res.data.total pageObj.value.total = res.data.total
...@@ -211,6 +245,7 @@ const searchData = async () => { ...@@ -211,6 +245,7 @@ const searchData = async () => {
onMounted(() => { onMounted(() => {
getData() getData()
getTaskList()
}) })
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment