123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- var _this, dataObj=[], _Tok = null;
- new Vue({
- el: '#app',
- data: function() {
- return {
- treeLi: [],
- checkTree:[],
- defaultProps: {
- children: 'children',
- label: 'label'
- },
- tableData: [],
- nowForm:{
- deptCheckStrictly: true,
- deptIds: [],
- menuCheckStrictly: true,
- roleName:"",
- roleKey:"",
- roleSort:0,
- remark:"",
- status:"0"
- },
- dialogVisible:false,
- inpKey:""
- }
- },
- created() {
- _this = this;
- _Tok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
- _this.getList();
- },
- methods: {
- getList() {
- let data1 = {
- pageNum:1,
- pageSize:100
- };
- let _opts = {
- url: baseUrl + "/system/role/list",
- type:"GET"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok
- };
- getAxios(_opts, data1,_he)
- .then(function(res) {
- if (res.code == 200) {
- _this.tableData = res.rows;
- dataObj = res.rows;
- }else{
- _this.$message.error(res.msg);
- }
- })
- },
- Search(_key){
- let newArr = [],_ovj = dataObj;
- if(_key == ""){
- newArr = dataObj;
- }else{
- for(var i=0;i<_ovj.length;i++){
- if( JSON.stringify(_ovj[i]).indexOf(_key) != -1){
- newArr.push(_ovj[i])
- }
- }
- }
- _this.tableData = newArr;
- },
- newAdd(){
- let data1 = {};
- let _opts = {
- url: baseUrl + "/system/menu/treeselect",
- type:"GET"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok
- };
- getAxios(_opts, data1,_he)
- .then(function(res) {
- if (res.code == 200) {
- _this.treeLi = res.data;
- _this.checkTree = [];
- _this.nowForm = {
- deptCheckStrictly: true,
- deptIds: [],
- menuCheckStrictly: true,
- roleName:"",
- roleKey:"",
- roleSort:0,
- remark:"",
- status:"0"
- };
- _this.dialogVisible = true;
- }
- })
- },
- Edit(_row){
- let data1 = {};
- let _opts = {
- url: baseUrl + "/system/menu/roleMenuTreeselect/" + _row.roleId,
- type:"GET"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok
- };
- getAxios(_opts, data1,_he)
- .then(function(res) {
- if (res.code == 200) {
- _this.checkTree = res.checkedKeys;
- _this.treeLi = res.menus;
- let data1 = {};
- let _opts = {
- url: baseUrl + "/system/role/" + _row.roleId,
- type:"GET"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok
- };
- getAxios(_opts, data1,_he)
- .then(function(res) {
- if (res.code == 200) {
- _this.nowForm = res.data;
- _this.dialogVisible = true;
- }
- })
- }
- })
-
- },
- Delete(_row){
- _this.$confirm('是否确认删除编号为"'+_row.roleId+'"的数据项?', '温馨提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- let data1 = {};
- let _opts = {
- url: baseUrl + "/system/role/"+_row.roleId,
- type:"DELETE"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok
- };
- getAxios(_opts, data1,_he)
- .then(function(res) {
- if(res.code == 200){
- _this.$message({
- type: 'success',
- message: '删除成功!'
- });
- _this.getList();
- }else{
- _this.$message.error(res.msg);
- }
- })
- }).catch(() => {
-
- });
- },
- conFirm(){
- if(_this.nowForm.roleName == ""){
- _this.$message({
- type: 'warning',
- message: "请输入角色名称"
- });
- return;
- }
- if(_this.nowForm.roleKey == ""){
- _this.$message({
- type: 'warning',
- message: "请输入权限字符"
- });
- return;
- }
- _this.nowForm.menuIds = _this.getMenuAllCheckedKeys();
- let data1 = JSON.stringify(_this.nowForm);
- let _opts = {
- url:baseUrl + "/system/role",
- type: _this.nowForm.roleId == undefined?"POST":"PUT"
- };
- let _he = {
- "Authorization":"Bearer "+_Tok,
- "Content-Type": 'application/json; charset=UTF-8'
- };
- postAxios(_opts,data1,_he)
- .then(function(res){
- if(res.code == 200){
- _this.$message({
- type: 'success',
- message: '操作成功!'
- });
- _this.getList();
- _this.dialogVisible = false;
- }else{
- _this.$message.error(res.msg);
- }
- })
- },
- // 所有菜单节点数据
- getMenuAllCheckedKeys() {
- // 目前被选中的菜单节点
- let checkedKeys = _this.$refs.menu.getCheckedKeys();
- // 半选中的菜单节点
- let halfCheckedKeys = _this.$refs.menu.getHalfCheckedKeys();
- checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
- return checkedKeys;
- },
- }
- })
|