webCrawlerList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  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-col>
  87. </el-row>
  88. </div>
  89. <!--分页 end------------------------------------------------------------>
  90. <!--表格内容 end------------------------------------------------------------>
  91. <!-- 弹出框 start------------------------------------------------------------>
  92. <el-dialog title="关联导航池" :visible.sync="dialogTableVisible" width="50%" :close-on-click-modal="false">
  93. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
  94. <div class="dialogText">
  95. <el-form-item label="关联导航池:" prop="name">
  96. <el-select v-model="ruleForm.name" placeholder="请选择关联的导航池名称">
  97. <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
  98. </el-option>
  99. </el-select>
  100. </el-form-item>
  101. </div>
  102. <div class="dialogBtn">
  103. <button class="cancel" @click="cancelForm">取消</button>
  104. <button class="submit" @click="submitForm">提交</button>
  105. </div>
  106. </el-form>
  107. </el-dialog>
  108. <!-- 弹出框 end------------------------------------------------------------>
  109. </div>
  110. </template>
  111. <script>
  112. //表格标题
  113. import tableTitle from './components/tableTitle.vue';
  114. //引入公用样式
  115. import '@/styles/global.less';
  116. import { getInfo, updateInfo, delInfo, addCatid, addArt } from '@/api/crawler'
  117. export default {
  118. components: {
  119. tableTitle,//表格标题
  120. },
  121. data() {
  122. return {
  123. tableDivTitle: "任务规则列表",//表格标题
  124. // searchWebName: "", //搜索网站名称
  125. // dialogName:'关联导航池',
  126. loading: true,
  127. //跳转传递的参数
  128. ruleId: "", //规则id
  129. source: "", //规则来源
  130. state: 0, //导入状态
  131. //搜索框
  132. message_name: '',//资讯名称
  133. message_from: '', //来源
  134. message_state: '', //导入状态
  135. //分页相关
  136. page: 1,
  137. pageSize: 10,
  138. total: 20,
  139. navigationPoolBoo: false, //是否关联导航池
  140. tableData: [], //表格内数据
  141. // currentPage: 4,
  142. dialogTableVisible: false,
  143. // dialogName: '',
  144. ruleForm: {
  145. name: '',
  146. },
  147. rules: { //规则
  148. name: [
  149. { required: true, message: '请选择关联的导航池名称', trigger: 'blur' },
  150. ]
  151. },
  152. // dialog 关联导航池
  153. options: [],
  154. statusOptions: [
  155. {
  156. value: '0',
  157. label: '未导入'
  158. },
  159. {
  160. value: '1',
  161. label: '已导入'
  162. },
  163. ]
  164. }
  165. },
  166. mounted() {
  167. // 接收跳转传递的参数
  168. this.ruleId = this.$route.query.id
  169. this.source = this.$route.query.source
  170. //请求数据
  171. this.getData()
  172. },
  173. methods: {
  174. //1.列表和分页相关 start ------------------------------------------------------------>
  175. //1.1 开始请求列表信息方法
  176. getData() {
  177. getInfo({
  178. // rule_id: 12,
  179. rule_id: this.ruleId,
  180. page: this.page,
  181. pageSize: this.pageSize
  182. }).then(data => {
  183. console.log('tableData', data.data.rep);
  184. this.loading = false
  185. this.total = data.data.count
  186. this.tableData = data.data.rep
  187. let status = false;
  188. for (let item of this.tableData) {
  189. if (item.state == 1) {
  190. item.state = "已导入"
  191. } else {
  192. item.state = "未导入";
  193. status = true;
  194. }
  195. }
  196. if(status){
  197. this.$message.error("有未导入的资讯!")
  198. }else{
  199. this.$message.success("导入成功!")
  200. }
  201. })
  202. },
  203. abc(){
  204. this.$message.error("abc!")
  205. },
  206. //1.2 删除内容
  207. deleteRow(id, val) {
  208. this.$confirm('注意:删除后,该条信息及其绑定关系全部删除', '是否确认删除该条信息?', {
  209. confirmButtonText: '确定',
  210. cancelButtonText: '取消',
  211. }).then(() => {
  212. delInfo({
  213. art_id: id
  214. }).then(data => {
  215. console.log(data);
  216. if (data.code == 200) {
  217. this.$message({
  218. type: 'success',
  219. message: '删除成功!'
  220. });
  221. this.getData()
  222. console.log("当前删除:" + id)
  223. } else if (data.code == 0) {
  224. this.$message({
  225. type: 'error',
  226. message: data.message
  227. });
  228. }
  229. })
  230. }).catch(() => {
  231. this.$message({
  232. type: 'warning',
  233. message: '已取消删除'
  234. });
  235. });
  236. },
  237. //1.3 修改网站状态
  238. //1.4 列表内容分页
  239. //直接跳转
  240. handleSizeChange(val) {
  241. this.page = val;
  242. this.getData();
  243. },
  244. //1.5 点击分页
  245. handleCurrentChange(val) {
  246. this.page = val;
  247. this.getData();
  248. },
  249. // 1.6 搜索按钮
  250. goSearch() {
  251. getInfo({
  252. rule_id: this.ruleId,
  253. page: this.page,
  254. pageSize: this.pageSize,
  255. title: this.message_name,
  256. source: this.message_from,
  257. state: this.message_state
  258. }).then(data => {
  259. console.log(data);
  260. this.total = data.data.count
  261. this.tableData = data.data.rep
  262. for (let item of this.tableData) {
  263. if (item.state == 1) {
  264. item.state = "已导入"
  265. } else {
  266. item.state = "未导入"
  267. }
  268. }
  269. })
  270. },
  271. //1.7 重置按钮
  272. goReset() {
  273. this.message_name = '',
  274. this.message_from = '',
  275. this.message_state = ''
  276. this.getData()
  277. },
  278. //列表和分页相关 end ------------------------------------------------------------>
  279. //1.8 编辑
  280. goEdit(id, val) {
  281. console.log(id, val);
  282. // this.$router.push('/webCrawlerListEdit')
  283. this.$router.push({
  284. path: '/webCrawlerListEdit',
  285. query: {
  286. ruleId: this.ruleId,
  287. source: this.source,
  288. id: id,
  289. // data: val
  290. }
  291. })
  292. },
  293. //1.9 关联导航池
  294. toNavigation() {
  295. addCatid({
  296. rule_id: this.ruleId,
  297. }).then(data => {
  298. console.log(data);
  299. if (data.code == 200) {
  300. this.dialogTableVisible = true
  301. this.options = data.data
  302. }
  303. if (data.code == 0) {
  304. this.$message({
  305. message: data.message,
  306. type: 'error'
  307. })
  308. }
  309. this.getData()
  310. })
  311. },
  312. //关联导航池的取消按钮
  313. cancelForm() {
  314. this.dialogTableVisible = false
  315. },
  316. //关联导航池的提交按钮
  317. submitForm() {
  318. addCatid({
  319. rule_id: this.ruleId,//任务规则id
  320. catid: this.ruleForm.name,//导航池栏目id
  321. }).then(data => {
  322. console.log(this.ruleForm.name);
  323. console.log(data);
  324. if (data.code == 200) {
  325. this.dialogTableVisible = false
  326. this.$message({
  327. message: '关联成功!',
  328. type: 'success'
  329. })
  330. this.getData()
  331. }
  332. if (data.code == 0) {
  333. this.$message({
  334. message: data.message,
  335. type: 'error'
  336. })
  337. this.getData()
  338. }
  339. })
  340. },
  341. //2.0 导入资讯列表
  342. importMessage() {
  343. for (let item of this.tableData) {
  344. if (!item.category) {
  345. this.navigationPoolBoo=true
  346. } else {
  347. this.navigationPoolBoo=false
  348. }
  349. }
  350. if (this.navigationPoolBoo) {
  351. this.$message({
  352. message: '还未关联导航池,请先关联导航池',
  353. type: 'error'
  354. })
  355. } else {
  356. this.$confirm('', '是否确认将所有未导入的信息导入资讯列表?', {
  357. confirmButtonText: '确定',
  358. cancelButtonText: '取消',
  359. }).then(() => {
  360. addArt({
  361. rule_id: this.ruleId
  362. }).then(data => {
  363. console.log(data);
  364. if (data.code == 200) {
  365. this.$message({
  366. message: '导入中',
  367. type: 'success'
  368. })
  369. this.getData()
  370. }
  371. if (data.code == 0) {
  372. this.$message({
  373. message: data.message,
  374. type: 'error'
  375. })
  376. }
  377. })
  378. }).catch(() => {
  379. this.$message({
  380. type: 'warning',
  381. message: '已取消'
  382. });
  383. });
  384. }
  385. }
  386. },
  387. }
  388. </script>
  389. <style scoped lang="less">
  390. .title {
  391. margin: 30px 30px 20px 30px;
  392. padding: 30px 30px 40px 30px;
  393. background-color: #fff;
  394. border-radius: 20px 20px 20px 20px;
  395. border: 1px solid #E9EDF7;
  396. .left {
  397. float: left;
  398. }
  399. .right {
  400. float: right;
  401. }
  402. .searchBox {
  403. margin-right: 30px;
  404. .searchTitle {
  405. padding-bottom: 10px;
  406. font-family: Microsoft YaHei, Microsoft YaHei;
  407. font-weight: 400;
  408. font-size: 14px;
  409. color: #999999;
  410. line-height: 16px;
  411. }
  412. .el-select {
  413. // width: 300px;
  414. display: inline-block;
  415. position: relative;
  416. }
  417. }
  418. .btnList {
  419. float: right;
  420. padding-top: 28px;
  421. button {
  422. // width: 120px;
  423. height: 38px;
  424. border: none;
  425. border-radius: 8px;
  426. padding: 0 20px;
  427. }
  428. .search {
  429. background-color: #5570f1;
  430. color: #fff;
  431. margin-right: 20px;
  432. }
  433. .reset {
  434. font-family: Microsoft YaHei, Microsoft YaHei;
  435. font-weight: 400;
  436. font-size: 16px;
  437. color: #333333;
  438. background: #F5F7FB;
  439. border-radius: 8px 8px 8px 8px;
  440. border: 1px solid rgba(85, 112, 241, 0.11);
  441. }
  442. }
  443. }
  444. .layerBox {
  445. padding: 30px 20px;
  446. position: relative;
  447. .btnList {
  448. position: absolute;
  449. top: 30px;
  450. right: 20px;
  451. height: 38px;
  452. >button {
  453. color: #fff;
  454. background-color: #5570f1;
  455. border: none;
  456. border-radius: 8px;
  457. padding: 8px 28px 9px;
  458. box-sizing: border-box;
  459. }
  460. >button:first-child {
  461. margin-right: 30px;
  462. }
  463. }
  464. .listBtnBox {
  465. justify-content: left;
  466. }
  467. .listDeleteBtn,
  468. .listEditBtn,
  469. .listLookBtn {
  470. margin-left: 0px;
  471. padding-left: 0px;
  472. margin-right: 20px;
  473. width: 76px;
  474. height: 36px;
  475. line-height: 36px;
  476. }
  477. .listLookBtn {
  478. text-align: center;
  479. border-radius: 8px;
  480. cursor: pointer;
  481. color: #999999;
  482. background-color: rgba(153, 153, 153, 0.16);
  483. >i {
  484. padding-right: 8px;
  485. }
  486. }
  487. }
  488. // 弹出层内容
  489. .dialogText {
  490. margin: 0 7px 0 3px;
  491. padding-top: 20px;
  492. padding-bottom: 1px;
  493. padding: 20px 60px 1px 20px;
  494. background-color: #f5f7fb;
  495. }
  496. // 弹出层按钮
  497. .dialogBtn {
  498. text-align: center;
  499. margin: 50px auto 20px;
  500. button {
  501. width: 184px;
  502. padding: 16px;
  503. font-family: Microsoft YaHei, Microsoft YaHei;
  504. font-weight: 400;
  505. font-size: 20px;
  506. border: none;
  507. border-radius: 12px 12px 12px 12px;
  508. }
  509. // 取消
  510. .cancel {
  511. color: #333333;
  512. background-color: #f5f7fb;
  513. border: 2px solid rgba(85, 112, 241, 0.11);
  514. }
  515. // 提交
  516. .submit {
  517. color: #fff;
  518. background-color: #5570F1;
  519. margin-left: 40px;
  520. }
  521. }
  522. ::v-deep .el-form-item {
  523. margin-bottom: 50px;
  524. }
  525. ::v-deep .el-select {
  526. width: 100%;
  527. }
  528. ::v-deep .el-input--medium,
  529. ::v-deep .el-form-item__label {
  530. line-height: 36px;
  531. font-size: 16px;
  532. }
  533. </style>