datascope.vue 20 KB

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