标准版政企呼叫中心业务系统

seatMonitor.vue 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <!-- 代码已包含 CSS:使用 TailwindCSS , 安装 TailwindCSS 后方可看到布局样式效果 -->
  2. <template>
  3. <div class="app-container ">
  4. <div class="max-h-screen">
  5. <!-- 状态统计区域 -->
  6. <div class="">
  7. <div class="max-w-7xl mx-auto px-4">
  8. <div class="grid grid-cols-6 gap-4">
  9. <div v-for="(stat, index) in statistics" :key="index" class="p-4 rounded-lg" :class="stat.bgColor">
  10. <div class="text-lg font-medium mb-2">{{ stat.label }}</div>
  11. <div class="text-2xl font-semibold">{{ stat.count }}</div>
  12. </div>
  13. </div>
  14. </div>
  15. </div>
  16. <!-- 坐席列表 -->
  17. <div class="pb-8">
  18. <div class="bg-white rounded-lg shadow-sm p-6">
  19. <div class="mb-6 flex justify-between items-center">
  20. <h1 class="text-lg font-medium">坐席监控</h1>
  21. <div>
  22. <el-select v-model="statusFilter" placeholder="状态筛选" style="width: 100px;">
  23. <el-option v-for="item in statusOptions" :key="item.value" :label="item.label" :value="item.value" />
  24. </el-select>
  25. <el-button v-if="!isStartMonitor" class="mx-10" @click="startMonitor">开启监控</el-button>
  26. <el-button type="success" v-if="isStartMonitor" class="mx-10" @click="cancelMonitor">关闭监控</el-button>
  27. </div>
  28. </div>
  29. <!-- <div class="grid grid-cols-5 gap-2"> -->
  30. <transition-group class="grid grid-cols-5 gap-2" tag="div" name="fade">
  31. <div v-for="agent in filteredAgents" :key="agent.id"
  32. class="relative bg-white border rounded-lg p-4 hover:shadow-md transition-shadow" :class="{
  33. 'border-green-500': agent.status === 'online',
  34. 'border-red-500': agent.status === 'offline',
  35. 'border-blue-500': ['ringing', 'calling'].includes(agent.status),
  36. 'border-yellow-500': agent.status === 'idle',
  37. 'border-purple-500': agent.status === 'afterCall'
  38. }">
  39. <div class="flex items-start">
  40. <el-avatar :size="48" :src="agent.avatar" />
  41. <div class="ml-3 flex-1">
  42. <div class="font-medium">{{ agent.name }}</div>
  43. <div class="text-sm text-gray-500">工号: {{ agent.workId }}</div>
  44. <div class="text-sm text-gray-500">姓名: {{ agent.nickName }}</div>
  45. <div class="text-sm text-gray-500">分机: {{ agent.extension }}</div>
  46. </div>
  47. <div :class="`status-dot ${agent.status}`" />
  48. </div>
  49. <div class="mt-3">
  50. <div class="text-sm mb-2" :class="getStatusClass(agent.status)">
  51. {{ getStatusText(agent.status) }}
  52. <span v-if="agent.status === 'calling' || agent.status === 'afterCall'">
  53. {{ agent.duration }}
  54. </span>
  55. </div>
  56. <div class="flex justify-between" v-if="isStartMonitor">
  57. <el-button v-if="['idle', 'online'].includes(agent.status)" type="primary" :icon="agent.status === 'idle' ? 'Mute' : 'VideoPlay'" size="small"
  58. class="!rounded-button whitespace-nowrap" @click="toggleStatus(agent)">
  59. {{ agent.status === 'idle' ? '置闲' : '置忙' }}
  60. </el-button>
  61. <el-dropdown trigger="click" v-if="!['offline', 'unknown'].includes(agent.status) && ['空闲', '小休'].includes(scoketState)">
  62. <el-button type="info" size="small" class="!rounded-button whitespace-nowrap">
  63. 更多操作
  64. </el-button>
  65. <template #dropdown>
  66. <el-dropdown-menu>
  67. <el-dropdown-item v-if="['calling'].includes(agent.status)" @click="oparateSeats(agent,'Break')">强拆</el-dropdown-item>
  68. <el-dropdown-item v-if="['calling'].includes(agent.status)" @click="oparateSeats(agent,'Insert')">强插</el-dropdown-item>
  69. <el-dropdown-item v-if="['calling'].includes(agent.status)" @click="oparateSeats(agent,'Listen')">监听</el-dropdown-item>
  70. <el-dropdown-item v-if="['ringing'].includes(agent.status)" @click="oparateSeats(agent,'Instead')">代接</el-dropdown-item>
  71. <el-dropdown-item v-if="['calling'].includes(agent.status)" @click="oparateSeats(agent,'Intercept')">拦截</el-dropdown-item>
  72. </el-dropdown-menu>
  73. </template>
  74. </el-dropdown>
  75. </div>
  76. </div>
  77. </div>
  78. </transition-group>
  79. <!-- </div> -->
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </template>
  85. <script lang="ts" setup name="SeatMonitor">
  86. import { ref, computed, onMounted, watch, onBeforeUnmount } from 'vue';
  87. import { Monitor, Search, Mute, VideoPlay } from '@element-plus/icons-vue';
  88. import { getPageListData } from '@/api/main/system/system';
  89. import { Send, ws } from '@/utils/telWebsocket'
  90. import useSocketStore from '@/store/modules/socket'
  91. import { shuffle} from 'lodash'
  92. const { proxy } = getCurrentInstance();
  93. const searchQuery = ref('');
  94. const statusFilter = ref('');
  95. const scoketDatas = ref({})
  96. const scoketState = ref('签出')
  97. // 创建定时,没一秒监听一下坐席状态,并把通话中的坐席的通话时长更新
  98. const timer: any = ref(null)
  99. const lineState = computed(() => {
  100. return useSocketStore().lineState
  101. })
  102. watch(lineState, (newValue, oldValue) => {
  103. // console.log(newValue);
  104. scoketState.value = newValue
  105. })
  106. const statistics = ref([
  107. { key: 'online', label: '空闲', count: 0, bgColor: 'bg-green-50' },
  108. { key: 'idle', label: '小休', count: 0, bgColor: 'bg-yellow-50' },
  109. { key: 'ringing', label: '振铃', count: 0, bgColor: 'bg-blue-50' },
  110. { key: 'calling', label: '通话中', count: 0, bgColor: 'bg-blue-100' },
  111. { key: 'afterCall', label: '话后处理', count: 0, bgColor: 'bg-purple-50' },
  112. { key: 'offline', label: '离线', count: 0, bgColor: 'bg-red-50' },
  113. ]);
  114. const statusOptions = [
  115. { label: '全部', value: '' },
  116. { label: '空闲', value: 'online' },
  117. { label: '振铃', value: 'ringing' },
  118. { label: '通话中', value: 'calling' },
  119. { label: '小休', value: 'idle' },
  120. { label: '话后处理', value: 'afterCall' },
  121. { label: '离线', value: 'offline' },
  122. // { label: '未知', value: 'unknown' }
  123. ];
  124. const agents: any = ref([]);
  125. // 获取坐席列表
  126. const getAgents = () => {
  127. getPageListData('/UserExtension/userextension').then((res) => {
  128. if (res.data.length > 0) {
  129. const info = statistics.value.find((item) => item.key === 'offline');
  130. if (info) info.count = res.data.length;
  131. res.data.forEach((ele) => {
  132. agents.value.push({
  133. id: ele.id,
  134. name: ele.username,
  135. workId: ele.usercode,
  136. extension: ele.extension, // 分机号
  137. nickName:ele.nickName,
  138. status: 'unknown', // 线路状态
  139. duration: '',
  140. time: '',
  141. avatar: 'https://ai-public.mastergo.com/ai/img_res/ab51d696ad01cfa012b8a51117797b21.jpg'
  142. })
  143. })
  144. }
  145. })
  146. }
  147. let num = 100;
  148. // setInterval(() => {
  149. // agents.value.push({
  150. // id: num++,
  151. // name: '张三',
  152. // workId: '1001',
  153. // extension: '1001', // 分机号
  154. // status: 'online', // 线路状态
  155. // duration: '',
  156. // avatar: 'https://ai-public.mastergo.com/ai/img_res/ab51d696ad01cfa012b8a51117797b21.jpg',
  157. // time: '',
  158. // });
  159. // }, 5000)
  160. // setInterval(() => {
  161. // // 随机剔除一条数据
  162. // // const index = Math.floor(Math.random() * agents.value.length);
  163. // // agents.value.splice(index, 1);
  164. // agents.value = shuffle(agents.value)
  165. // }, 8000)
  166. // 发送操作指令
  167. const oparateSeats = (agent, operType) => {
  168. if (agent.extension == useSocketStore().extensionNumber) {
  169. proxy.$modal.msgError('不能对自己进行操作');
  170. return false
  171. }
  172. const socketObj = {
  173. AgentId: useSocketStore().accountNumber,
  174. AgentExten: useSocketStore().extensionNumber,
  175. TargetAgentID: agent.workId,
  176. Type: operType,
  177. }
  178. Send(socketObj)
  179. }
  180. // 通过状态过滤坐席
  181. const filteredAgents = computed(() => {
  182. return agents.value.filter(agent => {
  183. const matchStatus = !statusFilter.value || agent.status === statusFilter.value;
  184. const matchSearch = !searchQuery.value ||
  185. agent.name.toLowerCase().includes(searchQuery.value.toLowerCase()) ||
  186. agent.workId.toLowerCase().includes(searchQuery.value.toLowerCase());
  187. return matchStatus && matchSearch;
  188. });
  189. });
  190. const getStatusText = (status: string) => {
  191. const statusMap: Record<string, string> = {
  192. online: '空闲',
  193. idle: '小休',
  194. offline: '离线',
  195. calling: '通话中 ',
  196. afterCall: '话后处理 ',
  197. unknown: '未上线',
  198. ringing: '振铃',
  199. };
  200. return statusMap[status] || status;
  201. };
  202. const getStatusClass = (status: string) => {
  203. const statusMap: Record<string, string> = {
  204. online: 'text-green-600',
  205. offline: 'text-red-600',
  206. ringing: 'text-blue-500',
  207. calling: 'text-blue-600',
  208. idle: 'text-yellow-600',
  209. afterCall: 'text-purple-600',
  210. unknown: 'text-gray-600'
  211. };
  212. return statusMap[status] || '';
  213. };
  214. const toggleStatus = (agent: any) => {
  215. if (agent.extension == useSocketStore().extensionNumber) {
  216. proxy.$modal.msgError('不能对自己进行操作');
  217. return false
  218. }
  219. const oldStatus = agent.status;
  220. agent.status = agent.status === 'idle' ? 'online' : 'idle';
  221. calculatCount(oldStatus, agent.status);
  222. const operType = agent.status === 'idle' ? 'ForceWorkOff' : 'ForceWorkOn';
  223. oparateSeats(agent, operType);
  224. };
  225. // 0离线,1登录中,2空闲,3通话中,4话后处理中,5忙碌,6振铃,7注销
  226. const stateMap = {
  227. 0: 'offline',
  228. 1: 'offline',
  229. 2: 'online',
  230. 3: 'calling',
  231. 4: 'afterCall',
  232. 5: 'idle',
  233. 6: 'ringing',
  234. 7: 'offline',
  235. }
  236. const monitorBack = (data) => {
  237. // console.log(data, 'monitorBack')
  238. const status = stateMap[data.State]
  239. if (data.AgentId && status) {
  240. const info = agents.value.find(item => item.workId === data.AgentId);
  241. if (!info) return;
  242. if (status === 'calling') info.time = new Date().getTime()
  243. else if (info.time) info.time = ''
  244. const oldStatus = info.status
  245. // console.log(info.time, status, 'info.time')
  246. info.status = status
  247. calculatCount(oldStatus, status)
  248. // 如果离线把该坐席移到最后,如果是通话中,则把该坐席移到最前面
  249. if (status === 'offline') {
  250. agents.value = agents.value.filter(item => item.workId !== data.AgentId)
  251. agents.value.push(info)
  252. // const index = Math.floor(Math.random() * agents.value.length);
  253. // agents.value.splice(index, 1);
  254. // if (status === 'calling')
  255. } else {
  256. agents.value = agents.value.filter(item => item.workId !== data.AgentId)
  257. agents.value.unshift(info)
  258. }
  259. // agents.value = shuffle(agents.value)
  260. }
  261. }
  262. const isStartMonitor = ref(false) // 是否开始监控
  263. const startMonitor = () => {
  264. // console.log(scoketState.value, 'scoketState.value')
  265. if (scoketState.value !== '签出') {
  266. isStartMonitor.value = true
  267. if (!timer.value) {
  268. timer.value = setInterval(() => {
  269. agents.value.forEach((agent) => {
  270. if (agent.status === 'calling' && agent.time) {
  271. const currentTime = new Date().getTime();
  272. agent.duration = proxy.getTimeDifference(agent.time, currentTime)
  273. }
  274. });
  275. }, 1000);
  276. }
  277. // 所有坐席设置为离线状态
  278. agents.value.forEach(ele => {
  279. ele.status = 'offline'
  280. })
  281. scoketDatas.value = {
  282. AgentId: useSocketStore().accountNumber,
  283. AgentExten: useSocketStore().extensionNumber,
  284. Type: 'SubScribeOn',
  285. }
  286. Send(scoketDatas.value)
  287. } else {
  288. proxy.$modal.msgSuccess('当前状态不能监控');
  289. }
  290. }
  291. // 取消监控
  292. const cancelMonitor = () => {
  293. isStartMonitor.value = false // 是否开始监控
  294. clearInterval(timer.value)
  295. timer.value = null
  296. scoketDatas.value = {
  297. AgentId: useSocketStore().accountNumber,
  298. AgentExten: useSocketStore().extensionNumber,
  299. Type: 'SubScribeOff',
  300. }
  301. Send(scoketDatas.value)
  302. // 所有坐席设置为未知状态
  303. agents.value.forEach(ele => {
  304. ele.status = 'unknown'
  305. })
  306. statistics.value.forEach(ele => {
  307. calculatCount('', ele.key, true)
  308. })
  309. }
  310. const calculatCount = (oldStata, stateCode, isInit = false) => {
  311. // console.log(oldStata, stateCode, 'stateCode')
  312. if (oldStata === stateCode) return;
  313. const info = statistics.value.find(item => item.key === stateCode);
  314. if (!info) return;
  315. if (isInit) {
  316. if (stateCode !== 'offline') info.count = 0
  317. else info.count = agents.value.length
  318. return;
  319. }
  320. info.count++;
  321. const oldInfo = statistics.value.find(item => item.key === oldStata);
  322. if (oldInfo) oldInfo.count--;
  323. }
  324. // 页面退出或注销取消定时
  325. onBeforeUnmount(() => {
  326. if (timer.value) clearInterval(timer.value)
  327. timer.value = null
  328. })
  329. onMounted(() => {
  330. scoketState.value = useSocketStore().lineState
  331. ws.addEventListener('message', function (evt) {
  332. const telWSData = JSON.parse(evt.data)
  333. if (telWSData) {
  334. switch (telWSData.Type.toLowerCase()) {
  335. case 'agentstate': // 来电 Incoming
  336. monitorBack(telWSData)
  337. break
  338. }
  339. }
  340. })
  341. getAgents()
  342. })
  343. </script>
  344. <style scoped>
  345. /* 1. 声明过渡效果 */
  346. .fade-move,
  347. .fade-enter-active,
  348. .fade-leave-active {
  349. transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1);
  350. }
  351. /* 2. 声明进入和离开的状态 */
  352. .fade-enter-from,
  353. .fade-leave-to {
  354. opacity: 0;
  355. transform: scaleY(0.01) translate(30px, 0);
  356. }
  357. /* 3. 确保离开的项目被移除出了布局流
  358. 以便正确地计算移动时的动画效果。 */
  359. .fade-leave-active {
  360. position: absolute;
  361. }
  362. .status-dot {
  363. width: 10px;
  364. height: 10px;
  365. border-radius: 50%;
  366. margin-left: 8px;
  367. }
  368. .status-dot.online {
  369. background-color: #10B981;
  370. }
  371. .status-dot.offline {
  372. background-color: #EF4444;
  373. }
  374. .status-dot.calling {
  375. background-color: #3B82F6;
  376. }
  377. .status-dot.idle {
  378. background-color: #F59E0B;
  379. }
  380. .status-dot.afterCall {
  381. background-color: #8B5CF6;
  382. }
  383. :deep(.el-input__wrapper) {
  384. background-color: #f3f4f6;
  385. box-shadow: none !important;
  386. }
  387. :deep(.el-input__inner) {
  388. height: 40px;
  389. }
  390. :deep(.el-dropdown-menu__item) {
  391. padding: 8px 20px;
  392. }
  393. </style>