roleManage.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. var _this, dataObj=[], _Tok = null;
  2. new Vue({
  3. el: '#app',
  4. data: function() {
  5. return {
  6. treeLi: [],
  7. checkTree:[],
  8. defaultProps: {
  9. children: 'children',
  10. label: 'label'
  11. },
  12. tableData: [],
  13. nowForm:{
  14. deptCheckStrictly: true,
  15. deptIds: [],
  16. menuCheckStrictly: true,
  17. roleName:"",
  18. roleKey:"",
  19. roleSort:0,
  20. remark:"",
  21. status:"0"
  22. },
  23. dialogVisible:false,
  24. inpKey:""
  25. }
  26. },
  27. created() {
  28. _this = this;
  29. _Tok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
  30. _this.getList();
  31. },
  32. methods: {
  33. getList() {
  34. let data1 = {
  35. pageNum:1,
  36. pageSize:100
  37. };
  38. let _opts = {
  39. url: baseUrl + "/system/role/list",
  40. type:"GET"
  41. };
  42. let _he = {
  43. "Authorization":"Bearer "+_Tok
  44. };
  45. getAxios(_opts, data1,_he)
  46. .then(function(res) {
  47. if (res.code == 200) {
  48. _this.tableData = res.rows;
  49. dataObj = res.rows;
  50. }else{
  51. _this.$message.error(res.msg);
  52. }
  53. })
  54. },
  55. Search(_key){
  56. let newArr = [],_ovj = dataObj;
  57. if(_key == ""){
  58. newArr = dataObj;
  59. }else{
  60. for(var i=0;i<_ovj.length;i++){
  61. if( JSON.stringify(_ovj[i]).indexOf(_key) != -1){
  62. newArr.push(_ovj[i])
  63. }
  64. }
  65. }
  66. _this.tableData = newArr;
  67. },
  68. newAdd(){
  69. let data1 = {};
  70. let _opts = {
  71. url: baseUrl + "/system/menu/treeselect",
  72. type:"GET"
  73. };
  74. let _he = {
  75. "Authorization":"Bearer "+_Tok
  76. };
  77. getAxios(_opts, data1,_he)
  78. .then(function(res) {
  79. if (res.code == 200) {
  80. _this.treeLi = res.data;
  81. _this.checkTree = [];
  82. _this.nowForm = {
  83. deptCheckStrictly: true,
  84. deptIds: [],
  85. menuCheckStrictly: true,
  86. roleName:"",
  87. roleKey:"",
  88. roleSort:0,
  89. remark:"",
  90. status:"0"
  91. };
  92. _this.dialogVisible = true;
  93. }
  94. })
  95. },
  96. Edit(_row){
  97. let data1 = {};
  98. let _opts = {
  99. url: baseUrl + "/system/menu/roleMenuTreeselect/" + _row.roleId,
  100. type:"GET"
  101. };
  102. let _he = {
  103. "Authorization":"Bearer "+_Tok
  104. };
  105. getAxios(_opts, data1,_he)
  106. .then(function(res) {
  107. if (res.code == 200) {
  108. _this.checkTree = res.checkedKeys;
  109. _this.treeLi = res.menus;
  110. let data1 = {};
  111. let _opts = {
  112. url: baseUrl + "/system/role/" + _row.roleId,
  113. type:"GET"
  114. };
  115. let _he = {
  116. "Authorization":"Bearer "+_Tok
  117. };
  118. getAxios(_opts, data1,_he)
  119. .then(function(res) {
  120. if (res.code == 200) {
  121. _this.nowForm = res.data;
  122. _this.dialogVisible = true;
  123. }
  124. })
  125. }
  126. })
  127. },
  128. Delete(_row){
  129. _this.$confirm('是否确认删除编号为"'+_row.roleId+'"的数据项?', '温馨提示', {
  130. confirmButtonText: '确定',
  131. cancelButtonText: '取消',
  132. type: 'warning'
  133. }).then(() => {
  134. let data1 = {};
  135. let _opts = {
  136. url: baseUrl + "/system/role/"+_row.roleId,
  137. type:"DELETE"
  138. };
  139. let _he = {
  140. "Authorization":"Bearer "+_Tok
  141. };
  142. getAxios(_opts, data1,_he)
  143. .then(function(res) {
  144. if(res.code == 200){
  145. _this.$message({
  146. type: 'success',
  147. message: '删除成功!'
  148. });
  149. _this.getList();
  150. }else{
  151. _this.$message.error(res.msg);
  152. }
  153. })
  154. }).catch(() => {
  155. });
  156. },
  157. conFirm(){
  158. if(_this.nowForm.roleName == ""){
  159. _this.$message({
  160. type: 'warning',
  161. message: "请输入角色名称"
  162. });
  163. return;
  164. }
  165. if(_this.nowForm.roleKey == ""){
  166. _this.$message({
  167. type: 'warning',
  168. message: "请输入权限字符"
  169. });
  170. return;
  171. }
  172. _this.nowForm.menuIds = _this.getMenuAllCheckedKeys();
  173. let data1 = JSON.stringify(_this.nowForm);
  174. let _opts = {
  175. url:baseUrl + "/system/role",
  176. type: _this.nowForm.roleId == undefined?"POST":"PUT"
  177. };
  178. let _he = {
  179. "Authorization":"Bearer "+_Tok,
  180. "Content-Type": 'application/json; charset=UTF-8'
  181. };
  182. postAxios(_opts,data1,_he)
  183. .then(function(res){
  184. if(res.code == 200){
  185. _this.$message({
  186. type: 'success',
  187. message: '操作成功!'
  188. });
  189. _this.getList();
  190. _this.dialogVisible = false;
  191. }else{
  192. _this.$message.error(res.msg);
  193. }
  194. })
  195. },
  196. // 所有菜单节点数据
  197. getMenuAllCheckedKeys() {
  198. // 目前被选中的菜单节点
  199. let checkedKeys = _this.$refs.menu.getCheckedKeys();
  200. // 半选中的菜单节点
  201. let halfCheckedKeys = _this.$refs.menu.getHalfCheckedKeys();
  202. checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
  203. return checkedKeys;
  204. },
  205. }
  206. })