app.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. import {
  2. callFunction,
  3. } from "../../utils/common.js";
  4. import permision from "@/js_sdk/wa-permission/permission.js";
  5. export default {
  6. namespaced: true,
  7. state: {
  8. dragOption: {
  9. x: uni.getSystemInfoSync().windowWidth,
  10. y: 200
  11. },
  12. currentVersion: "1.0.0",
  13. lastVersion: "1.0.0",
  14. callAccount: null,
  15. callSystem: null,
  16. currentPhone: "",
  17. recordId: undefined,
  18. signInState: false, // 是否签入成功
  19. redisStatus: false, // redis中的状态
  20. registerInfo: null, // 分机的注册信息
  21. dialing: false, // 拨号中
  22. incomingCallPhone: "",
  23. incomingCallId: null,
  24. lineList: [],
  25. phoneStatus : {
  26. isRing: false, // 外呼振铃
  27. isBusy: false, // 通话(来电外呼通用)
  28. isIncoming: false, // 来电振铃
  29. isEnd: false, // 挂断
  30. isLeisure: true // 空闲
  31. },
  32. isNotificationEnabled : false,
  33. isAlwaysAsk : false,
  34. },
  35. mutations: {
  36. SET_CALL_ACCOUNT(state, data) {
  37. state.callAccount = data;
  38. },
  39. SET_DRAGOPTION_Y(state, data) {
  40. state.dragOption.y = data;
  41. },
  42. SET_CURRENTVERSION(state, data) {
  43. state.currentVersion = data;
  44. },
  45. SET_LASTVERSION(state, data) {
  46. state.lastVersion = data;
  47. },
  48. SET_CALLSYSTEM(state, data) {
  49. state.callSystem = data;
  50. },
  51. SET_RECORDID(state, data) {
  52. state.recordId = data;
  53. },
  54. SET_CURRENTPHONE(state, data) {
  55. state.currentPhone = data;
  56. },
  57. SET_SIGNINSTATE(state, data) {
  58. state.signInState = data;
  59. },
  60. SET_DIALING(state, data) {
  61. state.phoneStatus = data;
  62. state.dialing = !data.isLeisure;
  63. },
  64. SET_INCOMINGCALLPHONE(state, data) {
  65. state.incomingCallPhone = data;
  66. },
  67. SET_INCOMINGCALLID(state, data) {
  68. state.incomingCallId = data;
  69. },
  70. SET_LINE_LIST(state, data) {
  71. state.lineList = data;
  72. },
  73. SET_REDIS_INFO(state, data) {
  74. state.redisStatus = data != null
  75. state.registerInfo = data;
  76. },
  77. },
  78. actions: {
  79. // 创建Wv的实例
  80. createWv({
  81. commit,
  82. state,
  83. rootState
  84. }) {
  85. if(state.callSystem != null){
  86. state.callSystem.close();
  87. }
  88. const wv = plus.webview.create("", "custom-webview", {
  89. 'uni-app': 'none'
  90. });
  91. const data = state.callAccount;
  92. const {
  93. ip,
  94. port,
  95. folder,
  96. webRtcIp,
  97. webRtcPort
  98. } = rootState.user.netConfig;
  99. const baseURL = ip + ":" + port + folder; /* 根域名 */
  100. wv.loadURL("/static/call/index.html?extension=" + data.extenNum + "&password=" + data.pwd +
  101. "&user_agent=app_" + data.userId + "&baseURL=" + baseURL + "&ip=" + webRtcIp + ":" + webRtcPort);
  102. // wv.loadURL("/static/call/index.html?extension=" + "yxx" + "&password=" + "1234" +
  103. // "&user_agent=app_" + data.userId + "&baseURL=" + baseURL + "&ip=" + webRtcIp + ":" + webRtcPort);
  104. // wv.loadURL("/static/call/index.html?extension=" + data.extenNum + "&password=" + data.pwd +
  105. // "&user_agent=app_" + data.userId + "&baseURL=" + "http://10.0.100.230:9500" + "&ip=" + "10.0.100.230" + ":9504");
  106. // wv.loadURL("/static/call/index.html?extension=" + data.extenNum + "&password=" + data.pwd +
  107. // "&user_agent=app_" + data.userId + "&baseURL=" + "http://59.42.9.166:9520/wfhl28gz_getwfxt0817" + "&ip=" + "59.42.9.166" + ":7564");
  108. // console.log("/static/call/index.html?extension=" + data.extenNum + "&password=" + data.pwd +
  109. // "&user_agent=app_" + data.userId + "&baseURL=" + baseURL + "&ip=" + ip.split("//")[1])
  110. // wv.loadURL("/static/call/index.html?extension=cyid1&password=1234&user_agent=app_1&baseURL=http://10.0.23.253:9500");
  111. // 设置线路
  112. wv.evalJS(`setLineList(${ JSON.stringify(state.lineList) })`);
  113. commit("SET_CALLSYSTEM", wv);
  114. },
  115. register({ state , dispatch , rootState}){
  116. if(rootState.user.userInfo.userId && rootState.user.netConfig.isCallOff === '1'){
  117. // 重新签出注册
  118. if(state.callSystem != null && state.phoneStatus.isLeisure){
  119. callFunction("unReg");
  120. }
  121. if(state.callSystem === null){
  122. dispatch("getExtensionByUserId", {
  123. userId: rootState.user.userInfo.userId
  124. }).then((res) => {
  125. Promise.all([permision.requestAndroidPermission("android.permission.RECORD_AUDIO"),permision.requestAndroidPermission('android.permission.MODIFY_AUDIO_SETTINGS')]).then(result=>{
  126. const flag = result.every(v=>v == 1);
  127. if(flag){
  128. dispatch("createWv");
  129. }
  130. })
  131. });
  132. }
  133. }
  134. },
  135. getExtensionByUserId({
  136. commit,
  137. dispatch
  138. }, params) {
  139. return new Promise((resolve, reject) => {
  140. uni.$u.api.getExtensionByUserId(params).then(({
  141. data
  142. }) => {
  143. if (data && data.length > 0) {
  144. commit("SET_CALL_ACCOUNT", data[0]);
  145. dispatch("getLineByIds", {
  146. extenId: data[0].id
  147. }).then(() => {
  148. resolve(data[0]);
  149. })
  150. } else {
  151. uni.$u.toast("检测到您未配置分机号");
  152. reject();
  153. }
  154. })
  155. })
  156. },
  157. getLineByIds({
  158. commit,
  159. state
  160. }, params) {
  161. return new Promise((resolve, reject) => {
  162. uni.$u.api.getLineByIds(params).then((lineRes) => {
  163. if (lineRes.data && lineRes.data.length === 0) {
  164. uni.$u.toast('检测到' + state.callAccount.extenNum + '没有配置线路');
  165. reject();
  166. } else {
  167. commit('SET_LINE_LIST', lineRes.data);
  168. resolve();
  169. }
  170. })
  171. })
  172. },
  173. call({ state, commit, rootState, dispatch }, { lineData, phoneId, caseId, caseDetail }){
  174. return new Promise(async (resolve,reject)=>{
  175. const { dialStr: dialer, phone: linePhone, type, callPhone } = lineData;
  176. if (!callPhone) {
  177. uni.$u.toast('没有外显号码,请前往呼叫中心补充')
  178. return
  179. }
  180. let flag = false
  181. if (type !== 'ip') {
  182. flag = true
  183. } else {
  184. const { code } = await uni.$u.api.setEffectiveCallerIdNumber({ extension: state.callAccount.extenNum, phone: linePhone });
  185. flag = code === 200
  186. }
  187. if (flag) {
  188. const { data } = await uni.$u.api.getJsSipExtra({ caller : linePhone, phoneId , callPhone , caseId , type : "2" });
  189. const { callee: x_callee, caller: x_caller, orgId, recordingId, base64P, callPhone: x_callPhone } = data;
  190. const afterPhone = new Buffer(base64P, 'base64').toString('utf8');
  191. const phone = afterPhone.replace('-', '').trim();
  192. const callParams = {
  193. replacedContact : dialer.replace('${destination_number}',phone),
  194. bankCode : caseDetail.bankCode ,
  195. bankBatchCode : caseDetail.bankBatchCode,
  196. userId : rootState.user.userInfo.userId,
  197. nickName : rootState.user.userInfo.nickName,
  198. deptId: rootState.user.userInfo.deptId,
  199. recordingId : recordingId,
  200. x_callee : x_callee,
  201. x_caller : x_caller,
  202. orgId : orgId,
  203. systemCode : rootState.user.system.value,
  204. extension : state.callAccount.extenNum,
  205. x_callPhone : x_callPhone,
  206. callPhone : callPhone,
  207. phone : phone,
  208. caseId : caseId
  209. }
  210. callFunction("handleCall",callParams);
  211. }
  212. })
  213. },
  214. saveUnionAppCall({
  215. commit
  216. }, params) {
  217. return new Promise((resolve, reject) => {
  218. uni.$u.api.saveUnionAppCall(params, {
  219. custom: {
  220. loading: false
  221. }
  222. }).then(({
  223. data
  224. }) => {
  225. if (params.action === "outbound") {
  226. commit("SET_RECORDID", data);
  227. commit("SET_CURRENTPHONE", params.phone);
  228. }else if (params.action === "incoming"){
  229. commit("SET_INCOMINGCALLPHONE",params.phone);
  230. commit("SET_INCOMINGCALLID",data)
  231. }
  232. resolve(data);
  233. }).catch(() => {
  234. reject();
  235. })
  236. })
  237. },
  238. logoutCloseData(store) {
  239. store.state.callAccount = null;
  240. store.commit("SET_CURRENTPHONE", "");
  241. store.commit("SET_RECORDID", undefined);
  242. store.state.dialing = false; // 拨号中
  243. store.state.incomingCallPhone = "";
  244. store.state.incomingCallId = null;
  245. store.rootState.user.userInfo = {};
  246. store.state.signInState = false;
  247. if(store.state.callSystem){
  248. store.state.callSystem.close();
  249. store.commit("SET_CALLSYSTEM", null);
  250. }
  251. },
  252. getIsUseCallSystem(store, action) {
  253. return new Promise((resolve, reject) => {
  254. const {
  255. signInState,
  256. callSystem,
  257. callAccount
  258. } = store.state;
  259. Promise.all([permision.requestAndroidPermission("android.permission.RECORD_AUDIO"), permision
  260. .requestAndroidPermission('android.permission.MODIFY_AUDIO_SETTINGS')
  261. ]).then(result => {
  262. const flag = result.every(v => v == 1);
  263. if (flag) {
  264. if (!callAccount) {
  265. uni.$u.toast("检测到您的账号未配置分机号");
  266. store.commit("SET_DIALING", false);
  267. reject()
  268. } else if (!callSystem) {
  269. uni.$u.toast("检测到呼叫系统被销毁,将为您重新创建,请稍等几秒后操作");
  270. store.dispatch("createWv");
  271. store.commit("SET_DIALING", false);
  272. reject();
  273. } else if (callSystem) {
  274. resolve();
  275. }
  276. } else {
  277. store.commit("SET_DIALING", false);
  278. uni.$u.toast("请提供录音权限");
  279. reject();
  280. }
  281. })
  282. })
  283. }
  284. },
  285. }