routerList.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. <template>
  2. <!-- 路由白名单位管理 -->
  3. <div>
  4. <!-- 头部搜索框部分 -->
  5. <div class="title">
  6. <el-row>
  7. <el-col :span="6" class="left">
  8. <div class="searchBox">
  9. <div class="searchTitle">网站名称</div>
  10. <el-select v-model="webSiteName_id" :multiple="false" :multiple-limit="1" filterable remote
  11. reserve-keyword placeholder="请输入网站名称" clearable :remote-method="getWebNavList"
  12. :loading="webSiteLoading" @change="selectWebSite">
  13. <el-option v-for="item in webSiteList" :key="item.id" :label="item.title"
  14. :value="item.id">
  15. </el-option>
  16. </el-select>
  17. </div>
  18. </el-col>
  19. <el-col :span="6" class="left">
  20. <div class="searchBox">
  21. <div class="searchTitle">所属功能</div>
  22. <el-input v-model="function_name" class="input" clearable placeholder="请输入所属功能"></el-input>
  23. </div>
  24. </el-col>
  25. <el-col :span="8" class="right">
  26. <div class="btnList">
  27. <button class="search" @click="goSearch">搜索</button>
  28. <button class="reset" @click="goReset">重置</button>
  29. </div>
  30. </el-col>
  31. </el-row>
  32. </div>
  33. <!--表格内容 start------------------------------------------------------------>
  34. <div class="layerBox">
  35. <tableTitle :name="tableDivTitle" />
  36. <button class="btn" @click="addWhiteRouter">添加路由</button>
  37. <el-row>
  38. <template>
  39. <el-table class="my-table" v-loading="loading" :data="tableData" style="width: 100%">
  40. <el-table-column fixed prop="id" label="编号" width="90">
  41. </el-table-column>
  42. <el-table-column prop="website_names" label="所属网站">
  43. <template slot-scope="scope">
  44. <div class="titleWidth">{{scope.row.website_names.join('、')}}</div>
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="router_url" label="路由路径" width="110">
  48. </el-table-column>
  49. <el-table-column prop="function_name" label="所属功能" width="110">
  50. </el-table-column>
  51. <el-table-column fixed="right" label="操作" width="200" align="center">
  52. <template slot-scope="scope">
  53. <div class="listBtnBox">
  54. <div class="listEditBtn" @click="goEdit(scope.row.id, scope.row)"><i
  55. class="el-icon-edit-outline"></i>编辑</div>
  56. <div class="listDeleteBtn" @click="deleteRow(scope.row.id, tableData)"><i
  57. class="el-icon-delete"></i>删除</div>
  58. </div>
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. </template>
  63. </el-row>
  64. </div>
  65. <!--分页 start------------------------------------------------------------>
  66. <div class="alignBox">
  67. <el-row>
  68. <el-col :span="24">
  69. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
  70. :current-page="page" :page-size="pageSize" layout="total, prev, pager, next, jumper"
  71. :total="total">
  72. </el-pagination>
  73. </el-col>
  74. </el-row>
  75. </div>
  76. <!--分页 end------------------------------------------------------------>
  77. <!--表格内容 end------------------------------------------------------------>
  78. <!-- 弹出框 编辑 start----------------------------------------------------------->
  79. <el-dialog :title="dialogName" :visible.sync="dialogTableVisible" width="50%" top="8vh"
  80. :close-on-click-modal="false">
  81. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
  82. <div class="dialogText">
  83. <el-form-item label="网站名称:" prop="website_id">
  84. <el-cascader
  85. :filter-method="getWebNavList"
  86. v-model="ruleForm.website_id"
  87. placeholder="请输入网站名称"
  88. :options="webSiteList"
  89. :props="props"
  90. clearable
  91. filterable
  92. collapse-tags>
  93. </el-cascader>
  94. </el-form-item>
  95. <el-form-item label="所属功能:" prop="function_name">
  96. <el-input v-model="ruleForm.function_name" placeholder="请输入所属功能"></el-input>
  97. </el-form-item>
  98. <el-form-item label="路由地址:" prop="router_url">
  99. <el-input v-model="ruleForm.router_url" placeholder="例如:/xiangcunshangcheng"></el-input>
  100. </el-form-item>
  101. </div>
  102. <div class="dialogBtn">
  103. <el-button type="info" @click="cancelForm">取消</el-button>
  104. <el-button type="primary" @click="submitForm">提交</el-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 { getWhiteRouterList,delWhiteRouter,addWhiteRouter,upWhiteRouter } from '@/api/router'
  117. export default {
  118. components: {
  119. tableTitle,//表格标题-
  120. },
  121. data() {
  122. const validateEmpty = (rule, value, callback) => {
  123. if (value.length == 0) {
  124. callback(new Error('该项不能为空!'))
  125. } else {
  126. callback()
  127. }
  128. }
  129. return {
  130. props:{
  131. multiple: true,
  132. label:"website_name",
  133. value:"id"
  134. },
  135. tableDivTitle: "路由白名单", //列表标题
  136. dialogTableVisible: false, //编辑弹框
  137. dialogName: '编辑', //编辑弹窗名称
  138. loading: true, //加载中
  139. tableData: [],//表格数据
  140. // 可以输入的搜索框相关
  141. webSiteList: [],//获取关联网站列表
  142. webSiteLoading: false,
  143. value: '',
  144. // 分页相关
  145. page: 1,
  146. pageSize: 10,
  147. total: 0,
  148. // 搜索框相关
  149. webSiteName_id: '', //网站名称id
  150. function_name: '', //所属功能
  151. website_id: [], //网站id
  152. id:"", //当前编辑的id
  153. ruleForm: {
  154. website_id: '', //网站名称
  155. function_name: '', //路由白名单位名称
  156. router_url: '', //路由白名单位标识
  157. },
  158. rules: {
  159. website_id: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  160. function_name: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  161. router_url: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  162. }
  163. }
  164. },
  165. methods: {
  166. //1.列表和分页相关 start ------------------------------------------------------------>
  167. //1.1 开始请求列表信息方法
  168. getData() {
  169. getWhiteRouterList({
  170. page: this.page,
  171. pageSize: this.pageSize,
  172. name: this.function_name,
  173. website_id: this.webSiteName_id, //路由白名单位名称 id
  174. }).then(data => {
  175. this.loading=false;
  176. console.log("返回数据",data);
  177. this.tableData = data.data.rows
  178. this.total = data.data.count
  179. })
  180. },
  181. //1.2 删除内容
  182. deleteRow(id) {
  183. let data = new FormData()
  184. data.append('id', id)
  185. this.$confirm('注意:删除后,该条信息及其绑定关系全部删除', '是否确认删除该条信息?', {
  186. confirmButtonText: '确定',
  187. cancelButtonText: '取消',
  188. }).then(() => {
  189. console.log("当前删除:" + id)
  190. delWhiteRouter({
  191. id: id
  192. }).then(data => {
  193. console.log(data);
  194. if (data.code = 200) {
  195. this.$message({
  196. message: '删除成功',
  197. type: 'success'
  198. })
  199. this.getData()
  200. } else if (data.code == 0) {
  201. this.$message({
  202. message: data.message,
  203. type: 'error'
  204. })
  205. }
  206. })
  207. }).catch(() => {
  208. this.$message({
  209. type: 'warning',
  210. message: '已取消删除'
  211. });
  212. });
  213. },
  214. //1.4 列表内容分页
  215. //直接跳转
  216. handleSizeChange(val) {
  217. this.page = val;
  218. this.getData();
  219. },
  220. //1.5 点击分页
  221. handleCurrentChange(val) {
  222. this.page = val;
  223. this.getData();
  224. },
  225. // 1.6 搜索按钮
  226. goSearch() {
  227. getWhiteRouterList({
  228. page: this.page,
  229. pageSize: this.pageSize,
  230. function_name: this.function_name,
  231. website_id: this.webSiteName_id, //路由白名单位名称 id
  232. }).then(data => {
  233. console.log(data);
  234. this.tableData = data.data.rows
  235. this.total = data.data.count
  236. })
  237. },
  238. //1.7 重置按钮
  239. goReset() {
  240. this.webSiteName_id = ""
  241. this.function_name = ""
  242. this.getData()
  243. },
  244. //列表和分页相关 end ------------------------------------------------------------>
  245. //1.8 编辑
  246. goEdit(id, val) {
  247. // console.log(id);
  248. this.dialogName = '编辑'
  249. this.id = id
  250. this.dialogTableVisible = true
  251. console.log(id, val);
  252. // console.log("状态", val.status);
  253. //数据回显
  254. this.ruleForm.website_id = val.website_id //网站id
  255. this.ruleForm.function_name = val.function_name //功能名称
  256. this.ruleForm.router_url = val.router_url //路由地址
  257. },
  258. //2.0 添加
  259. addWhiteRouter() {
  260. this.dialogTableVisible = true
  261. this.dialogName = "添加"
  262. //添加时清空回显回来的数据
  263. this.ruleForm.website_id = '' //网站id
  264. this.ruleForm.function_name = '' //功能名称
  265. this.ruleForm.router_url = '' //路由地址
  266. },
  267. // 2.1 弹出层相关方法
  268. // 提交表单
  269. submitForm() {
  270. // 判断用户是否输入数据
  271. if (this.dialogName == "添加") {
  272. this.$refs.ruleForm.validate(valid => {
  273. if (valid) {
  274. // Flatten the website_id array
  275. const flattenedWebsiteId = this.ruleForm.website_id.flat();
  276. addWhiteRouter({
  277. website_id: flattenedWebsiteId,
  278. function_name: this.ruleForm.function_name,
  279. router_url: this.ruleForm.router_url,
  280. }).then(data => {
  281. console.log(data);
  282. if (data.code == 200) {
  283. this.$message({
  284. message: '添加成功',
  285. type: 'success'
  286. })
  287. this.dialogTableVisible = false
  288. this.getData()
  289. } else {
  290. this.$message({
  291. message: data.message,
  292. type: 'error'
  293. })
  294. this.dialogTableVisible = true
  295. return
  296. }
  297. })
  298. }
  299. })
  300. }
  301. if (this.dialogName == "编辑") {
  302. // Flatten the website_id array
  303. this.$refs.ruleForm.validate(valid => {
  304. if (valid) {
  305. const flattenedWebsiteId = this.ruleForm.website_id.flat();
  306. upWhiteRouter({
  307. website_id: flattenedWebsiteId,
  308. function_name: this.ruleForm.function_name,
  309. router_url: this.ruleForm.router_url,
  310. id: this.id
  311. }).then(data => {
  312. console.log(data);
  313. if (data.code == 200) {
  314. this.$message({
  315. message: '编辑成功',
  316. type: 'success'
  317. })
  318. this.dialogTableVisible = false
  319. }else {
  320. this.$message({
  321. message: data.message,
  322. type: 'error'
  323. })
  324. this.dialogTableVisible = true
  325. }
  326. this.getData()
  327. })
  328. }
  329. })
  330. }
  331. },
  332. //取消添加或编辑
  333. cancelForm() {
  334. this.dialogTableVisible = false
  335. },
  336. //搜索部分的输入关键词下拉框
  337. selectWebSite(value) {
  338. this.webSiteName_id = value
  339. },
  340. //添加 / 编辑弹窗中输入关键词下拉框
  341. // 判断是否已经关联了网站
  342. detectionWebSite(value) {
  343. console.log(value);
  344. this.website_id = value
  345. console.log(this.website_id);
  346. },
  347. //
  348. getWebNavList(query) {
  349. if (query !== '') {
  350. this.webSiteLoading = true;
  351. let data = { keyword: query }
  352. let dataArr = [];
  353. this.$store.dispatch('pool/getNavWebList', data).then(res => {
  354. this.webSiteList = res.data;
  355. this.webSiteLoading = false;
  356. }).catch(() => {
  357. this.$message({
  358. type: 'info',
  359. message: '网络错误,请重试!'
  360. });
  361. })
  362. } else {
  363. this.navList = [];
  364. }
  365. },
  366. },
  367. mounted() {
  368. this.getData(),
  369. this.getWebNavList();
  370. },
  371. }
  372. </script>
  373. <style scoped lang="less">
  374. input[aria-hidden=true] {
  375. display: none !important;
  376. }
  377. // 提示信息
  378. .tips {
  379. margin: 30px;
  380. background-color: #e9ecf9;
  381. border-radius: 11px;
  382. .tipsIcon {
  383. margin: 10px 15px;
  384. display: inline-block;
  385. width: 24px;
  386. height: 24px;
  387. background: url("../../assets/advertise/Info Circle.png") no-repeat;
  388. vertical-align: middle;
  389. }
  390. .tipsText {
  391. font-size: 14px;
  392. color: #666666;
  393. }
  394. }
  395. // 头部
  396. .title {
  397. margin: 30px 30px 20px 30px;
  398. padding: 30px 30px 40px 30px;
  399. background-color: #fff;
  400. border-radius: 20px 20px 20px 20px;
  401. border: 1px solid #E9EDF7;
  402. .left {
  403. float: left;
  404. }
  405. .right {
  406. float: right;
  407. }
  408. .searchBox {
  409. ::v-deep .el-input {
  410. position: relative;
  411. font-size: 14px;
  412. display: inline-block;
  413. width: 80%;
  414. }
  415. .searchTitle {
  416. padding-bottom: 10px;
  417. font-family: Microsoft YaHei, Microsoft YaHei;
  418. font-weight: 400;
  419. font-size: 14px;
  420. color: #999999;
  421. line-height: 16px;
  422. }
  423. .el-select {
  424. width: 100%;
  425. display: inline-block;
  426. position: relative;
  427. }
  428. }
  429. .btnList {
  430. float: right;
  431. padding-top: 28px;
  432. button {
  433. height: 38px;
  434. border: none;
  435. border-radius: 8px;
  436. padding: 0 30px;
  437. }
  438. .search {
  439. background-color: #5570f1;
  440. color: #fff;
  441. margin-right: 20px;
  442. }
  443. .reset {
  444. font-family: Microsoft YaHei, Microsoft YaHei;
  445. font-weight: 400;
  446. font-size: 16px;
  447. color: #333333;
  448. background: #F5F7FB;
  449. border-radius: 8px 8px 8px 8px;
  450. border: 1px solid rgba(85, 112, 241, 0.11);
  451. }
  452. }
  453. }
  454. .layerBox {
  455. padding: 30px 20px;
  456. position: relative;
  457. .btn {
  458. position: absolute;
  459. top: 30px;
  460. right: 20px;
  461. height: 38px;
  462. color: #fff;
  463. background-color: #5570f1;
  464. border: none;
  465. border-radius: 8px;
  466. padding: 8px 28px 9px;
  467. box-sizing: border-box;
  468. }
  469. .listBtnBox {
  470. justify-content: left;
  471. }
  472. .listDeleteBtn,
  473. .listEditBtn,
  474. .listLookBtn {
  475. margin-left: 0px;
  476. padding-left: 0px;
  477. margin-right: 20px;
  478. width: 76px;
  479. height: 36px;
  480. line-height: 36px;
  481. }
  482. .listLookBtn {
  483. text-align: center;
  484. border-radius: 8px;
  485. cursor: pointer;
  486. color: #55b5f1;
  487. background-color: rgba(85, 181, 241, 0.16);
  488. >i {
  489. padding-right: 8px;
  490. }
  491. }
  492. ::v-deep .el-form-item {
  493. margin-bottom: 50px;
  494. }
  495. ::v-deep .el-select {
  496. width: 100%;
  497. }
  498. ::v-deep .el-input--medium,
  499. ::v-deep .el-form-item__label {
  500. line-height: 36px;
  501. font-size: 16px;
  502. }
  503. }
  504. // 弹出层内容
  505. .dialogText {
  506. margin: 0 7px 0 3px;
  507. padding-bottom: 1px;
  508. padding: 30px 60px 1px 20px;
  509. background-color: #f5f7fb;
  510. .adImage {
  511. width: 140px;
  512. height: 140px;
  513. line-height: 210px;
  514. border-radius: 12px;
  515. border: 1px solid rgba(85, 112, 241, 0.11);
  516. img {
  517. width: 140px;
  518. height: 80px;
  519. }
  520. }
  521. ::v-deep .avatar {
  522. width: 140px;
  523. height: auto;
  524. }
  525. .price {
  526. ::v-deep .el-input {
  527. width: 29%;
  528. }
  529. }
  530. .example {
  531. font-family: Microsoft YaHei;
  532. color: #5570F1;
  533. }
  534. .el_btnList {
  535. margin-right: 15px;
  536. margin-top: 20px;
  537. }
  538. //日期时间选择器的宽
  539. ::v-deep .el-date-editor.el-input {
  540. width: 48%;
  541. }
  542. ::v-deep .el-button+.el-button {
  543. margin-left: 0px;
  544. }
  545. ::v-deep .el-select {
  546. width: 100%;
  547. }
  548. ::v-deep .el-form-item {
  549. margin-bottom: 50px;
  550. }
  551. }
  552. // 弹出层按钮
  553. .dialogBtn {
  554. text-align: center;
  555. margin: 50px auto 20px;
  556. button {
  557. width: 184px;
  558. padding: 16px;
  559. font-family: Microsoft YaHei, Microsoft YaHei;
  560. font-weight: 400;
  561. font-size: 20px;
  562. border: none;
  563. border-radius: 12px 12px 12px 12px;
  564. }
  565. // 取消
  566. .cancel {
  567. color: #333333;
  568. background-color: #f5f7fb;
  569. border: 2px solid rgba(85, 112, 241, 0.11);
  570. }
  571. // 提交
  572. .submit {
  573. color: #fff;
  574. background-color: #5570F1;
  575. margin-left: 40px;
  576. }
  577. }
  578. //审核弹出框
  579. .radioGroup {
  580. ::v-deep .el-form-item {
  581. margin-top: 40px;
  582. margin-bottom: 0;
  583. }
  584. }
  585. .graph {
  586. background-color: #f5f7fb;
  587. padding: 60px 100px;
  588. overflow: hidden;
  589. li {
  590. float: left;
  591. }
  592. >li:first-child {
  593. margin-right: 100px;
  594. }
  595. }
  596. .dialog-footer {
  597. margin: 0 auto;
  598. }
  599. .titleWidth {
  600. width: 400px;
  601. white-space: nowrap;
  602. overflow: hidden;
  603. text-overflow: ellipsis;
  604. }
  605. ::v-deep.el-cascader{
  606. width: 100%;
  607. }
  608. </style>