mirror of https://github.com/mindoc-org/mindoc.git
实现用户组功能
parent
70f293668f
commit
8d2d4995f7
|
@ -705,13 +705,13 @@ func (c *BookController) SaveSort() {
|
||||||
c.Abort("404")
|
c.Abort("404")
|
||||||
}
|
}
|
||||||
|
|
||||||
book_id := 0
|
bookId := 0
|
||||||
if c.Member.IsAdministrator() {
|
if c.Member.IsAdministrator() {
|
||||||
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
}
|
}
|
||||||
book_id = book.BookId
|
bookId = book.BookId
|
||||||
} else {
|
} else {
|
||||||
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -722,7 +722,7 @@ func (c *BookController) SaveSort() {
|
||||||
if bookResult.RoleId == conf.BookObserver {
|
if bookResult.RoleId == conf.BookObserver {
|
||||||
c.JsonResult(6002, "项目不存在或权限不足")
|
c.JsonResult(6002, "项目不存在或权限不足")
|
||||||
}
|
}
|
||||||
book_id = bookResult.BookId
|
bookId = bookResult.BookId
|
||||||
}
|
}
|
||||||
|
|
||||||
content := c.Ctx.Input.RequestBody
|
content := c.Ctx.Input.RequestBody
|
||||||
|
@ -743,7 +743,7 @@ func (c *BookController) SaveSort() {
|
||||||
beego.Error(err)
|
beego.Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if doc.BookId != book_id {
|
if doc.BookId != bookId {
|
||||||
logs.Info("%s", "权限错误")
|
logs.Info("%s", "权限错误")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -758,7 +758,7 @@ func (c *BookController) SaveSort() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if parent_id > 0 {
|
if parent_id > 0 {
|
||||||
if parent, err := models.NewDocument().Find(int(parent_id)); err != nil || parent.BookId != book_id {
|
if parent, err := models.NewDocument().Find(int(parent_id)); err != nil || parent.BookId != bookId {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -757,7 +757,7 @@ func (c *ManagerController) MemberGroupEdit() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
c.TplName = "manager/member_group_edit.tpl"
|
c.TplName = "manager/member_group_edit.tpl"
|
||||||
|
|
||||||
if c.Member.Role != 0 {
|
if !c.Member.IsSuperAdministrator() {
|
||||||
c.ShowErrorPage(500,"只有超级管理员才能编辑或添加用户组")
|
c.ShowErrorPage(500,"只有超级管理员才能编辑或添加用户组")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -818,7 +818,7 @@ func (c *ManagerController) MemberGroupEdit() {
|
||||||
func (c *ManagerController) MemberGroupDelete() {
|
func (c *ManagerController) MemberGroupDelete() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
|
|
||||||
if c.Member.Role != 0 {
|
if !c.Member.IsSuperAdministrator() {
|
||||||
c.JsonResult(5001,"只有超级管理员才能删除用户组")
|
c.JsonResult(5001,"只有超级管理员才能删除用户组")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -877,6 +877,101 @@ func (c *ManagerController) MemberGroupMemberList() {
|
||||||
//添加用户组成员
|
//添加用户组成员
|
||||||
func (c *ManagerController) MemberGroupMemberEdit() {
|
func (c *ManagerController) MemberGroupMemberEdit() {
|
||||||
c.Prepare()
|
c.Prepare()
|
||||||
|
if !c.Member.IsSuperAdministrator() {
|
||||||
|
c.JsonResult(5000,"只有超级管理员才能添加用户")
|
||||||
|
}
|
||||||
|
if c.Ctx.Input.IsPost() {
|
||||||
|
memberId, err := c.GetInt("member_id", 0)
|
||||||
|
|
||||||
|
if err != nil || memberId <= 0 {
|
||||||
|
c.JsonResult(6001, "用户参数错误")
|
||||||
|
}
|
||||||
|
groupId, err := c.GetInt("group_id", 0)
|
||||||
|
|
||||||
|
if err != nil || groupId <= 0 {
|
||||||
|
c.JsonResult(6002, "用户组参数错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! models.NewMember().Exist("member_id", memberId) {
|
||||||
|
beego.Error("用户不存在 =>", err)
|
||||||
|
c.JsonResult(6001, "用户不存在")
|
||||||
|
}
|
||||||
|
|
||||||
|
if models.NewMemberGroupMembers().IsJoin(groupId, memberId) {
|
||||||
|
c.JsonResult(6003, "用户已加入当前用户组")
|
||||||
|
}
|
||||||
|
if !models.NewMember().Exist("member_id", memberId) {
|
||||||
|
c.JsonResult(6004, "用户不存在")
|
||||||
|
}
|
||||||
|
|
||||||
|
memberGroupMember := models.NewMemberGroupMembers()
|
||||||
|
|
||||||
|
memberGroupMember.MemberId = memberId
|
||||||
|
memberGroupMember.CreateAt = c.Member.MemberId
|
||||||
|
memberGroupMember.GroupId = groupId
|
||||||
|
memberGroupMember.CreateTime = time.Now()
|
||||||
|
|
||||||
|
if err := memberGroupMember.InsertOrUpdate(); err != nil {
|
||||||
|
beego.Error("添加用户失败 =>", err)
|
||||||
|
c.JsonResult(6005, "添加用户失败")
|
||||||
|
} else {
|
||||||
|
c.JsonResult(0, "添加成功",memberGroupMember.ToMemberRelationshipResult())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.ShowErrorPage(405, "不支持的请求方式")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//删除用户组中的成员
|
||||||
|
func (c *ManagerController) MemberGroupMemberDelete() {
|
||||||
|
c.Prepare()
|
||||||
|
if !c.Member.IsSuperAdministrator() {
|
||||||
|
c.JsonResult(5000,"只有超级管理员才能删除用户")
|
||||||
|
}
|
||||||
|
if c.Ctx.Input.IsPost() {
|
||||||
|
|
||||||
|
memberGroupId,err := c.GetInt("id",0)
|
||||||
|
|
||||||
|
if err != nil || memberGroupId <= 0 {
|
||||||
|
c.JsonResult(500,"参数错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := models.NewMemberGroupMembers().Delete(memberGroupId);err != nil {
|
||||||
|
beego.Error("添加用户失败 =>",err)
|
||||||
|
c.JsonResult(6005,"删除用户失败")
|
||||||
|
}else{
|
||||||
|
c.JsonResult(0,"删除成功")
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
c.ShowErrorPage(405,"不支持的请求方式")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ManagerController) MemberGroupMemberSearch() {
|
||||||
|
c.Prepare()
|
||||||
|
groupId,err := c.GetInt("group_id",0)
|
||||||
|
|
||||||
|
if err != nil || groupId <= 0 {
|
||||||
|
c.JsonResult(6002,"用户组参数错误")
|
||||||
|
}
|
||||||
|
q := strings.TrimSpace(c.GetString("q"))
|
||||||
|
|
||||||
|
members,err := models.NewMemberGroupMembers().FindMemberGroupMemberNoJoinSearchResult(groupId,q)
|
||||||
|
|
||||||
|
result := models.SelectMemberResult{}
|
||||||
|
items := make([]models.KeyValueItem, 0)
|
||||||
|
|
||||||
|
for _, member := range members {
|
||||||
|
item := models.KeyValueItem{}
|
||||||
|
item.Id = member.MemberId
|
||||||
|
item.Text = member.Account
|
||||||
|
items = append(items, item)
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Result = items
|
||||||
|
|
||||||
|
c.JsonResult(0, "OK", result)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -905,9 +1000,6 @@ func (c *ManagerController) MemberGroupMemberEdit() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"github.com/astaxie/beego/orm"
|
"github.com/astaxie/beego/orm"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
"fmt"
|
|
||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,14 +17,21 @@ type MemberGroupMembers struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemberGroupMemberResult struct {
|
type MemberGroupMemberResult struct {
|
||||||
GroupMemberId int
|
GroupMemberId int `json:"group_member_id"`
|
||||||
MemberId int
|
MemberId int `json:"member_id"`
|
||||||
Account string
|
Account string `json:"account"`
|
||||||
RealName string
|
RealName string `json:"real_name"`
|
||||||
Avatar string
|
RoleName string `json:"role_name"`
|
||||||
GroupId int
|
Avatar string `json:"avatar"`
|
||||||
CreateTime time.Time
|
GroupId int `json:"group_id"`
|
||||||
CreateAt int
|
CreateTime time.Time `json:"create_time"`
|
||||||
|
CreateAt int `json:"create_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//搜索未加入当前用户组的用户信息
|
||||||
|
type MemberGroupMemberNoJoinSearchResult struct {
|
||||||
|
MemberId int `json:"member_id"`
|
||||||
|
Account string `json:"account"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName 获取对应数据库表名.
|
// TableName 获取对应数据库表名.
|
||||||
|
@ -86,6 +92,14 @@ func (m *MemberGroupMembers) FindByGroupId(groupId int) ([]*MemberGroupMemberRes
|
||||||
}
|
}
|
||||||
return groupMembers,nil
|
return groupMembers,nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//判断一个用户是否加入了指定用户组
|
||||||
|
func (m *MemberGroupMembers) IsJoin(groupId ,memberId int) (bool) {
|
||||||
|
o := orm.NewOrm()
|
||||||
|
|
||||||
|
return o.QueryTable(m.TableNameWithPrefix()).Filter("group_id",groupId).Filter("member_id",memberId).Exist()
|
||||||
|
}
|
||||||
|
|
||||||
//添加或更新用户组成员
|
//添加或更新用户组成员
|
||||||
func (m *MemberGroupMembers) InsertOrUpdate(cols ...string) error {
|
func (m *MemberGroupMembers) InsertOrUpdate(cols ...string) error {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
|
@ -104,16 +118,22 @@ func (m *MemberGroupMembers) InsertOrUpdate(cols ...string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error("添加用户组成员失败 =>",err)
|
beego.Error("添加用户组成员失败 =>",err)
|
||||||
}else{
|
}else{
|
||||||
o.Raw(fmt.Sprintf("UPDATE %s SET group_number=group_number+1 WHERE group_id=%d",NewMemberGroup().TableNameWithPrefix(), m.GroupId)).Exec()
|
go NewMemberGroup().ResetMemberGroupNumber(m.GroupId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除用户组成员
|
//删除用户组成员
|
||||||
func (m *MemberGroupMembers) Delete(id int) error {
|
func (m *MemberGroupMembers) Delete(id int) error {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
|
|
||||||
|
if err := o.QueryTable(m.TableNameWithPrefix()).Filter("group_member_id",id).One(m);err != nil {
|
||||||
|
beego.Error("删除用户组成员失败 =>",err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
i,err := o.QueryTable(m.TableNameWithPrefix()).Filter("group_member_id",id).Delete()
|
i,err := o.QueryTable(m.TableNameWithPrefix()).Filter("group_member_id",id).Delete()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -124,6 +144,8 @@ func (m *MemberGroupMembers) Delete(id int) error {
|
||||||
beego.Info("删除用户组成员返回行数 =>",i)
|
beego.Info("删除用户组成员返回行数 =>",i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
go NewMemberGroup().ResetMemberGroupNumber(m.GroupId)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,22 +190,37 @@ func (m *MemberGroupMembers) ToMemberRelationshipResult() *MemberGroupMemberResu
|
||||||
memberGroupMemberResult.CreateAt = m.CreateAt
|
memberGroupMemberResult.CreateAt = m.CreateAt
|
||||||
memberGroupMemberResult.CreateTime = m.CreateTime
|
memberGroupMemberResult.CreateTime = m.CreateTime
|
||||||
|
|
||||||
|
|
||||||
if m.MemberId > 0 {
|
if m.MemberId > 0 {
|
||||||
o := orm.NewOrm()
|
member,err := NewMember().Find(memberGroupMemberResult.MemberId)
|
||||||
member := NewMember()
|
|
||||||
_,err := o.QueryTable(member.TableNameWithPrefix()).Filter("member_id", m.MemberId).All(&member)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beego.Error("查询用户组成员信息时出错 =>",err)
|
beego.Error("查询用户组成员信息时出错 =>",err)
|
||||||
}else{
|
}else{
|
||||||
memberGroupMemberResult.RealName = member.RealName
|
memberGroupMemberResult.RealName = member.RealName
|
||||||
memberGroupMemberResult.Avatar = member.Avatar
|
memberGroupMemberResult.Avatar = member.Avatar
|
||||||
memberGroupMemberResult.Account = member.Account
|
memberGroupMemberResult.Account = member.Account
|
||||||
|
memberGroupMemberResult.RoleName = member.RoleName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return memberGroupMemberResult
|
return memberGroupMemberResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取未加入用户组的用户成员
|
||||||
|
func (m *MemberGroupMembers) FindMemberGroupMemberNoJoinSearchResult(groupId int,q string) ([]*MemberGroupMemberNoJoinSearchResult,error) {
|
||||||
|
o := orm.NewOrm()
|
||||||
|
|
||||||
|
sql := "select member.member_id,member.account from md_members as member left join md_member_group_members as member_group on member_group.member_id = member.member_id and member_group.group_id=? where member_group.member_id isnull and account like ?limit 20;"
|
||||||
|
var memberGroupMembers []*MemberGroupMemberNoJoinSearchResult
|
||||||
|
|
||||||
|
_,err := o.Raw(sql,groupId,"%" + q + "%").QueryRows(&memberGroupMembers)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
beego.Error("获取未加入用户组的用户失败 =>",err)
|
||||||
|
}
|
||||||
|
return memberGroupMembers,err
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -215,8 +252,6 @@ func (m *MemberGroupMembers) ToMemberRelationshipResult() *MemberGroupMemberResu
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -160,8 +160,26 @@ func (m *MemberGroup) InsertOrUpdate(cols...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//重置用户组数量
|
||||||
|
func (m *MemberGroup) ResetMemberGroupNumber(groupId int) error {
|
||||||
|
o := orm.NewOrm()
|
||||||
|
|
||||||
|
i,err := o.QueryTable(NewMemberGroupMembers().TableNameWithPrefix()).Filter("group_id",groupId).Count()
|
||||||
|
if err != nil {
|
||||||
|
beego.Error("重置用户组用户数量失败 =>",err)
|
||||||
|
}else{
|
||||||
|
err := o.QueryTable(m.TableNameWithPrefix()).Filter("group_id",groupId).One(m)
|
||||||
|
if err != nil {
|
||||||
|
beego.Error("重置用户组用户数量失败 =>",err)
|
||||||
|
return err
|
||||||
|
}else{
|
||||||
|
m.GroupNumber = int(i)
|
||||||
|
_,err = o.Update(m)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ type Dashboard struct {
|
||||||
MemberNumber int64 `json:"member_number"`
|
MemberNumber int64 `json:"member_number"`
|
||||||
CommentNumber int64 `json:"comment_number"`
|
CommentNumber int64 `json:"comment_number"`
|
||||||
AttachmentNumber int64 `json:"attachment_number"`
|
AttachmentNumber int64 `json:"attachment_number"`
|
||||||
|
MemberGroupNumber int64 `json:"member_group_number"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDashboard() *Dashboard {
|
func NewDashboard() *Dashboard {
|
||||||
|
@ -30,9 +31,13 @@ func (m *Dashboard) Query() *Dashboard {
|
||||||
//comment_number,_ := o.QueryTable(NewComment().TableNameWithPrefix()).Count()
|
//comment_number,_ := o.QueryTable(NewComment().TableNameWithPrefix()).Count()
|
||||||
m.CommentNumber = 0
|
m.CommentNumber = 0
|
||||||
|
|
||||||
attachment_number, _ := o.QueryTable(NewAttachment().TableNameWithPrefix()).Count()
|
attachmentNumber, _ := o.QueryTable(NewAttachment().TableNameWithPrefix()).Count()
|
||||||
|
|
||||||
m.AttachmentNumber = attachment_number
|
m.AttachmentNumber = attachmentNumber
|
||||||
|
|
||||||
|
memberGroupNumber,_ := o.QueryTable(NewMemberGroup().TableNameWithPrefix()).Count()
|
||||||
|
|
||||||
|
m.MemberGroupNumber = memberGroupNumber
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,6 +236,7 @@ func (m *Member) FindByAccount(account string) (*Member, error) {
|
||||||
}
|
}
|
||||||
return m, err
|
return m, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//批量查询用户
|
//批量查询用户
|
||||||
func (m *Member) FindByAccountList(accounts ...string) ([]*Member,error) {
|
func (m *Member) FindByAccountList(accounts ...string) ([]*Member,error) {
|
||||||
o := orm.NewOrm()
|
o := orm.NewOrm()
|
||||||
|
@ -277,12 +278,26 @@ func (m *Member) FindToPager(pageIndex, pageSize int) ([]*Member, int, error) {
|
||||||
return members, int(totalCount), nil
|
return members, int(totalCount), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//指定的用户是否存在
|
||||||
|
func (m *Member) Exist(field string,value interface{}) bool {
|
||||||
|
o := orm.NewOrm()
|
||||||
|
|
||||||
|
return o.QueryTable(m.TableNameWithPrefix()).Filter(field,value).Exist()
|
||||||
|
}
|
||||||
|
//是否是管理员
|
||||||
func (c *Member) IsAdministrator() bool {
|
func (c *Member) IsAdministrator() bool {
|
||||||
if c == nil || c.MemberId <= 0 {
|
if c == nil || c.MemberId <= 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return c.Role == 0 || c.Role == 1
|
return c.Role == 0 || c.Role == 1
|
||||||
}
|
}
|
||||||
|
//是否是超级管理员
|
||||||
|
func (c *Member) IsSuperAdministrator() bool {
|
||||||
|
if c == nil || c.MemberId <= 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return c.Role == 0
|
||||||
|
}
|
||||||
|
|
||||||
//根据指定字段查找用户.
|
//根据指定字段查找用户.
|
||||||
func (m *Member) FindByFieldFirst(field string, value interface{}) (*Member, error) {
|
func (m *Member) FindByFieldFirst(field string, value interface{}) (*Member, error) {
|
||||||
|
@ -294,7 +309,7 @@ func (m *Member) FindByFieldFirst(field string, value interface{}) (*Member, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//校验用户.
|
//校验用户.
|
||||||
func (m *Member) Valid(is_hash_password bool) error {
|
func (m *Member) Valid(isHashPassword bool) error {
|
||||||
|
|
||||||
//邮箱不能为空
|
//邮箱不能为空
|
||||||
if m.Email == "" {
|
if m.Email == "" {
|
||||||
|
@ -315,7 +330,7 @@ func (m *Member) Valid(is_hash_password bool) error {
|
||||||
return ErrMemberEmailFormatError
|
return ErrMemberEmailFormatError
|
||||||
}
|
}
|
||||||
//如果是未加密密码,需要校验密码格式
|
//如果是未加密密码,需要校验密码格式
|
||||||
if !is_hash_password {
|
if !isHashPassword {
|
||||||
if l := strings.Count(m.Password, ""); m.Password == "" || l > 50 || l < 6 {
|
if l := strings.Count(m.Password, ""); m.Password == "" || l > 50 || l < 6 {
|
||||||
return ErrMemberPasswordFormatError
|
return ErrMemberPasswordFormatError
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,9 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(bookId, pageIndex, pageS
|
||||||
|
|
||||||
sql2 := "SELECT count(*) AS total_count FROM md_relationship AS rel LEFT JOIN md_members as member ON rel.member_id = member.member_id WHERE rel.book_id = ?"
|
sql2 := "SELECT count(*) AS total_count FROM md_relationship AS rel LEFT JOIN md_members as member ON rel.member_id = member.member_id WHERE rel.book_id = ?"
|
||||||
|
|
||||||
var total_count int
|
var totalCount int
|
||||||
|
|
||||||
err := o.Raw(sql2, bookId).QueryRow(&total_count)
|
err := o.Raw(sql2, bookId).QueryRow(&totalCount)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return members, 0, err
|
return members, 0, err
|
||||||
|
@ -92,7 +92,7 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(bookId, pageIndex, pageS
|
||||||
for _, item := range members {
|
for _, item := range members {
|
||||||
item.ResolveRoleName()
|
item.ResolveRoleName()
|
||||||
}
|
}
|
||||||
return members, total_count, nil
|
return members, totalCount, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询指定文档中不存在的用户列表
|
// 查询指定文档中不存在的用户列表
|
||||||
|
|
|
@ -36,11 +36,12 @@ func init() {
|
||||||
beego.Router("/manager/label/list", &controllers.ManagerController{},"get:LabelList")
|
beego.Router("/manager/label/list", &controllers.ManagerController{},"get:LabelList")
|
||||||
beego.Router("/manager/label/delete/:id", &controllers.ManagerController{},"post:LabelDelete")
|
beego.Router("/manager/label/delete/:id", &controllers.ManagerController{},"post:LabelDelete")
|
||||||
beego.Router("/manager/user_groups", &controllers.ManagerController{},"*:MemberGroupList")
|
beego.Router("/manager/user_groups", &controllers.ManagerController{},"*:MemberGroupList")
|
||||||
beego.Router("/manager/user_groups/edit/?:id", &controllers.ManagerController{},"*:MemberGroupEdit")
|
beego.Router("/manager/user_groups/edit/?:id:int", &controllers.ManagerController{},"*:MemberGroupEdit")
|
||||||
beego.Router("/manager/user_group/delete/", &controllers.ManagerController{},"*:MemberGroupDelete")
|
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:int", &controllers.ManagerController{},"post:MemberGroupMemberEdit")
|
||||||
beego.Router("/manager/user_group_member/edit/?:id", &controllers.ManagerController{},"*:MemberGroupMemberEdit")
|
beego.Router("/manager/user_group_member/delete", &controllers.ManagerController{},"post:MemberGroupMemberDelete")
|
||||||
|
beego.Router("/manager/user_group_member/search", &controllers.ManagerController{},"*:MemberGroupMemberSearch")
|
||||||
|
beego.Router("/manager/user_group_member/list/:id:int", &controllers.ManagerController{},"*:MemberGroupMemberList")
|
||||||
|
|
||||||
beego.Router("/setting", &controllers.SettingController{}, "*:Index")
|
beego.Router("/setting", &controllers.SettingController{}, "*:Index")
|
||||||
beego.Router("/setting/password", &controllers.SettingController{}, "*:Password")
|
beego.Router("/setting/password", &controllers.SettingController{}, "*:Password")
|
||||||
|
|
|
@ -190,7 +190,6 @@
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
processResults: function (data, params) {
|
processResults: function (data, params) {
|
||||||
console.log(data)
|
|
||||||
return {
|
return {
|
||||||
results : data.data.results
|
results : data.data.results
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,10 +47,15 @@
|
||||||
<span class="fa-class">{{.Model.DocumentNumber}}</span>
|
<span class="fa-class">{{.Model.DocumentNumber}}</span>
|
||||||
</div>
|
</div>
|
||||||
<a href="{{urlfor "ManagerController.Users"}}" class="dashboard-item">
|
<a href="{{urlfor "ManagerController.Users"}}" class="dashboard-item">
|
||||||
<span class="fa fa-users" aria-hidden="true"></span>
|
<span class="fa fa-user" aria-hidden="true"></span>
|
||||||
<span class="fa-class">会员数量</span>
|
<span class="fa-class">会员数量</span>
|
||||||
<span class="fa-class">{{.Model.MemberNumber}}</span>
|
<span class="fa-class">{{.Model.MemberNumber}}</span>
|
||||||
</a>
|
</a>
|
||||||
|
<a href="{{urlfor "ManagerController.MemberGroupList"}}" class="dashboard-item">
|
||||||
|
<span class="fa fa-users" aria-hidden="true"></span>
|
||||||
|
<span class="fa-class">用户组数量</span>
|
||||||
|
<span class="fa-class">{{.Model.MemberGroupNumber}}</span>
|
||||||
|
</a>
|
||||||
<!--
|
<!--
|
||||||
{{/*
|
{{/*
|
||||||
<div class="dashboard-item">
|
<div class="dashboard-item">
|
||||||
|
@ -64,6 +69,7 @@
|
||||||
<span class="fa-class">附件数量</span>
|
<span class="fa-class">附件数量</span>
|
||||||
<span class="fa-class">{{.Model.AttachmentNumber}}</span>
|
<span class="fa-class">{{.Model.AttachmentNumber}}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -69,8 +69,8 @@
|
||||||
<td>${item.create_name}</td>
|
<td>${item.create_name}</td>
|
||||||
<td>${(new Date(item.modify_time)).format("yyyy-MM-dd hh:mm:ss")}</td>
|
<td>${(new Date(item.modify_time)).format("yyyy-MM-dd hh:mm:ss")}</td>
|
||||||
<td>
|
<td>
|
||||||
<a :href="'{{urlfor "ManagerController.MemberGroupMemberList" ":id" ""}}' + item.group_id" class="btn btn-sm btn-success">成员</a>
|
<a :href="'{{urlfor "ManagerController.MemberGroupMemberList" ":id" "0"}}' + item.group_id" class="btn btn-sm btn-success">成员</a>
|
||||||
<a :href="'{{urlfor "ManagerController.MemberGroupEdit" ":id" ""}}' + item.group_id" class="btn btn-sm btn-default">编辑</a>
|
<a :href="'{{urlfor "ManagerController.MemberGroupEdit" ":id" "0"}}' + item.group_id" class="btn btn-sm btn-default">编辑</a>
|
||||||
<button type="button" class="btn btn-danger btn-sm" @click="deleteMemberGroup(item.group_id,$event)" data-loading-text="删除中">删除</button>
|
<button type="button" class="btn btn-danger btn-sm" @click="deleteMemberGroup(item.group_id,$event)" data-loading-text="删除中">删除</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<!-- Bootstrap -->
|
<!-- Bootstrap -->
|
||||||
<link href="{{cdncss "/static/bootstrap/css/bootstrap.min.css"}}" rel="stylesheet">
|
<link href="{{cdncss "/static/bootstrap/css/bootstrap.min.css"}}" rel="stylesheet">
|
||||||
<link href="{{cdncss "/static/font-awesome/css/font-awesome.min.css"}}" rel="stylesheet">
|
<link href="{{cdncss "/static/font-awesome/css/font-awesome.min.css"}}" rel="stylesheet">
|
||||||
|
<link href="{{cdncss "/static/select2/4.0.5/css/select2.min.css"}}" rel="stylesheet">
|
||||||
<link href="{{cdncss "/static/css/main.css"}}" rel="stylesheet">
|
<link href="{{cdncss "/static/css/main.css"}}" rel="stylesheet">
|
||||||
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
|
||||||
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
|
||||||
|
@ -56,39 +56,17 @@
|
||||||
<th>账号</th>
|
<th>账号</th>
|
||||||
<th>姓名</th>
|
<th>姓名</th>
|
||||||
<th>角色</th>
|
<th>角色</th>
|
||||||
<th>类型</th>
|
|
||||||
<th>状态</th>
|
<th>状态</th>
|
||||||
<th>操作</th>
|
<th>操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="item in lists">
|
<tr v-for="item in lists">
|
||||||
<td>${item.member_id}</td>
|
<td>${item.group_member_id}</td>
|
||||||
<td><img :src="item.avatar" onerror="this.src='{{cdnimg "/static/images/middle.gif"}}'" class="img-circle" width="34" height="34"></td>
|
<td><img :src="item.avatar" onerror="this.src='{{cdnimg "/static/images/middle.gif"}}'" class="img-circle" width="34" height="34"></td>
|
||||||
<td>${item.account}</td>
|
<td>${item.account}</td>
|
||||||
<td>${item.real_name}</td>
|
<td>${item.real_name}</td>
|
||||||
<td>
|
<td>${item.role_name}</td>
|
||||||
<template v-if="item.role == 0">
|
|
||||||
超级管理员
|
|
||||||
</template>
|
|
||||||
<template v-else-if="item.member_id == {{.Member.MemberId}}">
|
|
||||||
${item.role_name}
|
|
||||||
</template>
|
|
||||||
<template v-else>
|
|
||||||
<div class="btn-group">
|
|
||||||
<button type="button" class="btn btn-default btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
||||||
${item.role_name}
|
|
||||||
<span class="caret"></span></button>
|
|
||||||
<ul class="dropdown-menu">
|
|
||||||
<li><a href="javascript:;" @click="setMemberRole(item.member_id,1)">管理员</a> </li>
|
|
||||||
<li><a href="javascript:;" @click="setMemberRole(item.member_id,2)">普通用户</a> </li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
${item.auth_method}
|
|
||||||
</td>
|
|
||||||
<td>
|
<td>
|
||||||
<template v-if="item.status == 0">
|
<template v-if="item.status == 0">
|
||||||
<span class="label label-success">正常</span>
|
<span class="label label-success">正常</span>
|
||||||
|
@ -99,21 +77,7 @@
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
<template v-if="item.member_id == {{.Member.MemberId}}">
|
<button type="button" class="btn btn-danger btn-sm" @click="deleteMember(item.group_member_id,$event)" data-loading-text="删除中">删除</button>
|
||||||
|
|
||||||
</template>
|
|
||||||
<template v-else-if="item.role != 0">
|
|
||||||
<a :href="'{{urlfor "ManagerController.EditMember" ":id" ""}}' + item.member_id" class="btn btn-sm btn-default" @click="editMember(item.member_id)">
|
|
||||||
编辑
|
|
||||||
</a>
|
|
||||||
<template v-if="item.status == 0">
|
|
||||||
<button type="button" class="btn btn-danger btn-sm" @click="setMemberStatus(item.member_id,1,$event)" data-loading-text="启用中...">禁用</button>
|
|
||||||
</template>
|
|
||||||
<template v-else>
|
|
||||||
<button type="button" class="btn btn-success btn-sm" @click="setMemberStatus(item.member_id,0,$event)" data-loading-text="禁用中...">启用</button>
|
|
||||||
</template>
|
|
||||||
<button type="button" class="btn btn-danger btn-sm" @click="deleteMember(item.member_id,$event)" data-loading-text="删除中">删除</button>
|
|
||||||
</template>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -132,60 +96,19 @@
|
||||||
<!-- Modal -->
|
<!-- Modal -->
|
||||||
<div class="modal fade" id="addMemberDialogModal" tabindex="-1" role="dialog" aria-labelledby="addMemberDialogModalLabel">
|
<div class="modal fade" id="addMemberDialogModal" tabindex="-1" role="dialog" aria-labelledby="addMemberDialogModalLabel">
|
||||||
<div class="modal-dialog" role="document">
|
<div class="modal-dialog" role="document">
|
||||||
<form method="post" autocomplete="off" class="form-horizontal" action="{{urlfor "ManagerController.CreateMember"}}" id="addMemberDialogForm">
|
<form method="post" autocomplete="off" class="form-horizontal" action="{{urlfor "ManagerController.MemberGroupMemberEdit"}}" id="addMemberDialogForm">
|
||||||
|
<input type="hidden" name="group_id" value="{{.Model.GroupId}}">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||||
<h4 class="modal-title" id="myModalLabel">创建用户</h4>
|
<h4 class="modal-title" id="myModalLabel">添加用户组成员</h4>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-sm-2 control-label" for="account">账号<span class="error-message">*</span></label>
|
<label class="col-sm-2 control-label" for="account">账号<span class="error-message">*</span></label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-10">
|
||||||
<input type="text" name="account" class="form-control" placeholder="用户账号" id="account" maxlength="50">
|
<select class="js-data-example-ajax form-control" multiple="multiple" name="member_id" id="member_id"></select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-sm-2 control-label" for="password1">密码<span class="error-message">*</span></label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="password" class="form-control" placeholder="用户密码" name="password1" id="password1" maxlength="50">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-sm-2 control-label" for="password2">确认密码<span class="error-message">*</span></label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="password" class="form-control" placeholder="确认密码" name="password2" id="password2" maxlength="50">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-sm-2 control-label" for="email">邮箱<span class="error-message">*</span></label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="email" class="form-control" placeholder="邮箱" name="email" id="email" maxlength="50">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-sm-2 control-label">真实姓名</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="text" name="real_name" class="form-control" value="" placeholder="真实姓名">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-sm-2 control-label">手机号</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<input type="text" class="form-control" placeholder="手机号" name="phone" maxlength="50">
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label class="col-sm-2 control-label">角色</label>
|
|
||||||
<div class="col-sm-10">
|
|
||||||
<select name="role" class="form-control">
|
|
||||||
<option value="1">管理员</option>
|
|
||||||
<option value="2">普通用户</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -202,33 +125,44 @@
|
||||||
<script src="{{cdnjs "/static/bootstrap/js/bootstrap.min.js"}}"></script>
|
<script src="{{cdnjs "/static/bootstrap/js/bootstrap.min.js"}}"></script>
|
||||||
<script src="{{cdnjs "/static/vuejs/vue.min.js"}}"></script>
|
<script src="{{cdnjs "/static/vuejs/vue.min.js"}}"></script>
|
||||||
<script src="{{cdnjs "/static/js/jquery.form.js"}}" type="text/javascript"></script>
|
<script src="{{cdnjs "/static/js/jquery.form.js"}}" type="text/javascript"></script>
|
||||||
|
<script src="{{cdnjs "/static/select2/4.0.5/js/select2.full.min.js"}}"></script>
|
||||||
|
<script src="{{cdnjs "/static/select2/4.0.5/js/i18n/zh-CN.js"}}"></script>
|
||||||
<script src="{{cdnjs "/static/js/main.js"}}" type="text/javascript"></script>
|
<script src="{{cdnjs "/static/js/main.js"}}" type="text/javascript"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(function () {
|
$(function () {
|
||||||
$("#addMemberDialogModal").on("show.bs.modal",function () {
|
$("#addMemberDialogModal").on("show.bs.modal",function () {
|
||||||
window.addMemberDialogModalHtml = $(this).find("form").html();
|
window.addMemberDialogModalHtml = $(this).find("form").html();
|
||||||
|
$('#member_id').select2({
|
||||||
|
language: "zh-CN",
|
||||||
|
minimumInputLength : 1,
|
||||||
|
minimumResultsForSearch: Infinity,
|
||||||
|
maximumSelectionLength:1,
|
||||||
|
width : "100%",
|
||||||
|
ajax: {
|
||||||
|
url: '{{urlfor "ManagerController.MemberGroupMemberSearch" "group_id" .Model.GroupId}}',
|
||||||
|
dataType: 'json',
|
||||||
|
data: function (params) {
|
||||||
|
return {
|
||||||
|
q: params.term, // search term
|
||||||
|
page: params.page
|
||||||
|
};
|
||||||
|
},
|
||||||
|
processResults: function (data, params) {
|
||||||
|
return {
|
||||||
|
results : data.data.results
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}).on("hidden.bs.modal",function () {
|
}).on("hidden.bs.modal",function () {
|
||||||
$(this).find("form").html(window.addMemberDialogModalHtml);
|
$(this).find("form").html(window.addMemberDialogModalHtml);
|
||||||
});
|
});
|
||||||
$("#addMemberDialogForm").ajaxForm({
|
$("#addMemberDialogForm").ajaxForm({
|
||||||
beforeSubmit : function () {
|
beforeSubmit : function () {
|
||||||
var account = $.trim($("#account").val());
|
var member_id = $.trim($("#member_id").val());
|
||||||
if(account === ""){
|
if(member_id <= 0){
|
||||||
return showError("账号不能为空");
|
return showError("账号不能为空");
|
||||||
}
|
}
|
||||||
var password1 = $.trim($("#password1").val());
|
|
||||||
var password2 = $("#password2").val();
|
|
||||||
if (password1 === "") {
|
|
||||||
return showError("密码不能为空");
|
|
||||||
}
|
|
||||||
if (password1 !== password2) {
|
|
||||||
return showError("确认密码不正确");
|
|
||||||
}
|
|
||||||
var email = $.trim($("#email").val());
|
|
||||||
|
|
||||||
if (email === "") {
|
|
||||||
return showError("邮箱不能为空");
|
|
||||||
}
|
|
||||||
$("#btnAddMember").button("loading");
|
$("#btnAddMember").button("loading");
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
@ -254,61 +188,10 @@
|
||||||
},
|
},
|
||||||
delimiters : ['${','}'],
|
delimiters : ['${','}'],
|
||||||
methods : {
|
methods : {
|
||||||
setMemberStatus : function (id,status,e) {
|
|
||||||
var $this = this;
|
|
||||||
$.ajax({
|
|
||||||
url : "{{urlfor "ManagerController.UpdateMemberStatus"}}",
|
|
||||||
type : "post",
|
|
||||||
data : { "member_id":id,"status" : status},
|
|
||||||
dataType : "json",
|
|
||||||
success : function (res) {
|
|
||||||
if (res.errcode === 0) {
|
|
||||||
|
|
||||||
for (var index in $this.lists) {
|
|
||||||
var item = $this.lists[index];
|
|
||||||
|
|
||||||
if (item.member_id === id) {
|
|
||||||
console.log(item);
|
|
||||||
$this.lists[index].status = status;
|
|
||||||
break;
|
|
||||||
//$this.lists.splice(index,1,item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
alert("操作失败:" + res.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
},
|
|
||||||
setMemberRole : function (member_id, role) {
|
|
||||||
var $this = this;
|
|
||||||
$.ajax({
|
|
||||||
url :"{{urlfor "ManagerController.ChangeMemberRole"}}",
|
|
||||||
dataType :"json",
|
|
||||||
type :"post",
|
|
||||||
data : { "member_id" : member_id,"role" : role },
|
|
||||||
success : function (res) {
|
|
||||||
if(res.errcode === 0){
|
|
||||||
for (var index in $this.lists) {
|
|
||||||
var item = $this.lists[index];
|
|
||||||
|
|
||||||
if (item.member_id === member_id) {
|
|
||||||
|
|
||||||
$this.lists.splice(index,1,res.data);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
alert("操作失败:" + res.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
deleteMember : function (id, e) {
|
deleteMember : function (id, e) {
|
||||||
var $this = this;
|
var $this = this;
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url : "{{urlfor "ManagerController.DeleteMember"}}",
|
url : "{{urlfor "ManagerController.MemberGroupMemberDelete"}}",
|
||||||
type : "post",
|
type : "post",
|
||||||
data : { "id":id },
|
data : { "id":id },
|
||||||
dataType : "json",
|
dataType : "json",
|
||||||
|
@ -317,7 +200,7 @@
|
||||||
|
|
||||||
for (var index in $this.lists) {
|
for (var index in $this.lists) {
|
||||||
var item = $this.lists[index];
|
var item = $this.lists[index];
|
||||||
if (item.member_id == id) {
|
if (item.group_member_id == id) {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
$this.lists.splice(index,1);
|
$this.lists.splice(index,1);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue