修改refer和添加后台用户加角色

pull/30/head
taoshihan1991 4 years ago
parent 8c700f0d8a
commit f0d52f304c

@ -46,6 +46,14 @@ func PostKefuInfo(c *gin.Context){
//插入新用户 //插入新用户
if id==""{ if id==""{
uid:=models.CreateUser(name,tools.Md5(password),avator,nickname) uid:=models.CreateUser(name,tools.Md5(password),avator,nickname)
if uid==0{
c.JSON(200, gin.H{
"code": 400,
"msg": "增加用户失败",
"result":"",
})
return
}
roleIdInt,_:=strconv.Atoi(roleId) roleIdInt,_:=strconv.Atoi(roleId)
models.CreateUserRole(uid,uint(roleIdInt)) models.CreateUserRole(uid,uint(roleIdInt))
}else{ }else{

@ -9,7 +9,8 @@ type User struct {
Password string `json:"password"` Password string `json:"password"`
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
Avator string `json:"avator"` Avator string `json:"avator"`
RoleName string `json:"role_name"` RoleName string `json:"role_name" sql:"-"`
RoleId string `json:"role_id" sql:"-"`
} }
func CreateUser(name string,password string,avator string,nickname string)uint{ func CreateUser(name string,password string,avator string,nickname string)uint{
user:=&User{ user:=&User{
@ -18,7 +19,8 @@ func CreateUser(name string,password string,avator string,nickname string)uint{
Avator:avator, Avator:avator,
Nickname: nickname, Nickname: nickname,
} }
return DB.Create(user).Value.(*User).ID DB.Create(user)
return user.ID
} }
func UpdateUser(id string,name string,password string,avator string,nickname string){ func UpdateUser(id string,name string,password string,avator string,nickname string){
user:=&User{ user:=&User{
@ -38,7 +40,7 @@ func FindUser(username string)User{
} }
func FindUserById(id interface{})User{ func FindUserById(id interface{})User{
var user User var user User
DB.Where("id = ?", id).First(&user) DB.Select("user.*,role.name role_name").Joins("join user_role on user.id=user_role.user_id").Joins("join role on user_role.role_id=role.id").Where("user.id = ?", id).First(&user)
return user return user
} }
func DeleteUserById(id string){ func DeleteUserById(id string){

@ -184,7 +184,7 @@ setTimeout(function(){
area: ['510px', '520px'], area: ['510px', '520px'],
offset: 'rb', //右下角弹出 offset: 'rb', //右下角弹出
anim: 2, anim: 2,
content: ['/chat_page?lang=en', 'no'], //iframe的urlno代表不显示滚动条 content: ['/chatIndex?lang=en&refer='+window.document.title, 'no'], //iframe的urlno代表不显示滚动条
end: function(){ end: function(){
launchButtonFlag=false; launchButtonFlag=false;
$(".launchButton").show(); $(".launchButton").show();

@ -39,6 +39,9 @@
avator: [ avator: [
{ required: true, message: '请选择头像', trigger: 'blur' }, { required: true, message: '请选择头像', trigger: 'blur' },
], ],
role_id: [
{ required: true, message: '请选择角色', trigger: 'blur' },
],
password: [ password: [
{ required: true, message: '请输入密码', trigger: 'blur' }, { required: true, message: '请输入密码', trigger: 'blur' },
], ],
@ -61,6 +64,7 @@
avator:"", avator:"",
nickname:"", nickname:"",
role_name:"", role_name:"",
role_id:"",
}, },
roleList:[], roleList:[],
roleDialog:false, roleDialog:false,

@ -49,6 +49,7 @@
title="客服" title="客服"
:visible.sync="kefuDialog" :visible.sync="kefuDialog"
width="30%" width="30%"
top="0"
> >
<el-form ref="kefuForm" :model="kefuForm" :rules="rules" label-width="70px"> <el-form ref="kefuForm" :model="kefuForm" :rules="rules" label-width="70px">
<el-form-item label="用户名" prop="name"> <el-form-item label="用户名" prop="name">
@ -67,7 +68,7 @@
</el-option> </el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="角色" prop="avator"> <el-form-item label="角色" prop="role_id">
<el-select v-model="kefuForm.role_id" placeholder="请选择角色"> <el-select v-model="kefuForm.role_id" placeholder="请选择角色">
<el-option :label="item.role_name" :value="item.role_id" v-for="item in roleList" v-bind:key="item.role_id"> <el-option :label="item.role_name" :value="item.role_id" v-for="item in roleList" v-bind:key="item.role_id">
</el-option> </el-option>

@ -3,7 +3,7 @@ $("#launchButton").click(function() {
if (launchButtonFlag) return; if (launchButtonFlag) return;
var width=$(window).width(); var width=$(window).width();
if(width<768){ if(width<768){
window.open(GOFLY_URL+'/chatIndex?refer='+window.location.host); window.open(GOFLY_URL+'/chatIndex?refer='+window.document.title);
return; return;
} }
layer.open({ layer.open({
@ -14,7 +14,7 @@ $("#launchButton").click(function() {
area: ['520px', '530px'], area: ['520px', '530px'],
offset: 'rb', //右下角弹出 offset: 'rb', //右下角弹出
anim: 2, anim: 2,
content: [GOFLY_URL+'/chat_page?refer='+window.location.host, 'yes'], //iframe的urlno代表不显示滚动条 content: [GOFLY_URL+'/chatIndex?refer='+window.document.title, 'yes'], //iframe的urlno代表不显示滚动条
end: function(){ end: function(){
launchButtonFlag=false; launchButtonFlag=false;
$(".launchButton").show(); $(".launchButton").show();

@ -16,9 +16,9 @@ func PageChat(c *gin.Context) {
kefuId := c.Query("kefu_id") kefuId := c.Query("kefu_id")
lang,_ := c.Get("lang") lang,_ := c.Get("lang")
language:=config.CreateLanguage(lang.(string)) language:=config.CreateLanguage(lang.(string))
refer:=c.Request.Referer() refer := c.Query("refer")
if refer==""{ if refer==""{
refer = c.Query("refer") refer=c.Request.Referer()
} }
c.HTML(http.StatusOK, "chat_page.html", gin.H{ c.HTML(http.StatusOK, "chat_page.html", gin.H{
"KEFU_ID":kefuId, "KEFU_ID":kefuId,

Loading…
Cancel
Save