index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. <template>
  2. <div class="app-container">
  3. <el-row style="margin-top: 18px;">
  4. <el-col :span="5" class="searBoxs">
  5. <el-row class="roleBoxui">
  6. <el-col :span="24" class="roleBotyu">
  7. <el-row :gutter="10" class="mb8">
  8. <el-col :span="1.5">
  9. <el-button type="primary" style="background-color: #FF9639;color: #fff;border: none;" plain icon="el-icon-refresh"
  10. @click="efresh" v-hasPermi="['system:role:list']">刷新</el-button>
  11. </el-col>
  12. </el-row>
  13. </el-col>
  14. </el-row>
  15. <div class="searBox">
  16. <div class="searInput">
  17. <input type="text" placeholder="请输入角色" v-model="queryParams.roleName">
  18. </div>
  19. <div class="searBtn" @click="quregu">
  20. <img src="@/assets/images/icon_sr_ss@2x.png" alt="" class="icon">
  21. </div>
  22. </div>
  23. <div class="searList">
  24. <div class="searItem" v-for="item in roleList" :key="item.roleName" :class="{'active': false}" @click="jieese(item.id)">
  25. {{item.roleName}}
  26. </div>
  27. </div>
  28. </el-col>
  29. <el-col :span="19" class="roleContr">
  30. <el-row class="roleBox">
  31. <el-col :span="24" class="roleBot">
  32. <el-row :gutter="10" class="mb8">
  33. <el-col :span="1.5">
  34. <el-button type="primary" style="background-color: #2AC1CA;color: #fff;border: none;" plain icon="el-icon-plus"
  35. @click="handleAdd" v-hasPermi="['system:role:add']">新增</el-button>
  36. </el-col>
  37. <el-col :span="1.5">
  38. <el-button type="primary" style="background-color: #FF9639;color: #fff;border: none;" plain icon="el-icon-edit"
  39. @click="handleUpdate" :disabled="single" v-hasPermi="['system:role:list']">修改</el-button>
  40. </el-col>
  41. <el-col :span="1.5">
  42. <el-button type="primary" :disabled="multiple" style="background-color: #3C8DBC;color: #fff;border: none;" plain icon="el-icon-delete"
  43. @click="handleDelete" v-hasPermi="['system:role:edit']">删除</el-button>
  44. </el-col>
  45. </el-row>
  46. </el-col>
  47. </el-row>
  48. <div class="roleContrBox">
  49. <el-col :span="24">
  50. <div class="searContLeft">
  51. <el-table v-loading="loading" :data="cloumns" @selection-change="handleSelectionChange">
  52. <el-table-column type="selection" width="55" align="center" />
  53. <el-table-column label="序号" align="center" prop="id" />
  54. <el-table-column label="用户角色" align="center" prop="roleName" />
  55. <el-table-column label="权限表单" align="center" prop="tableName" />
  56. <el-table-column label="数据过滤" align="center" prop="dataScope">
  57. <!-- <template slot-scope="scope">
  58. {{scope.row.dataScope | relationTypeFn}}
  59. </template> -->
  60. </el-table-column>
  61. <el-table-column label="是否可用" align="center">
  62. <template slot-scope="scope">
  63. <el-checkbox true-label="Y" false-label="N" v-model="scope.row.isUse"></el-checkbox>
  64. </template>
  65. </el-table-column>
  66. </el-table>
  67. </div>
  68. </el-col>
  69. </div>
  70. </el-col>
  71. </el-row>
  72. <!-- 添加或修改对话框 -->
  73. <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="600px" append-to-body>
  74. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  75. <el-form-item label="权限表单:" prop="tableName">
  76. <el-input v-model="form.tableName" placeholder="请输入权限表单" />
  77. </el-form-item>
  78. <el-form-item label="权限范围:" prop="dataScope">
  79. <el-select style="width: 100%;" v-model="form.dataScope" placeholder="权限范围" clearable size="small">
  80. <el-option
  81. v-for="dict in statusOptions"
  82. :key="dict.dictValue"
  83. :label="dict.dictLabel"
  84. :value="dict.dictValue"
  85. />
  86. </el-select>
  87. </el-form-item>
  88. </el-form>
  89. <div slot="footer" class="dialog-footer">
  90. <el-button type="primary" @click="submitForm">确 定</el-button>
  91. <el-button @click="cancel">取 消</el-button>
  92. </div>
  93. </el-dialog>
  94. </div>
  95. </template>
  96. <script>
  97. import { listRole, getRole, delRole, addRole, updateRole, exportRole, dataScope, changeRoleStatus } from "@/api/system/role";
  98. import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/menu";
  99. import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept";
  100. import { listPostporen, addlistPostporen, getRoler,delelistPostporen,piutRoler } from "@/api/system/permisss.js";
  101. export default {
  102. name: "Role",
  103. data() {
  104. return {
  105. searIndex: '',
  106. defaultProps: {
  107. children: 'children',
  108. label: 'label'
  109. },
  110. indexs: 3,
  111. // 遮罩层
  112. loading: true,
  113. // 选中数组
  114. ids: [],
  115. // 非单个禁用
  116. single: true,
  117. // 非多个禁用
  118. multiple: true,
  119. // 显示搜索条件
  120. showSearch: true,
  121. // 总条数
  122. total: 0,
  123. // 角色表格数据
  124. roleList: [],
  125. // 弹出层标题
  126. title: "",
  127. // 是否显示弹出层
  128. open: false,
  129. // 是否显示弹出层(数据权限)
  130. openDataScope: false,
  131. menuExpand: false,
  132. menuNodeAll: false,
  133. deptExpand: true,
  134. deptNodeAll: false,
  135. // 日期范围
  136. dateRange: [],
  137. // 状态数据字典
  138. statusOptions: [],
  139. // 数据范围选项
  140. // 菜单列表
  141. menuOptions: [],
  142. // 部门列表
  143. deptOptions: [],
  144. // 查询参数
  145. queryParams: {
  146. roleName: undefined,
  147. roleId: undefined,
  148. status: undefined
  149. },
  150. queryParamstr:{
  151. roleId: undefined,
  152. },
  153. // 表单参数
  154. form: {},
  155. // 表单校验
  156. rules: {
  157. roleName: [{
  158. required: true,
  159. message: "角色名称不能为空",
  160. trigger: "blur"
  161. }],
  162. roleKey: [{
  163. required: true,
  164. message: "权限字符不能为空",
  165. trigger: "blur"
  166. }],
  167. roleSort: [{
  168. required: true,
  169. message: "角色顺序不能为空",
  170. trigger: "blur"
  171. }]
  172. },
  173. cloumns:[],
  174. relationType: [],
  175. // 表格的高度
  176. tableHeight: document.documentElement.scrollHeight - 245 + "px",
  177. ijeudid:-1
  178. };
  179. },
  180. created() {
  181. this.getDicts("role_data").then(response => {
  182. this.statusOptions = response.data;
  183. this.relationType = response.data
  184. this.getDeptTreeselect()
  185. console.log(this.relationType)
  186. });
  187. this.getList();
  188. },
  189. filters: {
  190. relationTypeFn(data) {
  191. var _this = this
  192. let is = ''
  193. console.log(data)
  194. console.log(_this.cloumns)
  195. for (let item of that.relationType) {
  196. if (item.dictValue == data) {
  197. is = item.dictLabel
  198. }
  199. }
  200. return is
  201. },
  202. },
  203. methods: {
  204. handleNodeClick() {
  205. console.log(221)
  206. },
  207. /** 查询角色列表 */
  208. getList() {
  209. this.loading = true;
  210. this.roleList = []
  211. listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
  212. response => {
  213. if(response.rows.length !==0){
  214. this.roleList = response.rows;
  215. }else{
  216. this.roleList.push({roleName:'暂无数据'})
  217. }
  218. this.total = response.total;
  219. this.loading = false;
  220. }
  221. );
  222. },
  223. /** 查询菜单树结构 */
  224. getMenuTreeselect() {
  225. menuTreeselect().then(response => {
  226. this.menuOptions = response.data;
  227. });
  228. },
  229. /** 查询列表数据*/
  230. getDeptTreeselect() {
  231. listPostporen(this.queryParamstr).then(response => {
  232. console.log(response.rows)
  233. this.cloumns = response.rows;
  234. // this.cloumns.
  235. this.cloumns.filter(route => {
  236. console.log(route)
  237. for(var item in route){
  238. console.log(item,78)
  239. if(item == 'dataScope'){
  240. console.log(route[item])
  241. console.log(this.relationType)
  242. this.relationType.filter(router =>{
  243. console.log(router)
  244. if(router.dictValue == route[item]){
  245. route[item] = router.dictLabel
  246. }
  247. console.log(route[item])
  248. })
  249. }
  250. }
  251. })
  252. });
  253. },
  254. /** 根据角色ID查询菜单树结构 */
  255. getRoleMenuTreeselect(id) {
  256. return roleMenuTreeselect(id).then(response => {
  257. this.menuOptions = response.menus;
  258. return response;
  259. });
  260. },
  261. /** 根据角色ID查询部门树结构 */
  262. getRoleDeptTreeselect(id) {
  263. return roleDeptTreeselect(id).then(response => {
  264. this.deptOptions = response.depts;
  265. return response;
  266. });
  267. },
  268. // 角色状态修改
  269. handleStatusChange(row) {
  270. let text = row.status === "0" ? "启用" : "停用";
  271. this.$confirm('确认要"' + text + '""' + row.roleName + '"角色吗?', "警告", {
  272. confirmButtonText: "确定",
  273. cancelButtonText: "取消",
  274. type: "warning"
  275. }).then(function() {
  276. return changeRoleStatus(row.id, row.status);
  277. }).then(() => {
  278. this.msgSuccess(text + "成功");
  279. }).catch(function() {
  280. row.status = row.status === "0" ? "1" : "0";
  281. });
  282. },
  283. // 取消按钮
  284. cancel() {
  285. this.open = false;
  286. this.reset();
  287. },
  288. // 取消按钮(数据权限)
  289. cancelDataScope() {
  290. this.openDataScope = false;
  291. this.reset();
  292. },
  293. // 表单重置
  294. reset() {
  295. this.form = {
  296. };
  297. this.resetForm("form");
  298. },
  299. /** 搜索按钮操作 */
  300. handleQuery() {
  301. this.queryParams.pageNum = 1;
  302. this.getList();
  303. },
  304. /** 重置按钮操作 */
  305. resetQuery() {
  306. this.dateRange = [];
  307. this.resetForm("queryForm");
  308. this.handleQuery();
  309. },
  310. // 多选框选中数据
  311. handleSelectionChange(selection) {
  312. this.ids = selection.map(item => item.id)
  313. this.single = selection.length != 1
  314. this.multiple = !selection.length
  315. },
  316. /** 新增按钮操作 */
  317. handleAdd() {
  318. this.reset();
  319. // this.getMenuTreeselect();
  320. this.open = true;
  321. this.title = "添加数据权限";
  322. },
  323. /** 修改按钮操作 */
  324. handleUpdate(row) {
  325. this.reset();
  326. const id = row.id || this.ids
  327. // const roleMenu = this.getRoleMenuTreeselect(id);
  328. getRoler(id).then(response => {
  329. this.form = response.data;
  330. this.open = true;
  331. this.$nextTick(() => {
  332. roleMenu.then(res => {
  333. let checkedKeys = res.checkedKeys
  334. checkedKeys.forEach((v) => {
  335. this.$nextTick(() => {
  336. this.$refs.menu.setChecked(v, true, false);
  337. })
  338. })
  339. });
  340. });
  341. this.title = "修改数据权限";
  342. });
  343. },
  344. /** 选择角色权限范围触发 */
  345. dataScopeSelectChange(value) {
  346. if (value !== '2') {
  347. this.$refs.dept.setCheckedKeys([]);
  348. }
  349. },
  350. /** 分配数据权限操作 */
  351. handleDataScope(row) {
  352. this.reset();
  353. const roleDeptTreeselect = this.getRoleDeptTreeselect(row.id);
  354. getRole(row.id).then(response => {
  355. this.form = response.data;
  356. this.openDataScope = true;
  357. this.$nextTick(() => {
  358. roleDeptTreeselect.then(res => {
  359. this.$refs.dept.setCheckedKeys(res.checkedKeys);
  360. });
  361. });
  362. this.title = "分配数据权限";
  363. });
  364. },
  365. /** 提交按钮 */
  366. submitForm: function() {
  367. this.$refs["form"].validate(valid => {
  368. if (valid) {
  369. if (this.form.id != undefined) {
  370. // this.form.menuIds = this.getMenuAllCheckedKeys();
  371. piutRoler(this.form).then(response => {
  372. this.msgSuccess("修改成功");
  373. this.open = false;
  374. this.getDeptTreeselect();
  375. });
  376. } else {
  377. // this.form.menuIds = this.getMenuAllCheckedKeys();
  378. this.form.roleId = this.ijeudid
  379. if(this.form.roleId !== -1){
  380. addlistPostporen(this.form).then(response => {
  381. this.msgSuccess("新增成功");
  382. this.open = false;
  383. this.getDeptTreeselect();
  384. });
  385. }else{
  386. this.msgSuccess("请先选择角色在添加");
  387. this.open = false
  388. }
  389. }
  390. }
  391. });
  392. },
  393. /** 提交按钮(数据权限) */
  394. submitDataScope: function() {
  395. if (this.form.id != undefined) {
  396. this.form.deptIds = this.getDeptAllCheckedKeys();
  397. dataScope(this.form).then(response => {
  398. this.msgSuccess("修改成功");
  399. this.openDataScope = false;
  400. // this.getDeptTreeselect();
  401. });
  402. }
  403. },
  404. /** 删除按钮操作 */
  405. handleDelete(row) {
  406. const ids = row.id || this.ids;
  407. this.$confirm('是否确认删除角色编号为"' + ids + '"的数据项?', "警告", {
  408. confirmButtonText: "确定",
  409. cancelButtonText: "取消",
  410. type: "warning"
  411. }).then(function() {
  412. return delelistPostporen(ids);
  413. }).then(() => {
  414. this.getDeptTreeselect();
  415. this.msgSuccess("删除成功");
  416. })
  417. },
  418. /** 导出按钮操作 */
  419. handleExport() {
  420. this.download('system/role/export', {
  421. ...this.queryParams
  422. }, `role_${new Date().getTime()}.xlsx`)
  423. },
  424. // 查询
  425. quregu(){
  426. this.getList()
  427. },
  428. // 刷新
  429. efresh(){
  430. this.queryParams.roleName = undefined
  431. this.getList()
  432. this.queryParamstr.roleId = undefined
  433. this.getDeptTreeselect()
  434. },
  435. // 点击角色id
  436. jieese(id){
  437. this.ijeudid = id
  438. this.queryParamstr.roleId = id
  439. this.getDeptTreeselect()
  440. console.log(this.form.roleId)
  441. }
  442. }
  443. };
  444. </script>
  445. <style lang="scss" scoped>
  446. .roleContrBox {
  447. background-color: #fff;
  448. // border-radius: 6px;
  449. overflow: hidden;
  450. padding: 23px 0;
  451. }
  452. .roleContr {
  453. padding-left: 17px;
  454. .searContLeft {
  455. padding:0 17px 23px 23px;
  456. // border-right: 2px solid #E5E5E5;
  457. }
  458. .searContRight {
  459. padding-left: 18px;
  460. .searTitle {
  461. display: flex;
  462. padding-left: 11px;
  463. margin-bottom: 26px;
  464. .searName {
  465. color: #343434;
  466. font-size: 12px;
  467. width: 156px;
  468. }
  469. .searItem {
  470. flex: 1;
  471. font-size: 12px;
  472. }
  473. }
  474. .searCont {
  475. display: flex;
  476. height: 23px;
  477. padding-left: 11px;
  478. align-items: center;
  479. margin-bottom: 4px;
  480. cursor: pointer;
  481. .searName {
  482. color: #343434;
  483. font-size: 12px;
  484. width: 156px;
  485. }
  486. .searItem {
  487. flex: 1;
  488. font-size: 12px;
  489. }
  490. &:hover {
  491. background-color: rgba(0, 0, 0, .1);
  492. }
  493. }
  494. .active {
  495. background-color: #CADBE4 !important;
  496. .searName {
  497. color: #fff;
  498. }
  499. }
  500. }
  501. }
  502. .searBoxs {
  503. background-color: #fff;
  504. border-radius: 6px;
  505. padding: 23px;
  506. .searBox {
  507. display: flex;
  508. .searInput {
  509. flex: 1;
  510. height: 32px;
  511. margin-right: 8px;
  512. box-sizing: border-box;
  513. border-radius: 4px;
  514. overflow: hidden;
  515. }
  516. input {
  517. width: 100%;
  518. height: 100%;
  519. background-color: #F7F6F6;
  520. border: none;
  521. padding: 0 7px;
  522. outline: none;
  523. &::placeholder {
  524. color: #AAAAAA;
  525. font-size: 12px;
  526. }
  527. }
  528. .searBtn {
  529. width: 30px;
  530. height: 32px;
  531. display: flex;
  532. justify-content: center;
  533. align-items: center;
  534. background-color: #3C8DBC;
  535. cursor: pointer;
  536. border-radius: 4px;
  537. overflow: hidden;
  538. .icon {
  539. width: 18px;
  540. height: 17px;
  541. }
  542. }
  543. }
  544. .searList {
  545. padding: 10px 0;
  546. .searItem {
  547. padding: 0 8px;
  548. line-height: 30px;
  549. font-size: 12px;
  550. color: #343434;
  551. cursor: pointer;
  552. }
  553. .active {
  554. background-color: #CADBE4;
  555. color: #3C8DBC;
  556. }
  557. }
  558. }
  559. .app-container {
  560. background-color: #EFF0FF;
  561. min-height: calc(100vh - 70px);
  562. box-sizing: border-box;
  563. box-sizing: border-box;
  564. }
  565. .roleBox {
  566. padding: 0 23px;
  567. background: #fff;
  568. // border-radius: 6px;
  569. .roleCol {
  570. padding: 20px 0;
  571. border-bottom: 1px solid #E5E5E5;
  572. .roleH {
  573. width: 18px;
  574. height: 8px;
  575. border-radius: 4px;
  576. background-color: #3C8DBC;
  577. margin-bottom: 8px;
  578. }
  579. span {
  580. font-size: 15px;
  581. color: #3C8DBC;
  582. }
  583. }
  584. .roleBot {
  585. padding: 22px 0;
  586. padding-bottom: 0;
  587. .roleBtn {
  588. height: 32px;
  589. display: flex;
  590. border-radius: 3px;
  591. justify-content: center;
  592. align-items: center;
  593. width: 83px;
  594. margin-right: 18px;
  595. .icon {
  596. width: 14px;
  597. height: 14px;
  598. margin-right: 7px;
  599. }
  600. span {
  601. color: #fff;
  602. font-size: 12px;
  603. }
  604. }
  605. }
  606. }
  607. .roleBotyu{
  608. padding: 0;
  609. padding-bottom: 22px;
  610. padding-top: 1px;
  611. }
  612. .roleBoxui{
  613. padding-left: 0;
  614. }
  615. </style>
  616. <style>
  617. .el-icon-my-export{
  618. background: url('~@/assets/images/icon_btn_bc@2x.png') center no-repeat;
  619. background-size: 13px 13px;
  620. /* background-size: cover;*/
  621. }
  622. .el-icon-my-export:before{
  623. content: "替";
  624. font-size: 16px;
  625. visibility: hidden;
  626. }
  627. .el-icon-my-export{
  628. font-size: 16px;
  629. }
  630. .el-icon-my-export:before{
  631. content: "\e611";
  632. }
  633. </style>