header.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div class="title_wrap">
  3. <!-- <el-button
  4. round
  5. class="title_wrap_btn"
  6. @click="signIn"
  7. v-if="!globalState.callCenterIsSignIn"
  8. :icon="Phone"
  9. >签入
  10. </el-button>
  11. <el-button
  12. round
  13. class="title_wrap_btn"
  14. @click="signOut"
  15. v-else
  16. :icon="PhoneFilled"
  17. >签出</el-button
  18. >-->
  19. <div class="title">
  20. <span class="title-text">{{ title }}</span>
  21. </div>
  22. <div class="timers">
  23. <span class="timers-text">
  24. {{ formatDate(now, "YYYY年mm月dd日 HH:MM:SS WWW") }}</span
  25. >
  26. </div>
  27. <div class="guang"></div>
  28. <div class="left_icons">
  29. <el-badge :value="readyCount" :max="99" class="left_icons_item">
  30. <img src="@/assets/img/seats/ready.png" alt="" />空闲
  31. </el-badge>
  32. <el-badge :value="restCount" :max="99" class="left_icons_item">
  33. <img src="@/assets/img/seats/unready.png" alt="" />小休
  34. </el-badge>
  35. <el-badge :value="meetingCount" :max="99" class="left_icons_item">
  36. <img src="@/assets/img/seats/threeWay.png" alt="" />三方会议
  37. </el-badge>
  38. <el-badge :value="logoutCount" :max="99" class="left_icons_item">
  39. <img src="@/assets/img/seats/logout.png" alt="" />签出
  40. </el-badge>
  41. <el-badge :value="callInCount" :max="99" class="left_icons_item">
  42. <img src="@/assets/img/seats/callIn.png" alt="" />呼入
  43. </el-badge>
  44. </div>
  45. <div class="right_icons">
  46. <el-badge :value="callOutCount" :max="99" class="right_icons_item">
  47. <img src="@/assets/img/seats/callOut.png" alt="" />呼出
  48. </el-badge>
  49. <el-badge :value="consultCount" :max="99" class="right_icons_item">
  50. <img src="@/assets/img/seats/ring.png" alt="" />咨询
  51. </el-badge>
  52. <el-badge :value="otherCount" :max="99" class="right_icons_item">
  53. <img src="@/assets/img/seats/other.png" alt="" />其他
  54. </el-badge>
  55. <el-badge :value="callCount" :max="99" class="right_icons_item">
  56. <img src="@/assets/img/seats/busy.png" alt="" />通话
  57. </el-badge>
  58. <el-badge :value="cawCount" :max="99" class="right_icons_item">
  59. <img src="@/assets/img/seats/acw.png" alt="" />整理
  60. </el-badge>
  61. <el-badge :value="logoffCount" :max="99" class="right_icons_item">
  62. <img src="@/assets/img/seats/logoff.png" alt="" />注销
  63. </el-badge>
  64. </div>
  65. <!-- 签入弹窗 -->
  66. <el-dialog
  67. v-model="state.dutyDialogVisible"
  68. draggable
  69. title="签入"
  70. width="500px"
  71. :show-close="false"
  72. append-to-body
  73. >
  74. <el-form :model="state.dutyForm" label-width="80px" ref="dutyFormRef">
  75. <el-form-item
  76. label="分机"
  77. prop="currentTel"
  78. :rules="[
  79. {
  80. required: true,
  81. message: '请选择需要签入的分机',
  82. trigger: 'change',
  83. },
  84. ]"
  85. >
  86. <el-select-v2
  87. v-model="state.dutyForm.currentTel"
  88. :options="state.telsList"
  89. placeholder="选择要签入的分机"
  90. filterable
  91. class="w-full"
  92. :height="500"
  93. :props="{
  94. label: 'telNo',
  95. value: 'telNo',
  96. }"
  97. />
  98. </el-form-item>
  99. </el-form>
  100. <template #footer>
  101. <span class="dialog-footer">
  102. <el-button
  103. @click="state.dutyDialogVisible = false"
  104. :loading="state.loading"
  105. >取 消</el-button
  106. >
  107. <el-button @click="clickOnDuty(dutyFormRef)" :loading="state.loading"
  108. >确 定</el-button
  109. >
  110. </span>
  111. </template>
  112. </el-dialog>
  113. </div>
  114. </template>
  115. <script setup lang="ts">
  116. import { computed, onMounted, onUnmounted, reactive, ref, watch } from "vue";
  117. import signalR from "@/utils/signalR";
  118. import { useNow, useTitle } from "@vueuse/core";
  119. import { formatDate } from "@/utils/formatTime";
  120. import { olaFn } from "@/utils/olaFn";
  121. import { getNowDateTime } from "@/utils/constants";
  122. import { callCenterLogout, useGlobalState } from "@/utils/callCenter";
  123. import { ElMessageBox, FormInstance } from "element-plus";
  124. import { Phone, PhoneFilled } from "@element-plus/icons-vue";
  125. import { useThemeConfig } from "@/stores/themeConfig";
  126. import { storeToRefs } from "pinia";
  127. import { getListenExtension } from "api/seats";
  128. import mittBus from "@/utils/mitt";
  129. const storesThemeConfig = useThemeConfig();
  130. const { themeConfig } = storeToRefs(storesThemeConfig);
  131. const props = defineProps({
  132. data: {
  133. type: Array,
  134. default: () => [],
  135. },
  136. });
  137. const now = useNow(); // 获取当前时间
  138. const state = reactive({
  139. dutyDialogVisible: false,
  140. dutyForm: {
  141. currentTel: null,
  142. },
  143. loading: false,
  144. telsList: [],
  145. });
  146. // 签入
  147. const signIn = () => {
  148. if (!globalState.callCenterIsSignIn) {
  149. state.dutyDialogVisible = true;
  150. } else {
  151. globalState.callCenterIsSignIn = false;
  152. }
  153. };
  154. const dutyFormRef = ref();
  155. // 确认签入
  156. const clickOnDuty = (formEl: FormInstance | undefined) => {
  157. if (!formEl) return;
  158. formEl.validate((valid: boolean) => {
  159. if (!valid) return;
  160. const currentPhone: any = state.telsList.find(
  161. (item: any) => item.telNo === state.dutyForm.currentTel
  162. );
  163. globalState.currentTel = {
  164. telNo: currentPhone.telNo,
  165. telGroup: currentPhone.queue,
  166. jobNum: currentPhone.TelNo,
  167. };
  168. websocket_connect(currentPhone.telNo, currentPhone.telPwd);
  169. state.dutyDialogVisible = false;
  170. });
  171. };
  172. // 签出
  173. const signOut = () => {
  174. ElMessageBox.confirm(`签出后无法监听和插话,确定签出?`, "提示", {
  175. confirmButtonText: "确认",
  176. cancelButtonText: "取消",
  177. type: "warning",
  178. draggable: true,
  179. cancelButtonClass: "default-button",
  180. autofocus: false,
  181. })
  182. .then(async () => {
  183. callCenterLogout();
  184. })
  185. .catch(() => {});
  186. };
  187. const globalState = useGlobalState();
  188. const olaRef = ref();
  189. const websocket_connect = (telNo: string, telPwd: string) => {
  190. olaRef.value = olaFn(themeConfig.value.callCenterSocketUrl, {
  191. username: telNo,
  192. password: telPwd,
  193. onConnected: onConnected, // 连接成功
  194. onDisconnected: onDisconnected, // 断开链接
  195. onMessage: onMessage, // 接收消息
  196. onError: onError, // 错误
  197. autoReconnect: {
  198. delay: 2000,
  199. // retries: 10,
  200. }, // 自动重连
  201. heartbeat: {
  202. message: JSON.stringify({ cmd: "ping" }),
  203. interval: 5000,
  204. // pongTimeout: 1000,
  205. },
  206. });
  207. console.log(`${getNowDateTime()}:开始链接呼叫中心`);
  208. };
  209. // 呼叫中心链接成功
  210. const onConnected = () => {
  211. olaRef.value.logout(globalState.currentTel.telNo); //连接之后,先登出一次,防止其他地方已经登陆
  212. let array_ola_queue = []; // 队列
  213. // 普通模式
  214. let array = globalState.currentTel.telGroup.split(",");
  215. for (let i = 0; i < array.length; i++) {
  216. array_ola_queue[i] = array[i];
  217. }
  218. olaRef.value.login(array_ola_queue, globalState.currentTel.telNo, {
  219. type: "onhook",
  220. });
  221. globalState.callCenterWs = olaRef.value;
  222. console.log(`${getNowDateTime()}:呼叫中心链接成功`);
  223. };
  224. // 呼叫中心链接关闭
  225. const onDisconnected = (event: any) => {
  226. globalState.callCenterWs = null;
  227. console.log(`${getNowDateTime()}:呼叫中心断开链接`, event);
  228. };
  229. // 呼叫中心链接错误
  230. const onError = (ws: any, e: any) => {
  231. globalState.callCenterIsSignIn = false; // 签出状态
  232. console.log(`${getNowDateTime()}:呼叫中心链接错误`, e);
  233. };
  234. // 呼叫中心消息
  235. const onMessage = async (event: any) => {
  236. const data = JSON.parse(event);
  237. // console.log(`${getNowDateTime()}:接收呼叫中心消息`, event);
  238. if (data.event_type == "agent_state") {
  239. switch (data.state) {
  240. case "login": // 签入消息回调
  241. globalState.callCenterIsSignIn = true; // 签入状态
  242. setTimeout(() => {
  243. // 设置示闲状态
  244. olaRef.value.go_ready();
  245. }, 300);
  246. console.log(
  247. `${getNowDateTime()}:接收消息:呼叫中心:已签入,当前分机:${
  248. globalState.currentTel.telNo
  249. }`
  250. );
  251. break;
  252. case "logout": // 签出消息回调
  253. globalState.callCenterIsSignIn = false; // 签出状态
  254. console.log(`${getNowDateTime()}:接收消息:呼叫中心:已签出`);
  255. break;
  256. case "acw": // 话后整理回到
  257. // 调用示闲
  258. olaRef.value.go_ready(); // 示闲
  259. console.log(`${getNowDateTime()}:接收消息:呼叫中心:已示闲`);
  260. break;
  261. case "unready": // 示忙消息回调
  262. // 调用示闲
  263. olaRef.value.go_ready(); // 示闲
  264. console.log(`${getNowDateTime()}:接收消息:呼叫中心:已示闲`);
  265. break;
  266. }
  267. }
  268. };
  269. // 空闲数量
  270. const readyCount = computed(() => {
  271. return seatsList.value.filter((item: any) => item.State === "0").length;
  272. });
  273. // 小休数量、
  274. const restCount = computed(() => {
  275. return seatsList.value.filter((item: any) => item.State === "1").length;
  276. });
  277. // 三方会议数量
  278. const meetingCount = computed(() => {
  279. return seatsList.value.filter((item: any) => item.State === "2").length;
  280. });
  281. // 签出数量
  282. const logoutCount = computed(() => {
  283. return seatsList.value.filter((item: any) => item.State === "3").length;
  284. });
  285. // 呼入数量
  286. const callInCount = computed(() => {
  287. return seatsList.value.filter((item: any) => item.State === "4").length;
  288. });
  289. // 呼出数量
  290. const callOutCount = computed(() => {
  291. return seatsList.value.filter((item: any) => item.State === "5").length;
  292. });
  293. // 咨询数量
  294. const consultCount = computed(() => {
  295. return seatsList.value.filter((item: any) => item.State === "6").length;
  296. });
  297. // 其他数量
  298. const otherCount = computed(() => {
  299. return seatsList.value.filter((item: any) => item.State === "7").length;
  300. });
  301. // 通话数量
  302. const callCount = computed(() => {
  303. return seatsList.value.filter((item: any) => item.State === "8").length;
  304. });
  305. // 通话数量
  306. const cawCount = computed(() => {
  307. return seatsList.value.filter((item: any) => item.State === "9").length;
  308. });
  309. // 注销数量
  310. const logoffCount = computed(() => {
  311. return seatsList.value.filter((item: any) => item.State === "10").length;
  312. });
  313. const seatsList = ref<any>([]);
  314. watch(
  315. () => props.data,
  316. (newData: any) => {
  317. seatsList.value = newData;
  318. },
  319. { immediate: true }
  320. );
  321. // 获取可以监听的分机列表
  322. const getSeatsList = async () => {
  323. try {
  324. const { result } = await getListenExtension();
  325. state.telsList = result;
  326. } catch (e) {
  327. console.log(e);
  328. }
  329. };
  330. const title = ref("12345坐席监控中心");
  331. onMounted(() => {
  332. getSeatsList();
  333. // 接收消息
  334. mittBus.on("monitorInfoTel", (data: any) => {
  335. const item = seatsList.value.find(
  336. (item: any) => item.Extension === data.Extension
  337. );
  338. item.loading = true;
  339. if (item) {
  340. setTimeout(() => {
  341. item.State = data.State;
  342. item.loading = false;
  343. }, 500);
  344. }
  345. });
  346. title.value = `${themeConfig.value.cityName}12345坐席监控中心`;
  347. useTitle(title.value);
  348. });
  349. onUnmounted(() => {
  350. signalR.SR.off("SeatState");
  351. });
  352. </script>
  353. <style scoped lang="scss">
  354. :deep(.el-badge__content) {
  355. border: none;
  356. top: -3px;
  357. right: calc(-3px + var(--el-badge-size) / 2);
  358. }
  359. .title_wrap {
  360. height: 140px;
  361. position: relative;
  362. &_btn {
  363. position: absolute;
  364. left: 40px;
  365. top: 12px;
  366. z-index: 2;
  367. border-color: var(--el-color-white);
  368. }
  369. &::after {
  370. content: "";
  371. position: absolute;
  372. bottom: 13px;
  373. background-image: radial-gradient(circle, #1b86d1 50%, #176bb5 50%);
  374. width: 100%;
  375. height: 2px;
  376. }
  377. .guang {
  378. position: absolute;
  379. bottom: -13px;
  380. background-image: url("../../assets/img/seats/guang.png");
  381. background-position: 80px center;
  382. width: 100%;
  383. height: 56px;
  384. }
  385. .timers {
  386. position: absolute;
  387. right: 16px;
  388. top: 20px;
  389. display: flex;
  390. align-items: center;
  391. color: var(--el-color-white);
  392. font-size: var(--el-font-size-extra-large);
  393. }
  394. }
  395. .title {
  396. position: relative;
  397. text-align: center;
  398. background-size: cover;
  399. color: transparent;
  400. height: 140px;
  401. line-height: 90px;
  402. &-text {
  403. font-size: 38px;
  404. font-weight: 900;
  405. letter-spacing: 6px;
  406. background: linear-gradient(
  407. 92deg,
  408. #0072ff 0%,
  409. #00eaff 48.8525390625%,
  410. #01aaff 100%
  411. );
  412. -webkit-background-clip: text;
  413. -webkit-text-fill-color: transparent;
  414. }
  415. }
  416. .left_icons {
  417. position: absolute;
  418. left: 40px;
  419. bottom: 25px;
  420. display: flex;
  421. align-items: center;
  422. .left_icons_item {
  423. display: flex;
  424. align-items: center;
  425. margin-right: 35px;
  426. &:last-child {
  427. margin-right: 10px;
  428. }
  429. img {
  430. margin-right: 5px;
  431. }
  432. }
  433. }
  434. .right_icons {
  435. position: absolute;
  436. right: 16px;
  437. bottom: 25px;
  438. display: flex;
  439. align-items: center;
  440. .right_icons_item {
  441. display: flex;
  442. align-items: center;
  443. margin-right: 35px;
  444. &:last-child {
  445. margin-right: 10px;
  446. }
  447. img {
  448. margin-right: 5px;
  449. }
  450. }
  451. }
  452. </style>