fz-index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. <template>
  2. <div class="app-container">
  3. <el-row class="roleBox">
  4. <el-col :span="24" class="roleCol">
  5. <div class="roleH"></div>
  6. <span>功能权限</span>
  7. </el-col>
  8. <el-col :span="24" class="roleBot">
  9. <el-row :gutter="10">
  10. <el-col :span="1.5">
  11. <el-button type="primary" style="background-color: #2AC1CA;color: #fff;border: none;" plain icon="el-icon-plus"
  12. @click="handleAdd" v-hasPermi="['system:role:add']">新增</el-button>
  13. </el-col>
  14. <el-col :span="1.5">
  15. <el-button type="primary" style="background-color: #FF9639;color: #fff;border: none;" plain icon="el-icon-refresh"
  16. @click="refreshFn" v-hasPermi="['system:role:list']">刷新</el-button>
  17. </el-col>
  18. <el-col :span="1.5">
  19. <el-button type="primary" style="background-color: #3C8DBC;color: #fff;border: none;" plain icon="el-icon-my-export"
  20. @click="handleMenu" v-hasPermi="['system:role:edit']">保存</el-button>
  21. </el-col>
  22. </el-row>
  23. </el-col>
  24. </el-row>
  25. <el-row class="roleCont" style="margin-top: 18px;">
  26. <el-col :span="5" class="searBoxs">
  27. <div class="searBox">
  28. <div class="searInput">
  29. <input type="text" v-model="queryParams.roleName" placeholder="请输入角色">
  30. </div>
  31. <div class="searBtn">
  32. <img src="@/assets/images/icon_sr_ss@2x.png" @click="handleQuery" alt="" class="icon">
  33. </div>
  34. </div>
  35. <div class="searList">
  36. <div class="searItem searItemLeft" v-for="item in roleList"
  37. @click="searBtnFn(item)" :class="{'active': item.id == roleId}" :key="item.id">
  38. <span>
  39. {{item.roleName}}
  40. </span>
  41. <i class="el-icon-delete" @click.stop="handleDelete(item)" v-if="item.id == roleId"></i>
  42. </div>
  43. </div>
  44. <pagination sty v-show="total>0" :total="total" layout="prev, pager, next" :page.sync="queryParams.pageNum"
  45. :limit.sync="queryParams.pageSize" />
  46. </el-col>
  47. <el-col :span="19" class="roleContr">
  48. <div class="roleContrBox">
  49. <el-col :span="7" style="height: 100%;">
  50. <div class="searContLeft">
  51. <el-tree class="tree-border" @node-click="qxList" :data="deptOptions"
  52. default-expand-all ref="dept" node-key="id" :props="defaultProps"></el-tree>
  53. </div>
  54. </el-col>
  55. <el-col :span="17">
  56. <div class="searContRight">
  57. <div class="searTitle">
  58. <div class="searName">
  59. 功能
  60. </div>
  61. <div class="searItem" v-for="item in menusList.heads" :key="item">
  62. {{item.name}}
  63. </div>
  64. </div>
  65. <div class="searCont" v-if="menusList.sysMenus.length" v-for="items in menusList.sysMenus" @click="searIndex = items.id"
  66. :class="{'active': searIndex == items.id}" :key="items.id">
  67. <div class="searName">
  68. {{items.menuName}}
  69. </div>
  70. <div class="searItem" v-for="(itemChild,indexChild) in items.containsHead" :key="indexChild">
  71. <el-checkbox @change="checkChange" :disabled="itemChild.type==='0'" v-model="itemChild.type"></el-checkbox>
  72. </div>
  73. </div>
  74. </div>
  75. </el-col>
  76. </div>
  77. </el-col>
  78. </el-row>
  79. <!-- 添加或修改角色配置对话框 -->
  80. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  81. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  82. <el-form-item label="角色名称" prop="roleName">
  83. <el-input v-model="form.roleName" placeholder="请输入角色名称" />
  84. </el-form-item>
  85. <el-form-item label="权限字符" prop="roleKey">
  86. <el-input v-model="form.roleKey" placeholder="请输入权限字符" />
  87. </el-form-item>
  88. <el-form-item label="角色顺序" prop="roleSort">
  89. <el-input-number v-model="form.roleSort" controls-position="right" :min="0" />
  90. </el-form-item>
  91. <el-form-item label="备注">
  92. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  93. </el-form-item>
  94. </el-form>
  95. <div slot="footer" class="dialog-footer">
  96. <el-button type="primary" @click="submitForm">确 定</el-button>
  97. <el-button @click="cancel">取 消</el-button>
  98. </div>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script>
  103. import {
  104. listRole,
  105. getRole,
  106. delRole,
  107. addRole,
  108. updateRole,
  109. exportRole,
  110. dataScope,
  111. setMenu,
  112. changeRoleStatus
  113. } from "@/api/system/role";
  114. import {
  115. treeselect as menuTreeselect,
  116. listMenus,
  117. treeMenuNotAddLeafNode
  118. } from "@/api/system/menu";
  119. import {
  120. treeselect as deptTreeselect,
  121. roleDeptTreeselect
  122. } from "@/api/system/dept";
  123. export default {
  124. name: "Role",
  125. inject: ['reload'],
  126. data() {
  127. return {
  128. modifyStatus: false,
  129. searIndex: '',
  130. data: [],
  131. defaultProps: {
  132. children: 'children',
  133. label: 'menuName'
  134. },
  135. indexs: 3,
  136. menusList: '',
  137. // 遮罩层
  138. loading: true,
  139. // 选中数组
  140. ids: [],
  141. // 非单个禁用
  142. single: true,
  143. // 非多个禁用
  144. multiple: true,
  145. // 显示搜索条件
  146. showSearch: true,
  147. // 总条数
  148. total: 0,
  149. // 角色表格数据
  150. roleList: [],
  151. // 弹出层标题
  152. title: "",
  153. // 是否显示弹出层
  154. open: false,
  155. // 是否显示弹出层(数据权限)
  156. openDataScope: false,
  157. menuExpand: false,
  158. menuNodeAll: false,
  159. deptExpand: true,
  160. deptNodeAll: false,
  161. // 日期范围
  162. dateRange: [],
  163. // 状态数据字典
  164. statusOptions: [],
  165. // 数据范围选项
  166. dataScopeOptions: [{
  167. value: "1",
  168. label: "全部数据权限"
  169. },
  170. {
  171. value: "2",
  172. label: "自定数据权限"
  173. },
  174. {
  175. value: "3",
  176. label: "本部门数据权限"
  177. },
  178. {
  179. value: "4",
  180. label: "本部门及以下数据权限"
  181. },
  182. {
  183. value: "5",
  184. label: "仅本人数据权限"
  185. }
  186. ],
  187. // 菜单列表
  188. menuOptions: [],
  189. // 部门列表
  190. deptOptions: [],
  191. // 查询参数
  192. queryParams: {
  193. pageNum: 1,
  194. pageSize: 10,
  195. roleName: undefined,
  196. roleKey: undefined,
  197. status: undefined
  198. },
  199. roleId: '',
  200. // 表单参数
  201. form: {},
  202. // 表单校验
  203. rules: {
  204. roleName: [{
  205. required: true,
  206. message: "角色名称不能为空",
  207. trigger: "blur"
  208. }],
  209. roleKey: [{
  210. required: true,
  211. message: "权限字符不能为空",
  212. trigger: "blur"
  213. }],
  214. roleSort: [{
  215. required: true,
  216. message: "角色顺序不能为空",
  217. trigger: "blur"
  218. }]
  219. }
  220. };
  221. },
  222. created() {
  223. this.getList();
  224. this.getDicts("sys_normal_disable").then(response => {
  225. this.statusOptions = response.data;
  226. });
  227. },
  228. methods: {
  229. checkChange() {
  230. this.modifyStatus = true
  231. },
  232. handleMenu() {
  233. if (!this.modifyStatus) {
  234. this.msgInfo('没有修改的内容!')
  235. return
  236. }
  237. let data = []
  238. for (let item of this.menusList.sysMenus) {
  239. let obj = {}
  240. obj.roleId = this.roleId
  241. obj.menuId = item.id
  242. obj.head = []
  243. for (let itemChild of item.containsHead) {
  244. if (itemChild.type === true) {
  245. obj.head.push(itemChild.name)
  246. }
  247. }
  248. data.push(obj)
  249. }
  250. setMenu(JSON.stringify(data)).then(res => {
  251. this.msgSuccess('保存成功')
  252. this.modifyStatus = false
  253. })
  254. },
  255. qxList(e) {
  256. const _this = this
  257. if (this.modifyStatus) {
  258. this.$confirm('当前页面存在未保存内容,是否保存后切换?', "提醒", {
  259. confirmButtonText: "留下",
  260. cancelButtonText: "取消",
  261. type: "warning"
  262. }).then(function() {
  263. }).catch(function() {
  264. _this.modifyStatus = false
  265. _this.qxList(e)
  266. });
  267. return
  268. }
  269. this.menusList = {}
  270. listMenus(e.id,this.roleId).then(res => {
  271. let data = res.data
  272. this.menusList = data
  273. })
  274. },
  275. refreshFn() {
  276. // this.getList()
  277. this.reload()
  278. // this.deptOptions = []
  279. },
  280. searBtnFn(item) {
  281. this.roleId = item.id
  282. this.handleUpdate()
  283. },
  284. handleNodeClick() {
  285. console.log(221)
  286. },
  287. /** 查询角色列表 */
  288. getList() {
  289. this.loading = true;
  290. listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
  291. response => {
  292. this.roleList = response.rows;
  293. this.total = response.total;
  294. this.loading = false;
  295. }
  296. );
  297. },
  298. /** 查询菜单树结构 */
  299. getMenuTreeselect() {
  300. menuTreeselect().then(response => {
  301. this.menuOptions = response.data;
  302. });
  303. },
  304. /** 查询部门树结构 */
  305. getDeptTreeselect() {
  306. deptTreeselect().then(response => {
  307. this.deptOptions = response.data;
  308. });
  309. },
  310. // 所有菜单节点数据
  311. getMenuAllCheckedKeys() {
  312. // 目前被选中的菜单节点
  313. let checkedKeys = this.$refs.menu.getCheckedKeys();
  314. // 半选中的菜单节点
  315. let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
  316. checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  317. return checkedKeys;
  318. },
  319. // 所有部门节点数据
  320. getDeptAllCheckedKeys() {
  321. // 目前被选中的部门节点
  322. let checkedKeys = this.$refs.dept.getCheckedKeys();
  323. // 半选中的部门节点
  324. let halfCheckedKeys = this.$refs.dept.getHalfCheckedKeys();
  325. checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  326. return checkedKeys;
  327. },
  328. /** 根据角色ID查询菜单树结构 */
  329. getRoleMenuTreeselect(id) {
  330. return treeMenuNotAddLeafNode(id).then(response => {
  331. this.menuOptions = response.data;
  332. return response;
  333. });
  334. },
  335. /** 根据角色ID查询部门树结构 */
  336. getRoleDeptTreeselect(id) {
  337. return roleDeptTreeselect(id).then(response => {
  338. this.deptOptions = response.depts;
  339. return response;
  340. });
  341. },
  342. // 角色状态修改
  343. handleStatusChange(row) {
  344. let text = row.status === "0" ? "启用" : "停用";
  345. this.$confirm('确认要"' + text + '""' + row.roleName + '"角色吗?', "警告", {
  346. confirmButtonText: "确定",
  347. cancelButtonText: "取消",
  348. type: "warning"
  349. }).then(function() {
  350. return changeRoleStatus(row.id, row.status);
  351. }).then(() => {
  352. this.msgSuccess(text + "成功");
  353. }).catch(function() {
  354. row.status = row.status === "0" ? "1" : "0";
  355. });
  356. },
  357. // 取消按钮
  358. cancel() {
  359. this.open = false;
  360. this.reset();
  361. },
  362. // 取消按钮(数据权限)
  363. cancelDataScope() {
  364. this.openDataScope = false;
  365. this.reset();
  366. },
  367. // 表单重置
  368. reset() {
  369. if (this.$refs.menu != undefined) {
  370. this.$refs.menu.setCheckedKeys([]);
  371. }
  372. this.menuExpand = false,
  373. this.menuNodeAll = false,
  374. this.deptExpand = true,
  375. this.deptNodeAll = false,
  376. this.form = {
  377. id: undefined,
  378. roleName: undefined,
  379. roleKey: undefined,
  380. roleSort: 0,
  381. status: "0",
  382. menuIds: [],
  383. deptIds: [],
  384. menuCheckStrictly: true,
  385. deptCheckStrictly: true,
  386. remark: undefined
  387. };
  388. this.resetForm("form");
  389. },
  390. /** 搜索按钮操作 */
  391. handleQuery() {
  392. this.queryParams.pageNum = 1;
  393. this.getList();
  394. },
  395. /** 重置按钮操作 */
  396. resetQuery() {
  397. this.dateRange = [];
  398. this.resetForm("queryForm");
  399. this.handleQuery();
  400. },
  401. // 多选框选中数据
  402. handleSelectionChange(selection) {
  403. this.ids = selection.map(item => item.id)
  404. this.single = selection.length != 1
  405. this.multiple = !selection.length
  406. },
  407. // 树权限(展开/折叠)
  408. handleCheckedTreeExpand(value, type) {
  409. if (type == 'menu') {
  410. let treeList = this.menuOptions;
  411. for (let i = 0; i < treeList.length; i++) {
  412. this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
  413. }
  414. } else if (type == 'dept') {
  415. let treeList = this.deptOptions;
  416. for (let i = 0; i < treeList.length; i++) {
  417. this.$refs.dept.store.nodesMap[treeList[i].id].expanded = value;
  418. }
  419. }
  420. },
  421. // 树权限(全选/全不选)
  422. handleCheckedTreeNodeAll(value, type) {
  423. if (type == 'menu') {
  424. this.$refs.menu.setCheckedNodes(value ? this.menuOptions : []);
  425. } else if (type == 'dept') {
  426. this.$refs.dept.setCheckedNodes(value ? this.deptOptions : []);
  427. }
  428. },
  429. // 树权限(父子联动)
  430. handleCheckedTreeConnect(value, type) {
  431. if (type == 'menu') {
  432. this.form.menuCheckStrictly = value ? true : false;
  433. } else if (type == 'dept') {
  434. this.form.deptCheckStrictly = value ? true : false;
  435. }
  436. },
  437. /** 新增按钮操作 */
  438. handleAdd() {
  439. this.reset();
  440. this.getMenuTreeselect();
  441. this.open = true;
  442. this.title = "添加角色";
  443. },
  444. /** 修改按钮操作 */
  445. handleUpdate() {
  446. this.reset();
  447. const roleMenu = this.getRoleMenuTreeselect(this.roleId);
  448. roleMenu.then(res => {
  449. this.deptOptions = res.data
  450. });
  451. },
  452. /** 选择角色权限范围触发 */
  453. dataScopeSelectChange(value) {
  454. if (value !== '2') {
  455. this.$refs.dept.setCheckedKeys([]);
  456. }
  457. },
  458. /** 分配数据权限操作 */
  459. handleDataScope(row) {
  460. this.reset();
  461. const roleDeptTreeselect = this.getRoleDeptTreeselect(row.id);
  462. getRole(row.id).then(response => {
  463. this.form = response.data;
  464. this.openDataScope = true;
  465. this.$nextTick(() => {
  466. roleDeptTreeselect.then(res => {
  467. this.$refs.dept.setCheckedKeys(res.checkedKeys);
  468. });
  469. });
  470. this.title = "分配数据权限";
  471. });
  472. },
  473. /** 提交按钮 */
  474. submitForm: function() {
  475. this.$refs["form"].validate(valid => {
  476. if (valid) {
  477. if (this.form.id != undefined) {
  478. // this.form.menuIds = this.getMenuAllCheckedKeys();
  479. updateRole(this.form).then(response => {
  480. this.msgSuccess("修改成功");
  481. this.open = false;
  482. this.getList();
  483. });
  484. } else {
  485. // this.form.menuIds = this.getMenuAllCheckedKeys();
  486. addRole(this.form).then(response => {
  487. this.msgSuccess("新增成功");
  488. this.open = false;
  489. this.getList();
  490. });
  491. }
  492. }
  493. });
  494. },
  495. /** 提交按钮(数据权限) */
  496. submitDataScope: function() {
  497. if (this.form.id != undefined) {
  498. this.form.deptIds = this.getDeptAllCheckedKeys();
  499. dataScope(this.form).then(response => {
  500. this.msgSuccess("修改成功");
  501. this.openDataScope = false;
  502. this.getList();
  503. });
  504. }
  505. },
  506. /** 删除按钮操作 */
  507. handleDelete(row) {
  508. const ids = row.id || this.ids;
  509. this.$confirm('是否确认删除角色编号为"' + ids + '"的数据项?', "警告", {
  510. confirmButtonText: "确定",
  511. cancelButtonText: "取消",
  512. type: "warning",
  513. }).then(function() {
  514. return delRole(ids);
  515. }).then(() => {
  516. this.getList();
  517. this.deptOptions = []
  518. this.msgSuccess("删除成功");
  519. })
  520. },
  521. /** 导出按钮操作 */
  522. handleExport() {
  523. this.download('system/role/export', {
  524. ...this.queryParams
  525. }, `role_${new Date().getTime()}.xlsx`)
  526. }
  527. }
  528. };
  529. </script>
  530. <style lang="scss" scoped>
  531. .searItemLeft {
  532. display: flex;
  533. justify-content: space-between;
  534. align-items: center;
  535. }
  536. .roleCont{
  537. height: calc(100% - 168px);
  538. }
  539. .roleContrBox {
  540. background-color: #fff;
  541. border-radius: 6px;
  542. overflow: hidden;
  543. padding: 23px 0;
  544. height: 100%;
  545. box-sizing: border-box;
  546. }
  547. .roleContr {
  548. padding-left: 17px;
  549. height: 100%;
  550. .searContLeft {
  551. height: 100%;
  552. overflow-y: auto;
  553. box-sizing: border-box;
  554. padding: 23px 17px 23px 23px;
  555. border-right: 2px solid #E5E5E5;
  556. &::-webkit-scrollbar {
  557. display: none;
  558. }
  559. }
  560. .searContRight {
  561. padding-left: 18px;
  562. .searTitle {
  563. display: flex;
  564. padding-left: 11px;
  565. margin-bottom: 26px;
  566. .searName {
  567. color: #343434;
  568. font-size: 12px;
  569. width: 116px;
  570. }
  571. .searItem {
  572. flex: 1;
  573. font-size: 12px;
  574. text-align: center;
  575. }
  576. }
  577. .searCont {
  578. display: flex;
  579. height: 23px;
  580. padding-left: 11px;
  581. align-items: center;
  582. margin-bottom: 4px;
  583. cursor: pointer;
  584. .searName {
  585. color: #343434;
  586. font-size: 12px;
  587. width: 116px;
  588. }
  589. .searItem {
  590. flex: 1;
  591. font-size: 12px;
  592. text-align: center;
  593. }
  594. &:hover {
  595. background-color: rgba(0, 0, 0, .1);
  596. }
  597. }
  598. .active {
  599. background-color: #CADBE4;
  600. .searName {
  601. color: #fff;
  602. }
  603. }
  604. }
  605. }
  606. .searBoxs {
  607. background-color: #fff;
  608. border-radius: 6px;
  609. box-sizing: border-box;
  610. padding: 23px;
  611. height: 100%;
  612. .searBox {
  613. display: flex;
  614. .searInput {
  615. flex: 1;
  616. height: 32px;
  617. margin-right: 8px;
  618. box-sizing: border-box;
  619. }
  620. input {
  621. width: 100%;
  622. height: 100%;
  623. background-color: #F7F6F6;
  624. border: none;
  625. padding: 0 7px;
  626. outline: none;
  627. &::placeholder {
  628. color: #AAAAAA;
  629. font-size: 12px;
  630. }
  631. }
  632. .searBtn {
  633. width: 30px;
  634. height: 32px;
  635. display: flex;
  636. justify-content: center;
  637. align-items: center;
  638. background-color: #3C8DBC;
  639. cursor: pointer;
  640. .icon {
  641. width: 18px;
  642. height: 17px;
  643. }
  644. }
  645. }
  646. .searList {
  647. padding: 10px 0;
  648. .searItem {
  649. padding: 0 8px;
  650. line-height: 30px;
  651. font-size: 12px;
  652. color: #343434;
  653. cursor: pointer;
  654. text-align: center;
  655. }
  656. .active {
  657. background-color: #CADBE4;
  658. color: #3C8DBC;
  659. }
  660. }
  661. }
  662. .app-container {
  663. background-color: #EFF0FF;
  664. height: calc(100vh - 84px);
  665. box-sizing: border-box;
  666. }
  667. .roleBox {
  668. padding: 0 23px;
  669. background: #fff;
  670. border-radius: 6px;
  671. .roleCol {
  672. padding: 20px 0;
  673. border-bottom: 1px solid #E5E5E5;
  674. .roleH {
  675. width: 18px;
  676. height: 8px;
  677. border-radius: 4px;
  678. background-color: #3C8DBC;
  679. margin-bottom: 8px;
  680. }
  681. span {
  682. font-size: 15px;
  683. color: #3C8DBC;
  684. }
  685. }
  686. .roleBot {
  687. padding: 22px 0;
  688. .roleBtn {
  689. height: 32px;
  690. display: flex;
  691. border-radius: 3px;
  692. justify-content: center;
  693. align-items: center;
  694. width: 83px;
  695. margin-right: 18px;
  696. .icon {
  697. width: 14px;
  698. height: 14px;
  699. margin-right: 7px;
  700. }
  701. span {
  702. color: #fff;
  703. font-size: 12px;
  704. }
  705. }
  706. }
  707. }
  708. </style>
  709. <style>
  710. .el-icon-my-export {
  711. background: url('~@/assets/images/icon_btn_bc@2x.png') center no-repeat;
  712. background-size: 13px 13px;
  713. /* background-size: cover;*/
  714. }
  715. .el-icon-my-export:before {
  716. content: "替";
  717. font-size: 16px;
  718. visibility: hidden;
  719. }
  720. .el-icon-my-export {
  721. font-size: 16px;
  722. }
  723. .el-icon-my-export:before {
  724. content: "\e611";
  725. }
  726. </style>