mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-04-05 20:17:53 +08:00
实现添加项目成员时下拉提示
This commit is contained in:
parent
c7d83576bd
commit
ba9c390a13
@ -385,6 +385,7 @@ func (c *BookController) Users() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Create 创建项目.
|
||||
func (c *BookController) Create() {
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/lifei6671/mindoc/conf"
|
||||
"github.com/lifei6671/mindoc/models"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type BookMemberController struct {
|
||||
@ -16,10 +17,10 @@ type BookMemberController struct {
|
||||
// AddMember 参加参与用户.
|
||||
func (c *BookMemberController) AddMember() {
|
||||
identify := c.GetString("identify")
|
||||
account := c.GetString("account")
|
||||
account,_ := c.GetInt("account")
|
||||
role_id, _ := c.GetInt("role_id", 3)
|
||||
|
||||
if identify == "" || account == "" {
|
||||
beego.Info(account)
|
||||
if identify == "" || account <= 0 {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
}
|
||||
book, err := c.IsPermission()
|
||||
@ -28,9 +29,10 @@ func (c *BookMemberController) AddMember() {
|
||||
c.JsonResult(6001, err.Error())
|
||||
}
|
||||
|
||||
|
||||
member := models.NewMember()
|
||||
|
||||
if _, err := member.FindByAccount(account); err != nil {
|
||||
if _, err := member.Find(account); err != nil {
|
||||
c.JsonResult(404, "用户不存在")
|
||||
}
|
||||
if member.Status == 1 {
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
type SearchController struct {
|
||||
BaseController
|
||||
}
|
||||
|
||||
//搜索首页
|
||||
func (c *SearchController) Index() {
|
||||
c.Prepare()
|
||||
c.TplName = "search/index.tpl"
|
||||
@ -95,3 +95,41 @@ func (c *SearchController) Index() {
|
||||
c.Data["Lists"] = search_result
|
||||
}
|
||||
}
|
||||
|
||||
//搜索用户
|
||||
func (c *SearchController) User() {
|
||||
c.Prepare()
|
||||
key := c.Ctx.Input.Param(":key")
|
||||
keyword := strings.TrimSpace(c.GetString("q"))
|
||||
if key == "" || keyword == ""{
|
||||
c.JsonResult(404,"参数错误")
|
||||
}
|
||||
|
||||
book, err := models.NewBookResult().FindByIdentify(key, c.Member.MemberId)
|
||||
if err != nil {
|
||||
if err == models.ErrPermissionDenied {
|
||||
c.JsonResult(403,"没有权限")
|
||||
}
|
||||
c.JsonResult(500,"项目不存在")
|
||||
}
|
||||
|
||||
members,err := models.NewMemberRelationshipResult().FindNotJoinUsersByAccount(book.BookId,10,"%"+keyword+"%")
|
||||
if err != nil {
|
||||
beego.Error("查询用户列表出错:" + err.Error())
|
||||
c.JsonResult(500,err.Error())
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -230,6 +230,20 @@ func (m *Member) FindByAccount(account string) (*Member, error) {
|
||||
}
|
||||
return m, err
|
||||
}
|
||||
//批量查询用户
|
||||
func (m *Member) FindByAccountList(accounts ...string) ([]*Member,error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
var members []*Member
|
||||
_,err := o.QueryTable(m.TableNameWithPrefix()).Filter("account__in", accounts).All(&members)
|
||||
|
||||
if err == nil {
|
||||
for _,item := range members {
|
||||
item.ResolveRoleName()
|
||||
}
|
||||
}
|
||||
return members, err
|
||||
}
|
||||
|
||||
//分页查找用户.
|
||||
func (m *Member) FindToPager(pageIndex, pageSize int) ([]*Member, int, error) {
|
||||
|
@ -24,6 +24,14 @@ type MemberRelationshipResult struct {
|
||||
RoleName string `json:"role_name"`
|
||||
}
|
||||
|
||||
type SelectMemberResult struct {
|
||||
Result []KeyValueItem `json:"results"`
|
||||
}
|
||||
type KeyValueItem struct {
|
||||
Id int `json:"id"`
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
func NewMemberRelationshipResult() *MemberRelationshipResult {
|
||||
return &MemberRelationshipResult{}
|
||||
}
|
||||
@ -53,8 +61,8 @@ func (m *MemberRelationshipResult) ResolveRoleName() *MemberRelationshipResult {
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MemberRelationshipResult) FindForUsersByBookId(book_id, pageIndex, pageSize int) ([]*MemberRelationshipResult, int, error) {
|
||||
// 根据项目ID查询用户
|
||||
func (m *MemberRelationshipResult) FindForUsersByBookId(bookId, pageIndex, pageSize int) ([]*MemberRelationshipResult, int, error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
var members []*MemberRelationshipResult
|
||||
@ -65,7 +73,7 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(book_id, pageIndex, page
|
||||
|
||||
var total_count int
|
||||
|
||||
err := o.Raw(sql2, book_id).QueryRow(&total_count)
|
||||
err := o.Raw(sql2, bookId).QueryRow(&total_count)
|
||||
|
||||
if err != nil {
|
||||
return members, 0, err
|
||||
@ -73,7 +81,7 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(book_id, pageIndex, page
|
||||
|
||||
offset := (pageIndex - 1) * pageSize
|
||||
|
||||
_, err = o.Raw(sql1, book_id, offset, pageSize).QueryRows(&members)
|
||||
_, err = o.Raw(sql1, bookId, offset, pageSize).QueryRows(&members)
|
||||
|
||||
if err != nil {
|
||||
return members, 0, err
|
||||
@ -84,3 +92,46 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(book_id, pageIndex, page
|
||||
}
|
||||
return members, total_count, nil
|
||||
}
|
||||
|
||||
// 查询指定文档中不存在的用户列表
|
||||
func (m *MemberRelationshipResult) FindNotJoinUsersByAccount(bookId, limit int,account string) ([]*Member,error){
|
||||
o := orm.NewOrm()
|
||||
|
||||
sql := "SELECT m.* FROM md_members as m LEFT JOIN md_relationship as rel ON m.member_id=rel.member_id WHERE (rel.book_id <> ? OR rel.relationship_id IS NULL) AND m.account LIKE ? LIMIT 0,?;"
|
||||
|
||||
var members []*Member
|
||||
|
||||
_,err := o.Raw(sql,bookId,account,limit).QueryRows(&members)
|
||||
|
||||
return members,err
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -65,6 +65,7 @@ func init() {
|
||||
beego.Router("/api/:key/delete", &controllers.DocumentController{}, "post:Delete")
|
||||
beego.Router("/api/:key/content/?:id", &controllers.DocumentController{}, "*:Content")
|
||||
beego.Router("/api/:key/compare/:id", &controllers.DocumentController{}, "*:Compare")
|
||||
beego.Router("/api/search/user/:key", &controllers.SearchController{}, "*:User")
|
||||
|
||||
beego.Router("/history/get", &controllers.DocumentController{}, "get:History")
|
||||
beego.Router("/history/delete", &controllers.DocumentController{}, "*:DeleteHistory")
|
||||
|
@ -10,8 +10,8 @@
|
||||
<!-- Bootstrap -->
|
||||
<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="/static/css/main.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">
|
||||
<!-- 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:// -->
|
||||
<!--[if lt IE 9]>
|
||||
@ -106,7 +106,8 @@
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">账号</label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="account" class="form-control" placeholder="用户账号" id="account" maxlength="50">
|
||||
{{/*<input type="text" name="account" class="form-control" placeholder="用户账号" id="account" maxlength="50">*/}}
|
||||
<select class="js-data-example-ajax form-control" multiple="multiple" name="account" id="account"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@ -135,9 +136,17 @@
|
||||
<script src="{{cdnjs "/static/bootstrap/js/bootstrap.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="/static/js/main.js" type="text/javascript"></script>
|
||||
<script src="/static/select2/4.0.5/js/select2.full.min.js"></script>
|
||||
<script src="/static/select2/4.0.5/js/i18n/zh-CN.js"></script>
|
||||
<script src="{{cdnjs "/static/js/main.js"}}" type="text/javascript"></script>
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
|
||||
var modalCache = $("#addBookMemberDialogModal form").html();
|
||||
|
||||
/**
|
||||
* 添加用户
|
||||
*/
|
||||
$("#addBookMemberDialogForm").ajaxForm({
|
||||
beforeSubmit : function () {
|
||||
var account = $.trim($("#account").val());
|
||||
@ -156,6 +165,33 @@
|
||||
$("#btnAddMember").button("reset");
|
||||
}
|
||||
});
|
||||
$("#addBookMemberDialogModal").on("hidden.bs.modal",function () {
|
||||
$(this).find("form").html(modalCache);
|
||||
}).on("show.bs.modal",function () {
|
||||
$('.js-data-example-ajax').select2({
|
||||
language: "zh-CN",
|
||||
minimumInputLength : 1,
|
||||
minimumResultsForSearch: Infinity,
|
||||
maximumSelectionLength:1,
|
||||
width : "100%",
|
||||
ajax: {
|
||||
url: '{{urlfor "SearchController.User" ":key" .Model.Identify}}',
|
||||
dataType: 'json',
|
||||
data: function (params) {
|
||||
return {
|
||||
q: params.term, // search term
|
||||
page: params.page
|
||||
};
|
||||
},
|
||||
processResults: function (data, params) {
|
||||
console.log(data)
|
||||
return {
|
||||
results : data.data.results
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var app = new Vue({
|
||||
el : "#userList",
|
||||
|
Loading…
Reference in New Issue
Block a user