App.vue 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279
  1. <script>
  2. import { getDictByKey, getAppVersion, getRealLinkDomainName,getAppPageConfig } from '@/api/common.js';
  3. //参考文档 插件市场 https://ext.dcloud.net.cn/plugin?id=741
  4. import { appCheckUdate, openDownload } from '@/utils/APPUpdate.js';
  5. import { getUserInfo, getPushLogRead } from '@/api/user';
  6. import { getUserLiveInfo } from '@/api/living.js'
  7. import { healthButlerPop } from '@/utils/healthButlerPop.js';
  8. import { mapGetters, mapActions } from 'vuex';
  9. import IMSDK, { IMMethods, MessageReceiveOptType, MessageType, SessionType } from 'openim-uniapp-polyfill';
  10. import { config } from '@/pages_im/common/config';
  11. import { getDbDir, Igexin, toastWithCallback } from '@/pages_im/util/common.js';
  12. import { conversationSort, secFormat, callingModule, meetingModule, parseMessageByType, prepareConversationState } from '@/pages_im/util/imCommon';
  13. import { PageEvents, UpdateMessageTypes, CustomType, ContactChooseTypes } from '@/pages_im/constant';
  14. import { openImLoginApi,testImLoginApi } from '@/pages_im/api/imBll';
  15. import NotificationUtil from '@/pages_im/util/notification';
  16. import newMessage from '@/pages_im/static/audio/newMessage.wav';
  17. import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update'
  18. let cacheConversationList = [];
  19. let updateDownloadTask = null;
  20. let notificationIntance = null;
  21. let pausing = false;
  22. let innerAudioContext;
  23. let notification;
  24. let uPushPlugin;
  25. let connectStart=0;
  26. // #ifdef APP-PLUS
  27. import permision1 from '@/utils/permission.js';
  28. // notification = uni.requireNativePlugin('Tuoyun-OpenIMSDK-Notification');
  29. // #endif
  30. import { getTlsSig } from '@/api/common.js';
  31. import { qconfig } from './utils/config';
  32. import { premissionCheck } from '@/js_sdk/wa-permission/permission.js';
  33. import { updateMsgDot } from '@/utils/common.js';
  34. import { getImAdminToken } from '@/pages_im/api/imApi';
  35. import { ar } from 'date-fns/locale';
  36. let healthTimer = null;
  37. let tSeconds = 0;
  38. const healthSeconds = 180;
  39. let offlineMsg=null;
  40. let offlineHandleNewMsg=null;
  41. let failImConnTime=0;
  42. // #ifdef APP-PLUS
  43. let complaintView = null; // 悬浮窗视图(主图标)
  44. let complaintCloseView = null; // 关闭按钮视图
  45. let viewLeft = 0;
  46. let viewTop = 0;
  47. let complaintPositionTimer = null; // 位置检查定时器
  48. let lastRoute = ''; // 上次的路由
  49. // #endif
  50. export default {
  51. globalData: {
  52. wsUrl: 'ws://doctor.ai.cdwjyyh.com',
  53. danmuWSUrl:'wss://websocket.cdwjyyh.com',
  54. aiWSUrl:'ws://doctor.ai.cdwjyyh.com',
  55. kfurl: 'https://work.weixin.qq.com/kfid/kfc3731c5008ebd8906', //企业微信客服链接
  56. corpId: 'ww70ac72e824957fc9', //客服企业id
  57. miniprogamId:"gh_feb7753a310b", //gh_7a6a32e5ef61 御君方互医
  58. shareCorpId: '', // 分享企业id
  59. shareSchema:"", // 应用跳转标识,显示在具体应用下的 Schema字段
  60. shareAgentid:"", // 企业微信管理后台 应用唯一标识。显示在具体应用下的 AgentId字段
  61. shareAppid_gh:"", // 必须是应用关联的小程序,注意要有@app后缀
  62. },
  63. onLaunch: function (options) {
  64. let fontsize = uni.getStorageSync('fontSize');
  65. if (fontsize) {
  66. uni.setStorageSync('fontSize', fontsize);
  67. }
  68. else {
  69. let scale = this.getSystemFontScale();
  70. let oriFontSize = 18;
  71. fontsize = oriFontSize * scale;
  72. if (fontsize < oriFontSize) {
  73. fontsize = oriFontSize;
  74. }
  75. if (fontsize < 16) {
  76. fontsize = 16;
  77. }
  78. if (fontsize >= 21) {
  79. fontsize = 21;
  80. }
  81. uni.setStorageSync('fontSize', fontsize);
  82. }
  83. // //设置im字体
  84. let RootFontSize= uni.getStorageSync('RootFontSize');
  85. if(!RootFontSize){
  86. uni.setStorageSync('RootFontSize', "24px");
  87. this.$store.commit('user/SET_ROOT_FONT_SIZE', "24px");
  88. }
  89. uni.removeStorageSync('openUrl');
  90. this.initOpenIm();
  91. if (this.$isLogin()) {
  92. uni.setStorageSync("onLaunch",1);
  93. }
  94. let that = this;
  95. uni.$on('refreshIM', () => {
  96. if (that.$isLogin()) {
  97. that.openImLogin();
  98. }
  99. });
  100. // 监听隐藏/显示投诉悬浮按钮事件
  101. uni.$on('hideComplaintButton', () => {
  102. // #ifdef APP-PLUS
  103. if (complaintView) complaintView.hide();
  104. if (complaintCloseView) complaintCloseView.hide();
  105. // #endif
  106. });
  107. uni.$on('showComplaintButton', () => {
  108. // #ifdef APP-PLUS
  109. if (complaintView) complaintView.show();
  110. if (complaintCloseView) complaintCloseView.show();
  111. // #endif
  112. });
  113. // #ifdef APP-PLUS
  114. uni.$on('showHealthButler', () => {
  115. if (plus.runtime.channel == 'baidu' || plus.runtime.channel == 'yybadv' || plus.runtime.channel == 'yybadv1') {
  116. that.runTimer();
  117. }
  118. });
  119. //离线推送
  120. this.handlerLaunchMsg();
  121. uni.onPushMessage((res) => { //unipush2.0 应用处于激活 监听消息推送
  122. //console.log("qxj onPushMessage",res);
  123. this.handlePushMessage(res);
  124. this.$updateMsgDot();
  125. });
  126. //#endif
  127. //this.getAppPageConfig();
  128. },
  129. onLoad() {
  130. },
  131. onShow() {
  132. // #ifdef APP-PLUS
  133. this.getDictByKeyFun()
  134. // 如果浮标未创建,尝试创建(可能启动页在其他地方关闭)
  135. setTimeout(()=>{
  136. if (!complaintView) {
  137. this.createComplaintFloatAfterSplash();
  138. } else {
  139. // 启动位置检查定时器
  140. this.startComplaintPositionCheck();
  141. }
  142. },3000);
  143. // #endif
  144. this.geth5Path();
  145. var that = this;
  146. // #ifdef APP-PLUS
  147. plus.navigator.closeSplashscreen();
  148. if (this.$isAgreePrivacy()) {
  149. if (this.$isLogin()) {
  150. this.getUserInfo(); //检测jpushId是否被清空,若为空就重新绑定
  151. }
  152. this.$getRegistrationID('update');
  153. if (plus.runtime.channel == 'baidu' || plus.runtime.channel == 'yybadv' || plus.runtime.channel == 'yybadv1') {
  154. this.runTimer();
  155. }
  156. }
  157. if(uni.$u.os() === 'android'){
  158. this.checkUpdateApp();
  159. IMSDK.asyncApi(IMSDK.IMMethods.SetAppBackgroundStatus, IMSDK.uuid(), false);
  160. meetingModule?.onListenerAppBackground(false);
  161. }
  162. var args= plus.runtime.arguments;
  163. uni.setStorageSync("appIsOnShow",1);
  164. if(args){
  165. // 处理args参数,如直达到某新页面等
  166. if(args=="rtlive://course"){
  167. uni.switchTab({url: '/pages/course/index'});
  168. }
  169. else if(args=="rtlive://livingApp"){
  170. uni.switchTab({url: '/pages/course/video/living-app'});
  171. }
  172. else {
  173. let url = ''
  174. if(args.indexOf("rtlive://pagesApp") != -1) { // 打开对应pages
  175. console.log("11111");
  176. url=args.replace("rtlive://pagesApp?pagesUrl=","");
  177. url=decodeURIComponent(url);
  178. }
  179. else if (args.indexOf("rtlive://courseAnswer") != -1) { // 看课
  180. console.log("22222");
  181. url=args.replace("rtlive://courseAnswer","");
  182. url="/pages/courseAnswer/index"+url;
  183. }
  184. else if(args.indexOf("rtlive://") != -1&&url) {
  185. uni.setStorageSync("openUrl",url)
  186. if(this.$isLogin()){
  187. uni.navigateTo({
  188. url: url,
  189. success: function(res) {
  190. uni.removeStorageSync("openUrl")
  191. plus.runtime.arguments = ''
  192. }
  193. })
  194. }
  195. }
  196. else if(args.indexOf("contentType")!=-1){ //unipush2.0 App打开状态点击通知
  197. let newServerMsg=JSON.parse(args);
  198. let serverMsgID=uni.getStorageSync('serverMsgID');
  199. // console.log("44444 newServerMsg",newServerMsg);
  200. let newServerMsgData=JSON.parse(newServerMsg.data);
  201. if(serverMsgID!=newServerMsgData.serverMsgID){
  202. uni.$u.throttle(() => that.notifyGoToChat(newServerMsgData), 2000);
  203. uni.setStorageSync('serverMsgID', newServerMsgData.serverMsgID);
  204. }
  205. }
  206. else if(args.indexOf("messageId")!=-1){ //oppo离线推送
  207. console.log("55555");
  208. offlineMsg=args;
  209. }
  210. else if(args.indexOf("rtlive://course")!=-1){
  211. console.log("66666");
  212. url=args.replace("rtlive://course","");
  213. url="/pages/course/info"+url;
  214. }
  215. }
  216. }
  217. // #endif
  218. },
  219. onHide() {
  220. // #ifdef APP-PLUS
  221. // 应用进入后台时停止位置检查
  222. this.stopComplaintPositionCheck();
  223. // #endif
  224. uni.removeStorageSync('onLaunch');
  225. uni.setStorageSync("appIsOnShow",0);
  226. if(uni.$u.os() === 'android'){
  227. IMSDK.asyncApi(IMSDK.IMMethods.SetAppBackgroundStatus, IMSDK.uuid(), true);
  228. meetingModule?.onListenerAppBackground(true);
  229. }
  230. },
  231. computed: {
  232. ...mapGetters([
  233. 'storeConversationList',
  234. 'storeCurrentConversation',
  235. 'storeCurrentUserID',
  236. 'storeSelfInfo',
  237. 'storeRecvFriendApplications',
  238. 'storeRecvGroupApplications',
  239. 'storeHistoryMessageList',
  240. 'storeIsSyncing',
  241. 'storeGroupList'
  242. ]),
  243. contactBadgeRely() {
  244. return {
  245. recvFriendApplications: this.storeRecvFriendApplications,
  246. recvGroupApplications: this.storeRecvGroupApplications,
  247. userKey: this.storeCurrentUserID
  248. };
  249. }
  250. },
  251. methods: {
  252. ...mapActions('message', ['pushNewMessage', 'updateOneMessage', 'updateQuoteMessageRevoke', 'updateMessageNicknameAndFaceUrl']),
  253. ...mapActions('conversation', ['updateCurrentMemberInGroup']),
  254. ...mapActions('contact', [
  255. 'updateFriendInfo',
  256. 'pushNewFriend',
  257. 'updateBlackInfo',
  258. 'pushNewBlack',
  259. 'pushNewGroup',
  260. 'updateGroupInfo',
  261. 'pushNewRecvFriendApplition',
  262. 'updateRecvFriendApplition',
  263. 'pushNewSentFriendApplition',
  264. 'updateSentFriendApplition',
  265. 'pushNewRecvGroupApplition',
  266. 'updateRecvGroupApplition',
  267. 'pushNewSentGroupApplition',
  268. 'updateSentGroupApplition'
  269. ]),
  270. async getDictByKeyFun() {
  271. let data = {
  272. key: 'app_pay_config'
  273. }
  274. const res = await getDictByKey(data)
  275. if (res.code == 200 && res.data && res.data.length > 0 && res.data[0].dictValue) {
  276. getApp().globalData.miniprogamId = res.data[0].dictValue
  277. }
  278. },
  279. getAppPageConfig() {
  280. getAppPageConfig().then(res=>{
  281. if(res.code == 200) {
  282. uni.setStorageSync('appPageConfig',JSON.stringify(res.appPageConfig))
  283. }
  284. })
  285. },
  286. //投诉建议
  287. // 根据当前页面路径获取 marginBottom 值
  288. getComplaintMarginBottom() {
  289. let marginBottom = 100; // 默认距底部
  290. try {
  291. const pages = getCurrentPages();
  292. if (pages && pages.length > 0) {
  293. const curPage = pages[pages.length - 1];
  294. const route = curPage.route || '';
  295. //console.log('当前路由:', route, 'marginBottom:', marginBottom);
  296. if (route === 'pages/course/video/living-app') {
  297. marginBottom = 40;
  298. } else if (route === 'pages/user/integral/integralGoodsDetails') {
  299. marginBottom = 150;
  300. } else {
  301. // 其他页面使用默认值 100
  302. marginBottom = 100;
  303. }
  304. //console.log('最终 marginBottom:', marginBottom);
  305. }
  306. } catch (err) {
  307. //console.error('获取路由失败:', err);
  308. }
  309. return marginBottom;
  310. },
  311. // 计算浮标位置
  312. getComplaintPosition() {
  313. const ww = plus.screen.resolutionWidth;
  314. const wh = plus.screen.resolutionHeight;
  315. const width = 48;
  316. const height = 70;
  317. const marginRight = 10;
  318. let marginBottom = this.getComplaintMarginBottom();
  319. const closeSize = 16;
  320. let left = ww - width - marginRight;
  321. let top = wh - height - marginBottom;
  322. if(this.$isIos()){
  323. top-=20;
  324. }
  325. let hidden = false;
  326. try {
  327. const pages = getCurrentPages();
  328. if (pages && pages.length > 0) {
  329. const curPage = pages[pages.length - 1];
  330. const route = curPage.route || '';
  331. if (route === 'pages/auth/login' || route === 'pages/auth/loginIndex' || route === 'pages/user/feedback'||route === 'pages_live/index'
  332. //|| route === 'pages_im/pages/conversation/conversationList/index' || route === 'pages_im/pages/conversation/chating/index'
  333. || ((route === 'pages_im/pages/conversation/chating/index' || route ==='pages_im1/pages/conversation/chating1/index') && this.$companyUserIsLogin())) {
  334. hidden = true;
  335. }
  336. // if (route === 'pages_im/pages/conversation/chating/index' || route === 'pages_im/pages/conversation/chating1/index') {
  337. // top = top-uni.upx2px(300);
  338. // }
  339. if (route === 'pages/pointsMall/points') {
  340. top=top-uni.upx2px(90);
  341. if(this.$isIos()){
  342. top-=30;
  343. }
  344. }
  345. if (route === 'pages/pointsMall/points') {
  346. top=top-uni.upx2px(90);
  347. if(this.$isIos()){
  348. top-=30;
  349. }
  350. }
  351. if (route === 'pages/course/video/living-app') {
  352. top = uni.upx2px(300);
  353. hidden = false;
  354. }
  355. if (route === 'pages/courseAnswer/index') {
  356. top=top-uni.upx2px(200);
  357. hidden = false;
  358. }
  359. }
  360. } catch (err) {
  361. console.error('getComplaintPosition error:', err);
  362. }
  363. const closeLeft = left + (width - closeSize) / 2;
  364. const closeTop = top + height - closeSize;
  365. return { left, top, closeLeft, closeTop, width, height, closeSize, marginBottom, hidden };
  366. },
  367. // 绑定主图标点击事件
  368. bindComplaintViewClick() {
  369. complaintView.addEventListener('click', (e) => {
  370. let target = '/pages/user/feedback';
  371. try {
  372. const pages = getCurrentPages();
  373. if (pages && pages.length > 0) {
  374. const curPage = pages[pages.length - 1];
  375. const pageParams = curPage.options;
  376. const route = curPage.route || '';
  377. if (route === 'pages/course/info') {
  378. target = '/pages/user/courseFeedback?courseId='+pageParams.courseId;
  379. }
  380. }
  381. } catch (err) {
  382. console.error('获取路由失败:', err);
  383. }
  384. uni.navigateTo({
  385. url: target,
  386. fail: (err) => {
  387. console.error('跳转失败:', err);
  388. }
  389. });
  390. });
  391. },
  392. // 绑定关闭按钮点击事件
  393. bindComplaintCloseViewClick() {
  394. complaintCloseView.addEventListener('click', (e) => {
  395. complaintView.hide();
  396. complaintCloseView.hide();
  397. });
  398. },
  399. // 创建主图标视图
  400. createComplaintMainView(pos) {
  401. complaintView = new plus.nativeObj.View('complaint-float', {
  402. left: pos.left + 'px',
  403. top: pos.top + 'px',
  404. width: pos.width + 'px',
  405. height: pos.height + 'px',
  406. zIndex: 9999
  407. }, [
  408. {
  409. tag: 'img',
  410. id: 'icon',
  411. src: '/static/images/ad/complaints_suggestions.png',
  412. position: {
  413. left: '0px',
  414. top: '0px',
  415. width: '48px',
  416. height: '48px'
  417. }
  418. }
  419. ]);
  420. this.bindComplaintViewClick();
  421. if (!pos.hidden) {
  422. complaintView.show();
  423. }
  424. },
  425. // 创建关闭按钮视图
  426. createComplaintCloseView(pos) {
  427. complaintCloseView = new plus.nativeObj.View('complaint-close', {
  428. left: pos.closeLeft + 'px',
  429. top: pos.closeTop + 'px',
  430. width: pos.closeSize + 'px',
  431. height: pos.closeSize + 'px',
  432. zIndex: 10000
  433. }, [
  434. {
  435. tag: 'img',
  436. id: 'close',
  437. src: '/static/images/ad/complaints_suggestions_close.png',
  438. position: {
  439. left: '0px',
  440. top: '0px',
  441. width: pos.closeSize + 'px',
  442. height: pos.closeSize + 'px'
  443. }
  444. }
  445. ]);
  446. this.bindComplaintCloseViewClick();
  447. if (!pos.hidden) {
  448. complaintCloseView.show();
  449. }
  450. },
  451. // 检查并更新浮标位置
  452. checkAndUpdateComplaintPosition() {
  453. // #ifdef APP-PLUS
  454. if (!complaintView || !complaintCloseView) return;
  455. try {
  456. const pages = getCurrentPages();
  457. if (pages && pages.length > 0) {
  458. const curPage = pages[pages.length - 1];
  459. const currentRoute = curPage.route || '';
  460. // 如果路由发生变化,更新位置
  461. if (currentRoute !== lastRoute) {
  462. //console.log('路由变化:', lastRoute, '->', currentRoute);
  463. lastRoute = currentRoute;
  464. this.updateComplaintFloatPosition();
  465. }
  466. }
  467. } catch (err) {
  468. console.error('检查路由失败:', err);
  469. }
  470. // #endif
  471. },
  472. // 启动位置检查定时器
  473. startComplaintPositionCheck() {
  474. // #ifdef APP-PLUS
  475. // 清除旧定时器
  476. if (complaintPositionTimer) {
  477. clearInterval(complaintPositionTimer);
  478. }
  479. // 立即检查一次
  480. this.checkAndUpdateComplaintPosition();
  481. // 每500ms检查一次路由变化
  482. complaintPositionTimer = setInterval(() => {
  483. this.checkAndUpdateComplaintPosition();
  484. }, 500);
  485. // #endif
  486. },
  487. // 停止位置检查定时器
  488. stopComplaintPositionCheck() {
  489. // #ifdef APP-PLUS
  490. if (complaintPositionTimer) {
  491. clearInterval(complaintPositionTimer);
  492. complaintPositionTimer = null;
  493. }
  494. // #endif
  495. },
  496. // 更新浮标位置
  497. updateComplaintFloatPosition() {
  498. // #ifdef APP-PLUS
  499. if (!complaintView || !complaintCloseView) return;
  500. const pos = this.getComplaintPosition();
  501. // 隐藏旧视图
  502. complaintView.hide();
  503. complaintCloseView.hide();
  504. //console.log('更新浮标位置 - marginBottom:', pos.marginBottom, 'top:', pos.top, 'route:', lastRoute);
  505. // 重新创建视图(使用新位置)
  506. this.createComplaintMainView(pos);
  507. this.createComplaintCloseView(pos);
  508. // #endif
  509. },
  510. // 启动页关闭后创建浮标
  511. createComplaintFloatAfterSplash() {
  512. // #ifdef APP-PLUS
  513. // 避免重复创建
  514. if (complaintView) return;
  515. // 延迟创建,确保启动页完全关闭
  516. setTimeout(() => {
  517. this.createComplaintFloat();
  518. }, 300);
  519. // #endif
  520. },
  521. // 创建投诉建议浮标
  522. createComplaintFloat() {
  523. // #ifdef APP-PLUS
  524. // 避免重复创建
  525. if (complaintView) return;
  526. plus.navigator.getStatusbarHeight(); // 确保 plus 已初始化
  527. // 初始化路由记录
  528. try {
  529. const pages = getCurrentPages();
  530. if (pages && pages.length > 0) {
  531. const curPage = pages[pages.length - 1];
  532. lastRoute = curPage.route || '';
  533. }
  534. } catch (err) {
  535. console.error('初始化路由失败:', err);
  536. }
  537. const pos = this.getComplaintPosition();
  538. viewLeft = pos.left;
  539. viewTop = pos.top;
  540. // 创建主图标和关闭按钮
  541. this.createComplaintMainView(pos);
  542. this.createComplaintCloseView(pos);
  543. // 启动位置检查
  544. this.startComplaintPositionCheck();
  545. // #endif
  546. },
  547. handlePushMessage(res) { //unipush2.0
  548. const that = this;
  549. console.log("qxj handlePushMessage",res);
  550. if (res.type == 'click') { //unipush2.0在线推送 如果需要跳转app内指定页面,则自己实现下方的跳转代码。
  551. if (this.$isLogin()) {
  552. const url=this.$getCurrentPage();
  553. console.log("qxj handlePushMessage click url",url);
  554. const isOnLaunch = uni.getStorageSync('onLaunch');
  555. // 判断前一个页面路径是一样
  556. const payloadData=JSON.parse(res.data.payload.data);
  557. const flag = url.route && res.data.payload.url.indexOf(url.route);
  558. const isIM=payloadData.type!=undefined && payloadData.type=='im';
  559. if(isIM){
  560. if (isOnLaunch && isOnLaunch == 1) {
  561. //offlineMsg=res.data.payload;
  562. uni.removeStorageSync('onLaunch');
  563. }else{
  564. //console.log("qxj handlePushMessage payloadData",payloadData);
  565. uni.$u.throttle(() => that.notifyGoToChat(payloadData), 2000);
  566. }
  567. }
  568. else{
  569. if (isOnLaunch && isOnLaunch == 1) {
  570. uni.showLoading({ title: '处理中..' });
  571. setTimeout(() => {
  572. uni.hideLoading();
  573. if (flag == -1) {
  574. uni.navigateTo({
  575. url: res.data.payload.url,
  576. success: function () {
  577. uni.removeStorageSync('openUrl');
  578. that.setReadAll(res.data.payload.url);
  579. }
  580. });
  581. }
  582. else {
  583. uni.redirectTo({
  584. url: res.data.payload.url,
  585. success: function () {
  586. uni.removeStorageSync('openUrl');
  587. that.setReadAll(res.data.payload.url);
  588. }
  589. });
  590. }
  591. }, 1000);
  592. }
  593. else {
  594. uni.hideLoading();
  595. if (flag == -1) {
  596. uni.navigateTo({
  597. url: res.data.payload.url,
  598. success: function () {
  599. uni.removeStorageSync('openUrl');
  600. that.setReadAll(res.data.payload.url);
  601. }
  602. });
  603. } else {
  604. uni.redirectTo({
  605. url: res.data.payload.url,
  606. success: function () {
  607. uni.removeStorageSync('openUrl');
  608. that.setReadAll(res.data.payload.url);
  609. }
  610. });
  611. }
  612. }
  613. }
  614. }
  615. }
  616. if (res.type == 'receive') { //监听在线推送消息,若云函数设置了 "force_notification":true,则不会触发此 receive。
  617. // const pages = getCurrentPages();
  618. // const url = pages[ pages.length - 1];
  619. const url=this.$getCurrentPage();
  620. console.log("qxj receive url",url);
  621. if(url && (url.route!="pages_im/pages/conversation/chating/index" || url.route!="pages_im/pages/conversation/chating1/index") ){
  622. // 检查应用是否在前台
  623. const appIsOnShow = uni.getStorageSync('appIsOnShow');
  624. //if(!!appIsOnShow){ // 应用在前台,处理消息但不显示通知
  625. let payload=res.data.payload;
  626. if(!!payload && !!payload.data){
  627. let payloadData=JSON.parse(payload.data);
  628. if(payloadData.contentType && payloadData.contentType==1601 && appIsOnShow){
  629. return;
  630. }
  631. }
  632. console.log("qxj payload",payload);
  633. uni.createPushMessage({
  634. title: res.data.title,
  635. content: res.data.content,
  636. payload: res.data.payload,
  637. when: new Date(),
  638. icon:"",
  639. sound: 'system', // 默认值为system
  640. category: res.data.category,
  641. success: () => {
  642. console.log('创建在线推送消息成功: ');
  643. this.$store.commit('newMsg/SET_UPDATATIME', new Date().getTime());
  644. },
  645. fail: (err) => {
  646. console.log('创建在线推送消息失败: ', err);
  647. }
  648. });
  649. //}
  650. plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
  651. if (widgetInfo.visible) {
  652. // 应用在前台,处理消息但不显示通知
  653. uni.createPushMessage({
  654. title: res.data.title,
  655. content: res.data.content,
  656. payload: res.data.payload,
  657. sound: 'system', // 默认值为system
  658. category: res.data.category,
  659. success: () => {
  660. console.log('创建在线推送消息成功: ');
  661. this.$store.commit('newMsg/SET_UPDATATIME', new Date().getTime());
  662. },
  663. fail: (err) => {
  664. console.log('创建在线推送消息失败: ', err);
  665. }
  666. });
  667. } else {
  668. // 应用在后台,可以显示通知(如果需要)
  669. }
  670. });
  671. }
  672. }
  673. },
  674. handlerLaunchMsg() { // 处理Launch信息
  675. let that=this;
  676. // 监听通知点击事件
  677. plus.push.addEventListener('click', function (msg) { //unipush2.0 离线推送 (小米)
  678. console.log('应用通过点击通知启动:', msg);
  679. let newServerMsg=msg.payload;
  680. offlineMsg=msg;
  681. });
  682. // 获取启动时的通知
  683. plus.push.getClientInfoAsync(function(info) { //unipush2.0连离线推送/点击桌面启动 (小米)
  684. //console.log("qxj getClientInfoAsync",info);
  685. if(info.id && info.id=="unipush"){ //unipush1.0 荣耀离线推送
  686. offlineMsg=info;
  687. }
  688. if (info.title && info.content && info.payload) {
  689. uni.switchTab({url: 'pages_im/pages/conversation/conversationList/index'});
  690. }
  691. if (info.launch && info.launch.payload) {
  692. let newServerMsg = info.launch.payload;
  693. console.log('应用通过通知启动:', info);
  694. uni.switchTab({url: 'pages_im/pages/conversation/conversationList/index'});
  695. //uni.$u.throttle(() => that.notifyGoToChat(newServerMsg), 1000);
  696. }
  697. }, function(err) {
  698. console.error("Error getting client info:", err);
  699. });
  700. },
  701. getSystemFontScale: function () {
  702. let scale = 1;
  703. if (uni.getSystemInfoSync) {
  704. let systemInfo = uni.getSystemInfoSync();
  705. if (systemInfo.fontSizeSetting) {
  706. scale = systemInfo.fontSizeSetting / 16; // 16 是默认字体大小
  707. }
  708. }
  709. return scale;
  710. },
  711. adjustFontSize: function () {
  712. let scale = this.getSystemFontScale();
  713. let rootElement = document.documentElement;
  714. rootElement.style.fontSize = 16 * scale + 'px';
  715. },
  716. setGlobalIMlistener() {
  717. const kickHander = (message) => {
  718. toastWithCallback(message, () => {
  719. uni.removeStorage({ key: 'IMToken' });
  720. uni.removeStorage({ key: 'BusinessToken' });
  721. callingModule?.endCall();
  722. meetingModule?.endCall();
  723. Igexin.unbindAlias(this.storeCurrentUserID);
  724. uni.$emit('loginOut');
  725. });
  726. };
  727. let that=this;
  728. IMSDK.subscribe(IMSDK.IMEvents.OnKickedOffline, (data) => {
  729. kickHander('您的账号在其他设备登录,请重新登录!');
  730. //that.removeImData();
  731. //that.openImLogin();
  732. });
  733. IMSDK.subscribe(IMSDK.IMEvents.OnUserTokenExpired, (data) => {
  734. kickHander('您的登录已过期,请重新登录!');
  735. //that.removeImData();
  736. //that.openImLogin();
  737. });
  738. IMSDK.subscribe(IMSDK.IMEvents.OnUserTokenInvalid, (data) => {
  739. kickHander('您的登录已无效,请重新登录!');
  740. //that.removeImData();
  741. //that.openImLogin();
  742. });
  743. // sync
  744. let lastSyncTime = 0;
  745. const syncStartHandler = ({ data }) => {
  746. this.$store.commit('user/SET_IS_SYNCING', true);
  747. this.$store.commit('user/SET_REINSTALL', data);
  748. this.$store.commit('user/SET_PROGRESS', 0);
  749. uni.setStorageSync("imSyncFinish",0);
  750. };
  751. const syncProgressHandler = ({ data }) => {
  752. const now = Date.now();
  753. if (now - lastSyncTime > 200 || data >= 100) {
  754. lastSyncTime = now;
  755. console.log("qxj syncProgressHandler",data);
  756. this.$store.commit('user/SET_PROGRESS', data);
  757. }
  758. };
  759. const syncFinishHandler = () => {
  760. this.$store.dispatch('conversation/getConversationList');
  761. this.$store.dispatch('contact/getFriendList');
  762. this.$store.dispatch('contact/getGrouplist');
  763. this.$store.dispatch('conversation/getUnReadCount');
  764. this.$store.commit('user/SET_IS_SYNCING', false);
  765. this.$store.commit('user/SET_PROGRESS', 100);
  766. //console.log("qxj syncFinishHandler offlineHandleNewMsg",offlineHandleNewMsg);
  767. //console.log("qxj syncFinishHandler offlineMsg",offlineMsg);
  768. uni.setStorageSync("imSyncFinish",1);
  769. if(offlineMsg!=null){
  770. uni.$u.throttle(() => this.notifyGoToChat(offlineHandleNewMsg), 1000);
  771. }
  772. uni.hideLoading();
  773. };
  774. const syncFailedHandler = () => {
  775. uni.hideLoading();
  776. //uni.$u.toast('同步消息失败');
  777. this.$store.dispatch('conversation/getConversationList');
  778. this.$store.dispatch('conversation/getUnReadCount');
  779. this.$store.commit('user/SET_IS_SYNCING', false);
  780. this.$store.commit('user/SET_PROGRESS', 0);
  781. uni.setStorageSync("imSyncFinish",0);
  782. };
  783. IMSDK.subscribe(IMSDK.IMEvents.OnSyncServerStart, syncStartHandler);
  784. IMSDK.subscribe(IMSDK.IMEvents.OnSyncServerFinish, syncFinishHandler);
  785. IMSDK.subscribe(IMSDK.IMEvents.OnSyncServerFailed, syncFailedHandler);
  786. IMSDK.subscribe(IMSDK.IMEvents.OnSyncServerProgress, syncProgressHandler);
  787. const setStateStart = () => {
  788. connectStart = 0;
  789. };
  790. const setStateSuccess= () => {
  791. IMSDK.asyncApi('getSignalingInvitationInfoStartApp', IMSDK.uuid()).then(({ data }) => {
  792. callingModule.launchLiveChat(data);
  793. });
  794. connectStart = 1;
  795. };
  796. const setStateError= () => {
  797. connectStart = -1;
  798. };
  799. IMSDK.subscribe(IMSDK.IMEvents.OnConnecting, setStateStart);
  800. //IMSDK.subscribe(IMSDK.IMEvents.OnConnectSuccess, setStateSuccess);
  801. IMSDK.subscribe(IMSDK.IMEvents.OnConnectFailed, setStateError);
  802. // self
  803. const selfInfoUpdateHandler = ({ data }) => {
  804. this.$store.commit('user/SET_SELF_INFO', {
  805. ...this.storeSelfInfo,
  806. ...data
  807. });
  808. this.updateMessageNicknameAndFaceUrl({
  809. sendID: data.userID,
  810. senderNickname: data.nickname,
  811. senderFaceUrl: data.faceURL
  812. });
  813. };
  814. IMSDK.subscribe(IMSDK.IMEvents.OnSelfInfoUpdated, selfInfoUpdateHandler);
  815. // message
  816. const newMessagesHandler = ({ data }) => {
  817. //console.log("-----qxj newMessagesHandler:",data);
  818. if(offlineMsg!=null){
  819. offlineHandleNewMsg=data[0];
  820. }
  821. if (this.storeIsSyncing) {
  822. return;
  823. }
  824. if(Array.isArray(data)){
  825. data.forEach(this.handleNewMessage);
  826. }else{
  827. this.handleNewMessage(data);
  828. }
  829. };
  830. const offlineMessageHandler = ({ data }) => {
  831. console.log("-----qxj offlineMessageHandler:"+JSON.stringify(data));
  832. };
  833. const offlineMessagesHandler = ({ data }) => {
  834. //console.log("------qxj offlineMessagesHandler:"+JSON.stringify(data));
  835. if (this.storeIsSyncing) {
  836. return;
  837. }
  838. data.forEach(this.handleOfflineMessages);
  839. };
  840. const c2cReadReceiptHandler = ({ data: receiptList }) => {
  841. if (receiptList[0].userID !== this.storeCurrentConversation.userID) {
  842. return;
  843. }
  844. receiptList.forEach((item) => {
  845. item.msgIDList.forEach((msgID) => {
  846. this.updateOneMessage({
  847. message: {
  848. clientMsgID: msgID
  849. },
  850. type: UpdateMessageTypes.KeyWords,
  851. keyWords: {
  852. key: 'isRead',
  853. value: true
  854. }
  855. });
  856. });
  857. });
  858. };
  859. const groupReadReceiptHandler = ({ data }) => {
  860. if (data.conversationID !== this.storeCurrentConversation.conversationID) {
  861. return;
  862. }
  863. data.groupMessageReadInfo.map((receipt) => {
  864. const oldMessage = this.storeHistoryMessageList.find((msg) => msg.clientMsgID === receipt.clientMsgID);
  865. if (oldMessage) {
  866. uni.$emit(PageEvents.GroupMessageReceipt, receipt);
  867. const newMessage = {
  868. ...oldMessage,
  869. isRead: true,
  870. attachedInfoElem: {
  871. ...oldMessage.attachedInfoElem,
  872. groupHasReadInfo: {
  873. hasReadCount: receipt.hasReadCount,
  874. unreadCount: receipt.unreadCount
  875. }
  876. }
  877. };
  878. console.log(newMessage);
  879. this.updateOneMessage({ message: newMessage });
  880. }
  881. });
  882. console.log(data);
  883. };
  884. const newRecvMessageRevokedHandler = ({ data: revokedMessage }) => {
  885. if (!this.storeCurrentConversation.conversationID) {
  886. return;
  887. }
  888. this.updateOneMessage({
  889. message: { clientMsgID: revokedMessage.clientMsgID },
  890. type: UpdateMessageTypes.KeyWords,
  891. keyWords: [
  892. {
  893. key: 'contentType',
  894. value: MessageType.RevokeMessage
  895. },
  896. {
  897. key: 'notificationElem',
  898. value: {
  899. detail: JSON.stringify(revokedMessage)
  900. }
  901. }
  902. ]
  903. });
  904. this.updateQuoteMessageRevoke({
  905. clientMsgID: revokedMessage.clientMsgID
  906. });
  907. };
  908. const inputStatusChanged = ({ data }) => {
  909. if (data.userID === this.storeCurrentConversation.userID && data.conversationID === this.storeCurrentConversation.conversationID) {
  910. if (data.platformIDs.length > 0) {
  911. uni.$emit(PageEvents.TypingUpdate);
  912. }
  913. }
  914. };
  915. IMSDK.subscribe(IMSDK.IMEvents.OnRecvOfflineNewMessage, offlineMessageHandler);
  916. IMSDK.subscribe(IMSDK.IMEvents.OnRecvOfflineNewMessages, offlineMessagesHandler);
  917. IMSDK.subscribe(IMSDK.IMEvents.OnRecvNewMessages, newMessagesHandler);
  918. IMSDK.subscribe("OnInputStatusChanged", inputStatusChanged);
  919. IMSDK.subscribe(IMSDK.IMEvents.OnRecvC2CReadReceipt, c2cReadReceiptHandler);
  920. IMSDK.subscribe(IMSDK.IMEvents.OnRecvGroupReadReceipt, groupReadReceiptHandler);
  921. IMSDK.subscribe(IMSDK.IMEvents.OnNewRecvMessageRevoked, newRecvMessageRevokedHandler);
  922. // friend
  923. const friendInfoChangeHandler = ({ data }) => {
  924. uni.$emit(IMSDK.IMEvents.OnFriendInfoChanged, { data });
  925. if (data.userID === this.storeCurrentConversation?.userID) {
  926. this.updateMessageNicknameAndFaceUrl({
  927. sendID: data.userID,
  928. senderNickname: data.remark || data.nickname,
  929. senderFaceUrl: data.faceURL
  930. });
  931. this.$store.commit('conversation/SET_CURRENT_CONVERSATION', { ...this.storeCurrentConversation, showName: data.remark || data.nickname });
  932. }
  933. //console.log(this.storeConversationList);
  934. this.updateFriendInfo({
  935. friendInfo: data
  936. });
  937. };
  938. const friendAddedHandler = ({ data }) => {
  939. this.pushNewFriend(data);
  940. };
  941. const friendDeletedHander = ({ data }) => {
  942. this.updateFriendInfo({
  943. friendInfo: data,
  944. isRemove: true
  945. });
  946. };
  947. IMSDK.subscribe(IMSDK.IMEvents.OnFriendInfoChanged, friendInfoChangeHandler);
  948. IMSDK.subscribe(IMSDK.IMEvents.OnFriendAdded, friendAddedHandler);
  949. IMSDK.subscribe(IMSDK.IMEvents.OnFriendDeleted, friendDeletedHander);
  950. // blacklist
  951. const blackAddedHandler = ({ data }) => {
  952. this.pushNewBlack(data);
  953. };
  954. const blackDeletedHandler = ({ data }) => {
  955. this.updateBlackInfo({
  956. blackInfo: data,
  957. isRemove: true
  958. });
  959. };
  960. IMSDK.subscribe(IMSDK.IMEvents.OnBlackAdded, blackAddedHandler);
  961. IMSDK.subscribe(IMSDK.IMEvents.OnBlackDeleted, blackDeletedHandler);
  962. // group
  963. const joinedGroupAddedHandler = ({ data }) => {
  964. uni.$emit(IMSDK.IMEvents.OnJoinedGroupAdded, { data });
  965. this.pushNewGroup(data);
  966. };
  967. const joinedGroupDeletedHandler = ({ data }) => {
  968. uni.$emit(IMSDK.IMEvents.OnJoinedGroupDeleted, { data });
  969. this.updateGroupInfo({
  970. groupInfo: data,
  971. isRemove: true
  972. });
  973. };
  974. const groupInfoChangedHandler = ({ data }) => {
  975. this.updateGroupInfo({
  976. groupInfo: data
  977. });
  978. };
  979. const groupMemberInfoChangedHandler = ({ data }) => {
  980. uni.$emit(IMSDK.IMEvents.OnGroupMemberInfoChanged, { data });
  981. if (data.groupID === this.storeCurrentConversation?.groupID) {
  982. this.updateMessageNicknameAndFaceUrl({
  983. sendID: data.userID,
  984. senderNickname: data.nickname,
  985. senderFaceUrl: data.faceURL
  986. });
  987. this.updateCurrentMemberInGroup(data);
  988. }
  989. };
  990. IMSDK.subscribe(IMSDK.IMEvents.OnJoinedGroupAdded, joinedGroupAddedHandler);
  991. IMSDK.subscribe(IMSDK.IMEvents.OnJoinedGroupDeleted, joinedGroupDeletedHandler);
  992. IMSDK.subscribe(IMSDK.IMEvents.OnGroupInfoChanged, groupInfoChangedHandler);
  993. IMSDK.subscribe(IMSDK.IMEvents.OnGroupMemberInfoChanged, groupMemberInfoChangedHandler);
  994. // application
  995. const friendApplicationNumHandler = ({ data }) => {
  996. console.log("qxj friendApplicationNumHandler");
  997. const isRecv = data.toUserID === this.storeCurrentUserID;
  998. if (isRecv) {
  999. this.pushNewRecvFriendApplition(data);
  1000. } else {
  1001. this.pushNewSentFriendApplition(data);
  1002. }
  1003. };
  1004. const friendApplicationAccessHandler = ({ data }) => {
  1005. console.log("qxj friendApplicationAccessHandler");
  1006. const isRecv = data.toUserID === this.storeCurrentUserID;
  1007. if (isRecv) {
  1008. this.updateRecvFriendApplition({
  1009. application: data
  1010. });
  1011. } else {
  1012. this.updateSentFriendApplition({
  1013. application: data
  1014. });
  1015. }
  1016. };
  1017. const groupApplicationNumHandler = ({ data }) => {
  1018. console.log("qxj groupApplicationNumHandler");
  1019. const isRecv = data.userID !== this.storeCurrentUserID;
  1020. if (isRecv) {
  1021. this.pushNewRecvGroupApplition(data);
  1022. } else {
  1023. this.pushNewSentGroupApplition(data);
  1024. }
  1025. };
  1026. const groupApplicationAccessHandler = ({ data }) => {
  1027. console.log("qxj groupApplicationAccessHandler");
  1028. const isRecv = data.userID !== this.storeCurrentUserID;
  1029. if (isRecv) {
  1030. this.updateRecvGroupApplition({application: data});
  1031. } else {
  1032. this.updateSentGroupApplition({application: data});
  1033. }
  1034. };
  1035. IMSDK.subscribe(IMSDK.IMEvents.OnFriendApplicationAdded, friendApplicationNumHandler);
  1036. IMSDK.subscribe(IMSDK.IMEvents.OnFriendApplicationAccepted, friendApplicationAccessHandler);
  1037. IMSDK.subscribe(IMSDK.IMEvents.OnFriendApplicationRejected, friendApplicationAccessHandler);
  1038. IMSDK.subscribe(IMSDK.IMEvents.OnGroupApplicationAdded, groupApplicationNumHandler);
  1039. IMSDK.subscribe(IMSDK.IMEvents.OnGroupApplicationAccepted, groupApplicationAccessHandler);
  1040. IMSDK.subscribe(IMSDK.IMEvents.OnGroupApplicationRejected, groupApplicationAccessHandler);
  1041. // conversation
  1042. const totalUnreadCountChangedHandler = ({ data }) => {
  1043. if (this.storeIsSyncing) {
  1044. return;
  1045. }
  1046. this.$store.commit('conversation/SET_UNREAD_COUNT', data);
  1047. };
  1048. const newConversationHandler = ({ data }) => {
  1049. console.log("qxj newConversationHandler");
  1050. if (this.storeIsSyncing) {
  1051. return;
  1052. }
  1053. const result = [...data, ...this.storeConversationList];
  1054. this.$store.commit('conversation/SET_CONVERSATION_LIST', conversationSort(result));
  1055. };
  1056. const conversationChangedHandler = ({ data }) => {
  1057. if (this.storeIsSyncing) {
  1058. return;
  1059. }
  1060. let filterArr = [];
  1061. //console.log("qxj conversationChangedHandler:::",data);
  1062. const chids = data.map((ch) => ch.conversationID);
  1063. filterArr = this.storeConversationList.filter((tc) => !chids.includes(tc.conversationID));
  1064. const idx = data.findIndex((c) => c.conversationID === this.storeCurrentConversation.conversationID);
  1065. if (idx !== -1) this.$store.commit('conversation/SET_CURRENT_CONVERSATION', data[idx]);
  1066. const result = [...data, ...filterArr];
  1067. this.$store.commit('conversation/SET_CONVERSATION_LIST', conversationSort(result));
  1068. };
  1069. IMSDK.subscribe(IMSDK.IMEvents.OnTotalUnreadMessageCountChanged, totalUnreadCountChangedHandler);
  1070. IMSDK.subscribe(IMSDK.IMEvents.OnNewConversation, newConversationHandler);
  1071. IMSDK.subscribe(IMSDK.IMEvents.OnConversationChanged, conversationChangedHandler);
  1072. const insertInCurrentConversation = (newServerMsg) => {
  1073. return newServerMsg.sendID === this.$store.getters.storeCurrentConversation.userID || newServerMsg.recvID === this.$store.getters.storeCurrentConversation.userID;
  1074. };
  1075. const onNativeCallEndHandler = async ({ invitation, duration, status }) => {
  1076. uni.$emit(PageEvents.NativeCallEnd);
  1077. if (!status || invitation.groupID) {
  1078. return;
  1079. }
  1080. const type = invitation.mediaType === 'video' ? CustomType.VideoCall : CustomType.VoiceCall;
  1081. const customData = {
  1082. customType: CustomType.Call,
  1083. data: { type, duration: secFormat(duration), status }
  1084. };
  1085. const nativeCallList = uni.getStorageSync(`${this.$store.getters.storeCurrentUserID}_nativecall`) || [];
  1086. const isSelf = invitation.inviterUserID === this.$store.getters.storeCurrentUserID;
  1087. const data = { ...invitation, duration, isSelf, type, time: new Date().getTime() };
  1088. uni.setStorage({
  1089. key: `${this.$store.getters.storeCurrentUserID}_nativecall`,
  1090. data: [...nativeCallList, data]
  1091. });
  1092. const message = await IMSDK.asyncApi(IMMethods.CreateCustomMessage, IMSDK.uuid(), {
  1093. data: JSON.stringify(customData),
  1094. extension: '',
  1095. description: 'RTC'
  1096. });
  1097. const recvID = invitation.inviteeUserIDList[0];
  1098. IMSDK.asyncApi(IMSDK.IMMethods.InsertSingleMessageToLocalStorage, IMSDK.uuid(), {
  1099. message,
  1100. recvID,
  1101. sendID: invitation.inviterUserID
  1102. }).then(({ data }) => {
  1103. if (insertInCurrentConversation(data)) {
  1104. this.$store.dispatch('message/pushNewMessage', data);
  1105. setTimeout(() => uni.$emit(PageEvents.ScrollToBottom, true));
  1106. }
  1107. }).catch((err) => {
  1108. console.log(err);
  1109. });
  1110. };
  1111. const onNativeInviteHandler = async (data) => {
  1112. // uni.$u.toast("onNativeInviteHandler")
  1113. uni.$u.route('/pages_im/pages/common/contactChoose/index', {
  1114. type: ContactChooseTypes.InviteMeeting,
  1115. forwardMessage: encodeURIComponent(JSON.stringify(data.data))
  1116. });
  1117. };
  1118. IMSDK.subscribe('onNativeCallEnd', onNativeCallEndHandler);
  1119. IMSDK.subscribe('Native_InviteUser', onNativeInviteHandler);
  1120. },
  1121. initOpenIm() {
  1122. innerAudioContext = uni.createInnerAudioContext();
  1123. innerAudioContext.autoplay = false;
  1124. innerAudioContext.src = newMessage;
  1125. // #ifdef APP-PLUS
  1126. Igexin.turnOnPush();
  1127. // #endif
  1128. this.setGlobalIMlistener();
  1129. this.tryLogin();
  1130. //this.testTryLogin("C63");
  1131. },
  1132. openImLogin() {
  1133. let that = this;
  1134. var uid="";
  1135. var nickName="";
  1136. var avatar="";
  1137. if(this.$companyUserIsLogin()){
  1138. var user = JSON.parse(uni.getStorageSync('companyUser'));
  1139. uid = 'C' + user.userId;
  1140. nickName=user.imNickName || user.nickName;
  1141. avatar=user.avatar;
  1142. }
  1143. else{
  1144. var user = JSON.parse(uni.getStorageSync('userInfo'));
  1145. uid = 'U' + user.userId;
  1146. nickName=user.nickName;
  1147. avatar=user.avatar;
  1148. }
  1149. if(this.$isEmpty(avatar)){
  1150. avatar="https://cos.his.cdwjyyh.com/fs/20250519/4e7c1c2de4b54ec4aaf1047394592a42.png";
  1151. }
  1152. let IMToken = uni.getStorageSync('IMToken');
  1153. let IMUserID = uid;
  1154. let reqData = { userID:uid, nickName:nickName, avatar:avatar };
  1155. openImLoginApi(reqData,IMToken,IMUserID,function (token) {
  1156. setTimeout(()=>{
  1157. that.tryLogin();
  1158. },100);
  1159. },
  1160. function () {
  1161. uni.$u.toast('IM登录失败!');
  1162. }
  1163. );
  1164. },
  1165. tryLogin() {
  1166. const initStore = () => {
  1167. this.$store.dispatch('user/initCache');
  1168. this.$store.dispatch('user/getSelfInfo');
  1169. this.$store.dispatch('conversation/getConversationList');
  1170. this.$store.dispatch('conversation/getUnReadCount');
  1171. this.$store.dispatch("contact/getFriendList");
  1172. this.$store.dispatch("contact/getGrouplist");
  1173. //this.$store.dispatch('contact/getBlacklist');
  1174. if(!this.$isIos()){
  1175. this.$store.dispatch('contact/getRecvFriendApplications');
  1176. this.$store.dispatch('contact/getSentFriendApplications');
  1177. this.$store.dispatch('contact/getRecvGroupApplications');
  1178. this.$store.dispatch('contact/getSentGroupApplications');
  1179. }
  1180. // #ifdef APP-PLUS
  1181. plus.navigator.closeSplashscreen();
  1182. // 启动页关闭后创建浮标
  1183. this.createComplaintFloatAfterSplash();
  1184. // #endif
  1185. };
  1186. let IMToken = uni.getStorageSync('IMToken');
  1187. let IMUserID = uni.getStorageSync('IMUserID');
  1188. //console.log("qxj IMToken:"+IMToken+" IMUserID:"+IMUserID);
  1189. // #ifdef APP-PLUS
  1190. getDbDir().then(async (path) => {
  1191. let platformID=uni.$u.os() === 'ios' ? 1 : 2;
  1192. const flag = await IMSDK.asyncApi(IMMethods.InitSDK, IMSDK.uuid(), {
  1193. systemType: 'uni-app',
  1194. platformID:platformID,
  1195. apiAddr: config.getApiUrl(),
  1196. wsAddr: config.getWsUrl(),
  1197. dataDir: path, // 数据存储路径
  1198. logLevel: 5,//正式环境2或者3 测试:5
  1199. logFilePath: path,
  1200. isLogStandardOutput: true // 是否输出到控制台
  1201. });
  1202. if (!flag) {
  1203. // #ifdef APP-PLUS
  1204. plus.navigator.closeSplashscreen();
  1205. // 启动页关闭后创建浮标
  1206. this.createComplaintFloatAfterSplash();
  1207. // #endif
  1208. uni.$u.toast('初始化IMSDK失败!');
  1209. return;
  1210. }
  1211. //1 未登录 2 登录中 3 已登录
  1212. const loginStatus = await IMSDK.asyncApi(IMSDK.IMMethods.GetLoginStatus, IMSDK.uuid());
  1213. if (loginStatus === 3) {
  1214. initStore();
  1215. return;
  1216. }
  1217. callingModule?.initModule();
  1218. if (IMToken && IMUserID) {
  1219. await IMSDK.asyncApi(IMSDK.IMMethods.Login, IMSDK.uuid(), {
  1220. userID: IMUserID,
  1221. token: IMToken,
  1222. }).then(initStore).catch((err) => {
  1223. console.log('qxj initStore err:' + JSON.stringify(err));
  1224. uni.$u.toast('初始化IMSDK异常:'+JSON.stringify(err));
  1225. uni.removeStorage({ key: 'IMToken' });
  1226. // #ifdef APP-PLUS
  1227. plus.navigator.closeSplashscreen();
  1228. // 启动页关闭后创建浮标
  1229. this.createComplaintFloatAfterSplash();
  1230. // #endif
  1231. });
  1232. } else {
  1233. if(this.$isLogin()){
  1234. this.openImLogin();
  1235. }
  1236. // #ifdef APP-PLUS
  1237. plus.navigator.closeSplashscreen();
  1238. // 启动页关闭后创建浮标
  1239. this.createComplaintFloatAfterSplash();
  1240. // #endif
  1241. }
  1242. }).catch((err) => {
  1243. console.log('get dir failed');
  1244. console.log(err);
  1245. // #ifdef APP-PLUS
  1246. plus.navigator.closeSplashscreen();
  1247. // 启动页关闭后创建浮标
  1248. this.createComplaintFloatAfterSplash();
  1249. // #endif
  1250. });
  1251. // #endif
  1252. // #ifdef H5
  1253. console.log("qxj IMTokenUserId",IMToken,IMUserID);
  1254. if (IMToken && IMUserID) {
  1255. IMSDK.asyncApi(IMSDK.IMMethods.Login, IMSDK.uuid(), {
  1256. userID: IMUserID,
  1257. token: IMToken,
  1258. platformID:5,
  1259. logLevel: 2,
  1260. apiAddr: config.getApiUrl(),
  1261. wsAddr: config.getWsUrl(),
  1262. }).then(initStore).catch((err) => {
  1263. console.log('qxj initStore:',err);
  1264. uni.removeStorage({ key: 'IMToken' });
  1265. });
  1266. return;
  1267. }
  1268. else{
  1269. if(this.$isLogin()){
  1270. this.openImLogin();
  1271. }
  1272. }
  1273. // #endif
  1274. },
  1275. testTryLogin(uid){
  1276. uni.setStorageSync('IMToken',null);
  1277. let IMToken = uni.getStorageSync('IMToken');
  1278. let IMUserID = uid;
  1279. let reqData = { userID:uid, nickName:"" };
  1280. let that=this;
  1281. testImLoginApi(reqData,IMToken,IMUserID,function (token) {
  1282. setTimeout(()=>{
  1283. that.tryLogin();
  1284. },100);
  1285. },
  1286. function () {
  1287. uni.$u.toast('IM登录失败!');
  1288. }
  1289. );
  1290. },
  1291. async newMessageNotify(newServerMsg) {
  1292. if (this.storeIsSyncing) {
  1293. return;
  1294. }
  1295. //console.log("qxj newMessageNotify1");
  1296. const disableNotify = uni.getStorageSync(`${this.storeCurrentUserID}_DisableNotify`);
  1297. if (disableNotify || this.storeSelfInfo.globalRecvMsgOpt !== MessageReceiveOptType.Nomal) {
  1298. return;
  1299. }
  1300. //console.log("qxj newMessageNotify2");
  1301. let cveItem = [...this.storeConversationList, ...cacheConversationList].find((conversation) => {
  1302. if (newServerMsg.sessionType === SessionType.WorkingGroup) {
  1303. return newServerMsg.groupID === conversation.groupID;
  1304. }
  1305. return newServerMsg.sendID === conversation.userID;
  1306. });
  1307. //console.log("qxj newMessageNotify3");
  1308. if (!cveItem) {
  1309. try {
  1310. const { data } = await IMSDK.asyncApi(IMSDK.IMMethods.GetOneConversation, IMSDK.uuid(), {
  1311. sourceID: newServerMsg.groupID || newServerMsg.sendID,
  1312. sessionType: newServerMsg.sessionType
  1313. });
  1314. cveItem = data;
  1315. cacheConversationList = [...cacheConversationList, data];
  1316. } catch (e) {
  1317. return;
  1318. }
  1319. }
  1320. //console.log("qxj newMessageNotify4");
  1321. if (cveItem.recvMsgOpt !== MessageReceiveOptType.Normal) {
  1322. return;
  1323. }
  1324. //console.log("qxj newMessageNotify5");
  1325. const notificationFun = () => {
  1326. const isSelf = newServerMsg.sendID === this.$store.getters.storeCurrentUserID;
  1327. if (isSelf) return;
  1328. // const pages = getCurrentPages();
  1329. // const url = pages[ pages.length - 1];
  1330. const url=this.$getCurrentPage();
  1331. if(url&& (url.route=="pages_im/pages/conversation/conversationList/index"
  1332. || url.route=="pages_im/pages/conversation/chating/index") ){
  1333. return;
  1334. }
  1335. // uni.createPushMessage({
  1336. // content: `${newServerMsg.senderNickname}: ${parseMessageByType(newServerMsg)}`,
  1337. // payload: {
  1338. // sessionType: newServerMsg.sessionType,
  1339. // sourceID: newServerMsg.groupID || newServerMsg.sendID,
  1340. // }
  1341. // });
  1342. const isSingle = newServerMsg.groupID ? false : true;
  1343. console.log(this.storeGroupList, newServerMsg);
  1344. const group = this.storeGroupList.filter((group) => group.groupID === newServerMsg.groupID);
  1345. const title = isSingle ? newServerMsg.senderNickname : group[0].groupName;
  1346. const desc = parseMessageByType(newServerMsg);
  1347. console.log('notification', title, desc);
  1348. // notificationIntance = new NotificationUtil();
  1349. // let tickerTips="通知提示";
  1350. // let notifyId=10001;
  1351. // let config={ title, desc,tickerTips,notifyId };
  1352. // notificationIntance.createNotification(config);
  1353. // setTimeout(()=>{
  1354. // notificationIntance.clearNotification(10001);
  1355. // },10000);
  1356. // notification.showNotice(0, title, desc, () => {
  1357. // prepareConversationState(cveItem);
  1358. // });
  1359. };
  1360. //notificationFun();
  1361. const platform = uni.getSystemInfoSync().platform;
  1362. if (platform == 'ios') {
  1363. if (this.storeSelfInfo.allowVibration === 1) {
  1364. plus.device.vibrate();
  1365. }
  1366. if (this.storeSelfInfo.allowBeep === 1) {
  1367. innerAudioContext.play();
  1368. // plus.device.beep();
  1369. }
  1370. }
  1371. else if (platform == 'android') {
  1372. if (this.storeSelfInfo.allowVibration === 1) {
  1373. plus.device.vibrate(500);
  1374. }
  1375. if (this.storeSelfInfo.allowBeep === 1) {
  1376. let main = plus.android.runtimeMainActivity();
  1377. let RingtoneManager = plus.android.importClass('android.media.RingtoneManager');
  1378. let uri = RingtoneManager.getActualDefaultRingtoneUri(main, RingtoneManager.TYPE_NOTIFICATION);
  1379. let MediaPlayer = plus.android.importClass('android.media.MediaPlayer');
  1380. let player = MediaPlayer.create(main, uri);
  1381. player.setLooping(false);
  1382. player.prepare();
  1383. player.start();
  1384. }
  1385. }
  1386. },
  1387. async notifyGoToChat(newServerMsg){
  1388. console.log("qxj notifyGoToChat",newServerMsg);
  1389. if (this.storeIsSyncing) {
  1390. return;
  1391. }
  1392. offlineHandleNewMsg=null;
  1393. offlineMsg=null;
  1394. // const disableNotify = uni.getStorageSync(`${this.storeCurrentUserID}_DisableNotify`);
  1395. // if (disableNotify || this.storeSelfInfo.globalRecvMsgOpt !== MessageReceiveOptType.Nomal) {
  1396. // return;
  1397. // }
  1398. let cveItem = [...this.storeConversationList, ...cacheConversationList].find((conversation) => {
  1399. if (newServerMsg.sessionType === SessionType.WorkingGroup) {
  1400. return newServerMsg.groupID === conversation.groupID;
  1401. }
  1402. return newServerMsg.sendID === conversation.userID;
  1403. });
  1404. console.log("qxj notifyGoToChat cveItem",cveItem);
  1405. if (!cveItem) {
  1406. try {
  1407. const { data } = await IMSDK.asyncApi(IMSDK.IMMethods.GetOneConversation, IMSDK.uuid(), {
  1408. sourceID: newServerMsg.groupID || newServerMsg.sendID,
  1409. sessionType: newServerMsg.sessionType
  1410. });
  1411. cveItem = data;
  1412. cacheConversationList = [...cacheConversationList, data];
  1413. } catch (e) {
  1414. return;
  1415. }
  1416. }
  1417. if (cveItem.recvMsgOpt !== MessageReceiveOptType.Normal) {
  1418. return;
  1419. }
  1420. const isSelf = newServerMsg.sendID === this.$store.getters.storeCurrentUserID;
  1421. if (isSelf) return;
  1422. // const pages = getCurrentPages();
  1423. // const url = pages[ pages.length - 1];
  1424. const url=this.$getCurrentPage();
  1425. if(url && (url.route=="pages_im/pages/conversation/chating/index" || url.route=="pages_im/pages/conversation/chating1/index") ){
  1426. return;
  1427. }
  1428. this.handlerConversation(cveItem);
  1429. setTimeout(()=>{
  1430. prepareConversationState(cveItem);
  1431. //uni.removeStorageSync("serverMsgID");
  1432. },200);
  1433. },
  1434. handlerConversation(source){
  1435. let userId=source.userID;
  1436. let isDoctor=false;
  1437. if(userId!=undefined && (userId!="" || userId.length>0)){
  1438. if(userId.indexOf('D')!==-1){
  1439. isDoctor=true;
  1440. }
  1441. }
  1442. if(this.$companyUserIsLogin() || !isDoctor){
  1443. this.$store.commit("timStore/setImType",1);
  1444. }
  1445. else{
  1446. let ex=source.ex;
  1447. if(source.latestMsg!=null && source.latestMsg!=''){
  1448. let latestMsg=JSON.parse(source.latestMsg);
  1449. if(!!latestMsg.ex && latestMsg.ex!=''){
  1450. ex=latestMsg.ex;
  1451. }
  1452. }
  1453. if(ex!=null || ex!=''){
  1454. try{
  1455. var json=JSON.parse(ex);
  1456. this.$store.commit("timStore/setImType", json.imType);
  1457. this.$store.commit("timStore/setOrderType", json.orderType);
  1458. this.$store.commit("timStore/setOrderId", json.orderId);
  1459. this.$store.commit("timStore/setFollowId", json.followId);
  1460. this.$store.commit("timStore/setType", json.type);
  1461. }
  1462. catch(e){
  1463. }
  1464. }
  1465. }
  1466. this.$store.commit("timStore/setConversationID", source.conversationID);
  1467. },
  1468. handleNewMessage(newServerMsg) {
  1469. if (this.inCurrentConversation(newServerMsg)) {
  1470. const isSingleMessage = newServerMsg.sessionType === SessionType.Single;
  1471. if (isSingleMessage) {
  1472. uni.$u.throttle(() => uni.$emit(PageEvents.OnlineStateCheck), 2000);
  1473. if(newServerMsg.ex!=null&&newServerMsg.ex!=''){
  1474. var json=JSON.parse(newServerMsg.ex);
  1475. this.$store.commit("timStore/setType",json.type);
  1476. this.$store.commit("timStore/setImType", json.imType);
  1477. this.$store.commit("timStore/setOrderId",json.orderId);
  1478. this.$store.commit("timStore/setOrderType",json.orderType);
  1479. this.$store.commit("timStore/setFollowId",json.followId);
  1480. if(json.type==="finishInquiry"){
  1481. this.$store.commit("timStore/setImType", 0);
  1482. uni.navigateTo({ url: "/pages_order/pingOrder?orderId="+json.orderId })
  1483. }
  1484. else if(json.type==="startInquiry"){
  1485. }
  1486. else if(json.type==="inquiry"){
  1487. }
  1488. else if(json.type==="startFollow"){
  1489. }
  1490. else if(json.type==="follow"){
  1491. }
  1492. else if(json.type==="finishFollow"){
  1493. }
  1494. else if(json.type==="startDrugReport"){
  1495. }
  1496. else if(json.type==="finishDrugReport"){
  1497. }
  1498. else if(json.type==="drugReport"){
  1499. }
  1500. }
  1501. }
  1502. if (newServerMsg.contentType === MessageType.TypingMessage) {
  1503. if (isSingleMessage) {
  1504. uni.$emit(PageEvents.TypingUpdate);
  1505. }
  1506. }
  1507. else {
  1508. if (newServerMsg.contentType != MessageType.RevokeMessage) {
  1509. newServerMsg.isAppend = true;
  1510. this.pushNewMessage(newServerMsg);
  1511. setTimeout(() => uni.$emit(PageEvents.ScrollToBottom, true));
  1512. }
  1513. uni.$u.debounce(this.markConversationAsRead, 2000);
  1514. }
  1515. }
  1516. else {
  1517. if (newServerMsg.contentType !== MessageType.TypingMessage) {
  1518. uni.$u.throttle(() => this.newMessageNotify(newServerMsg), 1000);
  1519. setTimeout(() => {
  1520. this.$store.dispatch('conversation/getUnReadCount');
  1521. },500);
  1522. }
  1523. }
  1524. },
  1525. handleOfflineMessages(newServerMsg){ //后台运行
  1526. const isSingle = newServerMsg.groupID ? false : true;
  1527. const group = this.storeGroupList.filter((group) => group.groupID === newServerMsg.groupID);
  1528. const title = isSingle ? newServerMsg.senderNickname : group[0].groupName;
  1529. const desc = parseMessageByType(newServerMsg);
  1530. // if(notification){
  1531. // notification.showNotice(0, title, desc, () => {
  1532. // console.log('qxj showNotice:', title);
  1533. // setTimeout(() => {
  1534. // uni.switchTab({url: 'pages_im/pages/conversation/conversationList/index'});
  1535. // },2000);
  1536. // });
  1537. // }
  1538. // const options = {
  1539. // title: title,
  1540. // content: desc,
  1541. // payload: newServerMsg, // 自定义参数,点击通知时传递给应用
  1542. // sound: 'default', // 通知声音
  1543. // cover: false, // 是否覆盖之前的通知
  1544. // //when: new Date(),
  1545. // icon:"",
  1546. // extras: {
  1547. // android: {
  1548. // importance: "high", // 高优先级
  1549. // channelId: "IM通知", // 必须配置通知渠道
  1550. // smallIcon: "transparent",
  1551. // showWhen: false,
  1552. // }
  1553. // }
  1554. // };
  1555. // plus.push.createMessage(options.content, options.payload, options);
  1556. // let when=new Date();
  1557. // uni.createPushMessage({
  1558. // title:title,
  1559. // content:desc,
  1560. // payload: newServerMsg,
  1561. // cover: false, // 是否覆盖之前的通知
  1562. // when: new Date()
  1563. // });
  1564. },
  1565. inCurrentConversation(newServerMsg) {
  1566. switch (newServerMsg.sessionType) {
  1567. case SessionType.Single:
  1568. return (
  1569. newServerMsg.sendID === this.storeCurrentConversation.userID ||
  1570. (newServerMsg.sendID === this.storeCurrentUserID && newServerMsg.recvID === this.storeCurrentConversation.userID)
  1571. );
  1572. case SessionType.WorkingGroup:
  1573. return newServerMsg.groupID === this.storeCurrentConversation.groupID;
  1574. case SessionType.Notification:
  1575. return newServerMsg.sendID === this.storeCurrentConversation.userID;
  1576. default:
  1577. return false;
  1578. }
  1579. },
  1580. markConversationAsRead() {
  1581. IMSDK.asyncApi(IMSDK.IMMethods.MarkConversationMessageAsRead, IMSDK.uuid(), this.storeCurrentConversation.conversationID);
  1582. },
  1583. removeImData(){
  1584. uni.removeStorage({ key: 'IMToken' });
  1585. uni.removeStorage({ key: 'IMUserID' });
  1586. },
  1587. async cidBindAlias(alias){
  1588. let registrationID=uni.getStorageSync("registrationID");
  1589. let params=[{
  1590. "cid":registrationID,
  1591. "alias":alias
  1592. }];
  1593. await uniPush.cidBindAlias(params);
  1594. },
  1595. runTimer() {
  1596. let that = this;
  1597. let dateNowDay = this.$dateFormatStr('YYYY-mm-dd', new Date());
  1598. let healthButler = uni.getStorageSync('healthButler');
  1599. let userInfo = uni.getStorageSync('userInfo');
  1600. console.log('------qxj dateStr:' + dateNowDay + ' healthButler:' + healthButler);
  1601. let dayNum = 0;
  1602. if (userInfo != null && userInfo.isAddQw) {
  1603. //已加过企微不在弹窗
  1604. return;
  1605. }
  1606. if (!!healthButler) {
  1607. healthButler = JSON.parse(healthButler);
  1608. dayNum = healthButler.dayNum;
  1609. if (healthButler.day == dateNowDay) {
  1610. //今天已经弹窗过 防止再弹窗
  1611. return;
  1612. }
  1613. }
  1614. if (dayNum == 0) {
  1615. //第一天下载App
  1616. if (this.$qconfig.healthTimer == null) {
  1617. this.$qconfig.healthTimer = setInterval(() => {
  1618. if (this.$qconfig.healthSeconds == healthSeconds) {
  1619. this.$qconfig.healthSeconds = 0;
  1620. healthButlerPop(function (data) {
  1621. if (data == 1) {
  1622. that.bdAdvFeedback();
  1623. clearInterval(that.$qconfig.healthTimer);
  1624. } else {
  1625. that.resetTimer();
  1626. that.$showLoginPage();
  1627. }
  1628. });
  1629. }
  1630. this.$qconfig.healthSeconds++;
  1631. //console.log("healthTimer tSeconds:"+this.$qconfig.healthSeconds);
  1632. }, 1000);
  1633. }
  1634. }
  1635. else {
  1636. //第二天,第三天,,
  1637. healthButlerPop(function (data) {
  1638. if (data == 1) {
  1639. clearInterval(that.$qconfig.healthTimer);
  1640. } else {
  1641. that.$showLoginPage();
  1642. }
  1643. });
  1644. }
  1645. },
  1646. resetTimer() {
  1647. clearInterval(this.$qconfig.healthTimer);
  1648. this.$qconfig.healthTimer = null; //重置定时器
  1649. this.$qconfig.healthSeconds = healthSeconds;
  1650. },
  1651. getUserInfo(healthButler) {
  1652. getUserInfo().then((res) => {
  1653. if (res.code == 200) {
  1654. if (res.user != null) {
  1655. let registrationID=uni.getStorageSync("registrationID");
  1656. let userInfo = res.user;
  1657. uni.setStorageSync('userInfo', JSON.stringify(res.user));
  1658. if(!userInfo.jpushId || registrationID!=userInfo.jpushId){
  1659. uni.setStorageSync("registrationID","");
  1660. }
  1661. if(!!healthButler){
  1662. healthButler.isAddQw = userInfo.isAddQw;
  1663. uni.setStorageSync('healthButler', JSON.stringify(healthButler));
  1664. }
  1665. }
  1666. }else if(res.code == 500){
  1667. uni.showToast({
  1668. title:"当前用户被禁用",
  1669. icon:"none",
  1670. duration:5000
  1671. });
  1672. setTimeout(()=>{
  1673. uni.$emit('loginOut');
  1674. },5500);
  1675. }
  1676. },
  1677. (rej) => {}
  1678. );
  1679. },
  1680. jumpToNotificationSettings() {
  1681. uni.request({
  1682. url: 'content://settings/action/notification_settings',
  1683. success: function (res) {
  1684. console.log('跳转成功:', res);
  1685. },
  1686. fail: function (err) {
  1687. console.log('跳转失败:', err);
  1688. }
  1689. });
  1690. },
  1691. bdAdvFeedback() {
  1692. // #ifdef APP-PLUS
  1693. if (this.$isAgreePrivacy()) {
  1694. if (plus.runtime.channel == 'baidu') {
  1695. let bdCmdType = uni.getStorageSync('bdCmdType');
  1696. if (this.$isEmpty(bdCmdType)) {
  1697. this.$registerIdCode('goToQw', 4, 0);
  1698. }
  1699. }
  1700. }
  1701. // #endif
  1702. },
  1703. async checkPush() {
  1704. //检测是否开启推送通知
  1705. const notificationAuthorized = uni.getAppAuthorizeSetting().notificationAuthorized;
  1706. if (notificationAuthorized == 'denied') {
  1707. uni.showModal({
  1708. title: '提示',
  1709. content: '是否前往打开通知权限',
  1710. success: (res) => {
  1711. if (res.confirm) {
  1712. let status = this.checkPermission();
  1713. if (status !== 1) {
  1714. console.log('未开启权限');
  1715. }
  1716. } else if (res.cancel) {
  1717. console.log('用户点击取消');
  1718. }
  1719. }
  1720. });
  1721. }
  1722. },
  1723. async checkPermission() {
  1724. let status = permision1.isIOS ? await permision1.requestIOS('push') :
  1725. await permision1.requestAndroid('android.permission.REQUEST_NOTIFICATION_POLICY');
  1726. if (status === null || status === 1) {
  1727. status = 1;
  1728. } else if (status === 2) {
  1729. uni.showModal({
  1730. content: '系统通知已关闭',
  1731. confirmText: '确定',
  1732. showCancel: false,
  1733. success: function (res) {}
  1734. });
  1735. } else if (status.code) {
  1736. uni.showModal({
  1737. content: status.message
  1738. });
  1739. } else {
  1740. uni.showModal({
  1741. content: '需要通知权限',
  1742. confirmText: '设置',
  1743. success: function (res) {
  1744. if (res.confirm) {
  1745. permision1.gotoAppSetting();
  1746. }
  1747. }
  1748. });
  1749. }
  1750. return status;
  1751. },
  1752. geth5Path() {
  1753. getRealLinkDomainName().then((res) => {
  1754. if (res.code == 200) {
  1755. uni.setStorageSync('h5Path', res.data);
  1756. }
  1757. });
  1758. },
  1759. // 系统通知全部已读
  1760. setReadAll(url) {
  1761. if (url && url.indexOf('/pages/courseAnswer/index') == -1) {
  1762. getPushLogRead([]).then((res) => {
  1763. if (res.code == 200) {
  1764. this.$updateMsgDot();
  1765. }
  1766. });
  1767. }
  1768. },
  1769. // 获取剪贴板内容跳转到看课
  1770. getClipboardData() {
  1771. // #ifdef APP-PLUS
  1772. console.log('获取剪贴板内容跳转到看课==========');
  1773. const course = {};
  1774. coursePopup(course, () => {
  1775. // uni.getClipboardData({
  1776. // success: function (res) {
  1777. // console.log("res.data===",res);
  1778. // let Context = plus.android.importClass("android.content.Context");
  1779. // let main = plus.android.runtimeMainActivity();
  1780. // let clip = main.getSystemService(Context.CLIPBOARD_SERVICE);
  1781. // plus.android.invoke(clip,"setText","");
  1782. // }
  1783. // });
  1784. });
  1785. // #endif
  1786. },
  1787. getRuntimePlatform() {
  1788. const systemInfo = uni.getSystemInfoSync();
  1789. const compilePlatform = process.env.UNI_PLATFORM;
  1790. //1:iOS,2:Android,3:Windows,4:OSX,5:WEB,6:小程序,7:linux,8:AndroidPad,9:IPad,10:Admin
  1791. let platformType=5;
  1792. // H5 环境
  1793. if (compilePlatform === 'h5') platformType= 5;
  1794. // 小程序环境
  1795. if (compilePlatform.startsWith('mp-')) {
  1796. const mpType = compilePlatform.split('-')[1]; // 如 weixin/alipay
  1797. platformType=6;
  1798. // return `小程序(${mpType})- ${systemInfo.platform}`;
  1799. }
  1800. // App 环境
  1801. if (compilePlatform === 'app-plus') {
  1802. if(systemInfo.platform.toLowerCase() === 'android'){
  1803. platformType=2;
  1804. }
  1805. if(systemInfo.platform.toLowerCase() === 'ios'){
  1806. platformType=1;
  1807. }
  1808. }
  1809. //uni.showToast({ title:" platformType:"+platformType,icon:'none', duration: 2000 });
  1810. return platformType;
  1811. },
  1812. /* 检查更新 在线更新 */
  1813. checkUpdateApp() {
  1814. //uni wgt包版本检测更新
  1815. //checkUpdate();
  1816. let that = this;
  1817. plus.runtime.getProperty(plus.runtime.appid, function (widgetinfo) {
  1818. if (widgetinfo.name == qconfig.appName) { //APP名称
  1819. let platform = uni.getSystemInfoSync().platform;
  1820. let isAndroid = platform == 'android';
  1821. let type = isAndroid ? 1 : 2;
  1822. getAppVersion(type).then((srcData) => {
  1823. //console.log("qxj getAppVersion srcData",srcData);
  1824. if (srcData.code == 200) {
  1825. if(isAndroid){
  1826. uni.setStorageSync('aVersion', JSON.stringify(srcData));
  1827. }
  1828. let data = srcData.data;
  1829. let version = widgetinfo.versionCode, //用户当前app版本
  1830. appVersion = data.versionCode, //升级包版本
  1831. appName = widgetinfo.name, //app名称
  1832. isForce = data.isForce, //是否强制热更新
  1833. updateConfig = JSON.parse(data.updateConfig),
  1834. appurl = data.url, //升级包地址
  1835. intro = data.note; //升级包提示
  1836. //如果用户版本号小于升级包版本号,先升级
  1837. let afterVer = false;
  1838. if (plus.runtime.channel == 'baidu') {
  1839. afterVer = that.$qconfig.isAppStore ? updateConfig.baidu : false;
  1840. } else if (plus.runtime.channel == 'huawei') {
  1841. afterVer = that.$qconfig.isAppStore ? updateConfig.huawei : false;
  1842. } else if (plus.runtime.channel == 'xiaomi') {
  1843. afterVer = that.$qconfig.isAppStore ? updateConfig.xiaomi : false;
  1844. } else if (plus.runtime.channel == 'yyb') {
  1845. afterVer = that.$qconfig.isAppStore ? updateConfig.yyb : false;
  1846. } else {
  1847. afterVer = that.$qconfig.isAppStore ? isForce : true;
  1848. }
  1849. if (data && version < appVersion && afterVer) {
  1850. uni.showModal({
  1851. title: '更新提示',
  1852. confirmText: '立即升级',
  1853. content: intro,
  1854. cancelText: '确定',
  1855. confirmText: '取消',
  1856. success: (res) => {
  1857. if (res.cancel) {
  1858. openDownload(srcData.data);
  1859. } else if (res.confirm) {
  1860. if (isForce == 1) {
  1861. uni.showToast({ title: '请先升级APP版本', icon: 'none', duration: 2000 });
  1862. //退出app
  1863. setTimeout(function () {
  1864. plus.runtime.quit();
  1865. }, 2000);
  1866. }
  1867. }
  1868. },
  1869. fail: () => {
  1870. uni.hideLoading();
  1871. }
  1872. });
  1873. }
  1874. }
  1875. },
  1876. (rej) => {}
  1877. ).catch(() => {
  1878. //联网失败, 结束加载
  1879. this.mescroll.endErr();
  1880. });
  1881. }
  1882. });
  1883. }
  1884. },
  1885. watch: {
  1886. storeCurrentUserID(newVal) {
  1887. if (newVal) {
  1888. cacheConversationList = [];
  1889. }
  1890. },
  1891. contactBadgeRely: {
  1892. handler(newValue) {
  1893. //console.log("qxj contactBadgeRely newValue",newValue);
  1894. const { recvFriendApplications, recvGroupApplications, userKey } = newValue;
  1895. if (!userKey) return;
  1896. const accessedFriendApplications = uni.getStorageSync(`${userKey}_accessedFriendApplications`) || [];
  1897. //console.log("qxj accessedFriendApplications",accessedFriendApplications);
  1898. let unHandleFriendApplicationNum = recvFriendApplications.filter(
  1899. (application) => application.handleResult === 0 && !accessedFriendApplications.includes(`${application.fromUserID}_${application.createTime}`)
  1900. ).length;
  1901. const accessedGroupApplications = uni.getStorageSync(`${userKey}_accessedGroupApplications`) || [];
  1902. let unHandleGroupApplicationNum = recvGroupApplications.filter(
  1903. (application) => application.handleResult === 0 && !accessedGroupApplications.includes(`${application.userID}_${application.createTime}`)
  1904. ).length;
  1905. //console.log("qxj unHandleFriendApplicationNum",unHandleFriendApplicationNum);
  1906. const total = unHandleFriendApplicationNum + unHandleGroupApplicationNum;
  1907. // if (total) {
  1908. // uni.setTabBarBadge({ index: 0, text: total < 99 ? total + '' : '99+' });
  1909. // } else {
  1910. // uni.removeTabBarBadge({ index: 0 });
  1911. // }
  1912. this.$store.commit('contact/SET_UNHANDLE_FRIEND_APPLICATION_NUM', unHandleFriendApplicationNum);
  1913. this.$store.commit('contact/SET_UNHANDLE_GROUP_APPLICATION_NUM', unHandleGroupApplicationNum);
  1914. },
  1915. deep: true
  1916. }
  1917. }
  1918. };
  1919. </script>
  1920. <style lang="scss">
  1921. /*每个页面公共css */
  1922. @import '@/assets/css/common.scss';
  1923. @import '@/uni_modules/uview-plus/index.scss';
  1924. /*#ifndef APP-NVUE*/
  1925. view {
  1926. box-sizing: border-box;
  1927. }
  1928. .ellipsis {
  1929. overflow: hidden;
  1930. text-overflow: ellipsis;
  1931. white-space: nowrap;
  1932. }
  1933. .ellipsis2 {
  1934. overflow: hidden;
  1935. text-overflow: ellipsis;
  1936. display: -webkit-box;
  1937. -webkit-box-orient: vertical;
  1938. -webkit-line-clamp: 2;
  1939. }
  1940. uni-modal {
  1941. z-index: 1100;
  1942. }
  1943. .no-data-box {
  1944. height: 100%;
  1945. width: 100%;
  1946. display: flex;
  1947. justify-content: center;
  1948. align-items: center;
  1949. flex-direction: column;
  1950. image {
  1951. width: 264upx;
  1952. height: 212upx;
  1953. }
  1954. .empty-title {
  1955. margin-top: 20rpx;
  1956. font-size: 28rpx;
  1957. color: gray;
  1958. }
  1959. }
  1960. .doctor-box {
  1961. margin-top: 15rpx;
  1962. padding: 20rpx 0rpx 0rpx;
  1963. display: flex;
  1964. flex-direction: column;
  1965. align-items: flex-start;
  1966. justify-content: flex-start;
  1967. .doctor {
  1968. width: 100%;
  1969. margin-bottom: 15rpx;
  1970. background: #f9f8fe;
  1971. padding: 15rpx;
  1972. display: flex;
  1973. flex-direction: column;
  1974. align-items: flex-start;
  1975. justify-content: flex-start;
  1976. &:last-child {
  1977. margin-bottom: 0rpx;
  1978. }
  1979. .item {
  1980. width: 100%;
  1981. display: flex;
  1982. align-items: flex-start;
  1983. justify-content: flex-start;
  1984. .left {
  1985. .head-box {
  1986. width: 92rpx;
  1987. height: 92rpx;
  1988. position: relative;
  1989. .isline {
  1990. width: 92rpx;
  1991. height: 92rpx;
  1992. border-radius: 50%;
  1993. border: 2rpx solid #e69a22;
  1994. display: flex;
  1995. align-items: center;
  1996. justify-content: center;
  1997. position: absolute;
  1998. bottom: 0rpx;
  1999. .img {
  2000. position: absolute;
  2001. bottom: 1rpx;
  2002. width: 75rpx;
  2003. height: 35rpx;
  2004. image {
  2005. width: 75rpx;
  2006. height: 35rpx;
  2007. }
  2008. .name {
  2009. width: 75rpx;
  2010. height: 35rpx;
  2011. bottom: -3rpx;
  2012. text-align: center;
  2013. position: absolute;
  2014. font-size: 16upx;
  2015. font-family: PingFang SC;
  2016. font-weight: bold;
  2017. color: #ffffff;
  2018. }
  2019. }
  2020. }
  2021. .doc-img {
  2022. border-radius: 50%;
  2023. width: 100%;
  2024. height: 100%;
  2025. }
  2026. }
  2027. }
  2028. .right {
  2029. width: calc(100% - 100rpx);
  2030. margin-left: 20rpx;
  2031. display: flex;
  2032. flex-direction: column;
  2033. align-items: flex-start;
  2034. justify-content: flex-start;
  2035. .doc-box {
  2036. display: flex;
  2037. align-items: center;
  2038. justify-content: space-between;
  2039. .doc-name {
  2040. font-size: 32upx;
  2041. font-family: PingFang SC;
  2042. font-weight: bold;
  2043. color: #111111;
  2044. }
  2045. .doc-position {
  2046. margin-left: 16rpx;
  2047. font-size: 26upx;
  2048. font-weight: bold;
  2049. font-family: PingFang SC;
  2050. color: #2a2b2e;
  2051. }
  2052. .doc-dept {
  2053. margin-left: 16rpx;
  2054. font-size: 26upx;
  2055. font-weight: bold;
  2056. font-family: PingFang SC;
  2057. color: #2a2b2e;
  2058. }
  2059. }
  2060. .hospital-box {
  2061. display: flex;
  2062. align-items: center;
  2063. justify-content: flex-start;
  2064. margin-top: 10rpx;
  2065. .tag {
  2066. display: flex;
  2067. align-items: center;
  2068. justify-content: center;
  2069. background-color: #4fc06b;
  2070. border-radius: 10rpx;
  2071. padding: 5rpx 10rpx;
  2072. font-size: 20upx;
  2073. font-weight: bold;
  2074. font-family: PingFang SC;
  2075. color: #ffffff;
  2076. }
  2077. .name {
  2078. margin-left: 6rpx;
  2079. font-size: 26upx;
  2080. font-weight: bold;
  2081. font-family: PingFang SC;
  2082. color: #2a2b2e;
  2083. }
  2084. }
  2085. .doc-spec {
  2086. width: 100%;
  2087. display: flex;
  2088. align-items: center;
  2089. justify-content: flex-start;
  2090. margin-top: 15rpx;
  2091. .spec {
  2092. font-size: 26upx;
  2093. font-family: PingFang SC;
  2094. color: #626468;
  2095. }
  2096. }
  2097. .doc-count {
  2098. margin-top: 15rpx;
  2099. display: flex;
  2100. align-items: center;
  2101. justify-content: flex-start;
  2102. .name {
  2103. font-size: 24upx;
  2104. font-family: PingFang SC;
  2105. color: #9b9b9b;
  2106. }
  2107. .count {
  2108. margin: 0rpx 5rpx;
  2109. font-size: 24upx;
  2110. font-family: PingFang SC;
  2111. color: #2a2b2e;
  2112. }
  2113. }
  2114. .doc-price {
  2115. width: 100%;
  2116. margin-top: 15rpx;
  2117. display: flex;
  2118. align-items: center;
  2119. justify-content: flex-start;
  2120. .btn {
  2121. display: flex;
  2122. align-items: center;
  2123. justify-content: center;
  2124. background-color: #feefd7;
  2125. padding: 15rpx 30rpx;
  2126. border-radius: 30rpx;
  2127. font-size: 26upx;
  2128. font-family: PingFang SC;
  2129. color: #e69a22;
  2130. }
  2131. }
  2132. }
  2133. }
  2134. }
  2135. }
  2136. /*#endif*/
  2137. </style>
  2138. <style lang="less">
  2139. /*每个页面公共css */
  2140. // @import './assets/iconfont/iconfont.css';
  2141. @import './assets/css/common.less';
  2142. /* 全局flex样式 */
  2143. @import './common/css/flexCommon.css';
  2144. /*引入全局补充样式*/
  2145. @import './assets/css/czy/es.1.base.css';
  2146. @import './assets/css/czy/es.2.color.css';
  2147. @import './assets/css/czy/es.3.icon.css';
  2148. @import './assets/css/czy/es.4.view.css';
  2149. .textOne {
  2150. overflow: hidden;
  2151. white-space: nowrap;
  2152. text-overflow: ellipsis;
  2153. }
  2154. .textTwo {
  2155. overflow: hidden;
  2156. text-overflow: ellipsis;
  2157. display: -webkit-box;
  2158. -webkit-line-clamp: 2;
  2159. -webkit-box-orient: vertical;
  2160. }
  2161. </style>