apiscope.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. ref="crud"
  7. v-model="form"
  8. :permission="permissionList"
  9. :before-open="beforeOpen"
  10. @row-del="rowDel"
  11. @row-update="rowUpdate"
  12. @row-save="rowSave"
  13. @search-change="searchChange"
  14. @search-reset="searchReset"
  15. @selection-change="selectionChange"
  16. @current-change="currentChange"
  17. @size-change="sizeChange"
  18. @on-load="onLoad">
  19. <template slot-scope="{row}" slot="menu">
  20. <el-button type="text"
  21. icon="el-icon-setting"
  22. size="small"
  23. v-if="permission.api_scope_setting"
  24. plain
  25. class="none-border"
  26. @click.stop="handleDataScope(row)">权限配置
  27. </el-button>
  28. </template>
  29. <template slot-scope="{row}" slot="source">
  30. <div style="text-align:center">
  31. <i :class="row.source"></i>
  32. </div>
  33. </template>
  34. </avue-crud>
  35. <avue-drawer :title="`[${scopeMenuName}] 接口权限配置`" show-close :width="1000" v-model="drawerVisible"
  36. :before-close="handleDrawerClose">
  37. <avue-crud :option="optionScope"
  38. :data="dataScope"
  39. :page="pageScope"
  40. v-model="formScope"
  41. ref="crudScope"
  42. @row-del="rowDelScope"
  43. @row-update="rowUpdateScope"
  44. @row-save="rowSaveScope"
  45. :before-open="beforeOpenScope"
  46. @search-change="searchChangeScope"
  47. @search-reset="searchResetScope"
  48. @selection-change="selectionChangeScope"
  49. @current-change="currentChangeScope"
  50. @size-change="sizeChangeScope"
  51. @on-load="onLoadScope">
  52. <template slot="menuLeft">
  53. <el-button type="danger"
  54. size="small"
  55. icon="el-icon-delete"
  56. plain
  57. @click="handleDeleteScope">删 除
  58. </el-button>
  59. </template>
  60. <template slot-scope="{row}"
  61. slot="scopeType">
  62. <el-tag>{{row.scopeTypeName}}</el-tag>
  63. </template>
  64. </avue-crud>
  65. </avue-drawer>
  66. </basic-container>
  67. </template>
  68. <script>
  69. import {
  70. add,
  71. remove,
  72. update,
  73. getMenuList,
  74. getMenu
  75. } from "@/api/system/menu";
  76. import {
  77. addApiScope,
  78. removeApiScope,
  79. updateApiScope,
  80. getListApiScope,
  81. getMenuApiScope
  82. } from "@/api/system/scope";
  83. import {mapGetters} from "vuex";
  84. import iconList from "@/config/iconList";
  85. export default {
  86. data() {
  87. return {
  88. form: {},
  89. selectionList: [],
  90. query: {},
  91. loading: true,
  92. page: {
  93. pageSize: 10,
  94. currentPage: 1,
  95. total: 0
  96. },
  97. drawerVisible: false,
  98. scopeMenuId: 0,
  99. scopeMenuName: "菜单",
  100. menu: true,
  101. option: {
  102. tip: false,
  103. dialogWidth: "60%",
  104. tree: true,
  105. border: true,
  106. index: true,
  107. selection: true,
  108. viewBtn: false,
  109. editBtn: false,
  110. addBtn: false,
  111. delBtn: false,
  112. menuWidth: 150,
  113. column: [
  114. {
  115. label: "菜单名称",
  116. prop: "name",
  117. search: true,
  118. rules: [
  119. {
  120. required: true,
  121. message: "请输入菜单名称",
  122. trigger: "blur"
  123. }
  124. ]
  125. },
  126. {
  127. label: "路由地址",
  128. prop: "path",
  129. rules: [
  130. {
  131. required: true,
  132. message: "请输入路由地址",
  133. trigger: "blur"
  134. }
  135. ]
  136. },
  137. {
  138. label: "上级菜单",
  139. prop: "parentId",
  140. type: "tree",
  141. dicUrl: "/api/blade-system/menu/tree",
  142. hide: true,
  143. props: {
  144. label: "title"
  145. },
  146. rules: [
  147. {
  148. required: false,
  149. message: "请选择上级菜单",
  150. trigger: "click"
  151. }
  152. ]
  153. },
  154. {
  155. label: "菜单图标",
  156. prop: "source",
  157. type: "icon-select",
  158. slot: true,
  159. width: 80,
  160. iconList: iconList,
  161. rules: [
  162. {
  163. required: true,
  164. message: "请输入菜单图标",
  165. trigger: "click"
  166. }
  167. ]
  168. },
  169. {
  170. label: "菜单编号",
  171. prop: "code",
  172. search: true,
  173. rules: [
  174. {
  175. required: true,
  176. message: "请输入菜单编号",
  177. trigger: "blur"
  178. }
  179. ]
  180. },
  181. {
  182. label: "菜单类型",
  183. prop: "category",
  184. type: "radio",
  185. dicData: [
  186. {
  187. label: "菜单",
  188. value: 1
  189. },
  190. {
  191. label: "按钮",
  192. value: 2
  193. }
  194. ],
  195. hide: true,
  196. rules: [
  197. {
  198. required: true,
  199. message: "请选择菜单类型",
  200. trigger: "blur"
  201. }
  202. ]
  203. },
  204. {
  205. label: "菜单别名",
  206. prop: "alias",
  207. rules: [
  208. {
  209. required: true,
  210. message: "请输入菜单别名",
  211. trigger: "blur"
  212. }
  213. ]
  214. },
  215. {
  216. label: "按钮功能",
  217. prop: "action",
  218. type: "radio",
  219. dicData: [
  220. {
  221. label: "工具栏",
  222. value: 0
  223. },
  224. {
  225. label: "操作栏",
  226. value: 1
  227. },
  228. {
  229. label: "工具操作栏",
  230. value: 2
  231. }
  232. ],
  233. hide: true,
  234. rules: [
  235. {
  236. required: true,
  237. message: "请选择按钮功能",
  238. trigger: "blur"
  239. }
  240. ]
  241. },
  242. {
  243. label: "菜单排序",
  244. prop: "sort",
  245. type: "number",
  246. width: 80,
  247. rules: [
  248. {
  249. required: true,
  250. message: "请输入菜单排序",
  251. trigger: "blur"
  252. }
  253. ]
  254. },
  255. {
  256. label: "新窗口",
  257. prop: "isOpen",
  258. type: "radio",
  259. dicData: [
  260. {
  261. label: "否",
  262. value: 0
  263. },
  264. {
  265. label: "是",
  266. value: 1
  267. },
  268. ],
  269. hide: true
  270. },
  271. {
  272. label: "菜单备注",
  273. prop: "remark",
  274. type: "textarea",
  275. span: 24,
  276. minRows: 6,
  277. hide: true
  278. }
  279. ]
  280. },
  281. data: [],
  282. formScope: {},
  283. selectionListScope: [],
  284. pageScope: {
  285. pageSize: 10,
  286. currentPage: 1,
  287. total: 0
  288. },
  289. optionScope: {
  290. tip: false,
  291. border: true,
  292. index: true,
  293. viewBtn: true,
  294. selection: true,
  295. menuWidth: 200,
  296. dialogWidth: 450,
  297. dialogHeight: 230,
  298. column: [
  299. {
  300. label: "权限名称",
  301. prop: "scopeName",
  302. search: true,
  303. rules: [{
  304. required: true,
  305. message: "请输入数据权限名称",
  306. trigger: "blur"
  307. }]
  308. },
  309. {
  310. label: "权限编号",
  311. prop: "resourceCode",
  312. search: true,
  313. width: 180,
  314. rules: [{
  315. required: true,
  316. message: "请输入数据权限编号",
  317. trigger: "blur"
  318. }]
  319. },
  320. {
  321. label: "权限路径",
  322. prop: "scopePath",
  323. width: 180,
  324. rules: [{
  325. required: true,
  326. message: "请输入数据权限编号",
  327. trigger: "blur"
  328. }]
  329. },
  330. {
  331. label: "接口类型",
  332. type: "select",
  333. dicUrl: "/api/blade-system/dict/dictionary?code=api_scope_type",
  334. props: {
  335. label: "dictValue",
  336. value: "dictKey"
  337. },
  338. slot: true,
  339. width: 100,
  340. prop: "scopeType",
  341. rules: [{
  342. required: true,
  343. message: "请输入通知类型",
  344. trigger: "blur"
  345. }]
  346. },
  347. {
  348. label: "备注",
  349. prop: "remark",
  350. span: 24,
  351. hide: true,
  352. },
  353. ]
  354. },
  355. dataScope: []
  356. };
  357. },
  358. computed: {
  359. ...mapGetters(["permission"]),
  360. permissionList() {
  361. return {
  362. addBtn: this.vaildData(this.permission.menu_add, false),
  363. viewBtn: this.vaildData(this.permission.menu_view, false),
  364. delBtn: this.vaildData(this.permission.menu_delete, false),
  365. editBtn: this.vaildData(this.permission.menu_edit, false)
  366. };
  367. },
  368. ids() {
  369. let ids = [];
  370. this.selectionList.forEach(ele => {
  371. ids.push(ele.id);
  372. });
  373. return ids.join(",");
  374. },
  375. scopeIds() {
  376. let ids = [];
  377. this.selectionListScope.forEach(ele => {
  378. ids.push(ele.id);
  379. });
  380. return ids.join(",");
  381. }
  382. },
  383. methods: {
  384. // 菜单管理模块
  385. rowSave(row, loading, done) {
  386. add(row).then(() => {
  387. loading();
  388. this.onLoad(this.page);
  389. this.$message({
  390. type: "success",
  391. message: "操作成功!"
  392. });
  393. }, error => {
  394. done();
  395. console.log(error);
  396. });
  397. },
  398. rowUpdate(row, index, loading, done) {
  399. update(row).then(() => {
  400. loading();
  401. this.onLoad(this.page);
  402. this.$message({
  403. type: "success",
  404. message: "操作成功!"
  405. });
  406. }, error => {
  407. done();
  408. console.log(error);
  409. });
  410. },
  411. rowDel(row) {
  412. this.$confirm("确定将选择数据删除?", {
  413. confirmButtonText: "确定",
  414. cancelButtonText: "取消",
  415. type: "warning"
  416. })
  417. .then(() => {
  418. return remove(row.id);
  419. })
  420. .then(() => {
  421. this.onLoad(this.page);
  422. this.$message({
  423. type: "success",
  424. message: "操作成功!"
  425. });
  426. });
  427. },
  428. searchReset() {
  429. this.query = {};
  430. this.onLoad(this.page);
  431. },
  432. searchChange(params) {
  433. this.query = params;
  434. this.onLoad(this.page, params);
  435. },
  436. selectionChange(list) {
  437. this.selectionList = list;
  438. },
  439. selectionClear() {
  440. this.selectionList = [];
  441. this.$refs.crud.toggleSelection();
  442. },
  443. handleDelete() {
  444. if (this.selectionList.length === 0) {
  445. this.$message.warning("请选择至少一条数据");
  446. return;
  447. }
  448. this.$confirm("确定将选择数据删除?", {
  449. confirmButtonText: "确定",
  450. cancelButtonText: "取消",
  451. type: "warning"
  452. })
  453. .then(() => {
  454. return remove(this.ids);
  455. })
  456. .then(() => {
  457. this.onLoad(this.page);
  458. this.$message({
  459. type: "success",
  460. message: "操作成功!"
  461. });
  462. this.$refs.crud.toggleSelection();
  463. });
  464. },
  465. beforeOpen(done, type) {
  466. if (["edit", "view"].includes(type)) {
  467. getMenu(this.form.id).then(res => {
  468. this.form = res.data.data;
  469. });
  470. }
  471. done();
  472. },
  473. currentChange(currentPage) {
  474. this.page.currentPage = currentPage;
  475. },
  476. sizeChange(pageSize) {
  477. this.page.pageSize = pageSize;
  478. },
  479. onLoad(page, params = {}) {
  480. this.loading = true;
  481. getMenuList(page.currentPage, page.pageSize, params).then(res => {
  482. this.data = res.data.data;
  483. this.loading = false;
  484. this.selectionClear();
  485. });
  486. },
  487. // 数据权限模块
  488. handleDataScope(row) {
  489. this.drawerVisible = true;
  490. this.scopeMenuId = row.id;
  491. this.scopeMenuName = row.name;
  492. },
  493. handleDrawerClose(hide) {
  494. hide();
  495. },
  496. rowSaveScope(row, loading, done) {
  497. row = {
  498. ...row,
  499. menuId: this.scopeMenuId,
  500. }
  501. addApiScope(row).then(() => {
  502. loading();
  503. this.onLoadScope(this.pageScope);
  504. this.$message({
  505. type: "success",
  506. message: "操作成功!"
  507. });
  508. }, error => {
  509. done();
  510. console.log(error);
  511. });
  512. },
  513. rowUpdateScope(row, index, loading, done) {
  514. row = {
  515. ...row,
  516. menuId: this.scopeMenuId,
  517. }
  518. updateApiScope(row).then(() => {
  519. loading();
  520. this.onLoadScope(this.pageScope);
  521. this.$message({
  522. type: "success",
  523. message: "操作成功!"
  524. });
  525. }, error => {
  526. done();
  527. console.log(error);
  528. });
  529. },
  530. rowDelScope(row) {
  531. this.$confirm("确定将选择数据删除?", {
  532. confirmButtonText: "确定",
  533. cancelButtonText: "取消",
  534. type: "warning"
  535. })
  536. .then(() => {
  537. return removeApiScope(row.id);
  538. })
  539. .then(() => {
  540. this.onLoadScope(this.pageScope);
  541. this.$message({
  542. type: "success",
  543. message: "操作成功!"
  544. });
  545. });
  546. },
  547. handleDeleteScope() {
  548. if (this.selectionListScope.length === 0) {
  549. this.$message.warning("请选择至少一条数据");
  550. return;
  551. }
  552. this.$confirm("确定将选择数据删除?", {
  553. confirmButtonText: "确定",
  554. cancelButtonText: "取消",
  555. type: "warning"
  556. })
  557. .then(() => {
  558. return removeApiScope(this.scopeIds);
  559. })
  560. .then(() => {
  561. this.onLoadScope(this.pageScope);
  562. this.$message({
  563. type: "success",
  564. message: "操作成功!"
  565. });
  566. this.$refs.crudScope.toggleSelection();
  567. });
  568. },
  569. beforeOpenScope(done, type) {
  570. if (["edit", "view"].includes(type)) {
  571. getMenuApiScope(this.formScope.id).then(res => {
  572. this.formScope = res.data.data;
  573. });
  574. }
  575. done();
  576. },
  577. searchResetScope() {
  578. this.onLoadScope(this.pageScope);
  579. },
  580. searchChangeScope(params) {
  581. this.onLoadScope(this.pageScope, params);
  582. },
  583. selectionChangeScope(list) {
  584. this.selectionListScope = list;
  585. },
  586. currentChangeScope(currentPage) {
  587. this.pageScope.currentPage = currentPage;
  588. },
  589. sizeChangeScope(pageSize) {
  590. this.pageScope.pageSize = pageSize;
  591. },
  592. onLoadScope(page, params = {}) {
  593. const values = {
  594. ...params,
  595. menuId: this.scopeMenuId,
  596. }
  597. getListApiScope(page.currentPage, page.pageSize, Object.assign(values, this.query)).then(res => {
  598. const data = res.data.data;
  599. this.pageScope.total = data.total;
  600. this.dataScope = data.records;
  601. this.selectionListScope = [];
  602. });
  603. },
  604. }
  605. };
  606. </script>
  607. <style>
  608. .none-border {
  609. border: 0;
  610. background-color: transparent !important;
  611. }
  612. </style>