menuManege.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. var _this, dataObj=[], _Tok = null;
  2. new Vue({
  3. el: '#app',
  4. data: function() {
  5. return {
  6. tableData: [],
  7. TreeData:[],
  8. nowForm:{
  9. icon: "",
  10. isCache: "0",
  11. isFrame: "1",
  12. menuName: "",
  13. menuType: "M",
  14. orderNum: "0",
  15. parentId: 0,
  16. path: "",
  17. status: "0",
  18. visible: "0",
  19. perms:""
  20. },
  21. dialogVisible:false,
  22. inpKey:"",
  23. defaultProps: {
  24. children: 'children',
  25. label: 'label'
  26. },
  27. parentName: {
  28. menuName: "请选择",
  29. menuId: ""
  30. }
  31. }
  32. },
  33. created() {
  34. _this = this;
  35. _Tok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
  36. _this.getList();
  37. },
  38. methods: {
  39. getList() {
  40. let data1 = {
  41. pageNum:1,
  42. pageSize:100
  43. };
  44. let _opts = {
  45. url: baseUrl + "/system/menu/list",
  46. type:"GET"
  47. };
  48. let _he = {
  49. "Authorization":"Bearer "+_Tok
  50. };
  51. getAxios(_opts, data1,_he)
  52. .then(function(res) {
  53. if (res.code == 200) {
  54. _this.tableData = _this.getTrees(res.data, 0)
  55. _this.TreeData = [{
  56. id: 0,
  57. label: "主类目",
  58. menuName:"主类目",
  59. menuId:0,
  60. children:(res.data.length? _this.getTrees(res.data, 0):[])
  61. }];
  62. dataObj = res.data;
  63. }else{
  64. _this.$message.error(res.msg);
  65. }
  66. })
  67. },
  68. getTrees(data, parentId) {
  69. var tree = [];
  70. var temp;
  71. for (var i = 0; i < data.length; i++) {
  72. data[i].label = data[i].menuName;
  73. data[i].id = data[i].menuId;
  74. if (data[i].parentId == parentId) {
  75. var obj = data[i];
  76. temp = _this.getTrees(data, data[i].menuId);
  77. if (temp.length > 0) {
  78. obj.children = [...temp];
  79. }
  80. tree.push(obj);
  81. }
  82. }
  83. return tree;
  84. },
  85. Search(_key){
  86. let newArr = [],_ovj = dataObj;
  87. if(_key == ""){
  88. newArr = dataObj;
  89. }else{
  90. for(var i=0;i<_ovj.length;i++){
  91. if( JSON.stringify(_ovj[i]).indexOf(_key) != -1){
  92. newArr.push(_ovj[i])
  93. }
  94. }
  95. }
  96. _this.tableData = _this.getTrees(newArr, 0);
  97. },
  98. newAdd(_row){
  99. if(_row.menuId != undefined){
  100. _this.parentName = {
  101. menuName: _row.menuName,
  102. menuId: _row.menuId
  103. };
  104. }else{
  105. _this.parentName = {
  106. menuName: _this.TreeData[0].menuName,
  107. menuId: _this.TreeData[0].menuId
  108. };
  109. }
  110. _this.nowForm = {
  111. icon:_row.menuId != undefined? "#":"",
  112. isCache: "0",
  113. isFrame: "1",
  114. menuName: "",
  115. menuType:_row.menuId != undefined?"C" :"M",
  116. orderNum: "0",
  117. parentId:_row.menuId != undefined? _row.menuId:0,
  118. path: "",
  119. status: "0",
  120. visible: "0",
  121. perms:""
  122. };
  123. _this.dialogVisible = true;
  124. },
  125. Edit(_row){
  126. let data1 = {};
  127. let _opts = {
  128. url: baseUrl + "/system/menu/" + _row.menuId,
  129. type:"GET"
  130. };
  131. let _he = {
  132. "Authorization":"Bearer "+_Tok
  133. };
  134. getAxios(_opts, data1,_he)
  135. .then(function(res) {
  136. if (res.code == 200) {
  137. if(_row.parentId == 0){
  138. _this.parentName = {
  139. menuName:"主类目",
  140. menuId:0,
  141. };
  142. }else{
  143. dataObj.forEach((it,ind)=>{
  144. if(it.menuId == _row.parentId){
  145. _this.parentName = {
  146. menuName: it.menuName,
  147. menuId: it.menuId
  148. };
  149. }
  150. })
  151. }
  152. _this.nowForm = res.data;
  153. _this.dialogVisible = true;
  154. }
  155. })
  156. },
  157. Delete(_row){
  158. _this.$confirm('是否确认删除编号为"'+_row.menuId+'"的数据项?', '温馨提示', {
  159. confirmButtonText: '确定',
  160. cancelButtonText: '取消',
  161. type: 'warning'
  162. }).then(() => {
  163. let data1 = {};
  164. let _opts = {
  165. url: baseUrl + "/system/menu/"+_row.menuId,
  166. type:"DELETE"
  167. };
  168. let _he = {
  169. "Authorization":"Bearer "+_Tok
  170. };
  171. getAxios(_opts, data1,_he)
  172. .then(function(res) {
  173. if(res.code == 200){
  174. _this.$message({
  175. type: 'success',
  176. message: '删除成功!'
  177. });
  178. _this.getList();
  179. }else{
  180. _this.$message.error(res.msg);
  181. }
  182. })
  183. }).catch(() => {
  184. });
  185. },
  186. conFirm(){
  187. _this.nowForm.parentId = _this.parentName.menuId;
  188. if(_this.nowForm.menuName == ""){
  189. _this.$message({
  190. type: 'warning',
  191. message: "请输入菜单名称"
  192. });
  193. return;
  194. }
  195. if(_this.nowForm.path == ""&&_this.nowForm.menuType == "C"){
  196. _this.$message({
  197. type: 'warning',
  198. message: '请输入页面路径',
  199. })
  200. return;
  201. }
  202. let data1 = JSON.stringify(_this.nowForm);
  203. let _opts = {
  204. url: baseUrl + "/system/menu",
  205. type: _this.nowForm.menuId == undefined?"POST":"PUT"
  206. };
  207. let _he = {
  208. "Authorization":"Bearer "+_Tok,
  209. "Content-Type": 'application/json; charset=UTF-8'
  210. };
  211. postAxios(_opts,data1,_he)
  212. .then(function(res){
  213. if(res.code == 200){
  214. _this.$message({
  215. type: 'success',
  216. message: '操作成功!'
  217. });
  218. _this.getList();
  219. _this.dialogVisible = false;
  220. }else{
  221. _this.$message.error(res.msg);
  222. }
  223. })
  224. },
  225. nodeClick(_e){
  226. _this.parentName = {
  227. menuName: _e.menuName,
  228. menuId: _e.menuId
  229. };
  230. this.$refs.conSelect.blur();
  231. }
  232. }
  233. })