apiscope.vue 17 KB

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