|
|
@@ -0,0 +1,534 @@
|
|
|
+<template>
|
|
|
+ <div class="app-container">
|
|
|
+ <!-- 搜索表单 -->
|
|
|
+ <el-form
|
|
|
+ :model="queryParams"
|
|
|
+ ref="queryForm"
|
|
|
+ size="small"
|
|
|
+ :inline="true"
|
|
|
+ v-show="showSearch"
|
|
|
+ label-width="68px"
|
|
|
+ >
|
|
|
+ <el-form-item label="采集页面URL" prop="pageUrl">
|
|
|
+ <el-input
|
|
|
+ v-model="queryParams.pageUrl"
|
|
|
+ placeholder="请输入采集页面URL"
|
|
|
+ clearable
|
|
|
+ @keyup.enter.native="handleQuery"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="采集时间">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="daterangeCollectionTime"
|
|
|
+ style="width: 240px"
|
|
|
+ value-format="yyyy-MM-dd"
|
|
|
+ type="daterange"
|
|
|
+ range-separator="-"
|
|
|
+ start-placeholder="开始日期"
|
|
|
+ end-placeholder="结束日期"
|
|
|
+ ></el-date-picker>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="关联采集任务ID" prop="taskId">
|
|
|
+ <el-input
|
|
|
+ v-model="queryParams.taskId"
|
|
|
+ placeholder="请输入关联采集任务ID"
|
|
|
+ clearable
|
|
|
+ @keyup.enter.native="handleQuery"
|
|
|
+ />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
|
|
+ <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
|
|
+ <el-button icon="el-icon-document" size="mini" @click="spiderQuery">采集</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <!-- 操作按钮区 -->
|
|
|
+ <el-row :gutter="10" class="mb8">
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ plain
|
|
|
+ icon="el-icon-plus"
|
|
|
+ size="mini"
|
|
|
+ @click="handleAdd"
|
|
|
+ v-hasPermi="['spiderData:sourceData:add']"
|
|
|
+ >新增
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="success"
|
|
|
+ plain
|
|
|
+ icon="el-icon-edit"
|
|
|
+ size="mini"
|
|
|
+ :disabled="!hasSingleSelection"
|
|
|
+ @click="handleUpdate"
|
|
|
+ v-hasPermi="['spiderData:sourceData:edit']"
|
|
|
+ >修改
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="danger"
|
|
|
+ plain
|
|
|
+ icon="el-icon-delete"
|
|
|
+ size="mini"
|
|
|
+ :disabled="!hasMultipleSelection"
|
|
|
+ @click="handleDelete"
|
|
|
+ v-hasPermi="['spiderData:sourceData:remove']"
|
|
|
+ >删除
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button
|
|
|
+ type="warning"
|
|
|
+ plain
|
|
|
+ icon="el-icon-download"
|
|
|
+ size="mini"
|
|
|
+ @click="handleExport"
|
|
|
+ v-hasPermi="['spiderData:sourceData:export']"
|
|
|
+ >导出
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <!-- 数据表格 -->
|
|
|
+ <el-table
|
|
|
+ v-loading="loading"
|
|
|
+ :data="spiderDataList"
|
|
|
+ @selection-change="handleSelectionChange"
|
|
|
+ row-key="id"
|
|
|
+ >
|
|
|
+ <el-table-column type="selection" width="55" align="center"/>
|
|
|
+
|
|
|
+ <el-table-column label="采集页面URL" align="center" prop="pageUrl" width="300">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-link
|
|
|
+ type="primary"
|
|
|
+ :href="scope.row.pageUrl"
|
|
|
+ target="_blank"
|
|
|
+ :underline="true"
|
|
|
+ class="text-ellipsis"
|
|
|
+ >
|
|
|
+ {{ formatLongText(scope.row.pageUrl, 30) }}
|
|
|
+ </el-link>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <el-table-column label="原始文本内容" align="center" prop="rawContent" width="200">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-link
|
|
|
+ type="primary"
|
|
|
+ @click="openRichTextNewPage(scope.row.rawContent, '原始文本内容')"
|
|
|
+ :underline="false"
|
|
|
+ class="text-ellipsis"
|
|
|
+ >
|
|
|
+ {{ formatLongText(scope.row.rawContent, 50) }}
|
|
|
+ </el-link>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <el-table-column label="优化文本内容" align="center" prop="rawContentFilter" width="200">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-link
|
|
|
+ type="primary"
|
|
|
+ @click="openRichTextNewPage(scope.row.rawContentFilter, '优化文本内容')"
|
|
|
+ :underline="false"
|
|
|
+ class="text-ellipsis"
|
|
|
+ >
|
|
|
+ {{ formatLongText(scope.row.rawContentFilter, 50) }}
|
|
|
+ </el-link>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <el-table-column label="原始附件信息" align="center" prop="rawAttachments" width="200">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-link
|
|
|
+ type="primary"
|
|
|
+ @click="openRichTextNewPage(scope.row.rawAttachments, '原始附件信息')"
|
|
|
+ :underline="false"
|
|
|
+ class="text-ellipsis"
|
|
|
+ >
|
|
|
+ {{ formatLongText(scope.row.rawAttachments, 50) }}
|
|
|
+ </el-link>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <el-table-column label="采集时间" align="center" prop="collectionTime" width="180">
|
|
|
+ <template #default="scope">
|
|
|
+ <span>{{ parseTime(scope.row.collectionTime, '{y}-{m}-{d}') }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+
|
|
|
+ <el-table-column label="关联采集任务ID" align="center" prop="taskId"/>
|
|
|
+
|
|
|
+ <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-edit"
|
|
|
+ @click="handleUpdate(scope.row)"
|
|
|
+ v-hasPermi="['spiderData:sourceData:edit']"
|
|
|
+ >修改
|
|
|
+ </el-button>
|
|
|
+ <el-button
|
|
|
+ size="mini"
|
|
|
+ type="text"
|
|
|
+ icon="el-icon-delete"
|
|
|
+ @click="handleDelete(scope.row)"
|
|
|
+ v-hasPermi="['spiderData:sourceData:remove']"
|
|
|
+ >删除
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+
|
|
|
+ <!-- 分页组件 -->
|
|
|
+ <pagination
|
|
|
+ v-show="total > 0"
|
|
|
+ :total="total"
|
|
|
+ :page.sync="queryParams.pageNum"
|
|
|
+ :limit.sync="queryParams.pageSize"
|
|
|
+ @pagination="getList"
|
|
|
+ />
|
|
|
+
|
|
|
+ <!-- 添加或修改原始采集数据对话框 -->
|
|
|
+ <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
|
|
|
+ <el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
|
|
+ <el-form-item label="采集页面URL" prop="pageUrl">
|
|
|
+ <el-input v-model="form.pageUrl" placeholder="请输入采集页面URL"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="原始文本内容">
|
|
|
+ <editor v-model="form.rawContent" :min-height="192"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="优化文本内容">
|
|
|
+ <editor v-model="form.rawContentFilter" :min-height="192"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="原始附件信息" prop="rawAttachments">
|
|
|
+ <el-input v-model="form.rawAttachments" type="textarea" placeholder="请输入内容"/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <div slot="footer" class="dialog-footer">
|
|
|
+ <el-button type="primary" @click="submitForm">确 定</el-button>
|
|
|
+ <el-button @click="cancel">取 消</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+
|
|
|
+<script>
|
|
|
+import {
|
|
|
+ listSpiderData,
|
|
|
+ getSpiderData,
|
|
|
+ delSpiderData,
|
|
|
+ addSpiderData,
|
|
|
+ updateSpiderData,
|
|
|
+ spiderCollect
|
|
|
+} from "@/api/spiderData/spiderData";
|
|
|
+
|
|
|
+// 常量定义
|
|
|
+const DEFAULT_PAGE_SIZE = 10;
|
|
|
+const DEFAULT_PAGE_NUM = 1;
|
|
|
+
|
|
|
+export default {
|
|
|
+ name: "SpiderData",
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ // 遮罩层
|
|
|
+ loading: true,
|
|
|
+ // 选中数组
|
|
|
+ ids: [],
|
|
|
+ // 显示搜索条件
|
|
|
+ showSearch: true,
|
|
|
+ // 总条数
|
|
|
+ total: 0,
|
|
|
+ // 原始采集数据表格数据
|
|
|
+ spiderDataList: [],
|
|
|
+ // 弹出层标题
|
|
|
+ title: "",
|
|
|
+ // 是否显示弹出层
|
|
|
+ open: false,
|
|
|
+ // 采集时间范围
|
|
|
+ daterangeCollectionTime: [],
|
|
|
+ // 查询参数
|
|
|
+ queryParams: {
|
|
|
+ pageNum: DEFAULT_PAGE_NUM,
|
|
|
+ pageSize: DEFAULT_PAGE_SIZE,
|
|
|
+ pageUrl: null,
|
|
|
+ rawContent: null,
|
|
|
+ rawContentFilter: null,
|
|
|
+ rawAttachments: null,
|
|
|
+ collectionTime: null,
|
|
|
+ taskId: null
|
|
|
+ },
|
|
|
+ // 表单参数
|
|
|
+ form: {},
|
|
|
+ // 表单校验
|
|
|
+ rules: {},
|
|
|
+ // 新增附件弹窗相关数据
|
|
|
+ attachmentsDialogVisible: false,
|
|
|
+ attachments: []
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ // 计算属性:是否有单个选中项
|
|
|
+ hasSingleSelection() {
|
|
|
+ return this.ids.length === 1;
|
|
|
+ },
|
|
|
+ // 计算属性:是否有选中项(用于删除)
|
|
|
+ hasMultipleSelection() {
|
|
|
+ return this.ids.length > 0;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.getList();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ /** 格式化长文本,超过指定长度显示省略号 */
|
|
|
+ formatLongText(text = '', maxLength) {
|
|
|
+ if (!text) return '无';
|
|
|
+ return text.length > maxLength
|
|
|
+ ? `${text.substring(0, maxLength)}...`
|
|
|
+ : text;
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 打开富文本新页面(新窗口) */
|
|
|
+ openRichTextNewPage(content, title = '文本内容') {
|
|
|
+ // 创建一个临时HTML内容
|
|
|
+ const htmlContent = `
|
|
|
+ <!DOCTYPE html>
|
|
|
+ <html lang="zh-CN">
|
|
|
+ <head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>${title}</title>
|
|
|
+ <style>
|
|
|
+ body {
|
|
|
+ font-family: Arial, sans-serif;
|
|
|
+ padding: 20px;
|
|
|
+ line-height: 1.6;
|
|
|
+ }
|
|
|
+ .container {
|
|
|
+ max-width: 1200px;
|
|
|
+ margin: 0 auto;
|
|
|
+ }
|
|
|
+ .title {
|
|
|
+ color: #333;
|
|
|
+ border-bottom: 1px solid #eee;
|
|
|
+ padding-bottom: 10px;
|
|
|
+ margin-bottom: 20px;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+ </head>
|
|
|
+ <body>
|
|
|
+ <div class="container">
|
|
|
+ <h2 class="title">${title}</h2>
|
|
|
+ <div class="content">${content || '无内容'}</div>
|
|
|
+ </div>
|
|
|
+ </body>
|
|
|
+ </html>
|
|
|
+ `;
|
|
|
+
|
|
|
+ // 创建Blob对象
|
|
|
+ const blob = new Blob([htmlContent], { type: 'text/html' });
|
|
|
+ // 创建临时URL
|
|
|
+ const url = URL.createObjectURL(blob);
|
|
|
+ // 打开新窗口
|
|
|
+ window.open(url, '_blank');
|
|
|
+
|
|
|
+ // 释放URL对象
|
|
|
+ setTimeout(() => {
|
|
|
+ URL.revokeObjectURL(url);
|
|
|
+ }, 1000);
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 查询原始采集数据列表 */
|
|
|
+ getList() {
|
|
|
+ this.loading = true;
|
|
|
+ // 处理查询参数
|
|
|
+ const params = { ...this.queryParams };
|
|
|
+
|
|
|
+ // 添加时间范围查询参数
|
|
|
+ if (this.daterangeCollectionTime && this.daterangeCollectionTime.length === 2) {
|
|
|
+ params.params = {
|
|
|
+ beginCollectionTime: this.daterangeCollectionTime[0],
|
|
|
+ endCollectionTime: this.daterangeCollectionTime[1]
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ listSpiderData(params)
|
|
|
+ .then(response => {
|
|
|
+ this.spiderDataList = response.rows || [];
|
|
|
+ this.total = response.total || 0;
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.error('获取数据列表失败:', error);
|
|
|
+ this.$modal.msgError('获取数据失败,请重试');
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 采集按钮操作 */
|
|
|
+ spiderQuery() {
|
|
|
+ // 校验:若pageUrl为空,给出提示
|
|
|
+ if (!this.queryParams.pageUrl) {
|
|
|
+ this.$modal.msgWarning("请输入采集页面URL");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 显示加载状态
|
|
|
+ this.loading = true;
|
|
|
+
|
|
|
+ // 调用采集接口
|
|
|
+ spiderCollect({ pageUrl: this.queryParams.pageUrl })
|
|
|
+ .then(() => {
|
|
|
+ this.$modal.msgSuccess("采集请求已发送,处理中...");
|
|
|
+ this.getList(); // 刷新列表
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ this.$modal.msgError(`采集失败:${error.response?.data?.msg || "服务器异常"}`);
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ this.loading = false;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ // 取消按钮
|
|
|
+ cancel() {
|
|
|
+ this.open = false;
|
|
|
+ this.reset();
|
|
|
+ },
|
|
|
+
|
|
|
+ // 表单重置
|
|
|
+ reset() {
|
|
|
+ this.form = {
|
|
|
+ id: null,
|
|
|
+ pageUrl: null,
|
|
|
+ rawContent: null,
|
|
|
+ rawContentFilter: null,
|
|
|
+ rawAttachments: null,
|
|
|
+ collectionTime: null,
|
|
|
+ taskId: null
|
|
|
+ };
|
|
|
+ this.resetForm("form");
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 搜索按钮操作 */
|
|
|
+ handleQuery() {
|
|
|
+ this.queryParams.pageNum = DEFAULT_PAGE_NUM;
|
|
|
+ this.getList();
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 重置按钮操作 */
|
|
|
+ resetQuery() {
|
|
|
+ this.daterangeCollectionTime = [];
|
|
|
+ this.resetForm("queryForm");
|
|
|
+ this.handleQuery();
|
|
|
+ },
|
|
|
+
|
|
|
+ // 多选框选中数据
|
|
|
+ handleSelectionChange(selection) {
|
|
|
+ this.ids = selection.map(item => item.id);
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 新增按钮操作 */
|
|
|
+ handleAdd() {
|
|
|
+ this.reset();
|
|
|
+ this.open = true;
|
|
|
+ this.title = "添加原始采集数据";
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 修改按钮操作 */
|
|
|
+ handleUpdate(row) {
|
|
|
+ this.reset();
|
|
|
+ const id = row?.id || this.ids[0];
|
|
|
+ if (!id) return;
|
|
|
+
|
|
|
+ getSpiderData(id)
|
|
|
+ .then(response => {
|
|
|
+ this.form = response.data;
|
|
|
+ this.open = true;
|
|
|
+ this.title = "修改原始采集数据";
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.error('获取数据详情失败:', error);
|
|
|
+ this.$modal.msgError('获取数据详情失败,请重试');
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 提交按钮 */
|
|
|
+ submitForm() {
|
|
|
+ this.$refs["form"].validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ const isEdit = this.form.id != null;
|
|
|
+ const apiMethod = isEdit ? updateSpiderData : addSpiderData;
|
|
|
+
|
|
|
+ apiMethod(this.form)
|
|
|
+ .then(() => {
|
|
|
+ this.$modal.msgSuccess(isEdit ? "修改成功" : "新增成功");
|
|
|
+ this.open = false;
|
|
|
+ this.getList();
|
|
|
+ })
|
|
|
+ .catch(error => {
|
|
|
+ console.error(`${isEdit ? '修改' : '新增'}失败:`, error);
|
|
|
+ this.$modal.msgError(`${isEdit ? '修改' : '新增'}失败,请重试`);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 删除按钮操作 */
|
|
|
+ handleDelete(row) {
|
|
|
+ const ids = row?.id || this.ids;
|
|
|
+ if (!ids || (Array.isArray(ids) && ids.length === 0)) return;
|
|
|
+
|
|
|
+ this.$modal.confirm(`是否确认删除原始采集数据编号为"${ids}"的数据项?`)
|
|
|
+ .then(() => delSpiderData(ids))
|
|
|
+ .then(() => {
|
|
|
+ this.getList();
|
|
|
+ this.$modal.msgSuccess("删除成功");
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ // 取消删除时的处理
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 导出按钮操作 */
|
|
|
+ handleExport() {
|
|
|
+ this.download(
|
|
|
+ 'spiderData/sourceData/export',
|
|
|
+ { ...this.queryParams },
|
|
|
+ `spiderData_${new Date().getTime()}.xlsx`
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+/* 附件列表样式,避免布局错乱 */
|
|
|
+.attachment-item {
|
|
|
+ padding: 12px 0;
|
|
|
+ border-bottom: 1px solid #f5f5f5;
|
|
|
+}
|
|
|
+.attachment-item:last-child {
|
|
|
+ border-bottom: none;
|
|
|
+}
|
|
|
+.text-ellipsis {
|
|
|
+ display: block;
|
|
|
+ white-space: nowrap;
|
|
|
+ overflow: hidden;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+}
|
|
|
+/* 容器样式 */
|
|
|
+.app-container {
|
|
|
+ padding: 16px;
|
|
|
+ box-sizing: border-box;
|
|
|
+}
|
|
|
+</style>
|