1
This commit is contained in:
parent
e976da94b7
commit
0a793caf80
@ -52,14 +52,6 @@ public class ChatController {
|
|||||||
public AjaxResult sendMessage(@RequestBody BusiChatItem message) {
|
public AjaxResult sendMessage(@RequestBody BusiChatItem message) {
|
||||||
return AjaxResult.success(busiChatItemService.sendMessage(message));
|
return AjaxResult.success(busiChatItemService.sendMessage(message));
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 根据租户ID查询会话列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/tenant/{tenantId}")
|
|
||||||
public AjaxResult getByTenantId(@PathVariable String tenantId) {
|
|
||||||
List<BusiChatMain> sessions = busiChatMainService.selectByTenantId(tenantId);
|
|
||||||
return AjaxResult.success(sessions);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户活跃会话
|
* 查询用户活跃会话
|
||||||
@ -93,7 +85,7 @@ public class ChatController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping("/read/{sessionId}")
|
@PutMapping("/read/{sessionId}")
|
||||||
public AjaxResult markAsRead(@PathVariable String sessionId, @RequestParam String receiverId) {
|
public AjaxResult markAsRead(@PathVariable String sessionId, @RequestParam String receiverId) {
|
||||||
boolean success = busiChatItemService.markAsRead(sessionId, receiverId);
|
busiChatItemService.markAsRead(sessionId, receiverId);
|
||||||
return success ? AjaxResult.success() : AjaxResult.error("标记已读失败");
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import com.ruoyi.busi.utils.CommonUtils;
|
|||||||
import com.ruoyi.busi.vo.BusiCategoryVO;
|
import com.ruoyi.busi.vo.BusiCategoryVO;
|
||||||
import com.ruoyi.busi.vo.SiteMapVO;
|
import com.ruoyi.busi.vo.SiteMapVO;
|
||||||
import com.ruoyi.busi.vo.WebDetailVO;
|
import com.ruoyi.busi.vo.WebDetailVO;
|
||||||
|
import com.ruoyi.common.config.GoogleConfig;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.domain.R;
|
import com.ruoyi.common.core.domain.R;
|
||||||
@ -37,7 +38,6 @@ import java.util.*;
|
|||||||
|
|
||||||
import static com.ruoyi.constant.DictConstants.*;
|
import static com.ruoyi.constant.DictConstants.*;
|
||||||
import static com.ruoyi.constant.DictConstants.CATG_TYPE_WZ;
|
import static com.ruoyi.constant.DictConstants.CATG_TYPE_WZ;
|
||||||
import static com.ruoyi.constant.StrConstants.UPLOAD_DIR;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Web 专用Controller
|
* Web 专用Controller
|
||||||
@ -71,6 +71,8 @@ public class WebController extends BaseController {
|
|||||||
private ISysDictDataService dictDataService;
|
private ISysDictDataService dictDataService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IBaseAppService appService;
|
private IBaseAppService appService;
|
||||||
|
@Autowired
|
||||||
|
private GoogleConfig googleConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导航栏接口--所有分类
|
* 导航栏接口--所有分类
|
||||||
@ -459,7 +461,7 @@ public class WebController extends BaseController {
|
|||||||
public void downloadApk(HttpServletResponse response) {
|
public void downloadApk(HttpServletResponse response) {
|
||||||
try {
|
try {
|
||||||
// APK文件路径
|
// APK文件路径
|
||||||
File file = new File(UPLOAD_DIR);
|
File file = new File(googleConfig.getAppDownload());
|
||||||
|
|
||||||
// 检查文件是否存在
|
// 检查文件是否存在
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
|
@ -118,7 +118,7 @@ public class BusiChatMainController extends BaseController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据客服ID查询会话列表---用到了
|
* 根据客服ID查询会话列表---只有服务端使用,所以挪过来
|
||||||
*/
|
*/
|
||||||
@GetMapping("/service")
|
@GetMapping("/service")
|
||||||
public AjaxResult getByServiceId() {
|
public AjaxResult getByServiceId() {
|
||||||
|
@ -48,14 +48,6 @@ public interface BusiChatMainMapper extends BaseMapper<BusiChatMain>
|
|||||||
|
|
||||||
List<BusiChatMain> selectLineChart(@Param("tenantId")String tenantId,@Param("startDate")String startDate,@Param("endDate")String endDate);
|
List<BusiChatMain> selectLineChart(@Param("tenantId")String tenantId,@Param("startDate")String startDate,@Param("endDate")String endDate);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据租户ID查询会话列表
|
|
||||||
* @param tenantId 租户ID
|
|
||||||
* @return 会话列表
|
|
||||||
*/
|
|
||||||
List<BusiChatMain> selectByTenantId(@Param("tenantId") String tenantId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据客服ID查询会话列表
|
* 根据客服ID查询会话列表
|
||||||
* @param serviceId 客服ID
|
* @param serviceId 客服ID
|
||||||
@ -66,12 +58,10 @@ public interface BusiChatMainMapper extends BaseMapper<BusiChatMain>
|
|||||||
/**
|
/**
|
||||||
* 根据用户标识查询活跃会话
|
* 根据用户标识查询活跃会话
|
||||||
* @param tenantId 租户ID
|
* @param tenantId 租户ID
|
||||||
* @param userIp 用户IP
|
|
||||||
* @param deviceCode 设备编码
|
* @param deviceCode 设备编码
|
||||||
* @return 会话信息
|
* @return 会话信息
|
||||||
*/
|
*/
|
||||||
BusiChatMain selectActiveSession(@Param("tenantId") String tenantId,
|
BusiChatMain selectActiveSession(@Param("tenantId") String tenantId,
|
||||||
@Param("userIp") String userIp,
|
|
||||||
@Param("deviceCode") String deviceCode,
|
@Param("deviceCode") String deviceCode,
|
||||||
@Param("prodId") String prodId);
|
@Param("prodId") String prodId);
|
||||||
}
|
}
|
||||||
|
@ -36,13 +36,6 @@ public interface IBusiChatMainService extends IService<BusiChatMain> {
|
|||||||
*/
|
*/
|
||||||
BusiChatMain createSession(BusiChatMain session);
|
BusiChatMain createSession(BusiChatMain session);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据租户ID查询会话列表
|
|
||||||
* @param tenantId 租户ID
|
|
||||||
* @return 会话列表
|
|
||||||
*/
|
|
||||||
List<BusiChatMain> selectByTenantId(String tenantId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据客服ID查询会话列表
|
* 根据客服ID查询会话列表
|
||||||
* @param serviceId 客服ID
|
* @param serviceId 客服ID
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi.busi.service.impl;
|
package com.ruoyi.busi.service.impl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@ -97,11 +98,6 @@ public class BusiChatMainServiceImpl extends ServiceImpl<BusiChatMainMapper,Busi
|
|||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<BusiChatMain> selectByTenantId(String tenantId) {
|
|
||||||
return busiChatMainMapper.selectByTenantId(tenantId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<BusiChatMain> selectByServiceId(Long serviceId) {
|
public List<BusiChatMain> selectByServiceId(Long serviceId) {
|
||||||
// 先查缓存
|
// 先查缓存
|
||||||
@ -111,9 +107,13 @@ public class BusiChatMainServiceImpl extends ServiceImpl<BusiChatMainMapper,Busi
|
|||||||
if (sessions == null || sessions.isEmpty()) {
|
if (sessions == null || sessions.isEmpty()) {
|
||||||
// 缓存未命中,查数据库
|
// 缓存未命中,查数据库
|
||||||
sessions = busiChatMainMapper.selectByServiceId(serviceId);
|
sessions = busiChatMainMapper.selectByServiceId(serviceId);
|
||||||
// 存入缓存,设置较短过期时间,避免缓存与数据库不一致
|
if(null!= sessions && sessions.size()>0){
|
||||||
redisCache.setCacheList(cacheKey, sessions);
|
// 存入缓存,设置较短过期时间,避免缓存与数据库不一致
|
||||||
redisCache.expire(cacheKey, 5, TimeUnit.MINUTES);
|
redisCache.setCacheList(cacheKey, sessions);
|
||||||
|
redisCache.expire(cacheKey, 5, TimeUnit.MINUTES);
|
||||||
|
}else{
|
||||||
|
sessions = new ArrayList<>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (BusiChatMain session : sessions) {
|
for (BusiChatMain session : sessions) {
|
||||||
session.setUnreadCount(busiChatItemService.selectUnreadCount(session.getId(),DATA_FROM_CUSTOMER));
|
session.setUnreadCount(busiChatItemService.selectUnreadCount(session.getId(),DATA_FROM_CUSTOMER));
|
||||||
@ -124,7 +124,7 @@ public class BusiChatMainServiceImpl extends ServiceImpl<BusiChatMainMapper,Busi
|
|||||||
@Override
|
@Override
|
||||||
public BusiChatMain selectActiveSession(String tenantId, String userIp, String deviceCode,String prodId) {
|
public BusiChatMain selectActiveSession(String tenantId, String userIp, String deviceCode,String prodId) {
|
||||||
// 先查缓存
|
// 先查缓存
|
||||||
String cacheKey = "im:active_session:" + tenantId + ":" + userIp + ":" + deviceCode;
|
String cacheKey = "im:active_session:" + tenantId + ":" + deviceCode;
|
||||||
if(null!=prodId){
|
if(null!=prodId){
|
||||||
cacheKey+=":"+prodId;
|
cacheKey+=":"+prodId;
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ public class BusiChatMainServiceImpl extends ServiceImpl<BusiChatMainMapper,Busi
|
|||||||
|
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
// 缓存未命中,查数据库
|
// 缓存未命中,查数据库
|
||||||
session = busiChatMainMapper.selectActiveSession(tenantId, userIp, deviceCode,prodId);
|
session = busiChatMainMapper.selectActiveSession(tenantId, deviceCode,prodId);
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
// 存入缓存
|
// 存入缓存
|
||||||
redisCache.setCacheObject(cacheKey, session, SESSION_CACHE_EXPIRE, TimeUnit.SECONDS);
|
redisCache.setCacheObject(cacheKey, session, SESSION_CACHE_EXPIRE, TimeUnit.SECONDS);
|
||||||
@ -161,7 +161,10 @@ public class BusiChatMainServiceImpl extends ServiceImpl<BusiChatMainMapper,Busi
|
|||||||
String serviceCacheKey = "im:service_sessions:" + session.getUserId();
|
String serviceCacheKey = "im:service_sessions:" + session.getUserId();
|
||||||
redisCache.deleteObject(serviceCacheKey);
|
redisCache.deleteObject(serviceCacheKey);
|
||||||
|
|
||||||
String activeCacheKey = "im:active_session:" + session.getTenantId() + ":" + session.getId() + ":" + session.getEquipment();
|
String activeCacheKey = "im:active_session:" + session.getTenantId() + ":" + session.getCusCode();
|
||||||
|
if(StringUtils.isNotEmpty(session.getProdId())){
|
||||||
|
activeCacheKey+=":"+session.getProdId();
|
||||||
|
}
|
||||||
redisCache.deleteObject(activeCacheKey);
|
redisCache.deleteObject(activeCacheKey);
|
||||||
}
|
}
|
||||||
return rows > 0;
|
return rows > 0;
|
||||||
|
@ -36,8 +36,4 @@ public class StrConstants {
|
|||||||
* 国家
|
* 国家
|
||||||
*/
|
*/
|
||||||
public static final String COUNTRY = "country";
|
public static final String COUNTRY = "country";
|
||||||
/**
|
|
||||||
* app下载目录
|
|
||||||
*/
|
|
||||||
public static final String UPLOAD_DIR = "/app/apk/truck.apk";
|
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,15 @@ spring:
|
|||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
druid:
|
druid:
|
||||||
# 主库数据源-点亮开发库
|
# 主库数据源-点亮开发库
|
||||||
master:
|
|
||||||
url: jdbc:mysql://82.156.161.160:3306/dl_site_system?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
|
||||||
username: site
|
|
||||||
password: 123456
|
|
||||||
#主库数据源-客户测试服务器
|
|
||||||
# master:
|
# master:
|
||||||
# url: jdbc:mysql://114.132.197.85:3306/dl_site_system?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
# url: jdbc:mysql://82.156.161.160:3306/dl_site_system?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
# username: site
|
# username: site
|
||||||
# password: 123456
|
# password: 123456
|
||||||
|
#主库数据源-客户测试服务器
|
||||||
|
master:
|
||||||
|
url: jdbc:mysql://127.0.0.1:3306/dl_site_system?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
|
username: site
|
||||||
|
password: 123456
|
||||||
# 从库数据源
|
# 从库数据源
|
||||||
slave:
|
slave:
|
||||||
# 从数据源开关/默认关闭
|
# 从数据源开关/默认关闭
|
||||||
|
@ -161,4 +161,6 @@ google:
|
|||||||
json-path: /www/wwwroot/nuxt/chengda.json
|
json-path: /www/wwwroot/nuxt/chengda.json
|
||||||
#月搜索量下限
|
#月搜索量下限
|
||||||
search-down: 500
|
search-down: 500
|
||||||
|
#App下载路径
|
||||||
|
app-download: /www/wwwroot/nuxt/truck.apk
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<sql id="selectBusiChatItemVo">
|
<sql id="selectBusiChatItemVo">
|
||||||
select id, main_id, data_from, sender_id,receiver_id,content,is_read, create_time from dl_busi_chat_item
|
select id, main_id, data_from, sender_id,receiver_id,content,is_read, create_time from dl_busi_chat_item
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="queryListPage" parameterType="BusiChatItem" resultMap="BusiChatItemResult">
|
<select id="queryListPage" parameterType="BusiChatItem" resultMap="BusiChatItemResult">
|
||||||
<include refid="selectBusiChatItemVo"/>
|
<include refid="selectBusiChatItemVo"/>
|
||||||
<where>
|
<where>
|
||||||
@ -55,4 +54,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
ORDER BY
|
ORDER BY
|
||||||
create_time
|
create_time
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<update id="updateReadStatus">
|
||||||
|
update dl_busi_chat_item
|
||||||
|
set is_read = 1
|
||||||
|
where main_id = #{sessionId}
|
||||||
|
and receiver_id = #{receiverId}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
@ -148,8 +148,7 @@
|
|||||||
FROM
|
FROM
|
||||||
dl_busi_chat_main
|
dl_busi_chat_main
|
||||||
WHERE
|
WHERE
|
||||||
ip = #{userIp}
|
cus_code = #{deviceCode}
|
||||||
AND cus_code = #{deviceCode}
|
|
||||||
AND `status` = 1
|
AND `status` = 1
|
||||||
AND del_flag = '0'
|
AND del_flag = '0'
|
||||||
AND tenant_id = #{tenantId}
|
AND tenant_id = #{tenantId}
|
||||||
|
@ -16,6 +16,8 @@ public class GoogleConfig {
|
|||||||
private String developerToken;
|
private String developerToken;
|
||||||
private String jsonPath;
|
private String jsonPath;
|
||||||
private Long searchDown;
|
private Long searchDown;
|
||||||
|
/** app下载路径 */
|
||||||
|
private String appDownload;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -74,3 +74,17 @@ export function sendMessage(data) {
|
|||||||
data: data
|
data: data
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function markAsRead(id, query) {
|
||||||
|
return request({
|
||||||
|
url: '/chat/read/'+id,
|
||||||
|
method: 'put',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
export function closeSession(id) {
|
||||||
|
return request({
|
||||||
|
url: '/chat/close/'+id,
|
||||||
|
method: 'put',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -33,9 +33,9 @@
|
|||||||
</span>
|
</span>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
<!--消息列表组件-->
|
<!--消息列表组件-->
|
||||||
<messageList ref="messageList" @switchSession="switchSession" @addNewMag="addNewMag"/>
|
<messageList ref="messageList" @switchSession="switchSession" @addNewMag="addNewMag" @closeForm="closeFormMes"/>
|
||||||
<!-- 聊天记录弹出框-->
|
<!-- 聊天记录弹出框-->
|
||||||
<chat-form ref="chatFrom"></chat-form>
|
<chat-form ref="chatFrom" @updateSessionRead="updateSessionRead" @closeForm="closeForm" @closeCurrentSession="closeCurrentSession"></chat-form>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -105,6 +105,22 @@ export default {
|
|||||||
this.getSiteList()
|
this.getSiteList()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
//结束当前会话
|
||||||
|
closeCurrentSession(){
|
||||||
|
this.$refs.messageList.closeCurrentSession()
|
||||||
|
},
|
||||||
|
//关闭聊天记录弹窗
|
||||||
|
closeForm(){
|
||||||
|
this.$refs.messageList.closeForm()
|
||||||
|
},
|
||||||
|
//关闭聊天记录弹窗
|
||||||
|
closeFormMes(){
|
||||||
|
this.$refs.chatFrom.open=false
|
||||||
|
},
|
||||||
|
//更新会话已读
|
||||||
|
updateSessionRead(sessionId){
|
||||||
|
this.$refs.messageList.updateSessionRead(sessionId)
|
||||||
|
},
|
||||||
//切换会话
|
//切换会话
|
||||||
switchSession(session){
|
switchSession(session){
|
||||||
this.$refs.chatFrom.show(session)
|
this.$refs.chatFrom.show(session)
|
||||||
|
@ -32,12 +32,13 @@
|
|||||||
@keyup.enter.native="sendToServer"
|
@keyup.enter.native="sendToServer"
|
||||||
></el-input>
|
></el-input>
|
||||||
<el-button type="primary" icon="el-icon-s-promotion" @click="sendToServer"></el-button>
|
<el-button type="primary" icon="el-icon-s-promotion" @click="sendToServer"></el-button>
|
||||||
|
<el-button type="warning" @click="closeCurrentSession">结束会话</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { getBySessionId ,sendMessage} from "@/api/busi/chatMain";
|
import { getBySessionId ,sendMessage,markAsRead} from "@/api/busi/chatMain";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
export default {
|
export default {
|
||||||
name: 'chatForm',
|
name: 'chatForm',
|
||||||
@ -52,8 +53,6 @@ export default {
|
|||||||
messages: [],
|
messages: [],
|
||||||
//发送的消息
|
//发送的消息
|
||||||
text:'',
|
text:'',
|
||||||
//消息id
|
|
||||||
chatId:'',
|
|
||||||
session: null,
|
session: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -66,13 +65,8 @@ export default {
|
|||||||
this.title = "来自"+session.oceania+"-"+session.national+"的客户"
|
this.title = "来自"+session.oceania+"-"+session.national+"的客户"
|
||||||
console.log(session)
|
console.log(session)
|
||||||
this.loadMessages(session.id)
|
this.loadMessages(session.id)
|
||||||
|
this.markAsRead(session.id)
|
||||||
this.open = true
|
this.open = true
|
||||||
// console.log(row)
|
|
||||||
// this.chatId = row.id
|
|
||||||
// if (row.itemJson!=null) {
|
|
||||||
// this.messages = JSON.parse(row.itemJson)
|
|
||||||
// this.$store.dispatch('set_message',this.messages);
|
|
||||||
// }
|
|
||||||
},
|
},
|
||||||
// 加载消息列表
|
// 加载消息列表
|
||||||
loadMessages(sessionId) {
|
loadMessages(sessionId) {
|
||||||
@ -82,6 +76,13 @@ export default {
|
|||||||
this.scrollBottom()
|
this.scrollBottom()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
// 标记消息为已读
|
||||||
|
markAsRead(sessionId) {
|
||||||
|
markAsRead(sessionId, {receiverId:this.session.userId}).then(() => {
|
||||||
|
// 更新会话未读状态,这里需要回调父组件方法
|
||||||
|
this.$emit("updateSessionRead",sessionId)
|
||||||
|
})
|
||||||
|
},
|
||||||
scrollBottom(){
|
scrollBottom(){
|
||||||
// 确保在对话框打开后滚动到底部
|
// 确保在对话框打开后滚动到底部
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
@ -91,13 +92,6 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// openForm(){
|
|
||||||
// if (!this.open) {
|
|
||||||
// this.open = true
|
|
||||||
// this.messages = this.$store._modules.root.state.websocket.message
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
|
|
||||||
/**发送消息*/
|
/**发送消息*/
|
||||||
sendToServer() {
|
sendToServer() {
|
||||||
// 构造消息对象
|
// 构造消息对象
|
||||||
@ -116,13 +110,25 @@ export default {
|
|||||||
type: 1,
|
type: 1,
|
||||||
toUserId: this.session.cusCode,
|
toUserId: this.session.cusCode,
|
||||||
content: this.text,
|
content: this.text,
|
||||||
sessionId: this.session.id
|
sessionId: this.session.id,
|
||||||
|
createTime:new Date()
|
||||||
}
|
}
|
||||||
this.$store.dispatch('websocket_send',JSON.stringify(wsMsg));
|
this.$store.dispatch('websocket_send',JSON.stringify(wsMsg));
|
||||||
this.text=''
|
this.text=''
|
||||||
this.scrollBottom()
|
this.scrollBottom()
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
//结束会话
|
||||||
|
closeCurrentSession(){
|
||||||
|
this.$confirm('确定要结束当前会话吗?', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '取消',
|
||||||
|
type: 'warning'
|
||||||
|
}).then(() => {
|
||||||
|
//回调父组件
|
||||||
|
this.$emit("closeCurrentSession")
|
||||||
|
})
|
||||||
|
},
|
||||||
//来新消息
|
//来新消息
|
||||||
addNewMsg(msg){
|
addNewMsg(msg){
|
||||||
this.messages.push(msg)
|
this.messages.push(msg)
|
||||||
@ -130,6 +136,8 @@ export default {
|
|||||||
},
|
},
|
||||||
close(){
|
close(){
|
||||||
this.open = false;
|
this.open = false;
|
||||||
|
//回调父组件方法
|
||||||
|
this.$emit("closeForm")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,15 +62,35 @@ export default {
|
|||||||
(session.lastMessage && session.lastMessage.includes(val))
|
(session.lastMessage && session.lastMessage.includes(val))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
currentSessionId(val) {
|
|
||||||
if (val) {
|
|
||||||
this.loadMessages(val)
|
|
||||||
// 标记为已读
|
|
||||||
this.markAsRead(val)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
//结束当前会话
|
||||||
|
closeCurrentSession(){
|
||||||
|
closeSession(this.currentSessionId).then(() => {
|
||||||
|
this.$message.success('会话已结束')
|
||||||
|
// 通知用户会话已结束
|
||||||
|
const wsMsg = {
|
||||||
|
type: 3,
|
||||||
|
toUserId: this.currentSession.cusCode,
|
||||||
|
content: '客服已结束会话',
|
||||||
|
sessionId: this.currentSessionId
|
||||||
|
}
|
||||||
|
this.$store.dispatch('websocket_send',JSON.stringify(wsMsg));
|
||||||
|
// 切换会话列表
|
||||||
|
this.currentSessionId = null
|
||||||
|
this.currentSession = {}
|
||||||
|
this.messages = []
|
||||||
|
// 重新加载会话列表
|
||||||
|
this.loadSessions()
|
||||||
|
// 关闭会话
|
||||||
|
this.$emit("closeForm")
|
||||||
|
})
|
||||||
|
},
|
||||||
|
//关闭聊天窗口了
|
||||||
|
closeForm(){
|
||||||
|
this.currentSessionId=null
|
||||||
|
this.currentSession= {}
|
||||||
|
},
|
||||||
// 加载会话列表
|
// 加载会话列表
|
||||||
loadSessions() {
|
loadSessions() {
|
||||||
getByServiceId(this.serviceId).then(response => {
|
getByServiceId(this.serviceId).then(response => {
|
||||||
@ -84,22 +104,12 @@ export default {
|
|||||||
this.currentSession = session
|
this.currentSession = session
|
||||||
this.$emit("switchSession",session)
|
this.$emit("switchSession",session)
|
||||||
},
|
},
|
||||||
// 加载消息列表
|
//更新会话未读状态
|
||||||
loadMessages(sessionId) {
|
updateSessionRead(sessionId){
|
||||||
// getBySessionId(sessionId).then(response => {
|
const session = this.sessions.find(s => s.id === sessionId)
|
||||||
// this.messages = response.data
|
if (session) {
|
||||||
// this.scrollToBottom()
|
session.unreadCount = 0
|
||||||
// })
|
}
|
||||||
},
|
|
||||||
// 标记消息为已读
|
|
||||||
markAsRead(sessionId) {
|
|
||||||
// markAsRead(sessionId, this.serviceId).then(() => {
|
|
||||||
// // 更新会话未读状态
|
|
||||||
// const session = this.sessions.find(s => s.id === sessionId)
|
|
||||||
// if (session) {
|
|
||||||
// session.unreadCount = 0
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
},
|
},
|
||||||
// 格式化时间
|
// 格式化时间
|
||||||
formatTime(time) {
|
formatTime(time) {
|
||||||
@ -134,7 +144,6 @@ export default {
|
|||||||
}
|
}
|
||||||
//调用父组件方法传递过去
|
//调用父组件方法传递过去
|
||||||
this.$emit("addNewMag",newMsg)
|
this.$emit("addNewMag",newMsg)
|
||||||
// this.scrollToBottom()
|
|
||||||
} else {
|
} else {
|
||||||
// 不是当前查看的会话,更新未读数量
|
// 不是当前查看的会话,更新未读数量
|
||||||
const session = this.sessions.find(s => s.id === message.sessionId)
|
const session = this.sessions.find(s => s.id === message.sessionId)
|
||||||
|
Loading…
Reference in New Issue
Block a user