VerifySpider.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!--爬虫配置自动校验-->
  2. <!-- 新增爬虫 -->
  3. <template>
  4. <el-dialog title="爬虫配置验证结果" v-model="dialogVisible" width="70%">
  5. <el-divider content-position="center">验证结果</el-divider>
  6. <el-descriptions direction="vertical" :column="4" border>
  7. <el-descriptions-item :class-name="formData.title ? 'c-success' : 'c-danger'" label="标题">{{ formatText(formData.title) }}</el-descriptions-item>
  8. <el-descriptions-item :class-name="formData.publishUnit ? 'c-success' : 'c-danger'" label="发布单位">{{ formatText(formData.publishUnit) }}</el-descriptions-item>
  9. <el-descriptions-item :class-name="formData.publishTime ? 'c-success' : 'c-danger'" label="发布时间">{{ formatText(formData.publishTime) }}</el-descriptions-item>
  10. <el-descriptions-item :class-name="formData.content ? 'c-success' : 'c-danger'" label="正文">{{ formatText(formData.content) }}</el-descriptions-item>
  11. <el-descriptions-item :class-name="formData.attaches ? 'c-success' : 'c-danger'" label="附件">{{ formatText(formData.attaches) }}</el-descriptions-item>
  12. <el-descriptions-item :class-name="formData.listItems ? 'c-success' : 'c-danger'" label="列表信息条数">{{ formatText(formData.listItems) }}</el-descriptions-item>
  13. <el-descriptions-item :class-name="formData.listTrunPage ? 'c-success' : 'c-danger'" label="列表翻页">{{ formatText(formData.listTrunPage) }}</el-descriptions-item>
  14. </el-descriptions>
  15. <el-divider content-position="center">样例数据</el-divider>
  16. <el-table :data="tableData" style="width: 100%" height="180" @row-click="handleRowClick">
  17. <el-table-column prop="no" label="序号" width="60" />
  18. <el-table-column prop="listTitle" label="标题" width="240" show-overflow-tooltip />
  19. <el-table-column prop="href" label="链接" show-overflow-tooltip />
  20. <el-table-column prop="listPublishTime" label="发布时间" show-overflow-tooltip />
  21. <el-table-column prop="contentShort" label="正文" show-overflow-tooltip />
  22. </el-table>
  23. <!-- <template #footer>-->
  24. <!-- <div class="dialog-footer">-->
  25. <!-- <el-button @click="dialogVisible = false" type="primary">关闭</el-button>-->
  26. <!-- </div>-->
  27. <!-- </template>-->
  28. <ViewArticle ref="articleDialog" />
  29. </el-dialog>
  30. </template>
  31. <script setup>
  32. import { ref, watch, defineExpose } from 'vue';
  33. import { ViewResultItemAll} from "../../../wailsjs/go/main/App"
  34. import ViewArticle from "./ViewArticle.vue";
  35. const tableData = ref([])
  36. const articleDialog = ref(null)
  37. let spiderInfo = {}
  38. const formData = ref({
  39. title: false,
  40. publishUnit: false,
  41. publishTime: false,
  42. content: false,
  43. attaches: false,
  44. listItems: false,
  45. listTrunPage: false,
  46. });
  47. const dialogVisible = ref(false)
  48. const setPageData = (show = false, info) => {
  49. dialogVisible.value = show
  50. if (info) {
  51. formData.value = info.ret || {}
  52. spiderInfo = info.row
  53. }
  54. }
  55. const replaceAll = function (src, search, replacement) {
  56. return src.split(search).join(replacement);
  57. };
  58. //行点击事件
  59. const handleRowClick = (row, column, event) => {
  60. articleDialog.value.dialogVisible = true
  61. row.content = replaceAll(row.content, '\n', '<br/>')
  62. articleDialog.value.formData = row
  63. articleDialog.value.scrollTop()
  64. }
  65. const formatText = (f = false) => {
  66. return f ? '通过' : '未通过'
  67. }
  68. const truncateString = (str, maxLength) => {
  69. return str.substring(0, maxLength) + "..";
  70. }
  71. const loadResultData = () => {
  72. ViewResultItemAll(spiderInfo.code).then(result => {
  73. result.forEach((v, i) => {
  74. v.contentShort = truncateString(v.content, 50)
  75. })
  76. tableData.value = result
  77. }).catch(err => {
  78. console.log(err)
  79. })
  80. }
  81. watch(dialogVisible, (v) => {
  82. if (v) {
  83. loadResultData()
  84. }
  85. })
  86. //这里是重点
  87. defineExpose({
  88. setPageData
  89. })
  90. </script>
  91. <style lang="scss" scoped>
  92. ::v-deep {
  93. .c-success {
  94. color: var(--el-color-success) !important;
  95. }
  96. .c-danger {
  97. color: var(--el-color-danger) !important;
  98. }
  99. }
  100. </style>