CustomerOnlineService.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <div class="autoBox box">
  3. <div class="service" style="display: inline-block;">
  4. <div class="service_title">
  5. 在线客服
  6. </div>
  7. <div style="width: 100%;">
  8. <div class="form-group" style="min-height: 600px;">
  9. <div class="chat-list form-control">
  10. <p :style="item.replyingPersonId==null?'float:left;':'float:right;'"
  11. v-for="item in list">
  12. <span v-if="item.replyingPersonId==null">{{item.questionerName}} :{{item.questionerContext}}</span></br>
  13. <span v-if="item.replyingPersonId!=null"> {{item.replyingPersonName}} : {{item.replyingContext}}</span></br>
  14. </p>
  15. </div>
  16. </div>
  17. <div class="down" style="width:100%;">
  18. <!-- <input type="text" ref="sendMsg" v-model="contentText" style="height: 130px;border: none;"/> -->
  19. <el-input
  20. type="textarea"
  21. placeholder="请输入内容"
  22. v-model="contentText"
  23. >
  24. </el-input>
  25. <button ref="btn" @click="sendText">发送</button>
  26. </div>
  27. </div>
  28. </div>
  29. <div style="display: inline-block;width: 300px;vertical-align: top;
  30. margin-left: 20px;border: 1px solid #ccc;height: 683px;">
  31. <div style="width: 100%;height: 30px;">
  32. <span class="problem">常见问题</span>
  33. <span class="ChangeTheBatch">换一批></span>
  34. </div>
  35. <div class="management">
  36. <div v-for="(i,j) in management" >{{i.menuName}}</div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import { getDicts } from "@/api/dict";
  43. import { getAllInformationByCustomer, getUmsUserOnlineServiceExchangeInformations } from "@/api/customer/umsUserOnlineServiceExchangeInformation";
  44. import Base from "@/views/base/Base";
  45. import { getToken, resetToken } from "@/utils/auth";
  46. export default {
  47. extends: Base,
  48. data () {
  49. return {
  50. event: {},
  51. ws: null,
  52. count: 0,
  53. userId: null,
  54. list: [],
  55. contentText: '',// input输入的值
  56. management:[],
  57. }
  58. },
  59. // created () {
  60. // this.getUserId()
  61. // },
  62. mounted () {
  63. this.initWebsocket()
  64. // this.$refs.sendMsg.focus()
  65. this.$nextTick(() => {
  66. setInterval(this.look, 30000);
  67. })
  68. },
  69. updated () {
  70. },
  71. methods: {
  72. look () {
  73. let user = window.localStorage.getItem("user");
  74. var users = JSON.parse(user);
  75. if (users == null) {
  76. alert("请先登录")
  77. return;
  78. }
  79. getAllInformationByCustomer(users.userId).then(result => {
  80. this.list = result.data.allInformationByCustomer;
  81. })
  82. },
  83. // 发送聊天消息
  84. sendText () {
  85. // Listen for messages
  86. debugger
  87. this.ws.addEventListener('message', function (event) {
  88. console.log('Message from server ', event.data);
  89. debugger
  90. });
  91. debugger
  92. let user = window.localStorage.getItem("user");
  93. var users = JSON.parse(user);
  94. if (users == null) {
  95. alert("请先登录")
  96. return;
  97. }
  98. let _this = this
  99. // _this.$refs.sendMsg.focus()
  100. if (!_this.contentText) {
  101. return false
  102. }
  103. let params = {
  104. userName: users.username,
  105. userId: users.userId,
  106. msg: _this.contentText,
  107. flag: "CustomerOnlineService",
  108. status: "离线"
  109. }
  110. _this.ws.send(JSON.stringify(params)) // 调用WebSocket send()发送信息的方法
  111. _this.contentText = ''
  112. getAllInformationByCustomer(users.userId).then(result => {
  113. this.list = result.data.allInformationByCustomer;
  114. })
  115. },
  116. initWebsocket () {
  117. let user = window.localStorage.getItem("user");
  118. var users = JSON.parse(user);
  119. var userId = users.userId;
  120. let _this = this
  121. // 判断页面有没有存在websocket连接
  122. if (window.WebSocket) {
  123. let ws = new WebSocket("ws://localhost:7028/robot/websocket/"+userId+",1")
  124. _this.ws = ws
  125. console.log(_this.ws+"_this.ws")
  126. ws.onopen = function (e) {
  127. console.log('服务器连接成功')
  128. }
  129. ws.onclose = function () {
  130. console.log('服务器连接关闭')
  131. }
  132. ws.onerror = function () {
  133. console.log('服务器连接出错')
  134. }
  135. ws.onmessage = function (e) {
  136. // 接收服务器返回的数据
  137. // console.log(e+"e")
  138. // let resData = JSON.parse(e.data)
  139. // console.log(resData+"resData")
  140. // console.log(e.text()+"e.text()")
  141. // if (resData.funName === 'userCount') {
  142. // _this.count = resData.users
  143. // _this.list = resData.chat
  144. // console.log(_this.list, '1234')
  145. // } else {
  146. // _this.list = [
  147. // ..._this.list,
  148. // { userId: resData.userId, content: resData.msg }
  149. // ]
  150. // }
  151. }
  152. ws.addEventListener('open', function (event) {
  153. });
  154. }
  155. getAllInformationByCustomer(userId).then(result => {
  156. this.list = result.data.allInformationByCustomer;
  157. })
  158. var infoParams = {
  159. pageNo: 0,
  160. pageSize: 10,
  161. language: this.$i18n.locale.toUpperCase(),
  162. reserveOne: "n",
  163. }
  164. getUmsUserOnlineServiceExchangeInformations(infoParams).then((result) => {
  165. this.management = result.data.umsUserOnlineServiceMenuInformations;
  166. })
  167. }
  168. },
  169. watch: {
  170. // list () {
  171. // this.$refs.scorll.refresh()
  172. // }
  173. }
  174. }
  175. </script>
  176. <style scoped>
  177. .message {
  178. padding-top: 60px;
  179. margin-bottom: 60px;
  180. height: 100%;
  181. overflow: hidden;
  182. }
  183. .box .service>>>.el-textarea__inner {
  184. min-height: 130px !important;
  185. max-height: 130px !important;
  186. }
  187. .problem{
  188. float: left;
  189. }
  190. .ChangeTheBatch{
  191. float: right;
  192. }
  193. .box {
  194. background: #fff;
  195. padding: 50px 0;
  196. }
  197. .service {
  198. width: 800px;
  199. margin-left: 50px;
  200. border: 1px solid #ccc;
  201. }
  202. .down {
  203. display: flex;
  204. align-items: center;
  205. }
  206. .service input {
  207. flex: 1;
  208. height: 40px;
  209. font-display: 18px;
  210. }
  211. .service button {
  212. border: none;
  213. width: 70px;
  214. height: 44px;
  215. background: blue;
  216. color: #fff;
  217. line-height: 40px;
  218. text-align: center;
  219. border-radius: 5px;
  220. margin-left: 10px;
  221. }
  222. .msg-box {
  223. display: flex;
  224. align-items: center;
  225. justify-content: flex-end;
  226. width: 100%;
  227. margin: 20px 10px 0px 0px;
  228. }
  229. .service_title {
  230. line-height: 60px;
  231. background:#f2f2f2;
  232. border: 1px solid rgba(228, 228, 228, 1);
  233. font-size: 26px;
  234. text-indent: 20px;
  235. color: #999;
  236. }
  237. .avtive {
  238. display: inline-block;
  239. background: blue;
  240. color: #fff;
  241. padding: 10px;
  242. font-size: 16px;
  243. border-radius: 6px;
  244. margin-right: 10px;
  245. flex-wrap: wrap;
  246. word-break: break-all;
  247. max-width: 220px;
  248. }
  249. .header-avtor {
  250. width: 40px !important;
  251. height: 40px;
  252. border-radius: 50%;
  253. background: #ccc;
  254. }
  255. .avtive-left {
  256. justify-content: flex-start;
  257. }
  258. .getClass1 {
  259. color:#0050d8
  260. }
  261. .getClass2 {
  262. color: #303133;
  263. }
  264. .management div{
  265. line-height: 50px;
  266. /* text-indent: 30px; */
  267. font-size: 14px;
  268. }
  269. .management div:hover {
  270. color: #ff0000;
  271. cursor: pointer;
  272. }
  273. </style>