parent
c536a743cf
commit
cb6794d44d
@ -1,11 +0,0 @@
|
||||
[request_definition]
|
||||
r = sub, obj, act
|
||||
|
||||
[policy_definition]
|
||||
p = sub, obj, act
|
||||
|
||||
[policy_effect]
|
||||
e = some(where (p.eft == allow))
|
||||
|
||||
[matchers]
|
||||
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
|
|
@ -1,270 +0,0 @@
|
||||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag at
|
||||
// 2020-10-19 23:32:55.3852666 +0800 CST m=+0.208956401
|
||||
|
||||
package docs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/alecthomas/template"
|
||||
"github.com/swaggo/swag"
|
||||
)
|
||||
|
||||
var doc = `{
|
||||
"schemes": {{ marshal .Schemes }},
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "{{.Description}}",
|
||||
"title": "{{.Title}}",
|
||||
"contact": {},
|
||||
"license": {},
|
||||
"version": "{{.Version}}"
|
||||
},
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/check": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "登陆验证接口",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "用户名",
|
||||
"name": "username",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "密码",
|
||||
"name": "password",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "类型",
|
||||
"name": "type",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/message": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "发送消息接口",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "来源uid",
|
||||
"name": "from_id",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "目标uid",
|
||||
"name": "to_id",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "内容",
|
||||
"name": "content",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "类型|kefu,visitor",
|
||||
"name": "type",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/messages": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "获取访客聊天信息接口",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "访客ID",
|
||||
"name": "visitorId",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "认证token",
|
||||
"name": "token",
|
||||
"in": "header",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/visitors": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "获取访客列表接口",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "分页",
|
||||
"name": "page",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "认证token",
|
||||
"name": "token",
|
||||
"in": "header",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/visitors_online": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "获取在线访客列表接口",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"controller.Response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer"
|
||||
},
|
||||
"msg": {
|
||||
"type": "string"
|
||||
},
|
||||
"result": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
type swaggerInfo struct {
|
||||
Version string
|
||||
Host string
|
||||
BasePath string
|
||||
Schemes []string
|
||||
Title string
|
||||
Description string
|
||||
}
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = swaggerInfo{
|
||||
Version: "",
|
||||
Host: "",
|
||||
BasePath: "",
|
||||
Schemes: []string{},
|
||||
Title: "",
|
||||
Description: "",
|
||||
}
|
||||
|
||||
type s struct{}
|
||||
|
||||
func (s *s) ReadDoc() string {
|
||||
sInfo := SwaggerInfo
|
||||
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)
|
||||
|
||||
t, err := template.New("swagger_info").Funcs(template.FuncMap{
|
||||
"marshal": func(v interface{}) string {
|
||||
a, _ := json.Marshal(v)
|
||||
return string(a)
|
||||
},
|
||||
}).Parse(doc)
|
||||
if err != nil {
|
||||
return doc
|
||||
}
|
||||
|
||||
var tpl bytes.Buffer
|
||||
if err := t.Execute(&tpl, sInfo); err != nil {
|
||||
return doc
|
||||
}
|
||||
|
||||
return tpl.String()
|
||||
}
|
||||
|
||||
func init() {
|
||||
swag.Register(swag.Name, &s{})
|
||||
}
|
@ -1,202 +0,0 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"contact": {},
|
||||
"license": {}
|
||||
},
|
||||
"paths": {
|
||||
"/check": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "登陆验证接口",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "用户名",
|
||||
"name": "username",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "密码",
|
||||
"name": "password",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "类型",
|
||||
"name": "type",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/message": {
|
||||
"post": {
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "发送消息接口",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "来源uid",
|
||||
"name": "from_id",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "目标uid",
|
||||
"name": "to_id",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "内容",
|
||||
"name": "content",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "类型|kefu,visitor",
|
||||
"name": "type",
|
||||
"in": "formData",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/messages": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "获取访客聊天信息接口",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "访客ID",
|
||||
"name": "visitorId",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "认证token",
|
||||
"name": "token",
|
||||
"in": "header",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/visitors": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"multipart/form-data"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "获取访客列表接口",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "分页",
|
||||
"name": "page",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "认证token",
|
||||
"name": "token",
|
||||
"in": "header",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/visitors_online": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "获取在线访客列表接口",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/controller.Response"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"controller.Response": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer"
|
||||
},
|
||||
"msg": {
|
||||
"type": "string"
|
||||
},
|
||||
"result": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
definitions:
|
||||
controller.Response:
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
msg:
|
||||
type: string
|
||||
result:
|
||||
type: object
|
||||
type: object
|
||||
info:
|
||||
contact: {}
|
||||
license: {}
|
||||
paths:
|
||||
/check:
|
||||
post:
|
||||
consumes:
|
||||
- multipart/form-data
|
||||
parameters:
|
||||
- description: 用户名
|
||||
in: formData
|
||||
name: username
|
||||
required: true
|
||||
type: string
|
||||
- description: 密码
|
||||
in: formData
|
||||
name: password
|
||||
required: true
|
||||
type: string
|
||||
- description: 类型
|
||||
in: formData
|
||||
name: type
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Response'
|
||||
summary: 登陆验证接口
|
||||
/message:
|
||||
post:
|
||||
consumes:
|
||||
- multipart/form-data
|
||||
parameters:
|
||||
- description: 来源uid
|
||||
in: formData
|
||||
name: from_id
|
||||
required: true
|
||||
type: string
|
||||
- description: 目标uid
|
||||
in: formData
|
||||
name: to_id
|
||||
required: true
|
||||
type: string
|
||||
- description: 内容
|
||||
in: formData
|
||||
name: content
|
||||
required: true
|
||||
type: string
|
||||
- description: 类型|kefu,visitor
|
||||
in: formData
|
||||
name: type
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Response'
|
||||
summary: 发送消息接口
|
||||
/messages:
|
||||
get:
|
||||
consumes:
|
||||
- multipart/form-data
|
||||
parameters:
|
||||
- description: 访客ID
|
||||
in: query
|
||||
name: visitorId
|
||||
required: true
|
||||
type: string
|
||||
- description: 认证token
|
||||
in: header
|
||||
name: token
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Response'
|
||||
summary: 获取访客聊天信息接口
|
||||
/visitors:
|
||||
get:
|
||||
consumes:
|
||||
- multipart/form-data
|
||||
parameters:
|
||||
- description: 分页
|
||||
in: query
|
||||
name: page
|
||||
required: true
|
||||
type: string
|
||||
- description: 认证token
|
||||
in: header
|
||||
name: token
|
||||
required: true
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Response'
|
||||
summary: 获取访客列表接口
|
||||
/visitors_online:
|
||||
get:
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Response'
|
||||
summary: 获取在线访客列表接口
|
||||
swagger: "2.0"
|
@ -1,32 +0,0 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/casbin/casbin/v2"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
)
|
||||
|
||||
func CasbinACL(c *gin.Context) {
|
||||
roleId, _ := c.Get("role_id")
|
||||
sub := fmt.Sprintf("%s_%d", "role", int(roleId.(float64)))
|
||||
obj := c.Request.RequestURI
|
||||
act := c.Request.Method
|
||||
e, err := casbin.NewEnforcer("config/model.conf", "config/policy.csv")
|
||||
log.Println(sub, obj, act, err)
|
||||
ok, err := e.Enforce(sub, obj, act)
|
||||
if err != nil {
|
||||
c.JSON(200, gin.H{
|
||||
"code": 403,
|
||||
"msg": "没有权限:" + err.Error(),
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
if !ok {
|
||||
c.JSON(200, gin.H{
|
||||
"code": 403,
|
||||
"msg": fmt.Sprintf("没有权限:%s,%s,%s", sub, obj, act),
|
||||
})
|
||||
c.Abort()
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
<html lang="cn">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="陶士涵">
|
||||
<title>GO-FLY客服页</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-ui@2.13.1/lib/theme-chalk/index.css">
|
||||
<script src="/static/js/functions.js?v=0.1.1"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue-router/dist/vue-router.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/element-ui@2.13.1/lib/index.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
|
||||
<link rel="stylesheet" href="/static/css/common.css?v=0.1.1" />
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
background: #fff;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app" class="chatKfPageApp">
|
||||
<router-view></router-view>
|
||||
</div>
|
||||
<template id="chatKfIndex">
|
||||
<el-row>
|
||||
<div style="cursor:pointer" v-for="item in visitors" :key="item.uid" class="onlineUsers">
|
||||
<router-link :to="'/chatKfBox/'+item.uid">
|
||||
<el-col :span="6">
|
||||
<el-avatar :size="40" :src="item.avator"></el-avatar>
|
||||
</el-col>
|
||||
<el-col :span="18">
|
||||
<{item.username}>
|
||||
</el-col>
|
||||
</router-link>
|
||||
</div>
|
||||
</el-row>
|
||||
</template>
|
||||
<template id="chatBox">
|
||||
<div>
|
||||
<div class="chatContext">
|
||||
<div class="chatBox">
|
||||
<el-row :gutter="2" v-for="v in msgList" v-bind:class="{'chatBoxMe': v.is_kefu==true}">
|
||||
<div class="chatTime" v-bind:class="{'chatTimeHide': v.show_time==false}"><{v.time}></div>
|
||||
<el-col :span="3"><el-avatar :src="v.avator"></el-avatar></el-col>
|
||||
<el-col :span="21">
|
||||
<div class="chatUser"><{v.name}></div>
|
||||
<div class="chatContent" v-html="v.content"></div>
|
||||
</el-col>
|
||||
<div class="clear"></div>
|
||||
</el-row>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chatBoxSend">
|
||||
<div class="iconBtns">
|
||||
<div class="faceBtn visitorFaceBtn"></div>
|
||||
<div class="imageBtn visitorImageBtn" id="uploadImg" v-on:click="uploadImg('/uploadimg')"></div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
<el-input type="textarea" class="chatArea" v-model="messageContent" v-on:keyup.enter.native="chatToUser"></el-input>
|
||||
<div class="faceBox visitorFaceBox">
|
||||
<ul class="faceBoxList">
|
||||
<li v-on:click="faceIconClick(i)" class="faceIcon" v-for="(v,i) in face" :title="v.name"><img :src=v.path></li>
|
||||
</ul>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
<div class="btnArea">
|
||||
<el-button type="primary" class="chatBoxSendBtn" size="small" v-on:click="chatToUser">发送</el-button>
|
||||
</div>
|
||||
<div class="clear"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</body>
|
||||
<script src="https://cdn.bootcss.com/reconnecting-websocket/1.0.0/reconnecting-websocket.min.js"></script>
|
||||
<script>
|
||||
var TOKEN='{{.Token}}';
|
||||
</script>
|
||||
<script src="/static/js/chat-kf-page.js?v=0.1.1"></script>
|
||||
</html>
|
@ -1,236 +0,0 @@
|
||||
//首页组件
|
||||
var chatKfIndex = {
|
||||
delimiters:["<{","}>"],
|
||||
data: function(){
|
||||
return {
|
||||
visitors: [],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
init(){
|
||||
this.getKefuInfo();
|
||||
},
|
||||
kfOnline() {
|
||||
let messsage = {}
|
||||
messsage.type = "kfOnline";
|
||||
messsage.data = this.$parent.kefuInfo;
|
||||
this.$parent.socket.send(JSON.stringify(messsage));
|
||||
},
|
||||
receiveMessage(e) {
|
||||
const retData = JSON.parse(e.data);
|
||||
switch (retData.type) {
|
||||
case "allUsers":
|
||||
this.visitors = retData.data;
|
||||
break;
|
||||
case "userOnline":
|
||||
this.visitors.push(retData.data);
|
||||
break;
|
||||
}
|
||||
},
|
||||
//初始化websocket
|
||||
initConn() {
|
||||
if(this.$parent.socket==null){
|
||||
this.$parent.socket = new ReconnectingWebSocket(this.$parent.server);
|
||||
}
|
||||
this.$parent.socket.onopen=this.kfOnline;
|
||||
this.$parent.socket.onmessage = this.receiveMessage;
|
||||
},
|
||||
//获取客服信息
|
||||
getKefuInfo(){
|
||||
let _this=this;
|
||||
$.ajax({
|
||||
type:"get",
|
||||
url:"/kefuinfo",
|
||||
headers:{
|
||||
"token":TOKEN
|
||||
},
|
||||
success: function(data) {
|
||||
if(data.code==200 && data.result!=null){
|
||||
_this.$parent.kefuInfo.id=data.result.id;
|
||||
_this.$parent.kefuInfo.name=data.result.name;
|
||||
_this.$parent.kefuInfo.avator=data.result.avator;
|
||||
_this.initConn();
|
||||
}
|
||||
if(data.code!=200){
|
||||
_this.$message({
|
||||
message: data.msg,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
created: function () {
|
||||
this.init();
|
||||
},
|
||||
template:$("#chatKfIndex").html()
|
||||
};
|
||||
//详情组件
|
||||
var chatKfBox = {
|
||||
delimiters:["<{","}>"],
|
||||
data: function(){
|
||||
return {
|
||||
visitorId:null,
|
||||
msgList: [],
|
||||
messageContent: "",
|
||||
face: [],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
receiveMessage(e) {
|
||||
const retData = JSON.parse(e.data);
|
||||
switch (retData.type) {
|
||||
case "message":
|
||||
alert(e.data);
|
||||
break;
|
||||
}
|
||||
},
|
||||
init(){
|
||||
//获取当前客户消息
|
||||
this.visitorId=this.$route.params.visitorId;
|
||||
this.getMesssagesByVisitorId(this.$route.params.visitorId);
|
||||
this.$parent.socket.onmessage = this.receiveMessage;
|
||||
},
|
||||
//获取信息列表
|
||||
getMesssagesByVisitorId(visitorId) {
|
||||
let _this = this;
|
||||
$.ajax({
|
||||
type: "get",
|
||||
url: "/messages?visitorId=" + visitorId,
|
||||
headers: {
|
||||
"token": TOKEN
|
||||
},
|
||||
success: function (data) {
|
||||
if (data.code == 200 && data.result != null) {
|
||||
let msgList = data.result;
|
||||
_this.msgList = [];
|
||||
for (let i = 0; i < msgList.length; i++) {
|
||||
let visitorMes = msgList[i];
|
||||
let content = {}
|
||||
if (visitorMes["mes_type"] == "kefu") {
|
||||
content.is_kefu = true;
|
||||
content.avator = visitorMes["kefu_avator"];
|
||||
content.name = visitorMes["kefu_name"];
|
||||
} else {
|
||||
content.is_kefu = false;
|
||||
content.avator = visitorMes["visitor_avator"];
|
||||
content.name = visitorMes["visitor_name"];
|
||||
}
|
||||
content.content = replaceContent(visitorMes["content"]);
|
||||
content.time = visitorMes["time"];
|
||||
_this.msgList.push(content);
|
||||
_this.scrollBottom();
|
||||
}
|
||||
}
|
||||
if (data.code != 200) {
|
||||
_this.$message({
|
||||
message: data.msg,
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
//发送给客户
|
||||
chatToUser() {
|
||||
this.messageContent=this.messageContent.trim("\r\n");
|
||||
if(this.messageContent==""||this.messageContent=="\r\n"||this.currentGuest==""){
|
||||
return;
|
||||
}
|
||||
let _this=this;
|
||||
let mes = {};
|
||||
mes.type = "kefu";
|
||||
mes.content = this.messageContent;
|
||||
mes.from_id = _this.$parent.kefuInfo.id;
|
||||
mes.to_id = this.visitorId;
|
||||
mes.content = this.messageContent;
|
||||
$.post("/message",mes,function(){
|
||||
_this.messageContent = "";
|
||||
});
|
||||
|
||||
let content = {}
|
||||
content.avator = _this.$parent.kefuInfo.avator;
|
||||
content.name = _this.$parent.kefuInfo.name;
|
||||
content.content = replaceContent(this.messageContent);
|
||||
content.is_kefu = true;
|
||||
content.time = '';
|
||||
this.msgList.push(content);
|
||||
this.scrollBottom();
|
||||
},
|
||||
//上传图片
|
||||
uploadImg (url){
|
||||
let _this=this;
|
||||
$('#uploadImg').after('<input type="file" accept="image/gif,image/jpeg,image/jpg,image/png" id="uploadImgFile" name="file" style="display:none" >');
|
||||
$("#uploadImgFile").click();
|
||||
$("#uploadImgFile").change(function (e) {
|
||||
var formData = new FormData();
|
||||
var file = $("#uploadImgFile")[0].files[0];
|
||||
formData.append("imgfile",file); //传给后台的file的key值是可以自己定义的
|
||||
filter(file) && $.ajax({
|
||||
url: url || '',
|
||||
type: "post",
|
||||
data: formData,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
dataType: 'JSON',
|
||||
mimeType: "multipart/form-data",
|
||||
success: function (res) {
|
||||
if(res.code!=200){
|
||||
_this.$message({
|
||||
message: res.msg,
|
||||
type: 'error'
|
||||
});
|
||||
}else{
|
||||
_this.messageContent+='img[/' + res.result.path + ']';
|
||||
_this.chatToUser();
|
||||
}
|
||||
},
|
||||
error: function (data) {
|
||||
console.log(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
//表情点击事件
|
||||
faceIconClick(index){
|
||||
$('.faceBox').hide();
|
||||
this.messageContent+="face"+this.face[index].name;
|
||||
},
|
||||
//滚到底部
|
||||
scrollBottom(){
|
||||
this.$nextTick(() => {
|
||||
$('body').scrollTop($("body")[0].scrollHeight);
|
||||
});
|
||||
},
|
||||
},
|
||||
created: function () {
|
||||
this.init();
|
||||
},
|
||||
template:$("#chatBox").html()
|
||||
};
|
||||
var routes = [
|
||||
{ path: '/',component:chatKfIndex}, // 这个表示会默认渲染
|
||||
{path:'/chatKfBox/:visitorId',component:chatKfBox},
|
||||
];
|
||||
var router = new VueRouter({
|
||||
routes: routes
|
||||
})
|
||||
|
||||
new Vue({
|
||||
router,
|
||||
el: '#app',
|
||||
|
||||
data: function(){
|
||||
return{
|
||||
server:getWsBaseUrl()+"/chat_server",
|
||||
socket:null,
|
||||
kefuInfo:{},
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
|
||||
},
|
||||
created: function () {
|
||||
},
|
||||
})
|
Before Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 30 KiB |
Loading…
Reference in new issue