RunSpider.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div class="dialog-content">
  3. <div class="flex gap-2">
  4. <el-space class="edit-tag-list">
  5. <el-tag class="edit-tag" type="primary"> {{ formData.code }}</el-tag>
  6. <el-tag class="edit-tag" type="success"> {{ formData.site }}</el-tag>
  7. <el-tag class="edit-tag" type="info"> {{ formData.channel }}</el-tag>
  8. <el-tag class="edit-tag" type="warning">{{ formData.href }}</el-tag>
  9. <el-tag class="edit-tag" type="primary"> {{ formData.modifyuser }}</el-tag>
  10. </el-space>
  11. </div>
  12. <div class="space"></div>
  13. <el-form ref="form" :model="formData" label-width="120px">
  14. <el-row>
  15. <el-col :span="8">
  16. <el-form-item label="URL">
  17. <el-input v-model="formData.href" disabled :title="formData.href"></el-input>
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="8"><el-form-item label="代理地址">
  21. <el-input v-model="formData.proxyServe"></el-input>
  22. </el-form-item></el-col>
  23. <el-col :span="8"><el-form-item label="最大页数">
  24. <el-input v-model="formData.maxPages"></el-input>
  25. </el-form-item></el-col>
  26. </el-row>
  27. <el-row>
  28. <el-col :span="8"><el-form-item label="列表延时(MS)">
  29. <el-input v-model="formData.listDelay"></el-input>
  30. </el-form-item></el-col>
  31. <el-col :span="8"><el-form-item label="翻页延时(MS)">
  32. <el-input v-model="formData.trunPageDelay"></el-input>
  33. </el-form-item></el-col>
  34. <el-col :span="8"><el-form-item label="详情延时(MS)">
  35. <el-input v-model="formData.contentDelay"></el-input>
  36. </el-form-item></el-col>
  37. </el-row>
  38. <el-row>
  39. <el-col :span="8"><el-form-item label="浏览器">
  40. <el-radio-group v-model="formData.headless">
  41. <el-radio :value="true">无头</el-radio>
  42. <el-radio :value="false">显式</el-radio>
  43. </el-radio-group> </el-form-item>
  44. </el-col>
  45. <el-col :span="8"><el-form-item label="显示图像">
  46. <el-radio-group v-model="formData.showImage">
  47. <el-radio :value="true">显示</el-radio>
  48. <el-radio :value="false">不显示</el-radio>
  49. </el-radio-group> </el-form-item>
  50. </el-col>
  51. <el-col :span="8"><el-form-item label="开启线程数">
  52. <el-input v-model="formData.threads"></el-input>
  53. </el-form-item></el-col>
  54. </el-row>
  55. </el-form>
  56. <div style="text-align: center;">
  57. <el-space>
  58. <el-button type="primary" @click="handleDebug"><el-icon>
  59. <VideoPlay />
  60. </el-icon>执行</el-button>
  61. <el-button type="primary" @click="handleStop"><el-icon>
  62. <VideoPause />
  63. </el-icon>终止</el-button>
  64. <el-button type="primary" @click="handleRefersh"><el-icon>
  65. <Refresh />
  66. </el-icon>刷新结果</el-button>
  67. <el-button type="primary" @click="handleCountYestday"><el-icon>
  68. <Refresh />
  69. </el-icon>统计昨日信息发布量</el-button>
  70. <el-dropdown>
  71. <el-button type="primary">
  72. 结果导出<el-icon class="el-icon--right"><arrow-down /></el-icon>
  73. </el-button>
  74. <template #dropdown>
  75. <el-dropdown-menu>
  76. <el-dropdown-item @click="handleExportEpub">导出EPUB格式文件</el-dropdown-item>
  77. <el-dropdown-item>导出JSON格式文件</el-dropdown-item>
  78. <el-dropdown-item @click="handleExportExcel">导出Excel格式文件</el-dropdown-item>
  79. <el-dropdown-item>补录/上推至平台</el-dropdown-item>
  80. </el-dropdown-menu>
  81. </template>
  82. </el-dropdown></el-space>
  83. </div>
  84. <el-divider />
  85. <div id="debugEventContian">执行日志:&nbsp;{{ debugLogLine }}</div>
  86. <el-divider />
  87. <el-table :data="tableData" style="width: 100%" :height="tableHeight" @row-click="handleRowClick">
  88. <el-table-column prop="no" label="序号" width="90" />
  89. <el-table-column prop="title" label="标题" width="240" show-overflow-tooltip />
  90. <el-table-column prop="href" label="链接" show-overflow-tooltip />
  91. <el-table-column prop="contentShort" label="正文" show-overflow-tooltip />
  92. </el-table>
  93. </div>
  94. <ViewArticle ref="articleDialog" />
  95. </template>
  96. <script setup>
  97. import { ref, computed } from 'vue';
  98. import { ElMessage, ElMessageBox } from 'element-plus'
  99. import ViewArticle from "./ViewArticle.vue"
  100. import { ViewCurrentSpiderConfig, DebugSpider, StopDebugSpider } from "../../../wailsjs/go/main/App"
  101. import { ViewResultItemAll, SelectSaveFilePath, ExportEpubFile, CountYestodayArts } from "../../../wailsjs/go/main/App"
  102. import { EventsOn, EventsOff } from "../../../wailsjs/runtime"
  103. let originData = {}
  104. const defaultFormValue = {
  105. maxPages: 2,
  106. }
  107. const formData = ref({
  108. // tags
  109. code: '',
  110. site: '',
  111. channel: '',
  112. href: '',
  113. modifyuser: '',
  114. // form
  115. proxyServe: '',
  116. maxPages: defaultFormValue.maxPages,
  117. listDelay: '',
  118. trunPageDelay: '',
  119. contentDelay: '',
  120. headless: false,
  121. showImage: false,
  122. threads: '1',
  123. cssmark: {}
  124. })
  125. const articleDialog = ref(null)
  126. const debugLogLine = ref("")
  127. const tableData = ref([])
  128. const tableHeight = computed(() => window.innerHeight - 480 + 'px');
  129. const setPageData = (e) => {
  130. originData = e
  131. const cssMark = e.cssmark
  132. formData.value.code = e.code
  133. formData.value.site = e.site
  134. formData.value.channel = e.channel
  135. formData.value.href = e.href
  136. formData.value.modifyuser = e.modifyuser
  137. if (cssMark) {
  138. // form
  139. // formData.value.maxPages = cssMark.maxPages
  140. formData.value.listDelay = cssMark.listDelayTime
  141. formData.value.trunPageDelay = cssMark.listTurnDelayTime
  142. formData.value.contentDelay = cssMark.contentDelayTime
  143. formData.value.cssmark = cssMark
  144. }
  145. }
  146. //开始调试
  147. const handleDebug = () => {
  148. ElMessage({
  149. message: `${[formData.value.url, formData.value.listDelay, formData.value.contentDelay,
  150. formData.value.headless, formData.value.showImage, formData.value.proxyServe, formData.value.threads,
  151. formData.value.maxPages].join("//")}!`,
  152. showClose: true,
  153. duration: 3000,
  154. });
  155. DebugSpider(
  156. formData.value.href,
  157. formData.value.proxyServe,
  158. parseInt(formData.value.maxPages),
  159. parseInt(formData.value.listDelay),
  160. parseInt(formData.value.trunPageDelay),
  161. parseInt(formData.value.contentDelay),
  162. formData.value.headless,
  163. formData.value.showImage,
  164. parseInt(formData.value.threads),
  165. formData.value.cssmark,
  166. )
  167. }
  168. //停止调试
  169. const handleStop = () => {
  170. StopDebugSpider()
  171. }
  172. //
  173. const truncateString = (str, maxLength) => {
  174. return str.substring(0, maxLength) + "..";
  175. }
  176. //刷新加载数据
  177. const handleRefersh = () => {
  178. ViewResultItemAll(formData.value.code).then(result => {
  179. //result = result.slice(-20);
  180. result.forEach((v, i) => {
  181. v.contentShort = truncateString(v.content, 50)
  182. })
  183. tableData.value = result
  184. })
  185. }
  186. //handleExportEpub导出文件
  187. const handleExportEpub = () => {
  188. ElMessageBox.prompt('请输入书名', '书名', {
  189. confirmButtonText: '确定',
  190. cancelButtonText: '取消',
  191. }).then(({ value }) => {
  192. SelectSaveFilePath("", value).then(save2file => {
  193. if (save2file == "") {
  194. console.log("无效的文件存储路径", save2file)
  195. return
  196. }
  197. ExportEpubFile(value, save2file).then(d => {
  198. ElMessage({
  199. message: `导出epub文件${save2file}完成!`,
  200. showClose: true,
  201. duration: 3000,
  202. });
  203. })
  204. })
  205. })
  206. }
  207. const handleExportExcel = () => {
  208. ElMessageBox.prompt('请输入数据集名称', '数据集名称', {
  209. confirmButtonText: '确定',
  210. cancelButtonText: '取消',
  211. }).then(({ value }) => {
  212. SelectSaveFilePath("", value).then(save2file => {
  213. if (save2file == "") {
  214. console.log("无效的文件存储路径", save2file)
  215. return
  216. }
  217. ExportExcelFile(save2file).then(d => {
  218. ElMessage({
  219. message: `导出epub文件${save2file}完成!`,
  220. showClose: true,
  221. duration: 3000,
  222. });
  223. })
  224. })
  225. })
  226. }
  227. const replaceAll = function (src, search, replacement) {
  228. return src.split(search).join(replacement);
  229. };
  230. //行点击事件
  231. const handleRowClick = (row, column, event) => {
  232. articleDialog.value.dialogVisible = true
  233. row.content = replaceAll(row.content, '\n', '<br/>')
  234. articleDialog.value.formData = row
  235. articleDialog.value.scrollTop()
  236. }
  237. //
  238. const handleCountYestday = () => {
  239. if (formData.value.listNextPageCss != "" && formData.value.listPublishTimeCss != "") {
  240. ElMessage({
  241. message: `${[formData.value.url, formData.value.listDelay, formData.value.contentDelay,
  242. formData.value.headless, formData.value.showImage, formData.value.proxyServe].join("//")}!`,
  243. showClose: true,
  244. duration: 3000,
  245. });
  246. CountYestodayArts(formData.value.url, parseInt(formData.value.listDelay), parseInt(formData.value.contentDelay),
  247. formData.value.headless == 'true', formData.value.showImage == 'true')
  248. } else {
  249. ElMessage({
  250. message: "当前爬虫设置,CSS选择器,不具备列表页发布时间+列表页翻页。",
  251. type: 'error',
  252. showClose: true,
  253. duration: 3000,
  254. });
  255. }
  256. }
  257. //Wails事件绑定
  258. EventsOff('debug_event')
  259. EventsOn("debug_event", data => {
  260. debugLogLine.value = data
  261. })
  262. //加载当前爬虫配置
  263. // ViewCurrentSpiderConfig().then(result => {
  264. // console.log(result)
  265. // // result['listDelay'] = 500
  266. // // result['contentDelay'] = 500
  267. // // result['proxyServe'] = ''
  268. // // result['showImage'] = 'false'
  269. // // result['headless'] = 'false'
  270. // // formData.value = { ...result }
  271. // })
  272. defineExpose({
  273. setPageData,
  274. })
  275. </script>
  276. <style scoped>
  277. .dialog-content {
  278. max-height: 60vh;
  279. overflow-y: scroll;
  280. }
  281. .edit-tag-list {
  282. flex-wrap: wrap;
  283. }
  284. .edit-tag {
  285. margin-bottom: 4px;
  286. }
  287. </style>