wenhongquan 9 лет назад
Родитель
Сommit
42982c33de

+ 75 - 0
VisualInspection/css/user/userManager.css

@@ -0,0 +1,75 @@
+.comboTreeArrowBtn{
+    display: none;
+}
+.comboTreeWrapper,.comboTreeInputWrapper{
+  width: 100% !important;
+}
+.comboTreeWrapper{
+	position: relative;
+	text-align: left !important;
+}
+
+.comboTreeInputWrapper{
+	position: relative;
+}
+
+.comboTreeArrowBtn {
+	position: absolute;
+	top: 0;
+	width: 20px;
+	padding: 0;
+	margin: 0;
+}
+
+.comboTreeDropDownContainer {
+	display: none;
+	background: #fff;
+	border: 1px solid #aaa;
+	max-height: 250px;
+	overflow-y: auto;
+	position: absolute;
+    width: 100%;
+    box-sizing: border-box;
+    z-index: 1;
+}
+
+.comboTreeDropDownContainer ul{
+	padding: 0px;
+	margin: 0;
+}
+
+.comboTreeDropDownContainer li{
+	list-style-type: none;
+	padding-left: 15px;
+    cursor: pointer;
+}
+
+.comboTreeDropDownContainer li:hover{
+	background-color: #ddd;}
+.comboTreeDropDownContainer li:hover ul{
+	background-color: #fff;}
+.comboTreeDropDownContainer li span.comboTreeItemTitle.comboTreeItemHover{
+	background-color: #418EFF;
+	color: #fff;}
+
+span.comboTreeItemTitle{
+	display: block;
+	padding: 2px 4px;
+}
+.comboTreeDropDownContainer label{
+    cursor: pointer;
+	width: 100%;
+    display: block;
+}
+.comboTreeDropDownContainer .comboTreeItemTitle input {
+	position: relative;
+    top: 2px;
+	margin: 0px 4px 0px 0px;
+}
+.comboTreeParentPlus{
+    position: relative;
+    left: -12px;
+    top: 4px;
+    width: 4px;
+    float: left;
+}

+ 4 - 4
VisualInspection/js/config.js

@@ -1,6 +1,6 @@
-var base_ui_url = "http://10.112.0.236:8088/";
-var base_server_url = "http://10.112.0.236:8089/";
+// var base_ui_url = "http://10.112.0.236:8088/";
+// var base_server_url = "http://10.112.0.236:8089/";
 var base_image_server_url = "http://10.112.0.236:8088/";
 
-// var base_ui_url = "http://localhost:8081/";
-// var base_server_url = "http://localhost:8089/";
+var base_ui_url = "http://localhost:8080/";
+var base_server_url = "http://localhost:8089/";

+ 417 - 0
VisualInspection/js/lib/combotree/comboTreePlugin.js

@@ -0,0 +1,417 @@
+/*!
+ * jQuery ComboTree Plugin 
+ * Author:  Erhan FIRAT
+ * Mail:    erhanfirat@gmail.com
+ * Licensed under the MIT license
+ */
+
+
+;(function ( $, window, document, undefined ) {
+    
+    // Create the defaults once
+    var comboTreePlugin = 'comboTree',
+        defaults = {
+            source: [], 
+            isMultiple: false
+        };
+
+    // The actual plugin constructor
+    function ComboTree( element, options ) {
+        this.elemInput = element;
+        this._elemInput = $(element);
+
+        this.options = $.extend( {}, defaults, options) ;
+        
+        this._defaults = defaults;
+        this._name = comboTreePlugin;
+        
+        this.init();
+    }
+
+    ComboTree.prototype.init = function () {
+        // Setting Doms
+        this.comboTreeId = 'comboTree' + Math.floor(Math.random() * 999999);
+
+        if(this._elemInput.attr('id') === undefined)
+            this._elemInput.attr('id', this.comboTreeId + 'Input');
+        this.elemInputId = this._elemInput.attr('id');
+
+        this._elemInput.wrap('<div id="'+ this.comboTreeId + 'Wrapper" class="comboTreeWrapper"></div>');
+        this._elemInput.wrap('<div id="'+ this.comboTreeId + 'InputWrapper" class="comboTreeInputWrapper"></div>');
+        this._elemWrapper = $('#' + this.comboTreeId + 'Wrapper');
+
+        this._elemArrowBtn = $('<button id="' + this.comboTreeId + 'ArrowBtn" class="comboTreeArrowBtn"><span class="comboTreeArrowBtnImg">▼</span></button>')
+                        .css({
+                            left: this._elemInput.outerWidth(),
+                            height: this._elemInput.outerHeight()
+                        });
+        this._elemInput.after(this._elemArrowBtn);
+        this._elemWrapper.css({ width: this._elemInput.outerWidth() + this._elemArrowBtn.outerWidth() });
+        this._elemWrapper.append('<div id="' + this.comboTreeId + 'DropDownContainer" class="comboTreeDropDownContainer"><div class="comboTreeDropDownContent"></div>');
+        
+        // DORP DOWN AREA
+        this._elemDropDownContainer = $('#' + this.comboTreeId + 'DropDownContainer');
+        this._elemDropDownContainer.html(this.createSourceHTML());
+        
+        this._elemItems = this._elemDropDownContainer.find('li');
+        this._elemItemsTitle = this._elemDropDownContainer.find('span.comboTreeItemTitle');
+
+        // VARIABLES
+        this._selectedItem = {};
+        this._selectedItems = [];
+
+        this.bindings();
+    };
+
+
+
+    // *********************************
+    // SOURCES CODES
+    // *********************************
+
+    ComboTree.prototype.removeSourceHTML = function () {
+        this._elemDropDownContainer.html('');
+    };
+
+    ComboTree.prototype.createSourceHTML = function () {
+        var htmlText = this.createSourceSubItemsHTML(this.options.source);
+        return htmlText;
+    };
+
+    ComboTree.prototype.createSourceSubItemsHTML = function (subItems) {
+        var subItemsHtml = '<UL>';
+        for (var i=0; i<subItems.length; i++){
+            subItemsHtml += this.createSourceItemHTML(subItems[i]);
+        }
+        subItemsHtml += '</UL>'
+        return subItemsHtml;
+    }
+
+    ComboTree.prototype.createSourceItemHTML = function (sourceItem) {
+        var itemHtml = "",
+            isThereSubs = sourceItem.hasOwnProperty("subs");
+        
+        itemHtml = '<LI class="ComboTreeItem' + (isThereSubs?'Parent':'Chlid') + '"> ';
+        
+        if (isThereSubs)
+            itemHtml += '<span class="comboTreeParentPlus">&minus;</span>';
+
+        if (this.options.isMultiple)
+            itemHtml += '<span data-id="' + sourceItem.id + '" class="comboTreeItemTitle"><input type="checkbox">' + sourceItem.title + '</span>';
+        else
+            itemHtml += '<span data-id="' + sourceItem.id + '" class="comboTreeItemTitle">' + sourceItem.title + '</span>';
+
+        if (isThereSubs)
+            itemHtml += this.createSourceSubItemsHTML(sourceItem.subs);
+
+        itemHtml += '</LI>';
+        return itemHtml;
+    };
+
+
+    // BINDINGS
+    // *****************************
+    ComboTree.prototype.bindings = function () {
+        var _this = this;
+
+        this._elemArrowBtn.on('click', function(e){
+            e.stopPropagation();
+            _this.toggleDropDown();
+        });
+        this._elemInput.on('click', function(e){
+            e.stopPropagation();
+            if (!_this._elemDropDownContainer.is(':visible'))
+                _this.toggleDropDown();
+        });
+        this._elemItems.on('click', function(e){
+            e.stopPropagation();
+            if ($(this).hasClass('ComboTreeItemParent')){
+                _this.toggleSelectionTree(this);
+            }
+        });        
+        this._elemItemsTitle.on('click', function(e){
+            e.stopPropagation();
+            if (_this.options.isMultiple)
+                _this.multiItemClick(this);
+            else
+                _this.singleItemClick(this);
+        });
+        this._elemItemsTitle.on("mousemove", function (e) {
+            e.stopPropagation();
+            _this.dropDownMenuHover(this);
+        });
+
+        // KEY BINDINGS
+        this._elemInput.on('keyup', function(e) {
+            e.stopPropagation();
+
+            switch (e.keyCode) {
+                case 27:
+                    _this.closeDropDownMenu(); break;
+                case 13:                  
+                case 39: case 37: case 40: case 38:
+                    e.preventDefault(); 
+                    break;
+                default: 
+                    if (!_this.options.isMultiple)
+                        _this.filterDropDownMenu(); 
+                    break;
+            }
+        });
+        this._elemInput.on('keydown', function(e) {
+            e.stopPropagation();
+
+            switch (e.keyCode) {
+            case 9:
+                _this.closeDropDownMenu(); break;
+            case 40: case 38:
+                e.preventDefault(); 
+                _this.dropDownInputKeyControl(e.keyCode - 39); break;
+            case 37: case 39:
+                e.preventDefault(); 
+                _this.dropDownInputKeyToggleTreeControl(e.keyCode - 38);
+                break;
+            case 13:
+                if (_this.options.isMultiple)
+                    _this.multiItemClick(_this._elemHoveredItem);
+                else
+                    _this.singleItemClick(_this._elemHoveredItem);
+                e.preventDefault(); 
+                break;
+            default: 
+                if (_this.options.isMultiple)
+                    e.preventDefault();
+        }
+        });
+        // ON FOCUS OUT CLOSE DROPDOWN
+        $(document).on('mouseup.' + _this.comboTreeId, function (e){
+            if (!_this._elemWrapper.is(e.target) && _this._elemWrapper.has(e.target).length === 0 && _this._elemDropDownContainer.is(':visible'))
+                _this.closeDropDownMenu();
+        });
+    };
+
+
+
+
+    // EVENTS HERE 
+    // ****************************
+
+    // DropDown Menu Open/Close
+    ComboTree.prototype.toggleDropDown = function () {
+        this._elemDropDownContainer.slideToggle(50);
+        this._elemInput.focus();
+    };
+    ComboTree.prototype.closeDropDownMenu = function () {
+        this._elemDropDownContainer.slideUp(50);
+    };
+    // Selection Tree Open/Close
+    ComboTree.prototype.toggleSelectionTree = function (item, direction) {
+        var subMenu = $(item).children('ul')[0];
+        if (direction === undefined){
+            if ($(subMenu).is(':visible'))
+                $(item).children('span.comboTreeParentPlus').html("+");
+            else
+                $(item).children('span.comboTreeParentPlus').html("&minus;");
+
+            $(subMenu).slideToggle(50);
+        }
+        else if (direction == 1 && !$(subMenu).is(':visible')){
+                $(item).children('span.comboTreeParentPlus').html("&minus;");
+                $(subMenu).slideDown(50);
+        }
+        else if (direction == -1){
+            if ($(subMenu).is(':visible')){
+                $(item).children('span.comboTreeParentPlus').html("+");
+                $(subMenu).slideUp(50);
+            }
+            else {
+                this.dropDownMenuHoverToParentItem(item);
+            }
+        }
+            
+    };
+
+
+    // SELECTION FUNCTIONS
+    // *****************************
+    ComboTree.prototype.singleItemClick = function (ctItem) {
+        this._selectedItem = {
+            id: $(ctItem).attr("data-id"),
+            title: $(ctItem).text()
+        };
+
+        this.refreshInputVal();
+        this.closeDropDownMenu();
+    };
+    ComboTree.prototype.multiItemClick = function (ctItem) {
+        this._selectedItem = {
+            id: $(ctItem).attr("data-id"),
+            title: $(ctItem).text()
+        };
+
+        var index = this.isItemInArray(this._selectedItem, this._selectedItems);
+        if (index){
+            this._selectedItems.splice(parseInt(index), 1);
+            $(ctItem).find("input").prop('checked', false);
+        }
+        else {
+            this._selectedItems.push(this._selectedItem);
+            $(ctItem).find("input").prop('checked', true);
+        }
+
+        this.refreshInputVal();
+    };
+
+    ComboTree.prototype.isItemInArray = function (item, arr) {
+
+        for (var i=0; i<arr.length; i++)
+            if (item.id == arr[i].id && item.title == arr[i].title)
+                return i + "";
+
+        return false;
+    }
+
+    ComboTree.prototype.refreshInputVal = function () {
+        var tmpTitle = "";
+        
+        if (this.options.isMultiple) {
+            for (var i=0; i<this._selectedItems.length; i++){
+                tmpTitle += this._selectedItems[i].title;
+                if (i<this._selectedItems.length-1)
+                    tmpTitle += ", ";
+            }
+        }
+        else {
+            tmpTitle = this._selectedItem.title;
+        }
+
+        this._elemInput.val(tmpTitle);
+    }
+
+    ComboTree.prototype.dropDownMenuHover = function (itemSpan, withScroll) {
+        this._elemItems.find('span.comboTreeItemHover').removeClass('comboTreeItemHover');
+        $(itemSpan).addClass('comboTreeItemHover');
+        this._elemHoveredItem = $(itemSpan);
+        if (withScroll)
+            this.dropDownScrollToHoveredItem(this._elemHoveredItem);
+    }
+
+    ComboTree.prototype.dropDownScrollToHoveredItem = function (itemSpan) {
+        var curScroll = this._elemDropDownContainer.scrollTop();
+        this._elemDropDownContainer.scrollTop(curScroll + $(itemSpan).parent().position().top - 80);
+    }
+
+    ComboTree.prototype.dropDownMenuHoverToParentItem = function (item) {
+        var parentSpanItem = $($(item).parents('li.ComboTreeItemParent')[0]).children("span.comboTreeItemTitle");
+        if (parentSpanItem.length)
+            this.dropDownMenuHover(parentSpanItem, true);
+        else 
+            this.dropDownMenuHover(this._elemItemsTitle[0], true);
+    }
+
+    ComboTree.prototype.dropDownInputKeyToggleTreeControl = function (direction) {
+        var item = this._elemHoveredItem;
+        if ($(item).parent('li').hasClass('ComboTreeItemParent'))
+            this.toggleSelectionTree($(item).parent('li'), direction);
+        else if (direction == -1)
+            this.dropDownMenuHoverToParentItem(item);
+    }
+
+    ComboTree.prototype.dropDownInputKeyControl = function (step) {
+        if (!this._elemDropDownContainer.is(":visible")) 
+            this.toggleDropDown();
+
+        var list = this._elemItems.find("span.comboTreeItemTitle:visible");
+        i = this._elemHoveredItem?list.index(this._elemHoveredItem) + step:0;
+        i = (list.length + i) % list.length;
+
+        this.dropDownMenuHover(list[i], true);        
+    },
+
+    ComboTree.prototype.filterDropDownMenu = function () {
+        var searchText = this._elemInput.val();
+        if (searchText != ""){
+            this._elemItemsTitle.hide();
+            this._elemItemsTitle.siblings("span.comboTreeParentPlus").hide();
+            list = this._elemItems.find("span:icontains('" + this._elemInput.val() + "')").each(function (i, elem) {
+                $(this).show();
+                $(this).siblings("span.comboTreeParentPlus").show();
+            });    
+        }
+        else{
+            this._elemItemsTitle.show();
+            this._elemItemsTitle.siblings("span.comboTreeParentPlus").show();
+        }
+    }
+
+    // Retuns Array (multiple), Integer (single), or False (No choice)
+    ComboTree.prototype.getSelectedItemsId = function () {
+        if (this.options.isMultiple && this._selectedItems.length>0){
+            var tmpArr = [];
+            for (i=0; i<this._selectedItems.length; i++)
+                tmpArr.push(this._selectedItems[i].id);
+
+            return tmpArr;
+        }
+        else if (!this.options.isMultiple && this._selectedItem.hasOwnProperty('id')){
+            return this._selectedItem.id;
+        }
+        return false;
+    }
+
+    // Retuns Array (multiple), Integer (single), or False (No choice)
+    ComboTree.prototype.getSelectedItemsTitle = function () {
+        if (this.options.isMultiple && this._selectedItems.length>0){
+            var tmpArr = [];
+            for (i=0; i<this._selectedItems.length; i++)
+                tmpArr.push(this._selectedItems[i].title);
+
+            return tmpArr;
+        }
+        else if (!this.options.isMultiple && this._selectedItem.hasOwnProperty('id')){
+            return this._selectedItem.title;
+        }
+        return false;
+    }
+
+
+    ComboTree.prototype.unbind = function () {
+        this._elemArrowBtn.off('click');
+        this._elemInput.off('click');
+        this._elemItems.off('click');        
+        this._elemItemsTitle.off('click');
+        this._elemItemsTitle.off("mousemove");
+        this._elemInput.off('keyup');
+        this._elemInput.off('keydown');
+        this._elemInput.off('mouseup.' + this.comboTreeId);
+        $(document).off('mouseup.' + this.comboTreeId);
+    }
+
+    ComboTree.prototype.destroy = function () {
+        this.unbind();
+        this._elemWrapper.before(this._elemInput);
+        this._elemWrapper.remove();
+        this._elemInput.removeData('plugin_' + comboTreePlugin);
+    }
+
+
+    $.fn[comboTreePlugin] = function ( options) {
+        var ctArr = [];
+        this.each(function () {
+            if (!$.data(this, 'plugin_' + comboTreePlugin)) {
+               $.data(this, 'plugin_' + comboTreePlugin, new ComboTree( this, options));
+               ctArr.push($(this).data()['plugin_' + comboTreePlugin]);
+            }
+        });
+
+        if (this.length == 1)
+            return ctArr[0];
+        else
+            return ctArr;
+    }
+
+})( jQuery, window, document );
+
+
+
+

+ 1 - 0
VisualInspection/js/lib/combotree/icontains.js

@@ -0,0 +1 @@
+$.expr[':'].icontains = function (obj, index, meta, stack) { return (obj.textContent || obj.innerText || jQuery(obj).text() || '').toLowerCase().indexOf(meta[3].toLowerCase()) >= 0; };

+ 40 - 10
VisualInspection/js/user/addUser.js

@@ -1,5 +1,7 @@
 var dept_selectinput;
 var usertemp;
+var role_selectinput;
+
 
 function loadUserData(nodedata) {
     var pnode = nodedata;
@@ -8,13 +10,26 @@ function loadUserData(nodedata) {
     if (edittype == "add") {
         $("#dept_name").val("")
     }
+
+    if (role_selectinput == null) {
+        role_selectinput = $('#user_role_select').comboTree({
+            source: roles,
+            isMultiple: true
+        });
+    }
+    role_selectinput.closeDropDownMenu();
+
     if (edittype == "edit") {
         usertemp = nodedata;
         pnode = [{ "id": usertemp.organid }]
         initUserInfo()
+
+
     }
 
 
+
+
     dept_selectinput = new TreeSelect({
         element: '#user_dept_select',
         data: zdata,
@@ -23,7 +38,7 @@ function loadUserData(nodedata) {
         selectvalue: pnode.length > 0 ? pnode[0].id : null
     });
 
-    $("#user_add_btn").on("click", function() {
+    $("#user_add_btn").on("click", function () {
         addUser();
     })
 
@@ -58,13 +73,13 @@ function initUserInfo() {
     $("#user_position").val(usertemp.positionid)
     $("#user_idno").val(usertemp.idno)
     $("#user_email").val(usertemp.email)
-    if (typeof(usertemp.pic) != "undefinde" && usertemp.pic != null) {
+    if (typeof (usertemp.pic) != "undefinde" && usertemp.pic != null) {
         $("#user_img_pre").removeClass("hide");
         $("#user_img_add").addClass("hide");
         var $section = $("#user_img_pre2");
         var $span = $("<span class='up-span'>");
         $span.appendTo($section);
-        var $img0 = $("<img class='close-upimg'>").on("click", function(event) {
+        var $img0 = $("<img class='close-upimg'>").on("click", function (event) {
             event.preventDefault();
             event.stopPropagation();
             // $(".works-mask").show();
@@ -89,6 +104,19 @@ function initUserInfo() {
         $(".up-img").removeClass("up-opcity");
     }
 
+    var attr = [];
+    if (usertemp.roles.length > 0) {
+        for (var j = 0; j < usertemp.roles.length; j++) {
+           var ii={};
+           ii["id"]=usertemp.roles[j].id;
+           ii["title"]=usertemp.roles[j].des;
+           attr.push(ii);
+        }
+    }
+
+    role_selectinput._selectedItems = attr;
+    role_selectinput.refreshInputVal();
+
 
 }
 
@@ -109,6 +137,7 @@ function addUser() {
     var userbirth = $("#user_birth").val();
     var userposition = $("#user_position").val();
     var usertruename = $("#user_true_name").val();
+    var userroles = role_selectinput.getSelectedItemsId();
 
     var parm = {
         "username": username,
@@ -122,32 +151,33 @@ function addUser() {
         "birth": userbirth,
         "organid": dept_selectinput.value,
         "positionid": 1,
-        "truename": usertruename
+        "truename": usertruename,
+        "roleids":userroles
     }
     if (edittype == "edit") {
         parm["id"] = usertemp.id;
-        UserUpdate(parm, function(data) {
+        UserUpdate(parm, function (data) {
             layer.msg('修改成功!', {
                 time: 2000, //20s后自动关闭
-            }, function() {
+            }, function () {
                 $('#addUserModal').modal('hide')
                 updateUser(dept_selectinput.value)
             });
-        }, function(error) {
+        }, function (error) {
 
         });
 
         return;
     }
 
-    UserAdd(parm, function(data) {
+    UserAdd(parm, function (data) {
         layer.msg('添加成功!', {
             time: 2000, //20s后自动关闭
-        }, function() {
+        }, function () {
             $('#addUserModal').modal('hide')
             updateUser(dept_selectinput.value)
         });
-    }, function(error) {
+    }, function (error) {
 
     });
 

+ 22 - 6
VisualInspection/js/user/userManager.js

@@ -47,6 +47,8 @@
      flex: true,
      colClass: 'text-center'
  }];
+
+ var roles = [];
  $(document).ready(function() {
 
      $("#main_content_title").html("用户管理")
@@ -65,6 +67,20 @@
          $('#addUserModal').modal('show')
      })
 
+   RoleGetALLNoData(function(data){
+       
+         roles = [];
+         for (var i = 0; i < data.length; i++) {
+             var m = data[i];
+             var zdataItem = {};
+             zdataItem["id"] = m.id;
+             zdataItem["title"] = m.des;
+             roles.push(zdataItem);
+         }
+   },function(error){
+
+   });
+
 
      $("#dept_add").on("click", function() {
          var nodedata = dept_tree.getSelectedNodes();
@@ -257,18 +273,18 @@
                      var user = data[i];
 
                      var attr = "";
-                     if (user.authorities.length > 0) {
-                         for (var j = 0; j < user.authorities.length; j++) {
-                             var at = user.authorities[j];
+                     if (user.roles.length > 0) {
+                         for (var j = 0; j < user.roles.length; j++) {
+                             var at = user.roles[j];
                              if (attr.length > 0) {
-                                 attr += "," + at.authority;
+                                 attr += "," + at.des;
                                  continue;
                              }
-                             attr += at.authority;
+                             attr += at.des;
                          }
                      }
 
-                     console.log(user.username + "..." + user.truename + '...' + user.workno + "..." + user.mobile + "..." + attr + "..." + user.id)
+                  
                      UserMap.set(user.id, user)
                      var userdata = {};
                      userdata["checked"] = false;

+ 13 - 1
VisualInspection/js/util/service.js

@@ -248,7 +248,19 @@ function uploadFile(file, name, successfunc, errorfunc) {
     });
 }
 
-
+function RoleGetALLNoData(success, fail) {
+    var url = base_server_url + ROLE_GET_ALL;
+    ajaxGet(url, "", function(response) {
+        var data = response;
+        if (data.result_code == 0) {
+            success(data.result_data)
+        } else {
+            fail(data.result_desc);
+        }
+    }, function(error) {
+        fail("网络错误");
+    });
+}
 
 function RoleGetALL(page,size, success, fail) {
     var url = base_server_url + ROLE_GET_ALL_DATA+"/"+page+"/"+size;

+ 5 - 0
VisualInspection/view/user/userManager.html

@@ -1,7 +1,12 @@
 <link rel="stylesheet" type="text/css" href="/css/user/userManager.css?__inline">
 <script type="text/javascript" src="/node_modules/zui/dist/lib/dashboard/zui.dashboard.min.js?__inline"></script>
 <link rel="stylesheet" type="text/css" href="/node_modules/zui/dist/lib/dashboard/zui.dashboard.min.css">
+
+<script type="text/javascript" src="/js/lib/combotree/icontains.js?__inline"></script>
+<script type="text/javascript" src="/js/lib/combotree/comboTreePlugin.js?__inline"></script>
+
 <script type="text/javascript" src="/js/user/userManager.js?__inline"></script>
+
 <div class="container-fluid ">
     <div id="dashboard" class="dashboard dashboard-draggable" data-height="500">
         <div class="row">

+ 2 - 1
VisualInspection_server/src/main/java/com/xintong/visualinspection/bean/User.java

@@ -74,8 +74,9 @@ public class User implements UserDetails {
 	private String token;
 	private String email;
 	private String pic;
+	
+	private List<String> roleids;
 
-	@JsonIgnore
 	private List<Role> roles;
 	private List<? extends GrantedAuthority> authorities;
 

+ 2 - 1
VisualInspection_server/src/main/java/com/xintong/visualinspection/controller/BaseController.java

@@ -177,7 +177,8 @@ public class BaseController {
     	String username = jwtTokenUtil.getUsernameFromToken(authToken);
 		if (username != null) {
 			UserDetails u = redisCacheUtil.getUserByUserName(username);
-			User user = CacheUtil.userMap.get(new Long(((User)u).getId()));
+			User u_t = (User) JSON.parseObject(JSON.toJSONString(u),User.class) ; 
+			User user = CacheUtil.userMap.get(new Long(u_t.getId()));
 			return user;
 		}
 		return null;

+ 4 - 4
VisualInspection_server/src/main/java/com/xintong/visualinspection/controller/RoleController.java

@@ -87,13 +87,13 @@ public class RoleController extends BaseController {
 	 * @param size
 	 * @return
 	 */
-	@RequestMapping(value = "/get/all/{page}/{size}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
-	public String getAllRole(@PathVariable Integer page, @PathVariable Integer size) {
+	@RequestMapping(value = "/get/all", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
+	public String getAllRole() {
 		try {
-			PageHelper.startPage(page, size);
+	
 			List<Role> roles = roleService.getRoles(new Role());
 
-			return returnResult(0, "获取成功", new PageInfo(roles));
+			return returnResult(0, "获取成功", roles);
 		} catch (Exception e) {
 			throw new BusinessException(20001);
 		}

+ 17 - 0
VisualInspection_server/src/main/java/com/xintong/visualinspection/controller/UserController.java

@@ -19,6 +19,7 @@ import com.xintong.system.err.BusinessException;
 import com.xintong.system.securityTools.RedisCacheUtil;
 import com.xintong.visualinspection.bean.User;
 import com.xintong.visualinspection.service.AuthService;
+import com.xintong.visualinspection.service.RoleService;
 import com.xintong.visualinspection.service.UserService;
 
 /**
@@ -38,6 +39,8 @@ public class UserController extends BaseController {
     
     @Autowired
     private AuthService authService;
+    @Autowired
+    private RoleService roleService;
     
     @Autowired
     private RedisCacheUtil redisCacheUtil;
@@ -80,6 +83,15 @@ public class UserController extends BaseController {
     public String addUser(@RequestBody User user) throws Exception{
     	user.setPassword(new Md5PasswordEncoder().encodePassword(user.getPassword(), null));
     	userService.insert(user);
+    	List<User> us=userService.getUsers(user);
+    	if(us.size()==1){
+    		if(user.getRoleids()!=null){
+        		for(String id:user.getRoleids()){
+        			roleService.roleBindUser(Integer.parseInt(id), us.get(0).getId());
+        		}
+        	}
+    	}
+    	
     	return returnResult(0, "添加成功", null);
     }
     
@@ -97,6 +109,11 @@ public class UserController extends BaseController {
         	if(user.getPassword()!=null){
         		user.setPassword(new Md5PasswordEncoder().encodePassword(user.getPassword(), null));
         	}
+        	if(user.getRoleids()!=null){
+        		for(String id:user.getRoleids()){
+        			roleService.roleBindUser(Integer.parseInt(id), user.getId());
+        		}
+        	}
         	userService.update(user);
         	return super.returnResult(0, "修改成功", null);
         }catch(Exception e){

+ 8 - 0
VisualInspection_server/src/main/java/com/xintong/visualinspection/service/impl/UserServiceImpl.java

@@ -13,9 +13,11 @@ import org.springframework.stereotype.Service;
 
 import com.mysql.jdbc.StringUtils;
 import com.xintong.visualinspection.bean.Permission;
+import com.xintong.visualinspection.bean.Role;
 import com.xintong.visualinspection.bean.User;
 import com.xintong.visualinspection.dao.cluster.UserInfoDao;
 import com.xintong.visualinspection.dao.master.PermissionDao;
+import com.xintong.visualinspection.dao.master.RoleDao;
 import com.xintong.visualinspection.dao.master.UserDao;
 import com.xintong.visualinspection.pojo.SimpleGrantedAuthority;
 import com.xintong.visualinspection.service.BaseService;
@@ -41,6 +43,8 @@ public class UserServiceImpl extends BaseService implements UserService {
     @Autowired
     private UserInfoDao userInfoDao;
     @Autowired
+    private RoleDao roleDao;
+    @Autowired
     private PermissionDao permissionDao;
 
     @Autowired
@@ -67,6 +71,8 @@ public class UserServiceImpl extends BaseService implements UserService {
 				u.setPassword(null);
 				List<Permission> permissions = permissionDao.findByAdminUserId(u.getId());
 	            List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
+	            List<Role> roles = roleDao.getRoleByUser(u.getId());
+	            u.setRoles(roles);
 	            for (Permission permission : permissions) {
 	                if (permission != null && permission.getName() != null) {
 	                    GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(permission.getName());
@@ -110,6 +116,8 @@ public class UserServiceImpl extends BaseService implements UserService {
         User user = userInfoDao.findByUserName(username);
         if (user != null) {
             List<Permission> permissions = permissionDao.findByAdminUserId(user.getId());
+            List<Role> roles = roleDao.getRoleByUser(user.getId());
+            user.setRoles(roles);
             List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
             for (Permission permission : permissions) {
                 if (permission != null && permission.getName() != null) {

+ 3 - 3
VisualInspection_server/src/main/resources/application.properties

@@ -2,14 +2,14 @@ server.port=8089
 spring.thymeleaf.cache=false
 context.listener.classes=com.xintong.SystemInit
 
-master.datasource.url = jdbc:mysql://10.112.0.236:3306/visualinspection?useUnicode=true&characterEncoding=utf-8
+master.datasource.url = jdbc:mysql://192.168.8.236:3306/visualinspection?useUnicode=true&characterEncoding=utf-8
 master.datasource.username = root
 master.datasource.password = root
 master.datasource.driver-class-name = com.mysql.jdbc.Driver
 master.mapper-locations=classpath:com/xintong/visualinspection/mapper/master/*.xml
 
 ## \u7528\u6237\u6570\u636e\u6e90\u914d\u7f6e
-cluster.datasource.url=jdbc:mysql://10.112.0.236:3306/yanhai?useUnicode=true&characterEncoding=utf8
+cluster.datasource.url=jdbc:mysql://192.168.8.236:3306/yanhai?useUnicode=true&characterEncoding=utf8
 cluster.datasource.username=root
 cluster.datasource.password=root
 cluster.datasource.driver-class-name = com.mysql.jdbc.Driver
@@ -50,7 +50,7 @@ spring.datasource.useGlobalDataSourceStat=true
 # Redis\u6570\u636e\u5e93\u7d22\u5f15\uff08\u9ed8\u8ba4\u4e3a0\uff09
 spring.redis.database=0  
 # Redis\u670d\u52a1\u5668\u5730\u5740
-spring.redis.host=10.112.0.236
+spring.redis.host=192.168.8.236
 # Redis\u670d\u52a1\u5668\u8fde\u63a5\u7aef\u53e3
 spring.redis.port=6379  
 # Redis\u670d\u52a1\u5668\u8fde\u63a5\u5bc6\u7801\uff08\u9ed8\u8ba4\u4e3a\u7a7a\uff09