接入客服消息

This commit is contained in:
龙运模 2024-11-10 22:30:39 +08:00
parent 372ca89f07
commit 483554e361
3 changed files with 78 additions and 26 deletions

View File

@ -10,20 +10,20 @@
<div class="bodyMain"> <div class="bodyMain">
<el-scrollbar> <el-scrollbar>
<div class="tagList"> <div class="tagList">
<div class="tagItem" v-for="(item,index) in tagList" :key="index">{{item.name}}</div> <div class="tagItem" v-for="(item,index) in tagList" :key="index" @click="typeActive(item)">{{item.label}}</div>
</div> </div>
<div class="msgList"> <div class="msgList">
<div class="msgItem" :class="item.type === 2?'msgRightItem':''" v-for="(item,index) in msgList" :key="index"> <div class="msgItem" :class="user_id != item.to_user_id?'msgRightItem':''" v-for="(item,index) in msgList" :key="index">
<div class="avatar" v-if="item.type === 1"> <div class="avatar" v-if="user_id === item.to_user_id">
<el-avatar :size="36" :src="item.avatar" fit="contain"> <el-avatar :size="36" :src="item.from_user.avatar" fit="contain">
<img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png"/> <img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png"/>
</el-avatar> </el-avatar>
</div> </div>
<div class="msgText"> <div class="msgText">
<div class="msgTitle">{{item.title}}</div> <div class="msgTitle">{{item.from_user && item.from_user.name?item.from_user.name:'匿名'}}</div>
<div class="textCom">{{item.msg}}</div> <div class="textCom">{{item.to_message}}</div>
</div> </div>
<div class="avatar" v-if="item.type === 2"> <div class="avatar" v-if="user_id != item.to_user_id">
<el-avatar :size="36" :src="item.avatar" fit="contain"> <el-avatar :size="36" :src="item.avatar" fit="contain">
<img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png"/> <img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png"/>
</el-avatar> </el-avatar>
@ -33,8 +33,8 @@
</el-scrollbar> </el-scrollbar>
</div> </div>
<div class="footer"> <div class="footer">
<el-input class="customTextarea" v-model="params.text" resize="none" type="textarea" :row="2" placeholder="请简短描述您的问题"></el-input> <el-input class="customTextarea" v-model="params.to_message" resize="none" type="textarea" :row="2" placeholder="请简短描述您的问题"></el-input>
<div class="saveBtn" :class="params.text!==''?'saveActive':''"> </div> <div class="saveBtn" :class="params.to_message!==''?'saveActive':''" @click="sendCustomer"> </div>
</div> </div>
</div> </div>
</div> </div>
@ -42,40 +42,88 @@
</template> </template>
<script> <script>
import {eventBus} from "@/utils/eventBus";
export default { export default {
name: "index", name: "index",
data(){ data(){
return{ return{
customerShow:false, customerShow:false,
params:{ params:{
text:'' type:"",
to_user_id:"",
to_message:"",
}, },
tagList:[ tagList:[],
{name:'搜索引擎和数据查询'}, msgList:[],
{name:'用户体验和设计'}, user_id:0,
{name:'技术和兼容性'},
{name:'质量问题'},
{name:'其他'},
],
msgList:[
{type:1,avatar:"https://dm-auto.oss-cn-shanghai.aliyuncs.com/xw_cloud/image/login_logo.png",title:"在线客服",msg:"您好,请问您需要什么帮助?"},
{type:1,avatar:"https://dm-auto.oss-cn-shanghai.aliyuncs.com/xw_cloud/image/login_logo.png",title:"在线客服",msg:"我是您的智能在线客服,您可以把你的问题告诉我,我会尽我所能帮助您。"},
{type:2,avatar:"https://dm-auto.oss-cn-shanghai.aliyuncs.com/xw_cloud/5.gif",title:"龙隆",msg:"怎么能快速的挣够一百万"}
]
} }
}, },
mounted() { mounted() {
let token = this.$TOOL.cookie.get('TOKEN');
if (token && token != null) {
//
eventBus.$on('sockBack', this.getWsResult);
const userInfo = this.$TOOL.data.get("USER_INFO");
this.user_id = userInfo.id;
}
},
unmounted() {
eventBus.$off('sockBack', this.getWsResult);
}, },
methods:{ methods:{
getWsResult(res){
if(res.data && (res.data.type == 36 || res.data.type == 37)){
switch(res.data.type) {
case 36:
this.msgList = res.data.rows;
break;
case 37:
this.params.to_user_id = res.data.user.uid;
break;
default:
break;
}
}
},
openCustomer(){ openCustomer(){
this.customerShow = !this.customerShow; this.customerShow = !this.customerShow;
if(this.customerShow){
this.getAssign();
this.getRecordList();
this.customerType();
}
}, },
closeCustomer(){ closeCustomer(){
this.customerShow = false; this.customerShow = false;
}, },
async getAssign() {
await this.$API.customer.customer.post();
},
async getRecordList() {
await this.$API.customer.list.post();
},
async sendCustomer() {
if(this.params.to_message =="") return
const res = await this.$API.customer.send.post(this.params);
if(res.code == 200){
this.tagList.push({});
this.params.to_message = "";
}
},
async customerType() {
const res = await this.$API.customer.typeList.post();
if (res.code == 200) {
this.tagList = res.data;
}
},
typeActive(item){
this.params.type = item.value;
}
} }
} }
</script> </script>
@ -91,8 +139,8 @@ export default {
height: 56px; height: 56px;
} }
.customerView{ .customerView{
width: 300px; width: 380px;
height: 430px; height: 580px;
position: absolute; position: absolute;
right: 0; right: 0;
bottom: 70px; bottom: 70px;

View File

@ -75,6 +75,9 @@
return false return false
} }
if(user.data.user.company_id === 0){ if(user.data.user.company_id === 0){
// ws
let global_callback = function () {};
this.$socketApi.createWebSocket(global_callback);
this.$router.replace({ this.$router.replace({
path: '/maintenance' path: '/maintenance'
}) })

View File

@ -123,7 +123,8 @@ export default {
bubble.style.background = `${item.color}`; bubble.style.background = `${item.color}`;
bubble.innerText =`${item.name}`; bubble.innerText =`${item.name}`;
return bubble return bubble
} },
} }
} }
</script> </script>