diff --git a/controllers/ManagerController.go b/controllers/ManagerController.go index 25c17820..8fb89254 100644 --- a/controllers/ManagerController.go +++ b/controllers/ManagerController.go @@ -19,6 +19,7 @@ import ( "github.com/lifei6671/mindoc/utils/filetil" "github.com/lifei6671/mindoc/utils/pagination" "gopkg.in/russross/blackfriday.v2" + "time" ) type ManagerController struct { @@ -29,7 +30,7 @@ func (c *ManagerController) Prepare() { c.BaseController.Prepare() if !c.Member.IsAdministrator() { - c.Abort("403") + c.ShowErrorPage(403,"用户权限不足") } } @@ -742,20 +743,66 @@ func (c *ManagerController) MemberGroupList() { } c.Data["TotalPages"] = int(math.Ceil(float64(totalCount) / float64(conf.PageSize))) - c.Data["Lists"] = memberGroupList + b, err := json.Marshal(memberGroupList) + + if err != nil { + c.Data["Result"] = template.JS("[]") + } else { + c.Data["Result"] = template.JS(string(b)) + } } + //编辑或添加用户组 func (c *ManagerController) MemberGroupEdit() { c.Prepare() c.TplName = "manager/member_group_edit.tpl" - if c.Ctx.Input.IsPost() { - + if c.Member.Role != 0 { + c.ShowErrorPage(500,"只有超级管理员才能编辑或添加用户组") } - groupId,_ := c.GetInt("group_id",0) + groupId,_ := strconv.Atoi(c.Ctx.Input.Param(":id")) memberGroup := models.NewMemberGroup() var err error + + if c.Ctx.Input.IsPost() { + groupId,_ := c.GetInt("group_id",0) + + groupName := strings.TrimSpace(c.GetString("group_name")) + if groupName == "" { + if c.Ctx.Input.IsAjax() { + c.JsonResult(6002,"用户组名称不能为空") + }else{ + c.ShowErrorPage(500,"用户组名称不能为空") + } + } + if groupId > 0 { + memberGroup,err = models.NewMemberGroup().FindFirst(groupId) + if err != nil { + beego.Error("查询用户组失败",err) + if c.Ctx.Input.IsAjax() { + c.JsonResult(6001,"未查到指定的用户组信息") + }else{ + c.ShowErrorPage(500,"用户组名称不能为空") + } + } + + memberGroup.GroupName = groupName + memberGroup.ModifyAt = c.Member.MemberId + }else{ + memberGroup.GroupName = groupName + memberGroup.CreateTime = time.Now() + memberGroup.CreateAt = c.Member.MemberId + } + if err := memberGroup.InsertOrUpdate(); err != nil { + beego.Error("保存用户组失败 =>",err) + c.JsonResult(500,"保存失败") + }else{ + c.JsonResult(0,"保存成功",memberGroup) + } + + } + if groupId > 0 { memberGroup,err = memberGroup.FindFirst(groupId) if err != nil { @@ -767,17 +814,43 @@ func (c *ManagerController) MemberGroupEdit() { } +//删除用户组 +func (c *ManagerController) MemberGroupDelete() { + c.Prepare() + + if c.Member.Role != 0 { + c.JsonResult(5001,"只有超级管理员才能删除用户组") + } + + groupId,err := c.GetInt("group_id",0) + + if err != nil { + beego.Error("获取参数失败 =>",err) + c.JsonResult(5001,"获取用户组参数失败") + } + err = models.NewMemberGroup().Delete(groupId) + if err != nil { + beego.Error("删除用户组失败 =>",err) + c.JsonResult(5001,"删除用户组失败") + } + c.JsonResult(0,"删除成功") +} + //用户组成员列表 func (c *ManagerController) MemberGroupMemberList() { c.Prepare() - c.TplName = "manager/member_group_member_list.gohtml" + c.TplName = "manager/member_group_member_list.tpl" pageIndex, _ := c.GetInt("page", 1) - groupId,_ := c.GetInt("group_id",0) + groupId,_ := strconv.Atoi(c.Ctx.Input.Param(":id")) if groupId <= 0 { c.ShowErrorPage(404,"用户组参数不能为空") } + memberGroup,err := models.NewMemberGroup().FindFirst(groupId) + if err != nil { + c.ShowErrorPage(404,"用户组不存在") + } memberGroupMemberList ,totalCount,err := models.NewMemberGroupMembers().FindToPager(pageIndex,conf.PageSize,groupId) if err != nil { @@ -791,10 +864,17 @@ func (c *ManagerController) MemberGroupMemberList() { } c.Data["TotalPages"] = int(math.Ceil(float64(totalCount) / float64(conf.PageSize))) - c.Data["Lists"] = memberGroupMemberList + b, err := json.Marshal(memberGroupMemberList) + if err != nil { + c.Data["Result"] = template.JS("[]") + } else { + c.Data["Result"] = template.JS(string(b)) + } + c.Data["Model"] = memberGroup } +//添加用户组成员 func (c *ManagerController) MemberGroupMemberEdit() { c.Prepare() } diff --git a/models/MemberGroupModel.go b/models/MemberGroupModel.go index cab6caf0..bfaf9c08 100644 --- a/models/MemberGroupModel.go +++ b/models/MemberGroupModel.go @@ -10,11 +10,15 @@ import ( type MemberGroup struct { GroupId int `orm:"column(group_id);pk;auto;unique;" json:"group_id"` GroupName string `orm:"column(group_name);size(255);" json:"group_name"` - GroupNumber int `orm:"column(group_number);" json:"group_number"` + GroupNumber int `orm:"column(group_number);default(0)" json:"group_number"` CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"` CreateAt int `orm:"type(int);column(create_at)" json:"create_at"` + CreateName string `orm:"-" json:"create_name"` + CreateRealName string `orm:"-" json:"create_real_name"` ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"` ModifyAt int `orm:"column(modify_at);type(int)" json:"-"` + ModifyName string `orm:"-" json:"modify_name"` + ModifyRealName string `orm:"-" json:"modify_real_name"` } @@ -45,6 +49,25 @@ func (m *MemberGroup) FindFirst(id int) (*MemberGroup,error){ beego.Error("查询用户组时出错 =>",err) return m,err } + createMember,err := NewMember().Find(m.CreateAt); + if err != nil { + beego.Error("查询用户组创建人失败 =>",err) + }else{ + + m.CreateName = createMember.Account + m.CreateRealName = createMember.RealName + } + + if m.ModifyAt > 0 { + modifyMember, err := NewMember().Find(m.ModifyAt) + if err != nil { + beego.Error("查询用户组修改人失败 =>",err) + }else{ + + m.ModifyName = modifyMember.Account + m.ModifyRealName = modifyMember.RealName + } + } return m,nil } @@ -52,12 +75,19 @@ func (m *MemberGroup) FindFirst(id int) (*MemberGroup,error){ func (m *MemberGroup) Delete(id int) error { o := orm.NewOrm() + o.Begin() _,err := o.QueryTable(m.TableNameWithPrefix()).Filter("group_id",id).Delete() if err != nil { + o.Rollback() beego.Error("删除用户组失败 =>",err) } - return err + _,err = o.QueryTable(NewMemberGroupMembers().TableNameWithPrefix()).Filter("group_id",id).Delete() + if err != nil { + o.Rollback() + beego.Error("删除用户组失败 =>",err) + } + return o.Commit() } //分页查询用户组 @@ -71,7 +101,7 @@ func (m *MemberGroup) FindByPager(pageIndex, pageSize int) ([]*MemberGroup,int,e offset := (pageIndex - 1) * pageSize var memberGroups []*MemberGroup totalCount := 0 - _,err := o.QueryTable(m.TableNameWithPrefix()).Offset(offset).Limit(pageSize).All(&memberGroups) + _,err := o.QueryTable(m.TableNameWithPrefix()).OrderBy("-group_id").Offset(offset).Limit(pageSize).All(&memberGroups) if err != nil { beego.Error("分页查询用户组失败 =>",err) @@ -83,10 +113,53 @@ func (m *MemberGroup) FindByPager(pageIndex, pageSize int) ([]*MemberGroup,int,e totalCount = int(i) } } + memberIds := make([]int,0) + + for _,memberGroup := range memberGroups { + if memberGroup.CreateAt > 0 { + memberIds = append(memberIds,memberGroup.CreateAt) + } + if memberGroup.ModifyAt > 0 { + memberIds = append(memberIds,memberGroup.ModifyAt) + } + } + + var members []*Member + + _,err = o.QueryTable(NewMember().TableNameWithPrefix()).Filter("member_id__in",memberIds).All(&members,"member_id","account","real_name") + + if err != nil { + beego.Error("查询用户组信息时出错 =>",err) + }else { + for _,memberGroup := range memberGroups { + for _,member := range members { + if memberGroup.ModifyAt == member.MemberId { + memberGroup.ModifyRealName = member.RealName + memberGroup.ModifyName = member.Account + } + if memberGroup.CreateAt == member.MemberId { + memberGroup.CreateRealName = member.RealName + memberGroup.CreateName = member.Account + } + } + } + } return memberGroups,totalCount,err } +//添加或更新用户组信息 +func (m *MemberGroup) InsertOrUpdate(cols...string) error { + o := orm.NewOrm() + var err error + if m.GroupId > 0 { + _,err = o.Update(m, cols...) + }else{ + _,err = o.Insert(m) + } + return err +} + @@ -100,5 +173,3 @@ func (m *MemberGroup) FindByPager(pageIndex, pageSize int) ([]*MemberGroup,int,e - - diff --git a/models/document.go b/models/document.go index 0174ab9d..ddc3bc72 100644 --- a/models/document.go +++ b/models/document.go @@ -92,7 +92,7 @@ func (m *Document) InsertOrUpdate(cols ...string) error { if m.Identify == "" { book := NewBook() identify := "docs" - if err := o.QueryTable(book.TableNameWithPrefix()).One(book,"identify");err == nil { + if err := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id",m.BookId).One(book,"identify");err == nil { identify = book.Identify } m.Identify = fmt.Sprintf("%s-%d%d",identify,m.BookId,time.Now().Unix()) diff --git a/routers/router.go b/routers/router.go index e624346e..80bd1490 100644 --- a/routers/router.go +++ b/routers/router.go @@ -37,9 +37,11 @@ func init() { beego.Router("/manager/label/delete/:id", &controllers.ManagerController{},"post:LabelDelete") beego.Router("/manager/user_groups", &controllers.ManagerController{},"*:MemberGroupList") beego.Router("/manager/user_groups/edit/?:id", &controllers.ManagerController{},"*:MemberGroupEdit") - beego.Router("/manager/user_group_member", &controllers.ManagerController{},"*:MemberGroupMemberList") + beego.Router("/manager/user_group/delete/", &controllers.ManagerController{},"*:MemberGroupDelete") + beego.Router("/manager/user_group_member/:id", &controllers.ManagerController{},"*:MemberGroupMemberList") beego.Router("/manager/user_group_member/edit/?:id", &controllers.ManagerController{},"*:MemberGroupMemberEdit") + beego.Router("/setting", &controllers.SettingController{}, "*:Index") beego.Router("/setting/password", &controllers.SettingController{}, "*:Password") beego.Router("/setting/upload", &controllers.SettingController{}, "*:Upload") diff --git a/static/js/markdown.js b/static/js/markdown.js index fccf96d1..31692d28 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -1,4 +1,5 @@ $(function () { + window.isLoad = true; editormd.katexURL = { js : window.baseUrl + "/static/katex/katex", css : window.baseUrl + "/static/katex/katex" @@ -163,7 +164,11 @@ $(function () { window.isLoad = true; try { window.editor.clear(); - window.editor.insertValue(res.data.markdown); + if(res.data.markdown !== ""){ + window.editor.insertValue(res.data.markdown); + }else{ + window.isLoad = true; + } window.editor.setCursor({line: 0, ch: 0}); }catch(e){ console.log(e); @@ -256,6 +261,8 @@ $(function () { * @param $is_change */ function resetEditorChanged($is_change) { + // console.log($is_change); + // console.log(window.isLoad); if ($is_change && !window.isLoad) { var type = window.treeCatalog.get_type(window.selectNode); if(type === "lock"){ diff --git a/views/manager/attach_detailed.tpl b/views/manager/attach_detailed.tpl index 204974de..dcb320a1 100644 --- a/views/manager/attach_detailed.tpl +++ b/views/manager/attach_detailed.tpl @@ -26,12 +26,7 @@
ID | +头像 | +账号 | +姓名 | +角色 | +类型 | +状态 | +操作 | +
---|---|---|---|---|---|---|---|
${item.member_id} | ++ | ${item.account} | +${item.real_name} | +
+
+ 超级管理员
+
+
+ ${item.role_name}
+
+
+
+
+
+
+
+ |
+ + ${item.auth_method} + | ++ + 正常 + + + 禁用 + + | + ++ + + + + + 编辑 + + + + + + + + + + | +