webCrawlerList.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <template>
  2. <!-- 采集列表 -->
  3. <div>
  4. <div class="title">
  5. <el-row>
  6. <el-col :span="6" class="left">
  7. <div class="searchBox">
  8. <div class="searchTitle">资讯题目</div>
  9. <el-input v-model="message_name" placeholder="请输入资讯名称" clearable></el-input>
  10. </div>
  11. </el-col>
  12. <el-col :span="6" class="left">
  13. <div class="searchBox">
  14. <div class="searchTitle">来源</div>
  15. <el-input v-model="message_from" placeholder="请输入来源" clearable></el-input>
  16. </div>
  17. </el-col>
  18. <el-col :span="6" class="left">
  19. <div class="searchBox">
  20. <div class="searchTitle">导入状态</div>
  21. <el-select v-model="message_state" clearable placeholder="请选择导入状态">
  22. <el-option v-for="item in statusOptions" :key="item.value" :label="item.label"
  23. :value="item.value">
  24. </el-option>
  25. </el-select>
  26. </div>
  27. </el-col>
  28. <el-col :span="6" class="right">
  29. <div class="btnList">
  30. <button class="search" @click="goSearch">搜索</button>
  31. <button class="reset" @click="goReset">重置</button>
  32. </div>
  33. </el-col>
  34. </el-row>
  35. </div>
  36. <!--表格内容 start------------------------------------------------------------>
  37. <div class="layerBox">
  38. <tableTitle :name="tableDivTitle" />
  39. <div class="btnList">
  40. <button class="navigation" @click="toNavigation">关联导航池</button>
  41. <button class="consultList" @click="importMessage">导入资讯列表</button>
  42. </div>
  43. <el-row>
  44. <template>
  45. <el-table class="my-table" v-loading="loading" :data="tableData" style="width: 100%">
  46. <el-table-column fixed prop="id" label="编号" width="80">
  47. </el-table-column>
  48. <el-table-column prop="title" label="资讯题目" width="230">
  49. </el-table-column>
  50. <el-table-column prop="oldtitle" label="原始资讯题目" width="230">
  51. </el-table-column>
  52. <el-table-column prop="category.name" label="导航池名称" width="120">
  53. </el-table-column>
  54. <el-table-column prop="source" label="来源" width="120">
  55. </el-table-column>
  56. <el-table-column label="导入状态" prop="state" width="100">
  57. </el-table-column>
  58. <el-table-column prop="author" label="作者" width="90">
  59. </el-table-column>
  60. <el-table-column prop="created_at" label="采集时间" width="160">
  61. </el-table-column>
  62. <el-table-column prop="updated_at" label="修改时间" width="160">
  63. </el-table-column>
  64. <el-table-column fixed="right" label="操作" width="200">
  65. <template slot-scope="scope">
  66. <div class="listBtnBox">
  67. <div class="listDeleteBtn" @click="deleteRow(scope.row.id, scope.row)"><i
  68. class="el-icon-delete"></i>删除</div>
  69. <div class="listEditBtn" @click="goEdit(scope.row.id, scope.row)"><i
  70. class="el-icon-edit-outline"></i>编辑</div>
  71. </div>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. </template>
  76. </el-row>
  77. </div>
  78. <!--分页 start------------------------------------------------------------>
  79. <div class="alignBox">
  80. <el-row>
  81. <el-col :span="24">
  82. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
  83. :current-page="page" :page-size="pageSize" layout="total, prev, pager, next, jumper"
  84. :total="total">
  85. </el-pagination>
  86. <!-- <el-pagination @size-change="handleSizeChange" :current-page="getApiData.page"
  87. @current-change="handleCurrentChange" :page-size="10" layout="total, prev, pager, next, jumper"
  88. :total="allCount"></el-pagination> -->
  89. </el-col>
  90. </el-row>
  91. </div>
  92. <!--分页 end------------------------------------------------------------>
  93. <!--表格内容 end------------------------------------------------------------>
  94. <!-- 弹出框 start------------------------------------------------------------>
  95. <el-dialog title="关联导航池" :visible.sync="dialogTableVisible" width="50%" :close-on-click-modal="false">
  96. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
  97. <div class="dialogText">
  98. <!-- <el-form-item label="关联导航池:" prop="name">
  99. <el-select v-model="ruleForm.name" placeholder="请选择关联的导航池名称">
  100. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
  101. </el-option>
  102. </el-select>
  103. </el-form-item> -->
  104. <el-form-item label="关联导航池:" :label-width="formLabelWidth" class="custom-align-right">
  105. <el-cascader :key="parentKey" v-model="ruleForm.name" placeholder="请选择关联的导航池名称"
  106. :props="parentData" filterable clearable></el-cascader>
  107. </el-form-item>
  108. </div>
  109. <div class="dialogBtn">
  110. <button class="cancel" @click="cancelForm">取消</button>
  111. <button class="submit" @click="submitForm">提交</button>
  112. </div>
  113. </el-form>
  114. </el-dialog>
  115. <!-- 弹出框 end------------------------------------------------------------>
  116. </div>
  117. </template>
  118. <script>
  119. //表格标题
  120. import tableTitle from './components/tableTitle.vue';
  121. //引入公用样式
  122. import '@/styles/global.less';
  123. import { getInfo, updateInfo, delInfo, addCatid, addArt } from '@/api/crawler'
  124. export default {
  125. components: {
  126. tableTitle,//表格标题
  127. },
  128. data() {
  129. let self = this;
  130. return {
  131. tableDivTitle: "任务规则列表",//表格标题
  132. // searchWebName: "", //搜索网站名称
  133. // dialogName:'关联导航池',
  134. loading: true,
  135. //跳转传递的参数
  136. ruleId: "", //规则id
  137. source: "", //规则来源
  138. state: 0, //导入状态
  139. //搜索框
  140. message_name: '',//资讯名称
  141. message_from: '', //来源
  142. message_state: '', //导入状态
  143. //分页相关
  144. page: 1,
  145. pageSize: 10,
  146. total: 20,
  147. //查询状态
  148. setTime: '',
  149. listStatus: false,
  150. navigationPoolBoo: false, //是否关联导航池
  151. tableData: [], //表格内数据
  152. // currentPage: 4,
  153. dialogTableVisible: false,
  154. // dialogName: '',
  155. ruleForm: {
  156. name: '',
  157. },
  158. rules: { //规则
  159. name: [
  160. { required: true, message: '请选择关联的导航池名称', trigger: 'blur' },
  161. ]
  162. },
  163. // dialog 关联导航池
  164. options: [],
  165. statusOptions: [
  166. {
  167. value: '0',
  168. label: '未导入'
  169. },
  170. {
  171. value: '1',
  172. label: '已导入'
  173. },
  174. ],
  175. formLabelWidth: '120px',
  176. parentKey: 0,//获取父级导航
  177. parentData: {
  178. checkStrictly: true,
  179. lazy: true,
  180. async lazyLoad(node, resolve) {
  181. const { level, data } = node;
  182. if (data && data.children && data.children.length !== 0) {
  183. return resolve(node)
  184. }
  185. console.log(level)
  186. let parentId = level == 0 ? 0 : data.value
  187. let parames = {
  188. 'pid': parentId
  189. }
  190. self.$store.dispatch('pool/categoryList', parames).then(res => {
  191. if (res.data) {
  192. const nodes = res.data.map(item => ({
  193. value: item.id,
  194. label: item.name,
  195. leaf: level >= 3,
  196. children: []
  197. }))
  198. resolve(nodes)
  199. }
  200. })
  201. }
  202. },
  203. }
  204. },
  205. mounted() {
  206. // 接收跳转传递的参数
  207. this.ruleId = this.$route.query.id
  208. this.source = this.$route.query.source
  209. //请求数据
  210. this.getData()
  211. },
  212. methods: {
  213. //1.列表和分页相关 start ------------------------------------------------------------>
  214. //1.1 开始请求列表信息方法
  215. getData() {
  216. if (this.message_name == '' && this.message_from == '' && this.message_state == '') {
  217. getInfo({
  218. // rule_id: 12,
  219. rule_id: this.ruleId,
  220. page: this.page,
  221. pageSize: this.pageSize
  222. }).then(data => {
  223. console.log('tableData', data.data.rep);
  224. this.loading = false
  225. this.total = data.data.count
  226. this.tableData = data.data.rep
  227. for (let item of this.tableData) {
  228. if (item.state == 1) {
  229. item.state = "已导入"
  230. } else {
  231. item.state = "未导入";
  232. this.listStatus = true;
  233. }
  234. }
  235. console.log(this.listStatus);
  236. if (this.listStatus) {
  237. } else {
  238. this.clearTask()
  239. // this.$message.success("导入成功!")
  240. }
  241. })
  242. } else {
  243. getInfo({
  244. rule_id: this.ruleId,
  245. page: this.page,
  246. pageSize: this.pageSize,
  247. title: this.message_name,
  248. source: this.message_from,
  249. state: this.message_state
  250. }).then(data => {
  251. console.log(data);
  252. this.total = data.data.count
  253. this.tableData = data.data.rep
  254. for (let item of this.tableData) {
  255. if (item.state == 1) {
  256. item.state = "已导入"
  257. } else {
  258. item.state = "未导入"
  259. }
  260. }
  261. })
  262. }
  263. },
  264. setTask() {
  265. let that = this;
  266. this.setTime = setInterval(() => {
  267. that.getData();
  268. }, 5000)
  269. },
  270. clearTask() {
  271. clearInterval(this.setTime)
  272. },
  273. //1.2 删除内容
  274. deleteRow(id, val) {
  275. this.$confirm('注意:删除后,该条信息及其绑定关系全部删除', '是否确认删除该条信息?', {
  276. confirmButtonText: '确定',
  277. cancelButtonText: '取消',
  278. }).then(() => {
  279. delInfo({
  280. art_id: id
  281. }).then(data => {
  282. console.log(data);
  283. if (data.code == 200) {
  284. this.$message({
  285. type: 'success',
  286. message: '删除成功!'
  287. });
  288. this.getData()
  289. console.log("当前删除:" + id)
  290. } else if (data.code == 0) {
  291. this.$message({
  292. type: 'error',
  293. message: data.message
  294. });
  295. }
  296. })
  297. }).catch(() => {
  298. this.$message({
  299. type: 'warning',
  300. message: '已取消删除'
  301. });
  302. });
  303. },
  304. //1.3 修改网站状态
  305. //1.4 列表内容分页
  306. //直接跳转
  307. handleSizeChange(val) {
  308. this.page = val;
  309. this.getData();
  310. },
  311. //1.5 点击分页
  312. handleCurrentChange(val) {
  313. this.page = val;
  314. this.getData();
  315. },
  316. // 1.6 搜索按钮
  317. goSearch() {
  318. getInfo({
  319. rule_id: this.ruleId,
  320. page: this.page,
  321. pageSize: this.pageSize,
  322. title: this.message_name,
  323. source: this.message_from,
  324. state: this.message_state
  325. }).then(data => {
  326. console.log(data);
  327. this.total = data.data.count
  328. this.tableData = data.data.rep
  329. for (let item of this.tableData) {
  330. if (item.state == 1) {
  331. item.state = "已导入"
  332. } else {
  333. item.state = "未导入"
  334. }
  335. }
  336. })
  337. },
  338. //1.7 重置按钮
  339. goReset() {
  340. this.message_name = '',
  341. this.message_from = '',
  342. this.message_state = ''
  343. this.getData()
  344. },
  345. //列表和分页相关 end ------------------------------------------------------------>
  346. //1.8 编辑
  347. goEdit(id, val) {
  348. console.log(id, val);
  349. // this.$router.push('/webCrawlerListEdit')
  350. this.$router.push({
  351. path: '/webCrawlerListEdit',
  352. query: {
  353. ruleId: this.ruleId,
  354. source: this.source,
  355. id: id,
  356. // data: val
  357. }
  358. })
  359. },
  360. //1.9 关联导航池
  361. toNavigation() {
  362. addCatid({
  363. rule_id: this.ruleId,
  364. }).then(data => {
  365. console.log('关联导航池', data);
  366. if (data.code == 200) {
  367. this.dialogTableVisible = true
  368. this.options = data.data
  369. }
  370. if (data.code == 0) {
  371. this.$message({
  372. message: data.message,
  373. type: 'error'
  374. })
  375. }
  376. this.getData()
  377. })
  378. },
  379. //关联导航池的取消按钮
  380. cancelForm() {
  381. this.dialogTableVisible = true
  382. },
  383. //关联导航池的提交按钮
  384. submitForm() {
  385. //console.log(this.ruleForm.name);
  386. addCatid({
  387. rule_id: this.ruleId,//任务规则id
  388. cat_arr_id: this.ruleForm.name,//导航池栏目id
  389. }).then(data => {
  390. console.log(this.ruleForm.name);
  391. console.log(data);
  392. if (data.code == 200) {
  393. this.dialogTableVisible = false
  394. this.$message({
  395. message: '关联成功!',
  396. type: 'success'
  397. })
  398. this.getData()
  399. }
  400. if (data.code == 0) {
  401. this.$message({
  402. message: data.message,
  403. type: 'error'
  404. })
  405. this.getData()
  406. }
  407. })
  408. },
  409. //2.0 导入资讯列表
  410. importMessage() {
  411. for (let item of this.tableData) {
  412. if (!item.category) {
  413. this.navigationPoolBoo = true
  414. } else {
  415. this.navigationPoolBoo = false
  416. }
  417. }
  418. if (this.navigationPoolBoo) {
  419. this.$message({
  420. message: '还未关联导航池,请先关联导航池',
  421. type: 'error'
  422. })
  423. } else {
  424. this.$confirm('', '是否确认将所有未导入的信息导入资讯列表?', {
  425. confirmButtonText: '确定',
  426. cancelButtonText: '取消',
  427. }).then(() => {
  428. addArt({
  429. rule_id: this.ruleId
  430. }).then(data => {
  431. console.log(data);
  432. if (data.code == 200) {
  433. this.$message({
  434. message: '导入中',
  435. type: 'success'
  436. })
  437. this.getData()
  438. this.setTask()
  439. }
  440. if (data.code == 0) {
  441. this.$message({
  442. message: data.message,
  443. type: 'error'
  444. })
  445. }
  446. })
  447. }).catch(() => {
  448. this.$message({
  449. type: 'warning',
  450. message: '已取消'
  451. });
  452. });
  453. }
  454. }
  455. },
  456. }
  457. </script>
  458. <style scoped lang="less">
  459. .title {
  460. margin: 30px 30px 20px 30px;
  461. padding: 30px 30px 40px 30px;
  462. background-color: #fff;
  463. border-radius: 20px 20px 20px 20px;
  464. border: 1px solid #E9EDF7;
  465. .left {
  466. float: left;
  467. }
  468. .right {
  469. float: right;
  470. }
  471. .searchBox {
  472. margin-right: 30px;
  473. .searchTitle {
  474. padding-bottom: 10px;
  475. font-family: Microsoft YaHei, Microsoft YaHei;
  476. font-weight: 400;
  477. font-size: 14px;
  478. color: #999999;
  479. line-height: 16px;
  480. }
  481. .el-select {
  482. // width: 300px;
  483. display: inline-block;
  484. position: relative;
  485. }
  486. }
  487. .btnList {
  488. float: right;
  489. padding-top: 28px;
  490. button {
  491. // width: 120px;
  492. height: 38px;
  493. border: none;
  494. border-radius: 8px;
  495. padding: 0 20px;
  496. }
  497. .search {
  498. background-color: #5570f1;
  499. color: #fff;
  500. margin-right: 20px;
  501. }
  502. .reset {
  503. font-family: Microsoft YaHei, Microsoft YaHei;
  504. font-weight: 400;
  505. font-size: 16px;
  506. color: #333333;
  507. background: #F5F7FB;
  508. border-radius: 8px 8px 8px 8px;
  509. border: 1px solid rgba(85, 112, 241, 0.11);
  510. }
  511. }
  512. }
  513. .layerBox {
  514. padding: 30px 20px;
  515. position: relative;
  516. .btnList {
  517. position: absolute;
  518. top: 30px;
  519. right: 20px;
  520. height: 38px;
  521. >button {
  522. color: #fff;
  523. background-color: #5570f1;
  524. border: none;
  525. border-radius: 8px;
  526. padding: 8px 28px 9px;
  527. box-sizing: border-box;
  528. }
  529. >button:first-child {
  530. margin-right: 30px;
  531. }
  532. }
  533. .listBtnBox {
  534. justify-content: left;
  535. }
  536. .listDeleteBtn,
  537. .listEditBtn,
  538. .listLookBtn {
  539. margin-left: 0px;
  540. padding-left: 0px;
  541. margin-right: 20px;
  542. width: 76px;
  543. height: 36px;
  544. line-height: 36px;
  545. }
  546. .listLookBtn {
  547. text-align: center;
  548. border-radius: 8px;
  549. cursor: pointer;
  550. color: #999999;
  551. background-color: rgba(153, 153, 153, 0.16);
  552. >i {
  553. padding-right: 8px;
  554. }
  555. }
  556. }
  557. // 弹出层内容
  558. .dialogText {
  559. margin: 0 7px 0 3px;
  560. padding-top: 20px;
  561. padding-bottom: 1px;
  562. padding: 20px 60px 1px 20px;
  563. background-color: #f5f7fb;
  564. }
  565. // 弹出层按钮
  566. .dialogBtn {
  567. text-align: center;
  568. margin: 50px auto 20px;
  569. button {
  570. width: 184px;
  571. padding: 16px;
  572. font-family: Microsoft YaHei, Microsoft YaHei;
  573. font-weight: 400;
  574. font-size: 20px;
  575. border: none;
  576. border-radius: 12px 12px 12px 12px;
  577. }
  578. // 取消
  579. .cancel {
  580. color: #333333;
  581. background-color: #f5f7fb;
  582. border: 2px solid rgba(85, 112, 241, 0.11);
  583. }
  584. // 提交
  585. .submit {
  586. color: #fff;
  587. background-color: #5570F1;
  588. margin-left: 40px;
  589. }
  590. }
  591. ::v-deep .el-form-item {
  592. margin-bottom: 50px;
  593. }
  594. ::v-deep .el-select {
  595. width: 100%;
  596. }
  597. ::v-deep .el-input--medium,
  598. ::v-deep .el-form-item__label {
  599. line-height: 36px;
  600. font-size: 16px;
  601. }
  602. ::v-deep .el-cascader--medium {
  603. width: 100%;
  604. font-size: 14px;
  605. line-height: 36px;
  606. }
  607. </style>