var _this, dataObj=[], _Tok = null; new Vue({ el: '#app', data: function() { return { tableData: [], TreeData:[], nowForm:{ icon: "", isCache: "0", isFrame: "1", menuName: "", menuType: "M", orderNum: "0", parentId: 0, path: "", status: "0", visible: "0", perms:"" }, dialogVisible:false, inpKey:"", defaultProps: { children: 'children', label: 'label' }, parentName: { menuName: "请选择", menuId: "" } } }, 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/menu/list", type:"GET" }; let _he = { "Authorization":"Bearer "+_Tok }; getAxios(_opts, data1,_he) .then(function(res) { if (res.code == 200) { _this.tableData = _this.getTrees(res.data, 0) _this.TreeData = [{ id: 0, label: "主类目", menuName:"主类目", menuId:0, children:(res.data.length? _this.getTrees(res.data, 0):[]) }]; dataObj = res.data; }else{ _this.$message.error(res.msg); } }) }, getTrees(data, parentId) { var tree = []; var temp; for (var i = 0; i < data.length; i++) { data[i].label = data[i].menuName; data[i].id = data[i].menuId; if (data[i].parentId == parentId) { var obj = data[i]; temp = _this.getTrees(data, data[i].menuId); if (temp.length > 0) { obj.children = [...temp]; } tree.push(obj); } } return tree; }, 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 = _this.getTrees(newArr, 0); }, newAdd(_row){ if(_row.menuId != undefined){ _this.parentName = { menuName: _row.menuName, menuId: _row.menuId }; }else{ _this.parentName = { menuName: _this.TreeData[0].menuName, menuId: _this.TreeData[0].menuId }; } _this.nowForm = { icon:_row.menuId != undefined? "#":"", isCache: "0", isFrame: "1", menuName: "", menuType:_row.menuId != undefined?"C" :"M", orderNum: "0", parentId:_row.menuId != undefined? _row.menuId:0, path: "", status: "0", visible: "0", perms:"" }; _this.dialogVisible = true; }, Edit(_row){ let data1 = {}; let _opts = { url: baseUrl + "/system/menu/" + _row.menuId, type:"GET" }; let _he = { "Authorization":"Bearer "+_Tok }; getAxios(_opts, data1,_he) .then(function(res) { if (res.code == 200) { if(_row.parentId == 0){ _this.parentName = { menuName:"主类目", menuId:0, }; }else{ dataObj.forEach((it,ind)=>{ if(it.menuId == _row.parentId){ _this.parentName = { menuName: it.menuName, menuId: it.menuId }; } }) } _this.nowForm = res.data; _this.dialogVisible = true; } }) }, Delete(_row){ _this.$confirm('是否确认删除编号为"'+_row.menuId+'"的数据项?', '温馨提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' }).then(() => { let data1 = {}; let _opts = { url: baseUrl + "/system/menu/"+_row.menuId, 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(){ _this.nowForm.parentId = _this.parentName.menuId; if(_this.nowForm.menuName == ""){ _this.$message({ type: 'warning', message: "请输入菜单名称" }); return; } if(_this.nowForm.path == ""&&_this.nowForm.menuType == "C"){ _this.$message({ type: 'warning', message: '请输入页面路径', }) return; } let data1 = JSON.stringify(_this.nowForm); let _opts = { url: baseUrl + "/system/menu", type: _this.nowForm.menuId == 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); } }) }, nodeClick(_e){ _this.parentName = { menuName: _e.menuName, menuId: _e.menuId }; this.$refs.conSelect.blur(); } } })