index.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098
  1. <template>
  2. <view class="content">
  3. <view class="bg"></view>
  4. <view class="cont-box">
  5. <!-- <view class="user-cont">
  6. <view class="user-box" v-if="user!=null" >
  7. <view class="left">
  8. <image :src="user.avatar"></image>
  9. <view class="user" >
  10. <view class="username">{{user.name}}</view>
  11. <view class="account" v-if="user.gender!=null" >{{user.gender==1?'男':'女'}}</view>
  12. </view>
  13. </view>
  14. <view class="right" >
  15. <image src="../../static/images/right_arrow.png"></image>
  16. </view>
  17. </view>
  18. <view class="company" v-if="user!=null">
  19. <image src="../../static/images/icon_comp.png"></image>
  20. <view class="name">{{user.companyName}}</view>
  21. </view>
  22. </view> -->
  23. <view class="menu-box">
  24. <view class="title-box">
  25. <image class="icon" src="../../static/images/office.png"></image>
  26. <view class="title">常用功能</view>
  27. </view>
  28. <view class="line"></view>
  29. <view class="menus">
  30. <view class="menu-item" @click="navTo('/pages/course/index?externalUserId='+externalUserId)">
  31. <image src="../../static/images/menu_info.png"></image>
  32. <view class="m-name">课程管理</view>
  33. </view>
  34. <view class="menu-item" @click="navTo('/pages/user/qwSop/sopLogsList?externalUserId='+externalUserId)">
  35. <image src="../../static/images/menu_info.png"></image>
  36. <view class="m-name">SOP记录</view>
  37. </view>
  38. <view class="menu-item" >
  39. <image src="../../static/images/menu_info.png"></image>
  40. <view class="m-name">催课管理</view>
  41. </view>
  42. <!-- <view class="menu-item" @click="clear()">
  43. <image src="../../static/images/menu_info.png"></image>
  44. <view class="m-name">清除缓存</view>
  45. </view> -->
  46. <view class="menu-item" @click="deleteQwSopLogsByJsApi()">
  47. <image src="../../static/images/menu_info.png"></image>
  48. <view class="m-name">拉黑</view>
  49. </view>
  50. <!-- <view class="menu-item" @click="refresh()">
  51. <image src="../../static/images/menu_info.png"></image>
  52. <view class="m-name">刷新</view>
  53. </view> -->
  54. </view>
  55. </view>
  56. <!-- <view class="text">code:{{code}}</view>
  57. <view class="text">allurl:{{allUrl}}</view>
  58. <view class="text">url:{{url}}</view> -->
  59. </view>
  60. <view class="text">CODE:{{code}}</view>
  61. <view class="text">外部联系人:{{externalUserId}}</view>
  62. <!-- <view class="text">消息:{{msg}}</view> -->
  63. </view>
  64. </template>
  65. <script>
  66. import { getConfigSignature,getQwExternalContactDetails } from '@/api/common.js'
  67. import { getQwSopLogsByJsApi,updateQwSopLogs,deleteQwSopLogsByJsApi} from '@/api/qwSop.js'
  68. export default {
  69. data() {
  70. return {
  71. isStop:false,
  72. msg:"",
  73. isConfig:false,
  74. logsInterval:null,
  75. initInterval:null,
  76. externalUserId:null,
  77. userId:null,
  78. wxSdk:null,
  79. corpId:"",
  80. code:"",
  81. url:"",
  82. show:false,
  83. sendFlag:false,
  84. // websocketFlag:false,
  85. isInit:false,//是否定位
  86. user:{
  87. gender:null,
  88. name:"",
  89. avatar:"",
  90. remarkMobiles:""
  91. },
  92. }
  93. },
  94. onLoad(options) {
  95. var that=this;
  96. this.url=window.location.href;
  97. console.log(this.url)
  98. this.code=options.code;
  99. this.corpId=options.corpId;
  100. uni.setStorageSync("corpId",this.corpId);
  101. // this.externalUserId=uni.getStorageSync("externalUserId");
  102. var userId=uni.getStorageSync("qwUserId");
  103. if(userId!=null&&userId!=undefined&&userId!=""){
  104. this.userId=userId;
  105. }
  106. // console.log(this.externalUserId)
  107. // console.log(this.userId)
  108. // var that=this;
  109. if(this.externalUserId!=null&&this.externalUserId!=undefined&&this.userId!=null&&this.userId!=undefined){
  110. console.log("获取外部联系人")
  111. this.getQwExternalContactDetails()
  112. that.initInterval=setInterval(function(){
  113. if(that.isInit){
  114. clearInterval(that.initInterval);
  115. that.getQwSopLogsByJsApi();
  116. setInterval(function(){
  117. that.getQwSopLogsByJsApi();
  118. },60000);
  119. }
  120. },200)
  121. }
  122. // else{
  123. // console.log("获取配置信息")
  124. // }
  125. this.wxSdk=uni.getStorageSync("wxSdk");
  126. var that=this;
  127. // uni.$on('deleteId', () => {
  128. // console.log("删除外部联系人");
  129. // that.deleteQwSopLogsByJsApi(that.nextExternalUserId)
  130. // })
  131. uni.$on('refresh', (data) => {
  132. //window.location.reload()
  133. })
  134. uni.$on('init', (data) => {
  135. that.isInit=data==1?true:false;
  136. })
  137. // var sendMsg=uni.getStorageSync("sendMsg");
  138. // if(sendMsg!=null&&sendMsg!=""){
  139. // //发送
  140. // //清除缓存
  141. // uni.setStorageSync("sendMsg",null);
  142. // }
  143. // uni.$on('sendMsg', (data) => {
  144. // //先把数据保存
  145. // //切换下一个外部联系人
  146. // var sendData=JSON.parse(data)
  147. // if(sendData.data.qwExtUserId!=null){
  148. // uni.setStorageSync("sendMsg",JSON.stringify(data));
  149. // that.openNextChat(sendData.data.qwExtUserId)
  150. // }
  151. // })
  152. uni.$on('reload', (data) => {
  153. //that.refresh();
  154. })
  155. uni.$on('sendStatus', (data) => {
  156. console.log("更新发送状态");
  157. that.sendFlag=false;
  158. })
  159. // uni.$on('getLogs', (data) => {
  160. // console.log("接口调用失败");
  161. // that.getQwSopLogsByJsApi()
  162. // })
  163. // uni.$on('websocket', (data) => {
  164. // console.log("插件状态"+data);
  165. // if(data==0){
  166. // that.websocketFlag=false;
  167. // uni.showToast({
  168. // title: "插件离线",
  169. // icon: 'none',
  170. // });
  171. // }
  172. // else if(data==1){
  173. // that.websocketFlag=true;
  174. // uni.showToast({
  175. // title: "插件在线",
  176. // icon: 'none',
  177. // });
  178. // }
  179. // })
  180. //如果接口请求异常,重试
  181. this.getConfigSignature()
  182. // setTimeout(function(){
  183. // if(!that.isConfig){
  184. // that.getConfigSignature()
  185. // }
  186. // },5000);
  187. this.logsInterval=setInterval(function(){
  188. if(that.isInit&&that.externalUserId!=null){
  189. that.getQwSopLogsByJsApi();
  190. }
  191. },60000);
  192. },
  193. onShow() {
  194. //https://blog.csdn.net/u013361179/article/details/132336082?spm=1001.2014.3001.5501
  195. //https://www.cnblogs.com/goloving/p/16742077.html
  196. },
  197. onUnload() {
  198. if(this.initInterval!=null){
  199. clearInterval(this.initInterval);
  200. }
  201. if(this.logsInterval!=null){
  202. clearInterval(this.logsInterval);
  203. }
  204. },
  205. methods: {
  206. refresh(){
  207. window.location.reload();
  208. },
  209. sendTest(){
  210. jWeixin.invoke('sendChatMessage', {
  211. msgtype:"miniprogram", //消息类型,必填
  212. enterChat: true,
  213. miniprogram:
  214. {
  215. appid: "wx73f85f8d62769119",
  216. title: "测试",
  217. imgUrl: "https://cos.his.cdwjyyh.com/fs/20250310/de1b349b4240433fba29cf6e79135e9e.png",
  218. page: "/pages/index/index.html?companuUserId=123"
  219. }
  220. }, function(res) {
  221. console.log("小程序发送")
  222. console.log(res)
  223. uni.showToast({
  224. title: res,
  225. });
  226. })
  227. },
  228. clear(){
  229. //uni.setStorageSync("externalUserId",null);
  230. uni.setStorageSync("qwUserId",null);
  231. },
  232. getQwSopLogsByJsApi(){
  233. // if(this.isStop){
  234. // console.log("插件未响应,已暂停")
  235. // return;
  236. // }
  237. // var obj={cmd:"log",data:"getQwSopLogsByJsApi开始"};
  238. // uni.$emit('sendMsg',obj);
  239. var data = {
  240. corpId:this.corpId,
  241. externalUserId:this.externalUserId,
  242. qwUserId:this.userId,
  243. };
  244. var that=this;
  245. try{
  246. getQwSopLogsByJsApi(data).then(
  247. res => {
  248. // var obj={cmd:"log",data:JSON.stringify(res)};
  249. // uni.$emit('sendMsg',obj);
  250. if(res.data.appKey!=null&&res.data.appKey!=""){
  251. uni.setStorageSync("key",res.data.appKey);
  252. }
  253. else{
  254. uni.setStorageSync("key","");
  255. }
  256. if(res.data.sendList!=null){
  257. this.msg="获取待发送记录"+res.data.sendList.length;
  258. uni.showToast({
  259. title: "获取待发送记录"+res.data.sendList.length,
  260. icon: 'none',
  261. });
  262. console.log("获取待发送记录"+res.data.sendList.length)
  263. }
  264. else{
  265. console.log("获取待发送记录null")
  266. }
  267. console.log(res)
  268. //判断插件是否INIT
  269. if(that.isInit){
  270. console.log("已初始化")
  271. that.nextExternalUserId=res.data.nextExternalUserId;
  272. this.msg="外部联系人:"+res.data.nextExternalUserId;
  273. if(res.data.sendList!=null&&res.data.sendList.length>0){
  274. console.log("开始发送")
  275. that.sendSop(res.data.sendList,res.data.nextExternalUserId);
  276. }
  277. else if(res.data.nextExternalUserId!=null){
  278. console.log("切换页面")
  279. that.openNextChat(res.data.nextExternalUserId);
  280. }
  281. else{
  282. this.msg="外部联系人:"+res.data.nextExternalUserId;
  283. }
  284. }
  285. else{
  286. this.msg="插件未INIT";
  287. }
  288. },
  289. rej => {
  290. // var obj={cmd:"log",data:"接口获取数据失败"+JSON.stringify(rej)};
  291. // uni.$emit('sendMsg',obj);
  292. console.log("接口获取数据失败")
  293. }
  294. );
  295. }
  296. catch(e){
  297. }
  298. },
  299. openNextChat(nextExternalUserId){
  300. // var that=this;
  301. // jWeixin.invoke('openUserProfile', {
  302. // "type": 2, //1表示该userid是企业成员,2表示该userid是外部联系人
  303. // "userid": nextExternalUserId //可以是企业成员,也可以是外部联系人
  304. // }, function(res) {
  305. // console.log(res)
  306. // if(res.err_msg == "openUserProfile:ok") {
  307. // }
  308. // else{
  309. // uni.showToast({
  310. // title: nextExternalUserId+"不属于本人",
  311. // icon: 'none',
  312. // });
  313. // that.deleteQwSopLogsByJsApi(nextExternalUserId);
  314. // }
  315. // });
  316. try{
  317. jWeixin.openEnterpriseChat({
  318. // 注意:userIds和externalUserIds至少选填一个。内部群最多2000人;外部群最多500人;如果有微信联系人,最多40人
  319. externalUserIds: nextExternalUserId, // 参与会话的外部联系人列表,格式为userId1;userId2;…,用分号隔开。
  320. groupName: '', // 会话名称。单聊时该参数传入空字符串""即可。
  321. chatId: "", // 若要打开已有会话,需指定此参数。如果是新建会话,chatId必须为空串
  322. success: function(res) {
  323. console.log(res);
  324. console.log("切换成功")
  325. uni.showToast({
  326. title: "切换成功",
  327. icon: 'none',
  328. });
  329. var data={cmd:"switchPage"};
  330. uni.$emit('sendMsg',data);
  331. },
  332. fail: function(res) {
  333. console.log(res);
  334. console.log("切换失败")
  335. uni.showToast({
  336. title: "切换失败",
  337. icon: 'none',
  338. });
  339. var data={cmd:"switchPage"};
  340. uni.$emit('sendMsg',data);
  341. }
  342. });
  343. }
  344. catch(e){
  345. console.log(e);
  346. console.log("切换成功")
  347. }
  348. },
  349. async sendMsg(msgItem){
  350. var that=this;
  351. that.sendFlag=true;
  352. uni.showToast({
  353. title: "发送中请勿操作",
  354. icon: 'none',
  355. });
  356. if(msgItem.contentType==1){
  357. //await that.sleep(500);
  358. jWeixin.invoke('sendChatMessage', {
  359. msgtype:"text", //消息类型,必填
  360. enterChat: true,
  361. text: {
  362. content:msgItem.value, //文本内容
  363. }
  364. }, function(res) {
  365. console.log("发送成功")
  366. console.log(res)
  367. var data={cmd:"enter"};
  368. uni.$emit('sendMsg',data);
  369. if (res.err_msg == 'sendChatMessage:ok') {
  370. }
  371. })
  372. }
  373. else if(msgItem.contentType==2){
  374. //图片
  375. //await that.sleep(2000);
  376. var data={cmd:"img",data:msgItem.imgUrl};
  377. uni.$emit('sendMsg',data);
  378. }
  379. else if(msgItem.contentType==5){
  380. //文件
  381. //await that.sleep(2000);
  382. var data={cmd:"file",data:msgItem.fileUrl};
  383. uni.$emit('sendMsg',data);
  384. }
  385. else if(msgItem.contentType==6){
  386. //视频
  387. //await that.sleep(2000);
  388. var data={cmd:"video",data:msgItem.videoUrl};
  389. uni.$emit('sendMsg',data);
  390. }
  391. else if(msgItem.contentType==7){
  392. //语音
  393. //await that.sleep(2000);
  394. // if(msgItem.voiceUrl!=null&&msgItem.voiceUrl!=undefined&&msgItem.voiceUrl!=""){
  395. // var data={cmd:"voice",data:msgItem.voiceUrl,time:msgItem.voiceDuration,openId:that.externalUserId};
  396. // uni.$emit('sendMsg',data);
  397. // }
  398. // else{
  399. // that.sendFlag=true;
  400. // return;
  401. // }
  402. that.sendFlag=true;
  403. return;
  404. // if(msgItem.voiceUrl!=null&&msgItem.voiceUrl!=undefined&&msgItem.voiceUrl!=""){
  405. // var data={cmd:"voice",data:msgItem.voiceUrl,time:msgItem.voiceDuration,openId:that.externalUserId};
  406. // uni.$emit('sendMsg',data);
  407. // }
  408. // else{
  409. // that.sendFlag=true;
  410. // return;
  411. // }
  412. // if(this.userId=="ZhangZhanYue"){
  413. // if(msgItem.voiceUrl!=null&&msgItem.voiceUrl!=undefined&&msgItem.voiceUrl!=""){
  414. // var data={cmd:"voice",data:msgItem.voiceUrl,time:msgItem.voiceDuration,openId:that.externalUserId};
  415. // uni.$emit('sendMsg',data);
  416. // }
  417. // else{
  418. // that.sendFlag=true;
  419. // return;
  420. // }
  421. // }
  422. // else{
  423. // that.sendFlag=true;
  424. // return;
  425. // }
  426. }
  427. else if(msgItem.contentType==8){
  428. //视频号
  429. //await that.sleep(2000);
  430. // var video={
  431. // nickname:msgItem.nickname,
  432. // avatar:msgItem.avatar,
  433. // coverUrl:msgItem.coverUrl,
  434. // thumbUrl:msgItem.thumbUrl,
  435. // desc:msgItem.desc,
  436. // url:msgItem.url,
  437. // extras:msgItem.extras,
  438. // }
  439. // var data={cmd:"videoNum",data:JSON.stringify(video),openId:that.externalUserId};
  440. // uni.$emit('sendMsg',data);
  441. that.sendFlag=true;
  442. return;
  443. }
  444. else if(msgItem.contentType==3){
  445. //await that.sleep(500);
  446. jWeixin.invoke('sendChatMessage', {
  447. msgtype:"news", //消息类型,必填
  448. enterChat: true,
  449. news:
  450. {
  451. link: msgItem.linkUrl, //H5消息页面url 必填
  452. title: msgItem.linkTitle, //H5消息标题
  453. desc: msgItem.linkDescribe, //H5消息摘要
  454. imgUrl: msgItem.linkImageUrl, //H5消息封面图片URL
  455. }
  456. }, function(res) {
  457. console.log("发送成功")
  458. console.log(res)
  459. var data={cmd:"enter"};
  460. uni.$emit('sendMsg',data);
  461. if (res.err_msg == 'sendChatMessage:ok') {
  462. }
  463. })
  464. }
  465. else if(msgItem.contentType==4){
  466. //await that.sleep(500);
  467. jWeixin.invoke('sendChatMessage', {
  468. msgtype:"miniprogram", //消息类型,必填
  469. enterChat: true,
  470. miniprogram:
  471. {
  472. appid: msgItem.miniprogramAppid,
  473. title: msgItem.miniprogramTitle,
  474. imgUrl: msgItem.miniprogramPicUrl,
  475. page: msgItem.miniprogramPage
  476. }
  477. }, function(res) {
  478. console.log("发送成功")
  479. console.log(res)
  480. var data={cmd:"enter"};
  481. uni.$emit('sendMsg',data);
  482. // if (res.err_msg == 'sendChatMessage:ok') {
  483. // }
  484. })
  485. }
  486. else if(msgItem.contentType==9){
  487. //await that.sleep(500);
  488. jWeixin.invoke('sendChatMessage', {
  489. msgtype:"news", //消息类型,必填
  490. enterChat: true,
  491. news:
  492. {
  493. link: msgItem.linkUrl, //H5消息页面url 必填
  494. title: msgItem.linkTitle, //H5消息标题
  495. desc: msgItem.linkDescribe, //H5消息摘要
  496. imgUrl: msgItem.linkImageUrl, //H5消息封面图片URL
  497. }
  498. }, function(res) {
  499. console.log("发送成功")
  500. console.log(res)
  501. var data={cmd:"enter"};
  502. uni.$emit('sendMsg',data);
  503. if (res.err_msg == 'sendChatMessage:ok') {
  504. }
  505. })
  506. }
  507. else if(msgItem.contentType==10){
  508. //清除草稿
  509. var data={cmd:"clear"};
  510. uni.$emit('sendMsg',data);
  511. }
  512. else if(msgItem.contentType==11){
  513. //await that.sleep(500);
  514. //清除草稿
  515. var data={cmd:"reSend"};
  516. uni.$emit('sendMsg',data);
  517. }
  518. else{
  519. return;
  520. }
  521. var time=150;
  522. while(time>0){
  523. console.log(time)
  524. if(!that.sendFlag){
  525. break;
  526. }
  527. else{
  528. time--;
  529. await this.sleep(200);
  530. }
  531. }
  532. //如果没有收到消息回复
  533. // that.isStop=true
  534. },
  535. sleep(ms) {
  536. return new Promise(resolve => setTimeout(resolve, ms));
  537. },
  538. async sendSop(sendList,nextExternalUserId){
  539. var that=this;
  540. console.log("开始发消息");
  541. for (const item of sendList) {
  542. console.log(item);
  543. var msgs=JSON.parse(item.contentJson);
  544. var that=this;
  545. if(msgs.setting.length>0){
  546. for(var i=0;i<msgs.setting.length;i++){
  547. var msgItem=msgs.setting[i]
  548. console.log("消息");
  549. console.log(msgItem);
  550. await that.sendMsg(msgItem)
  551. }
  552. }
  553. //更新消息
  554. that.updateQwSopLogs(item.id);
  555. }
  556. var data={cmd:"enterok"};
  557. uni.$emit('sendMsg',data);
  558. that.sendFlag=true;
  559. var time=50;
  560. while(time>0){
  561. console.log(time)
  562. if(!that.sendFlag){
  563. break;
  564. }
  565. else{
  566. time--;
  567. await this.sleep(200);
  568. }
  569. }
  570. uni.showToast({
  571. title: "回车发送",
  572. icon: 'none',
  573. });
  574. await that.sleep(500);
  575. if(nextExternalUserId!=null){
  576. that.openNextChat(nextExternalUserId)
  577. }
  578. else{
  579. // setTimeout(function(){
  580. // that.getQwSopLogsByJsApi()
  581. // },60000);
  582. }
  583. },
  584. updateQwSopLogs(id){
  585. console.log("更新发送状态")
  586. var data = {
  587. id:id,
  588. sendStatus:1,
  589. receivingStatus:1
  590. };
  591. var that=this;
  592. updateQwSopLogs(data).then(
  593. res => {
  594. },
  595. rej => {
  596. that.updateQwSopLogs2(data);
  597. }
  598. );
  599. },
  600. updateQwSopLogs2(data){
  601. var that=this;
  602. updateQwSopLogs(data).then(
  603. res => {
  604. },
  605. rej => {
  606. }
  607. );
  608. },
  609. deleteQwSopLogsByJsApi(){
  610. var that=this;
  611. uni.showModal({
  612. title:"提示",
  613. content:"确认拉黑吗?",
  614. showCancel:true,
  615. cancelText:'取消',
  616. confirmText:'确定',
  617. success:res=>{
  618. if(res.confirm){
  619. var data = {
  620. corpId:this.corpId,
  621. externalUserId:this.externalUserId,
  622. qwUserId:this.userId,
  623. };
  624. console.log(data)
  625. var that=this;
  626. deleteQwSopLogsByJsApi(data).then(
  627. res => {
  628. if(res.code==200){
  629. uni.showToast({
  630. title: "操作成功",
  631. icon: 'none',
  632. });
  633. }
  634. else{
  635. uni.showToast({
  636. title: res.msg,
  637. icon: 'none',
  638. });
  639. }
  640. },
  641. rej => {
  642. }
  643. );
  644. }else{
  645. // 否则点击了取消
  646. }
  647. }
  648. })
  649. },
  650. getConfigSignature(){
  651. var data = {
  652. corpId: this.corpId,
  653. url: this.url,
  654. code: this.code
  655. };
  656. if(this.userId!=null){
  657. data.isGetUserId=0;
  658. }
  659. else{
  660. data.isGetUserId=1;
  661. }
  662. var that=this;
  663. // var obj={cmd:"log",data:"getConfigSignature开始"};
  664. // uni.$emit('sendMsg',obj);
  665. getConfigSignature(data).then(
  666. res => {
  667. console.log(res)
  668. // var obj={cmd:"log",data:JSON.stringify(res)};
  669. // uni.$emit('sendMsg',obj);
  670. if(res.code==200){
  671. that.isConfig=true;
  672. const agentConfigSignature = res.config.agentConfigSignature;
  673. const configSignature = res.config.configSignature;
  674. const corpId = res.config.corpId;
  675. const nonceStr = res.config.nonceStr;
  676. const timestamp = res.config.timestamp;
  677. const agentId = res.config.agentId;
  678. if(res.config.userid!=null&&res.config.userid!=''){
  679. that.userId = res.config.userid;//当前员工ID
  680. uni.setStorageSync("qwUserId",that.userId);
  681. console.log("获取到USERID")
  682. }
  683. else{
  684. console.log("不需要获取USERID")
  685. }
  686. console.log(this.userId)
  687. jWeixin.config({
  688. beta: true,
  689. debug: false,
  690. appId: corpId,
  691. timestamp: timestamp,
  692. nonceStr: nonceStr,
  693. signature: configSignature,
  694. jsApiList: ['getCurExternalContact','sendChatMessage','openEnterpriseChat']
  695. });
  696. // const newSignature={
  697. // 'timestamp':timestamp,
  698. // 'nonceStr':nonceStr,
  699. // 'signature':configSignature,
  700. // }
  701. // ww.register({
  702. // corpId: corpId, // 必填,当前用户企业所属企业ID
  703. // jsApiList: ['openEnterpriseChat'], // 必填,需要使用的JSAPI列表
  704. // newSignature // 必填,根据url生成企业签名的回调函数
  705. // })
  706. jWeixin.ready(() => {
  707. jWeixin.agentConfig({
  708. corpid: corpId,
  709. agentid: agentId,
  710. timestamp: timestamp,
  711. nonceStr: nonceStr,
  712. signature: agentConfigSignature,
  713. jsApiList: ['getCurExternalContact','sendChatMessage','openEnterpriseChat'],
  714. success: (res) => {
  715. jWeixin.invoke('getCurExternalContact', {}, async (res) => {
  716. if (res.err_msg === "getCurExternalContact:ok") {
  717. that.externalUserId = res.userId;
  718. //that.getQwExternalContactDetails()
  719. that.initInterval=setInterval(function(){
  720. if(that.isInit){
  721. clearInterval(that.initInterval);
  722. that.getQwSopLogsByJsApi();
  723. }
  724. },200)
  725. } else {
  726. // 错误处理
  727. }
  728. });
  729. // jWeixin.openEnterpriseChat({
  730. // // 注意:userIds和externalUserIds至少选填一个。内部群最多2000人;外部群最多500人;如果有微信联系人,最多40人
  731. // externalUserIds: 'wmfFKfDQAAhvgwhJr9fqkRWjvN0CzFcA', // 参与会话的外部联系人列表,格式为userId1;userId2;…,用分号隔开。
  732. // groupName: '', // 会话名称。单聊时该参数传入空字符串""即可。
  733. // chatId: "", // 若要打开已有会话,需指定此参数。如果是新建会话,chatId必须为空串
  734. // success: function(res) {
  735. // var chatId = res.chatId; //返回当前群聊ID,仅当使用agentConfig注入该接口权限时才返回chatId
  736. // // 回调
  737. // that.externalUserId=res.chatId;
  738. // console.log(res)
  739. // setTimeout(function(){
  740. // jWeixin.invoke('sendChatMessage', {
  741. // msgtype:"news", //消息类型,必填
  742. // enterChat: true,
  743. // text: {
  744. // content:"你好11111111111111111", //文本内容
  745. // },
  746. // news:
  747. // {
  748. // link: "https://www.baidu.com/", //H5消息页面url 必填
  749. // title: "百度一下", //H5消息标题
  750. // desc: "百度一下你就知道", //H5消息摘要
  751. // imgUrl: "https://cos.his.cdwjyyh.com/fs/20240914/efc6995ee755489b8a3e0c8413846a4e.jpg", //H5消息封面图片URL
  752. // },
  753. // }, function(res) {
  754. // if (res.err_msg == 'sendChatMessage:ok') {
  755. // //发送成功
  756. // uni.showToast({
  757. // title: "回车发送",
  758. // icon: 'none',
  759. // });
  760. // }
  761. // })
  762. // },500);
  763. // },
  764. // fail: function(res) {
  765. // if(res.errMsg.indexOf('function not exist') > -1){
  766. // alert('版本过低请升级')
  767. // }
  768. // }
  769. // });
  770. },
  771. fail: (res) => {
  772. console.error('agentConfig fail:', res);
  773. },
  774. });
  775. });
  776. jWeixin.error((res) => {
  777. console.error('wx.error:', res);
  778. });
  779. }
  780. else{
  781. // uni.setStorageSync("qwUserId",null);
  782. console.log("获取USERID失败")
  783. // setTimeout(function(){
  784. // window.location.reload();
  785. // },5000);
  786. }
  787. },
  788. rej => {
  789. setTimeout(function(){
  790. window.location.reload();
  791. },5000);
  792. }
  793. );
  794. },
  795. navTo(url){
  796. console.log(url)
  797. uni.navigateTo({
  798. url
  799. })
  800. },
  801. getQwExternalContactDetails(){
  802. var that=this
  803. var data = {
  804. corpId: this.corpId,
  805. userId:this.userId,
  806. externalUserId:this.externalUserId,
  807. };
  808. getQwExternalContactDetails(data).then(res => {
  809. if(res.code==200){
  810. this.user=res.data;
  811. }else{
  812. }
  813. });
  814. },
  815. }
  816. }
  817. </script>
  818. <style lang="scss">
  819. page{
  820. height: 100%;
  821. background: #f6f6f6;
  822. }
  823. </style>
  824. <style scoped lang="scss">
  825. .content{
  826. position: relative;
  827. height: 100%;
  828. width: 100%;
  829. .bg{
  830. width: 100%;
  831. height: 400upx;
  832. position: absolute;
  833. top: 0;
  834. left: 0;
  835. z-index: 1;
  836. background: linear-gradient(to bottom,#82aeff, #82aeff);
  837. // border-radius: 0rpx 0rpx 60rpx 60rpx;
  838. }
  839. .cont-box{
  840. position: relative;
  841. z-index: 2;
  842. padding: 30rpx 30rpx 200rpx;
  843. .user-cont{
  844. box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
  845. padding: 30rpx;
  846. background-color: #fff;
  847. border-radius: 15rpx;
  848. .user-box{
  849. width: 100%;
  850. display: flex;
  851. align-items: center;
  852. justify-content: flex-start;
  853. .left{
  854. flex:1;
  855. display: flex;
  856. align-items: center;
  857. justify-content: flex-start;
  858. image{
  859. border-radius: 50%;
  860. width:120rpx;
  861. height:120rpx;
  862. }
  863. .user{
  864. margin-left: 20rpx;
  865. width: calc(100% - 140rpx);
  866. display: flex;
  867. flex-direction: column;
  868. align-items: flex-start;
  869. justify-content: flex-start;
  870. .username{
  871. font-size: 38rpx;
  872. font-family: PingFang SC;
  873. color: #111;
  874. font-weight: bold;
  875. }
  876. .account{
  877. padding: 5rpx 20rpx;
  878. border-radius: 30rpx;
  879. background-color: #115296;
  880. margin-top: 20rpx;
  881. font-size: 24rpx;
  882. font-family: PingFang SC;
  883. color: #fff;
  884. }
  885. }
  886. }
  887. .right{
  888. image{
  889. width: 15rpx;
  890. height:30rpx;
  891. }
  892. }
  893. }
  894. .company{
  895. margin-top: 30rpx;
  896. display: flex;
  897. align-items: center;
  898. justify-content: flex-start;
  899. image{
  900. width:40rpx;
  901. height:40rpx;
  902. }
  903. .name{
  904. margin-left: 15rpx;
  905. font-size: 28rpx;
  906. color: #111;
  907. }
  908. }
  909. }
  910. .menu-box{
  911. box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
  912. width: 100%;
  913. margin-top: 30rpx;
  914. padding: 30rpx;
  915. background-color: #fff;
  916. border-radius: 15rpx;
  917. .title-box{
  918. display: flex;
  919. align-items: center;
  920. justify-content: flex-start;
  921. .icon{
  922. width: 30rpx;
  923. height:30rpx;
  924. }
  925. .title{
  926. margin-left: 10rpx;
  927. font-size: 28rpx;
  928. font-family: PingFang SC;
  929. color: #111;
  930. }
  931. }
  932. .line{
  933. margin-top: 15rpx;
  934. height: 0.5rpx;
  935. width: 100%;
  936. background-color: #efefef;
  937. }
  938. .menus{
  939. margin-top: 30rpx;
  940. display: flex;
  941. align-items: center;
  942. justify-content: flex-start;
  943. flex-wrap: wrap;
  944. }
  945. .menu-item{
  946. display: flex;
  947. flex-direction: column;
  948. align-items: center;
  949. justify-content: center;
  950. width: 25%;
  951. margin-bottom: 20rpx;
  952. image{
  953. width:60rpx;
  954. height:60rpx;
  955. }
  956. .m-name{
  957. margin-top: 10rpx;
  958. font-size: 24rpx;
  959. font-family: PingFang SC;
  960. color: #111;
  961. }
  962. }
  963. }
  964. .menu-box1{
  965. width: 100%;
  966. margin-top: 30rpx;
  967. padding: 0rpx 30rpx;
  968. background-color: #fff;
  969. border-radius: 15rpx;
  970. .menu-item{
  971. width: 100%;
  972. display: flex;
  973. align-items: center;
  974. justify-content: flex-start;
  975. line-height: 100rpx;
  976. .left{
  977. flex:1;
  978. display: flex;
  979. align-items: center;
  980. justify-content: flex-start;
  981. image{
  982. width: 30rpx;
  983. height:30rpx;
  984. }
  985. .label{
  986. margin-left: 10rpx;
  987. }
  988. }
  989. .right{
  990. image{
  991. width: 10rpx;
  992. height:15rpx;
  993. }
  994. }
  995. }
  996. }
  997. }
  998. }
  999. .btn-box{
  1000. margin: 60rpx 0rpx 30rpx;
  1001. display: flex;
  1002. align-items: center;
  1003. justify-content: center;
  1004. .sub-btn{
  1005. // box-shadow: 0px 0px 5px 2px rgba(0,0,0,0.05);
  1006. border: 1rpx solid #f8f8f8;
  1007. background: #FFFFFF;
  1008. width: 100%;
  1009. height: 88upx;
  1010. line-height: 88upx;
  1011. text-align: center;
  1012. font-size: 30upx;
  1013. font-family: PingFang SC;
  1014. color: #111;
  1015. }
  1016. }
  1017. .text{
  1018. width: 100%;
  1019. font-size: 24rpx;
  1020. }
  1021. </style>