maxiaoshan 5 anni fa
parent
commit
7976eb1605

+ 60 - 4
dataprocess/src/front/front.go

@@ -2,6 +2,7 @@ package front
 
 import (
 	qu "qfw/util"
+	"strconv"
 	"time"
 
 	. "../util"
@@ -10,6 +11,12 @@ import (
 	"gopkg.in/mgo.v2/bson"
 )
 
+var UserMenu map[string][]map[string]interface{} //存储菜单
+
+func init() {
+	UserMenu = make(map[string][]map[string]interface{})
+}
+
 type Front struct {
 	*xweb.Action
 	login     xweb.Mapper `xweb:"/"`                //登录页面
@@ -27,7 +34,7 @@ type Front struct {
 	menuSecond     xweb.Mapper `xweb:"/front/menuSecond"`      //查二级菜单
 	menuSecondSave xweb.Mapper `xweb:"/front/menuSecond/save"` //保存二级菜单
 	menuSecondDel  xweb.Mapper `xweb:"/front/menuSecond/del"`  //删除二级菜单
-
+	personalMenu   xweb.Mapper `xweb:"/front/personalMenu"`    //个人菜单
 }
 
 func (f *Front) Login() {
@@ -43,7 +50,7 @@ func (f *Front) Login() {
 		}
 		user, _ := Mgo.FindOne("user", query)
 		checked := false
-		if (*user) != nil {
+		if user != nil && len(*user) > 0 {
 			checked = true
 			f.SetSession("user", map[string]interface{}{
 				"name":  (*user)["s_name"],
@@ -52,6 +59,7 @@ func (f *Front) Login() {
 				"email": email,
 				"id":    qu.BsonIdToSId((*user)["_id"]),
 			})
+			UserMenu[email] = GetUserMenu(qu.ObjToString((*user)["s_role"]))
 		}
 		f.ServeJson(map[string]interface{}{
 			"checked": checked,
@@ -92,7 +100,12 @@ func (f *Front) UpdatePwd() {
 func (f *Front) User() {
 	defer qu.Catch()
 	if f.Method() == "POST" {
-		data, _ := Mgo.Find("user", nil, `{"_id":1}`, nil, false, -1, -1)
+		query := bson.M{
+			"s_role": bson.M{
+				"$ne": "0",
+			},
+		}
+		data, _ := Mgo.Find("user", query, `{"_id":1}`, nil, false, -1, -1)
 		for _, d := range *data {
 			d["s_pwd"] = qu.SE.DecodeString(qu.ObjToString(d["s_pwd"]))
 		}
@@ -139,10 +152,53 @@ func (f *Front) UserSave() {
 			"_id": bson.NewObjectId(),
 		}
 	}
-
 	b := Mgo.Update("user", query, set, true, false)
 	//b := Mgo.UpdateById("user", _id, set)
 	f.ServeJson(map[string]interface{}{
 		"rep": b,
 	})
 }
+
+func (f *Front) PersonalMenu() {
+	user := f.GetSession("user").(map[string]interface{})
+	list := UserMenu[qu.ObjToString(user["email"])]
+	f.ServeJson(map[string]interface{}{
+		"data": list,
+	})
+}
+
+func GetUserMenu(role string) []map[string]interface{} {
+	list := []map[string]interface{}{}
+	maps := map[string]interface{}{}
+	if role == "0" {
+		maps = map[string]interface{}{}
+	} else {
+		maps = map[string]interface{}{
+			"role." + role: true,
+		}
+	}
+	data, _ := Mgo.Find("menu_first", maps, nil, nil, false, -1, -1)
+	for _, d := range *data {
+		_id := d["_id"]
+		if role == "0" {
+			maps = map[string]interface{}{
+				"s_pid": qu.BsonIdToSId(_id),
+			}
+		} else {
+			maps = map[string]interface{}{
+				"role." + role: true,
+				"s_pid":        qu.BsonIdToSId(_id),
+			}
+		}
+		secdatas, _ := Mgo.Find("menu_second", maps, nil, nil, false, -1, -1)
+		secmenumap := map[string]interface{}{}
+		for index, secdata := range *secdatas {
+			secmenumap[strconv.Itoa(index+1)] = secdata
+		}
+		if len(secmenumap) != 0 {
+			d["secondmenu"] = secmenumap
+		}
+		list = append(list, d)
+	}
+	return list
+}

+ 1 - 2
dataprocess/src/main.go

@@ -4,9 +4,8 @@ import (
 	qu "qfw/util"
 	"time"
 
-	. "./util"
-
 	"./front"
+	. "./util"
 
 	"github.com/go-xweb/xweb"
 )

+ 2 - 2
dataprocess/src/web/templates/com/header.html

@@ -88,9 +88,9 @@
 								if(role=="2"){
 									document.write("开发员")
 								}else if(role=="1"){
-									document.write("审核员")
-								}else{
 									document.write("管理员")
+								}else{
+									document.write("系统管理员")
 								}
 							</script>
 							</option>

+ 13 - 11
dataprocess/src/web/templates/com/menu.html

@@ -3,7 +3,8 @@
       <ul id="menu" class="sidebar-menu" data-widget="tree">
         <li class="header">HEADER</li>
         <!-- Optionally, you can add icons to the links -->
-        <li class="treeview">
+        <!--
+		<li class="treeview">
           	<a href="#"><i class="fa fa-clock-o"></i> <span>任务管理</span>
             <span class="pull-right-container">
                 <i class="fa fa-angle-left pull-right"></i>
@@ -38,26 +39,27 @@
 				<li><a href="/admin/rule/pre"><i class="fa fa-circle-o"></i>角色管理</a></li>
 				<li><a href="/front/menu"><i class="fa fa-circle-o"></i>菜单管理</a></li>
 			</ul>
-		</li>
+		</li>-->
       </ul>
     </section>
-	<!--<span id="role" class="hidden">{{session "role"}}</span>-->
+	<span id="role" class="hidden">{{(session "user").role}}</span>
 </aside>
 <script>
-/**$(function () {
-	$.post('/admin/menu','',function (data,status) {
+$(function () {
+	$.post('/front/personalMenu','',function (data,status) {
 		for(var a=0;a<data.data.length;a++) {
             var info=data.data[a]
+			console.log(info)
 		    if (info.secondmenu){
                 var str=""
-                for(var sec=1;sec<=Object.keys(info.secondmenu).length;sec++){
+               	for(var sec=1;sec<=Object.keys(info.secondmenu).length;sec++){
                     var ro=$("#role").text()
-                    if(ro=="3" || info.secondmenu[sec.toString(10)].role[ro] ) {
-                        str = str + '<li><a href=' + info.secondmenu[sec.toString(10)].href + '><i class="' + info.secondmenu[sec.toString(10)].pic + '"></i>' + info.secondmenu[sec.toString(10)].name + '</a></li>'
+                    if(ro=="0" || info.secondmenu[sec.toString(10)].role[ro] ) {
+                        str = str + '<li><a href=' + info.secondmenu[sec.toString(10)].s_href + '><i class="' + info.secondmenu[sec.toString(10)].s_css + '"></i>' + info.secondmenu[sec.toString(10)].s_name + '</a></li>'
                     }
                 }
                 $('#menu').append('<li class="treeview">' +
-                        '          <a href="#"><i class="'+info.pic+'"></i> <span>'+info.name+'</span>' +
+                        '          <a href="#"><i class="'+info.s_css+'"></i> <span>'+info.s_name+'</span>' +
                         '            <span class="pull-right-container">' +
                         '                <i class="fa fa-angle-left pull-right"></i>' +
                         '            </span>' +
@@ -65,11 +67,11 @@
                         '          <ul class="treeview-menu">' + str+ '</ul>' +
                         '        </li>')
 			}else{
-                $('#menu').append('<li><a href='+info.href+'><i class="'+info.pic+'"></i> <span>'+info.name+'</span></a></li>')
+                $('#menu').append('<li><a href='+info.s_href+'><i class="'+info.s_css+'"></i> <span>'+info.s_name+'</span></a></li>')
 			}
         }
     })
-})*/
+})
 function menuActive(name){
     setTimeout(function(){
         $(".sidebar-menu").tree();

+ 1 - 1
dataprocess/src/web/templates/com/menu_first.html

@@ -144,7 +144,7 @@
 		var name=$("#modal-info #name").val();
 		var href=$("#modal-info #href").val();
 		var css=$("#modal-info #css").val();
-		if(name==""||href==""||css==""){
+		if(name==""||css==""){
 			alert("表单填写不完整!")
 			return false;
 		}

+ 5 - 7
dataprocess/src/web/templates/com/user.html

@@ -73,8 +73,8 @@
 				    <div class="col-sm-10">
 				     	<select id="role" name="role" class="form-control">
 							<option value="2">开发员</option>
-							<option value="1">审核员</option>
-					  		<option value="0">管理员</option>
+							<option value="1">管理员</option>
+					  		<option value="0">系统管理员</option>
 						</select>
 				    </div>
 				</div>	
@@ -124,12 +124,10 @@ $(function () {
 				if(val==2){
 					role="开发员"
 				}else if(val==1){
-					role="审核员"
+					role="管理员"
 				}else if(val==0){
-                    role="管理员"
-                }else{
-					role="超级管理员"
-				}
+                    role="系统管理员"
+                }
 				return role
 			}},
 			{ "data":"_id",render:function(val,a,row){