RoleMa.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta name="renderer" content="webkit">
  5. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  6. <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
  7. <meta http-equiv="pragma" content="no-cache">
  8. <meta http-equiv="Cache" content="no-cache">
  9. <meta http-equiv="cache-control" content="no-cache, must-revalidate">
  10. <meta http-equiv="expires" content="0">
  11. <meta name="viewport"
  12. content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  13. <title>角色管理</title>
  14. <link rel="stylesheet" href="../css/index.css">
  15. <link rel="stylesheet" href="../css/style.css">
  16. <script src="../js/vue.min.js"></script>
  17. <script src="../js/jquery.min.js"></script>
  18. <script src="../js/index.js"></script>
  19. <script src="../js/yz/init.js"></script>
  20. <script>
  21. checkLogin();
  22. </script>
  23. <style type="text/css">
  24. *{
  25. padding: 0;
  26. margin: 0;
  27. box-sizing: border-box;
  28. }
  29. body{
  30. padding: 10px;
  31. background-color: #040d32;
  32. }
  33. .search_ input {
  34. position: relative;
  35. width: 100%;
  36. height: 32px;
  37. line-height: 32px;
  38. border-radius: 4px;
  39. font-size: 14px;
  40. padding: 0 5px 0 25px;
  41. color: #dcdcdc;
  42. background-color: rgba(255, 255, 255, 0.2);
  43. border: 1px solid rgba(232, 232, 232, 0.3);
  44. }
  45. .search_ input::-webkit-input-placeholder {
  46. color: #dcdcdc;
  47. }
  48. .search_ .el-icon-search {
  49. position: absolute;
  50. left: 12px;
  51. top: 16px;
  52. color: #dcdcdc;
  53. }
  54. .elTable{
  55. width: 100%;
  56. border: 1px solid rgba(255, 255, 255, 0.2);
  57. }
  58. .el-table::before{
  59. height: 0;
  60. }
  61. .el-table::after{
  62. width: 0;
  63. }
  64. .el-table,.el-table__expanded-cell {
  65. color: #ddd;
  66. background-color: transparent !important;
  67. }
  68. .el-table tr,
  69. .el-table td {
  70. font-size: 14px;
  71. background-color: transparent !important;
  72. }
  73. .el-table td.el-table__cell,.el-table th.el-table__cell.is-leaf{
  74. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  75. }
  76. .el-table--border .el-table__cell{
  77. border-right: 1px solid rgba(255, 255, 255, 0.2);
  78. }
  79. .el-dialog__header{
  80. padding: 10px;
  81. }
  82. .el-dialog__title{
  83. font-size: 15px;
  84. }
  85. .el-dialog__headerbtn{
  86. top: 14px;
  87. }
  88. .el-dialog__body{
  89. padding: 10px;
  90. color: #fff;
  91. background-color: #082041;
  92. }
  93. .el-tree{
  94. color: #fff;
  95. background-color: transparent;
  96. }
  97. .br{
  98. border: 1px solid rgba(255, 255, 255, 0.2);
  99. }
  100. ._Form{
  101. flex:1;
  102. flex-direction: column;
  103. border-right: 1px solid rgba(255, 255, 255, 0.2);
  104. }
  105. ._Form>div{
  106. height: 20%;
  107. min-height: 60px;
  108. border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  109. }
  110. ._Form>div>div:first-child{
  111. display: flex;
  112. align-items: center;
  113. justify-content: center;
  114. width: 100px;
  115. height: 100%;
  116. min-height: 60px;
  117. border-right: 1px solid rgba(255, 255, 255, 0.2);
  118. }
  119. ._Form>div>div:last-child{
  120. width: calc(100% - 100px);
  121. padding: 0 10px;
  122. }
  123. .el-input__inner{
  124. height: 34px;
  125. line-height: 34px;
  126. }
  127. .el-input__inner,._Form .el-textarea__inner{
  128. color: #ececec;
  129. border-color: transparent;
  130. background-color: rgba(255, 255, 255, 0.2);
  131. }
  132. .el-input__inner::-webkit-input-placeholder {
  133. color: #b9b9b9;
  134. }
  135. ._Form .el-radio{
  136. color: #fff;
  137. }
  138. ._treeTxt{
  139. display: flex;
  140. align-items: center;
  141. justify-content: center;
  142. width: 120px;
  143. min-height: 360px;
  144. height: 100%;
  145. border-right: 1px solid rgba(255, 255, 255, 0.2);
  146. }
  147. .el-radio__input.is-checked .el-radio__inner,
  148. .el-checkbox__input.is-checked .el-checkbox__inner,
  149. .el-checkbox__input.is-indeterminate .el-checkbox__inner,
  150. .el-button--success{
  151. border-color: #39b54a;
  152. background: #39b54a;
  153. }
  154. .el-radio__input.is-checked+.el-radio__label{
  155. color: #39b54a;
  156. }
  157. .el-tree-node__content:hover,.el-tree-node:focus>.el-tree-node__content {
  158. background-color: transparent;
  159. }
  160. </style>
  161. </head>
  162. <body>
  163. <div id="app">
  164. <div>
  165. <div class="flex align-center margin-bottom-sm">
  166. <div>
  167. <el-input placeholder="请输入关键词" v-model="inpKey" @input="_Search">
  168. <i slot="prefix" class="el-input__icon el-icon-search"></i>
  169. </el-input>
  170. </div>
  171. <div class="tableTool">
  172. <el-button type="primary" size="small" class="margin-left-sm">查询</el-button>
  173. <el-button type="success" size="small" @click="newAdd">新增</el-button>
  174. </div>
  175. </div>
  176. <el-table class="elTable" :data="tableData" border :header-cell-style="{background:'#082041',color:'#fff'}">
  177. <el-table-column align="center" type="index" width="60" label="序号"></el-table-column>
  178. <el-table-column align="center" prop="roleId" label="角色编号"> </el-table-column>
  179. <el-table-column align="center" prop="roleName" label="角色名称"> </el-table-column>
  180. <el-table-column align="center" prop="roleKey" label="权限字符"> </el-table-column>
  181. <el-table-column align="center" prop="roleSort" label="显示顺序"> </el-table-column>
  182. <el-table-column align="center" prop="status" label="状态">
  183. <template slot-scope="scope">
  184. <el-switch
  185. :value="scope.row.status == 0"
  186. disabled
  187. active-color="#13ce66"
  188. inactive-color="#ff4949">
  189. </el-switch>
  190. </template>
  191. </el-table-column>
  192. <el-table-column align="center" prop="createTime" label="创建时间"> </el-table-column>
  193. <el-table-column
  194. align="center"
  195. width="140"
  196. label="操作">
  197. <template slot-scope="scope" v-if="!scope.row.admin">
  198. <el-button type="text" size="small" @click="Edit(scope.row)" class="text-green"><i class="el-icon-edit"></i>编辑</el-button>
  199. <el-button type="text" size="small" @click="Delete(scope.row)" class="text-red"><i class="el-icon-delete"></i>删除</el-button>
  200. </template>
  201. </el-table-column>
  202. </el-table>
  203. </div>
  204. <el-dialog title="角色信息" :visible.sync="dialogVisible" width="50%">
  205. <div class="flex br" style="text-align: center;">
  206. <div class="_Form">
  207. <div class="flex align-center">
  208. <div><span class="text-red">*</span>角色名称</div>
  209. <div><el-input v-model="nowForm.roleName" placeholder="角色名称"></el-input></div>
  210. </div>
  211. <div class="flex align-center">
  212. <div><span class="text-red">*</span>权限字符</div>
  213. <div><el-input v-model="nowForm.roleKey" placeholder="权限字符"></el-input></div>
  214. </div>
  215. <div class="flex align-center">
  216. <div><span class="text-red">*</span>角色顺序</div>
  217. <div><el-input type="number" min="0" v-model="nowForm.roleSort" placeholder="请输入内容"></el-input></div>
  218. </div>
  219. <div class="flex align-center">
  220. <div>状态</div>
  221. <div>
  222. <el-radio v-model="nowForm.status" label="0">正常</el-radio>
  223. <el-radio v-model="nowForm.status" label="1">停用</el-radio>
  224. </div>
  225. </div>
  226. <div class="flex align-center" style="border: none;">
  227. <div>备注</div>
  228. <div><el-input type="textarea" :rows="2" placeholder="请输入备注" v-model="nowForm.remark"></el-input></div>
  229. </div>
  230. </div>
  231. <div class="flex-sub flex align-center">
  232. <div class="_treeTxt">菜单权限</div>
  233. <div style="padding: 10px;">
  234. <el-tree :data="treeLi"
  235. show-checkbox node-key="id"
  236. :default-expanded-keys="[]"
  237. :default-checked-keys="checkTree"
  238. :props="defaultProps"
  239. ref="menu"
  240. show-checkbox>
  241. </el-tree>
  242. </div>
  243. </div>
  244. </div>
  245. <div class="padding-sm text-center">
  246. <el-button size="small" @click="dialogVisible = false;">取消</el-button>
  247. <el-button size="small" type="success" @click="conFirm">提交</el-button>
  248. </div>
  249. </el-dialog>
  250. </div>
  251. <script>
  252. var _this, dataObj=[];
  253. new Vue({
  254. el: '#app',
  255. data: function() {
  256. return {
  257. treeLi: [],
  258. checkTree:[],
  259. defaultProps: {
  260. children: 'children',
  261. label: 'label'
  262. },
  263. tableData: [],
  264. nowForm:{
  265. deptCheckStrictly: true,
  266. deptIds: [],
  267. menuCheckStrictly: true,
  268. roleName:"",
  269. roleKey:"",
  270. roleSort:0,
  271. remark:"",
  272. status:"0"
  273. },
  274. dialogVisible:false,
  275. inpKey:""
  276. }
  277. },
  278. created() {
  279. _this = this;
  280. _this.getList();
  281. },
  282. methods: {
  283. getList() {
  284. let data1 = {
  285. pageNum:1,
  286. pageSize:100
  287. };
  288. let _opts = {
  289. url: "/system/role/list",
  290. type:"GET"
  291. };
  292. tokenAjax(_opts, data1)
  293. .then(function(res) {
  294. if (res.code == 200) {
  295. _this.tableData = res.rows;
  296. dataObj = res.rows;
  297. }else{
  298. _this.$message.error(res.msg);
  299. }
  300. })
  301. },
  302. _Search(_key){
  303. let newArr = [],_ovj = dataObj;
  304. if(_key == ""){
  305. newArr = dataObj;
  306. }else{
  307. for(var i=0;i<_ovj.length;i++){
  308. if( JSON.stringify(_ovj[i]).indexOf(_key) != -1){
  309. newArr.push(_ovj[i])
  310. }
  311. }
  312. }
  313. _this.tableData = newArr;
  314. },
  315. newAdd(){
  316. let data1 = {};
  317. let _opts = {
  318. url: "/system/menu/treeselect",
  319. type:"GET"
  320. };
  321. tokenAjax(_opts, data1)
  322. .then(function(res) {
  323. if (res.code == 200) {
  324. _this.treeLi = res.data;
  325. _this.checkTree = [];
  326. _this.nowForm = {
  327. deptCheckStrictly: true,
  328. deptIds: [],
  329. menuCheckStrictly: true,
  330. roleName:"",
  331. roleKey:"",
  332. roleSort:0,
  333. remark:"",
  334. status:"0"
  335. };
  336. _this.dialogVisible = true;
  337. }
  338. })
  339. },
  340. Edit(_row){
  341. let data1 = {};
  342. let _opts = {
  343. url: "/system/menu/roleMenuTreeselect/" + _row.roleId,
  344. type:"GET"
  345. };
  346. tokenAjax(_opts, data1)
  347. .then(function(res) {
  348. if (res.code == 200) {
  349. _this.checkTree = res.checkedKeys;
  350. _this.treeLi = res.menus;
  351. let data1 = {};
  352. let _opts = {
  353. url: "/system/role/" + _row.roleId,
  354. type:"GET"
  355. };
  356. tokenAjax(_opts, data1)
  357. .then(function(res) {
  358. if (res.code == 200) {
  359. _this.nowForm = res.data;
  360. _this.dialogVisible = true;
  361. }
  362. })
  363. }
  364. })
  365. },
  366. Delete(_row){
  367. _this.$confirm('是否确认删除编号为"'+_row.roleId+'"的数据项?', '温馨提示', {
  368. confirmButtonText: '确定',
  369. cancelButtonText: '取消',
  370. type: 'warning'
  371. }).then(() => {
  372. let data1 = {};
  373. let _opts = {
  374. url: "/system/role/"+_row.roleId,
  375. type:"DELETE"
  376. };
  377. tokenAjax(_opts, data1)
  378. .then(function(res) {
  379. if(res.code == 200){
  380. _this.$message({
  381. type: 'success',
  382. message: '删除成功!'
  383. });
  384. _this.getList();
  385. }else{
  386. _this.$message.error(res.msg);
  387. }
  388. })
  389. }).catch(() => {
  390. });
  391. },
  392. conFirm(){
  393. if(_this.nowForm.roleName == ""){
  394. _this.$message({
  395. type: 'warning',
  396. message: "请输入角色名称"
  397. });
  398. return;
  399. }
  400. if(_this.nowForm.roleKey == ""){
  401. _this.$message({
  402. type: 'warning',
  403. message: "请输入权限字符"
  404. });
  405. return;
  406. }
  407. _this.nowForm.menuIds = _this.getMenuAllCheckedKeys();
  408. let data1 = _this.nowForm;
  409. let _opts = {
  410. url:"/system/role",
  411. type: _this.nowForm.roleId == undefined?"POST":"PUT"
  412. };
  413. tokenPostAjax(_opts,data1)
  414. .then(function(res){
  415. if(res.code == 200){
  416. _this.$message({
  417. type: 'success',
  418. message: '操作成功!'
  419. });
  420. _this.getList();
  421. _this.dialogVisible = false;
  422. }else{
  423. _this.$message.error(res.msg);
  424. }
  425. })
  426. },
  427. // 所有菜单节点数据
  428. getMenuAllCheckedKeys() {
  429. // 目前被选中的菜单节点
  430. let checkedKeys = _this.$refs.menu.getCheckedKeys();
  431. // 半选中的菜单节点
  432. let halfCheckedKeys = _this.$refs.menu.getHalfCheckedKeys();
  433. checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  434. return checkedKeys;
  435. },
  436. }
  437. })
  438. </script>
  439. </body>
  440. </html>