App.vue 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295
  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("U4056541205");
  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. this.$store.dispatch('contact/getRecvFriendApplications');
  1175. this.$store.dispatch('contact/getSentFriendApplications');
  1176. this.$store.dispatch('contact/getRecvGroupApplications');
  1177. this.$store.dispatch('contact/getSentGroupApplications');
  1178. // #ifdef APP-PLUS
  1179. plus.navigator.closeSplashscreen();
  1180. // 启动页关闭后创建浮标
  1181. this.createComplaintFloatAfterSplash();
  1182. // #endif
  1183. };
  1184. let IMToken = uni.getStorageSync('IMToken');
  1185. let IMUserID = uni.getStorageSync('IMUserID');
  1186. //console.log("qxj IMToken:"+IMToken+" IMUserID:"+IMUserID);
  1187. // #ifdef APP-PLUS
  1188. getDbDir().then(async (path) => {
  1189. let platformID=uni.$u.os() === 'ios' ? 1 : 2;
  1190. const flag = await IMSDK.asyncApi(IMMethods.InitSDK, IMSDK.uuid(), {
  1191. systemType: 'uni-app',
  1192. platformID:platformID,
  1193. apiAddr: config.getApiUrl(),
  1194. wsAddr: config.getWsUrl(),
  1195. dataDir: path, // 数据存储路径
  1196. logLevel: 2,//正式环境2或者3 测试:5
  1197. logFilePath: path,
  1198. isLogStandardOutput: true // 是否输出到控制台
  1199. });
  1200. if (!flag) {
  1201. // #ifdef APP-PLUS
  1202. plus.navigator.closeSplashscreen();
  1203. // 启动页关闭后创建浮标
  1204. this.createComplaintFloatAfterSplash();
  1205. // #endif
  1206. uni.$u.toast('初始化IMSDK失败!');
  1207. return;
  1208. }
  1209. //1 未登录 2 登录中 3 已登录
  1210. const loginStatus = await IMSDK.asyncApi(IMSDK.IMMethods.GetLoginStatus, IMSDK.uuid());
  1211. if (loginStatus === 3) {
  1212. initStore();
  1213. return;
  1214. }
  1215. callingModule?.initModule();
  1216. if (IMToken && IMUserID) {
  1217. await IMSDK.asyncApi(IMSDK.IMMethods.Login, IMSDK.uuid(), {
  1218. userID: IMUserID,
  1219. token: IMToken,
  1220. }).then(initStore).catch((err) => {
  1221. console.log('qxj initStore err:' + JSON.stringify(err));
  1222. uni.$u.toast('初始化IMSDK异常:'+JSON.stringify(err));
  1223. uni.removeStorage({ key: 'IMToken' });
  1224. // #ifdef APP-PLUS
  1225. plus.navigator.closeSplashscreen();
  1226. // 启动页关闭后创建浮标
  1227. this.createComplaintFloatAfterSplash();
  1228. // #endif
  1229. });
  1230. } else {
  1231. if(this.$isLogin()){
  1232. this.openImLogin();
  1233. }
  1234. // #ifdef APP-PLUS
  1235. plus.navigator.closeSplashscreen();
  1236. // 启动页关闭后创建浮标
  1237. this.createComplaintFloatAfterSplash();
  1238. // #endif
  1239. }
  1240. }).catch((err) => {
  1241. console.log('get dir failed');
  1242. console.log(err);
  1243. // #ifdef APP-PLUS
  1244. plus.navigator.closeSplashscreen();
  1245. // 启动页关闭后创建浮标
  1246. this.createComplaintFloatAfterSplash();
  1247. // #endif
  1248. });
  1249. // #endif
  1250. // #ifdef H5
  1251. console.log("qxj IMTokenUserId",IMToken,IMUserID);
  1252. if (IMToken && IMUserID) {
  1253. IMSDK.asyncApi(IMSDK.IMMethods.Login, IMSDK.uuid(), {
  1254. userID: IMUserID,
  1255. token: IMToken,
  1256. platformID:5,
  1257. logLevel: 2,
  1258. apiAddr: config.getApiUrl(),
  1259. wsAddr: config.getWsUrl(),
  1260. }).then(initStore).catch((err) => {
  1261. console.log('qxj initStore:',err);
  1262. uni.removeStorage({ key: 'IMToken' });
  1263. });
  1264. return;
  1265. }
  1266. else{
  1267. if(this.$isLogin()){
  1268. this.openImLogin();
  1269. }
  1270. }
  1271. // #endif
  1272. },
  1273. testTryLogin(uid){
  1274. uni.setStorageSync('IMToken',null);
  1275. let IMToken = uni.getStorageSync('IMToken');
  1276. let IMUserID = uid;
  1277. let reqData = { userID:uid, nickName:"" };
  1278. let that=this;
  1279. testImLoginApi(reqData,IMToken,IMUserID,function (token) {
  1280. setTimeout(()=>{
  1281. that.tryLogin();
  1282. },100);
  1283. },
  1284. function () {
  1285. uni.$u.toast('IM登录失败!');
  1286. }
  1287. );
  1288. },
  1289. async newMessageNotify(newServerMsg) {
  1290. if (this.storeIsSyncing) {
  1291. return;
  1292. }
  1293. //console.log("qxj newMessageNotify1");
  1294. const disableNotify = uni.getStorageSync(`${this.storeCurrentUserID}_DisableNotify`);
  1295. if (disableNotify || this.storeSelfInfo.globalRecvMsgOpt !== MessageReceiveOptType.Nomal) {
  1296. return;
  1297. }
  1298. //console.log("qxj newMessageNotify2");
  1299. let cveItem = [...this.storeConversationList, ...cacheConversationList].find((conversation) => {
  1300. if (newServerMsg.sessionType === SessionType.WorkingGroup) {
  1301. return newServerMsg.groupID === conversation.groupID;
  1302. }
  1303. return newServerMsg.sendID === conversation.userID;
  1304. });
  1305. //console.log("qxj newMessageNotify3");
  1306. if (!cveItem) {
  1307. try {
  1308. const { data } = await IMSDK.asyncApi(IMSDK.IMMethods.GetOneConversation, IMSDK.uuid(), {
  1309. sourceID: newServerMsg.groupID || newServerMsg.sendID,
  1310. sessionType: newServerMsg.sessionType
  1311. });
  1312. cveItem = data;
  1313. cacheConversationList = [...cacheConversationList, data];
  1314. } catch (e) {
  1315. return;
  1316. }
  1317. }
  1318. //console.log("qxj newMessageNotify4");
  1319. if (cveItem.recvMsgOpt !== MessageReceiveOptType.Normal) {
  1320. return;
  1321. }
  1322. //console.log("qxj newMessageNotify5");
  1323. const notificationFun = () => {
  1324. const isSelf = newServerMsg.sendID === this.$store.getters.storeCurrentUserID;
  1325. if (isSelf) return;
  1326. // const pages = getCurrentPages();
  1327. // const url = pages[ pages.length - 1];
  1328. const url=this.$getCurrentPage();
  1329. if(url&& (url.route=="pages_im/pages/conversation/conversationList/index"
  1330. || url.route=="pages_im/pages/conversation/chating/index") ){
  1331. return;
  1332. }
  1333. // uni.createPushMessage({
  1334. // content: `${newServerMsg.senderNickname}: ${parseMessageByType(newServerMsg)}`,
  1335. // payload: {
  1336. // sessionType: newServerMsg.sessionType,
  1337. // sourceID: newServerMsg.groupID || newServerMsg.sendID,
  1338. // }
  1339. // });
  1340. const isSingle = newServerMsg.groupID ? false : true;
  1341. console.log(this.storeGroupList, newServerMsg);
  1342. const group = this.storeGroupList.filter((group) => group.groupID === newServerMsg.groupID);
  1343. const title = isSingle ? newServerMsg.senderNickname : group[0].groupName;
  1344. const desc = parseMessageByType(newServerMsg);
  1345. console.log('notification', title, desc);
  1346. // notificationIntance = new NotificationUtil();
  1347. // let tickerTips="通知提示";
  1348. // let notifyId=10001;
  1349. // let config={ title, desc,tickerTips,notifyId };
  1350. // notificationIntance.createNotification(config);
  1351. // setTimeout(()=>{
  1352. // notificationIntance.clearNotification(10001);
  1353. // },10000);
  1354. // notification.showNotice(0, title, desc, () => {
  1355. // prepareConversationState(cveItem);
  1356. // });
  1357. };
  1358. //notificationFun();
  1359. const platform = uni.getSystemInfoSync().platform;
  1360. if (platform == 'ios') {
  1361. if (this.storeSelfInfo.allowVibration === 1) {
  1362. plus.device.vibrate();
  1363. }
  1364. if (this.storeSelfInfo.allowBeep === 1) {
  1365. innerAudioContext.play();
  1366. // plus.device.beep();
  1367. }
  1368. }
  1369. else if (platform == 'android') {
  1370. if (this.storeSelfInfo.allowVibration === 1) {
  1371. plus.device.vibrate(500);
  1372. }
  1373. if (this.storeSelfInfo.allowBeep === 1) {
  1374. let main = plus.android.runtimeMainActivity();
  1375. let RingtoneManager = plus.android.importClass('android.media.RingtoneManager');
  1376. let uri = RingtoneManager.getActualDefaultRingtoneUri(main, RingtoneManager.TYPE_NOTIFICATION);
  1377. let MediaPlayer = plus.android.importClass('android.media.MediaPlayer');
  1378. let player = MediaPlayer.create(main, uri);
  1379. player.setLooping(false);
  1380. player.prepare();
  1381. player.start();
  1382. }
  1383. }
  1384. },
  1385. async notifyGoToChat(newServerMsg){
  1386. console.log("qxj notifyGoToChat",newServerMsg);
  1387. if (this.storeIsSyncing) {
  1388. return;
  1389. }
  1390. offlineHandleNewMsg=null;
  1391. offlineMsg=null;
  1392. // const disableNotify = uni.getStorageSync(`${this.storeCurrentUserID}_DisableNotify`);
  1393. // if (disableNotify || this.storeSelfInfo.globalRecvMsgOpt !== MessageReceiveOptType.Nomal) {
  1394. // return;
  1395. // }
  1396. let cveItem = [...this.storeConversationList, ...cacheConversationList].find((conversation) => {
  1397. if (newServerMsg.sessionType === SessionType.WorkingGroup) {
  1398. return newServerMsg.groupID === conversation.groupID;
  1399. }
  1400. return newServerMsg.sendID === conversation.userID;
  1401. });
  1402. console.log("qxj notifyGoToChat cveItem",cveItem);
  1403. if (!cveItem) {
  1404. try {
  1405. const { data } = await IMSDK.asyncApi(IMSDK.IMMethods.GetOneConversation, IMSDK.uuid(), {
  1406. sourceID: newServerMsg.groupID || newServerMsg.sendID,
  1407. sessionType: newServerMsg.sessionType
  1408. });
  1409. cveItem = data;
  1410. cacheConversationList = [...cacheConversationList, data];
  1411. } catch (e) {
  1412. return;
  1413. }
  1414. }
  1415. if (cveItem.recvMsgOpt !== MessageReceiveOptType.Normal) {
  1416. return;
  1417. }
  1418. const isSelf = newServerMsg.sendID === this.$store.getters.storeCurrentUserID;
  1419. if (isSelf) return;
  1420. // const pages = getCurrentPages();
  1421. // const url = pages[ pages.length - 1];
  1422. const url=this.$getCurrentPage();
  1423. if(url && (url.route=="pages_im/pages/conversation/chating/index" || url.route=="pages_im/pages/conversation/chating1/index") ){
  1424. return;
  1425. }
  1426. this.handlerConversation(cveItem);
  1427. setTimeout(()=>{
  1428. prepareConversationState(cveItem);
  1429. //uni.removeStorageSync("serverMsgID");
  1430. },200);
  1431. },
  1432. handlerConversation(source){
  1433. let userId=source.userID;
  1434. let isDoctor=false;
  1435. if(userId!=undefined && (userId!="" || userId.length>0)){
  1436. if(userId.indexOf('D')!==-1){
  1437. isDoctor=true;
  1438. }
  1439. }
  1440. if(this.$companyUserIsLogin() || !isDoctor){
  1441. this.$store.commit("timStore/setImType",1);
  1442. }
  1443. else{
  1444. let ex=source.ex;
  1445. if(source.latestMsg!=null && source.latestMsg!=''){
  1446. let latestMsg=JSON.parse(source.latestMsg);
  1447. if(!!latestMsg.ex && latestMsg.ex!=''){
  1448. ex=latestMsg.ex;
  1449. }
  1450. }
  1451. if(ex!=null || ex!=''){
  1452. try{
  1453. var json=JSON.parse(ex);
  1454. this.$store.commit("timStore/setImType", json.imType);
  1455. this.$store.commit("timStore/setOrderType", json.orderType);
  1456. this.$store.commit("timStore/setOrderId", json.orderId);
  1457. this.$store.commit("timStore/setFollowId", json.followId);
  1458. this.$store.commit("timStore/setType", json.type);
  1459. }
  1460. catch(e){
  1461. }
  1462. }
  1463. }
  1464. this.$store.commit("timStore/setConversationID", source.conversationID);
  1465. },
  1466. handleNewMessage(newServerMsg) {
  1467. //console.log("---qxj handleNewMessage",newServerMsg);
  1468. if (this.inCurrentConversation(newServerMsg)) {
  1469. const isSingleMessage = newServerMsg.sessionType === SessionType.Single;
  1470. if (isSingleMessage) {
  1471. uni.$u.throttle(() => uni.$emit(PageEvents.OnlineStateCheck), 2000);
  1472. if(newServerMsg.ex!=null&&newServerMsg.ex!=''){
  1473. var json=JSON.parse(newServerMsg.ex);
  1474. this.$store.commit("timStore/setType",json.type);
  1475. this.$store.commit("timStore/setImType", json.imType);
  1476. this.$store.commit("timStore/setOrderId",json.orderId);
  1477. this.$store.commit("timStore/setOrderType",json.orderType);
  1478. this.$store.commit("timStore/setFollowId",json.followId);
  1479. if(json.type==="finishInquiry"){
  1480. this.$store.commit("timStore/setImType", 0);
  1481. uni.navigateTo({ url: "/pages_order/pingOrder?orderId="+json.orderId })
  1482. }
  1483. else if(json.type==="startInquiry"){
  1484. }
  1485. else if(json.type==="inquiry"){
  1486. }
  1487. else if(json.type==="startFollow"){
  1488. }
  1489. else if(json.type==="follow"){
  1490. }
  1491. else if(json.type==="finishFollow"){
  1492. }
  1493. else if(json.type==="startDrugReport"){
  1494. }
  1495. else if(json.type==="finishDrugReport"){
  1496. }
  1497. else if(json.type==="drugReport"){
  1498. }
  1499. }
  1500. }
  1501. if (newServerMsg.contentType === MessageType.TypingMessage) {
  1502. if (isSingleMessage) {
  1503. uni.$emit(PageEvents.TypingUpdate);
  1504. }
  1505. }
  1506. else {
  1507. if (newServerMsg.contentType != MessageType.RevokeMessage) {
  1508. newServerMsg.isAppend = true;
  1509. this.pushNewMessage(newServerMsg);
  1510. setTimeout(() => uni.$emit(PageEvents.ScrollToBottom, true));
  1511. }
  1512. uni.$u.debounce(this.markConversationAsRead, 2000);
  1513. }
  1514. }
  1515. else {
  1516. if (newServerMsg.contentType !== MessageType.TypingMessage) {
  1517. uni.$u.throttle(() => this.newMessageNotify(newServerMsg), 1000);
  1518. setTimeout(() => {
  1519. this.$store.dispatch('conversation/getUnReadCount');
  1520. },500);
  1521. }
  1522. }
  1523. },
  1524. handleOfflineMessages(newServerMsg){ //后台运行
  1525. const isSingle = newServerMsg.groupID ? false : true;
  1526. const group = this.storeGroupList.filter((group) => group.groupID === newServerMsg.groupID);
  1527. const title = isSingle ? newServerMsg.senderNickname : group[0].groupName;
  1528. const desc = parseMessageByType(newServerMsg);
  1529. // if(notification){
  1530. // notification.showNotice(0, title, desc, () => {
  1531. // console.log('qxj showNotice:', title);
  1532. // setTimeout(() => {
  1533. // uni.switchTab({url: 'pages_im/pages/conversation/conversationList/index'});
  1534. // },2000);
  1535. // });
  1536. // }
  1537. // const options = {
  1538. // title: title,
  1539. // content: desc,
  1540. // payload: newServerMsg, // 自定义参数,点击通知时传递给应用
  1541. // sound: 'default', // 通知声音
  1542. // cover: false, // 是否覆盖之前的通知
  1543. // //when: new Date(),
  1544. // icon:"",
  1545. // extras: {
  1546. // android: {
  1547. // importance: "high", // 高优先级
  1548. // channelId: "IM通知", // 必须配置通知渠道
  1549. // smallIcon: "transparent",
  1550. // showWhen: false,
  1551. // }
  1552. // }
  1553. // };
  1554. // plus.push.createMessage(options.content, options.payload, options);
  1555. // let when=new Date();
  1556. // uni.createPushMessage({
  1557. // title:title,
  1558. // content:desc,
  1559. // payload: newServerMsg,
  1560. // cover: false, // 是否覆盖之前的通知
  1561. // when: new Date()
  1562. // });
  1563. },
  1564. inCurrentConversation(newServerMsg) {
  1565. switch (newServerMsg.sessionType) {
  1566. case SessionType.Single:
  1567. return (
  1568. newServerMsg.sendID === this.storeCurrentConversation.userID ||
  1569. (newServerMsg.sendID === this.storeCurrentUserID && newServerMsg.recvID === this.storeCurrentConversation.userID)
  1570. );
  1571. case SessionType.WorkingGroup:
  1572. return newServerMsg.groupID === this.storeCurrentConversation.groupID;
  1573. case SessionType.Notification:
  1574. return newServerMsg.sendID === this.storeCurrentConversation.userID;
  1575. default:
  1576. return false;
  1577. }
  1578. },
  1579. markConversationAsRead() {
  1580. IMSDK.asyncApi(IMSDK.IMMethods.MarkConversationMessageAsRead, IMSDK.uuid(), this.storeCurrentConversation.conversationID);
  1581. },
  1582. removeImData(){
  1583. uni.removeStorage({ key: 'IMToken' });
  1584. uni.removeStorage({ key: 'IMUserID' });
  1585. },
  1586. async cidBindAlias(alias){
  1587. let registrationID=uni.getStorageSync("registrationID");
  1588. let params=[{
  1589. "cid":registrationID,
  1590. "alias":alias
  1591. }];
  1592. console.log("qxj cidBindAlias params:"+JSON.stringify(params));
  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 '@/uni_modules/uview-plus/index.scss';
  1923. /*#ifndef APP-NVUE*/
  1924. view {
  1925. box-sizing: border-box;
  1926. }
  1927. .ellipsis {
  1928. overflow: hidden;
  1929. text-overflow: ellipsis;
  1930. white-space: nowrap;
  1931. }
  1932. .ellipsis2 {
  1933. overflow: hidden;
  1934. text-overflow: ellipsis;
  1935. display: -webkit-box;
  1936. -webkit-box-orient: vertical;
  1937. -webkit-line-clamp: 2;
  1938. }
  1939. uni-modal {
  1940. z-index: 1100;
  1941. }
  1942. // 猜你喜欢样式
  1943. .like-box {
  1944. display: flex;
  1945. align-items: center;
  1946. justify-content: center;
  1947. image {
  1948. height: 40upx;
  1949. width: 40upx;
  1950. }
  1951. .text {
  1952. font-size: 28upx;
  1953. color: #000;
  1954. font-weight: bold;
  1955. margin: 0 10upx;
  1956. }
  1957. }
  1958. .no-data-box {
  1959. height: 100%;
  1960. width: 100%;
  1961. display: flex;
  1962. justify-content: center;
  1963. align-items: center;
  1964. flex-direction: column;
  1965. image {
  1966. width: 264upx;
  1967. height: 212upx;
  1968. }
  1969. .empty-title {
  1970. margin-top: 20rpx;
  1971. font-size: 28rpx;
  1972. color: gray;
  1973. }
  1974. }
  1975. .doctor-box {
  1976. margin-top: 15rpx;
  1977. padding: 20rpx 0rpx 0rpx;
  1978. display: flex;
  1979. flex-direction: column;
  1980. align-items: flex-start;
  1981. justify-content: flex-start;
  1982. .doctor {
  1983. width: 100%;
  1984. margin-bottom: 15rpx;
  1985. background: #f9f8fe;
  1986. padding: 15rpx;
  1987. display: flex;
  1988. flex-direction: column;
  1989. align-items: flex-start;
  1990. justify-content: flex-start;
  1991. &:last-child {
  1992. margin-bottom: 0rpx;
  1993. }
  1994. .item {
  1995. width: 100%;
  1996. display: flex;
  1997. align-items: flex-start;
  1998. justify-content: flex-start;
  1999. .left {
  2000. .head-box {
  2001. width: 92rpx;
  2002. height: 92rpx;
  2003. position: relative;
  2004. .isline {
  2005. width: 92rpx;
  2006. height: 92rpx;
  2007. border-radius: 50%;
  2008. border: 2rpx solid #e69a22;
  2009. display: flex;
  2010. align-items: center;
  2011. justify-content: center;
  2012. position: absolute;
  2013. bottom: 0rpx;
  2014. .img {
  2015. position: absolute;
  2016. bottom: 1rpx;
  2017. width: 75rpx;
  2018. height: 35rpx;
  2019. image {
  2020. width: 75rpx;
  2021. height: 35rpx;
  2022. }
  2023. .name {
  2024. width: 75rpx;
  2025. height: 35rpx;
  2026. bottom: -3rpx;
  2027. text-align: center;
  2028. position: absolute;
  2029. font-size: 16upx;
  2030. font-family: PingFang SC;
  2031. font-weight: bold;
  2032. color: #ffffff;
  2033. }
  2034. }
  2035. }
  2036. .doc-img {
  2037. border-radius: 50%;
  2038. width: 100%;
  2039. height: 100%;
  2040. }
  2041. }
  2042. }
  2043. .right {
  2044. width: calc(100% - 100rpx);
  2045. margin-left: 20rpx;
  2046. display: flex;
  2047. flex-direction: column;
  2048. align-items: flex-start;
  2049. justify-content: flex-start;
  2050. .doc-box {
  2051. display: flex;
  2052. align-items: center;
  2053. justify-content: space-between;
  2054. .doc-name {
  2055. font-size: 32upx;
  2056. font-family: PingFang SC;
  2057. font-weight: bold;
  2058. color: #111111;
  2059. }
  2060. .doc-position {
  2061. margin-left: 16rpx;
  2062. font-size: 26upx;
  2063. font-weight: bold;
  2064. font-family: PingFang SC;
  2065. color: #2a2b2e;
  2066. }
  2067. .doc-dept {
  2068. margin-left: 16rpx;
  2069. font-size: 26upx;
  2070. font-weight: bold;
  2071. font-family: PingFang SC;
  2072. color: #2a2b2e;
  2073. }
  2074. }
  2075. .hospital-box {
  2076. display: flex;
  2077. align-items: center;
  2078. justify-content: flex-start;
  2079. margin-top: 10rpx;
  2080. .tag {
  2081. display: flex;
  2082. align-items: center;
  2083. justify-content: center;
  2084. background-color: #4fc06b;
  2085. border-radius: 10rpx;
  2086. padding: 5rpx 10rpx;
  2087. font-size: 20upx;
  2088. font-weight: bold;
  2089. font-family: PingFang SC;
  2090. color: #ffffff;
  2091. }
  2092. .name {
  2093. margin-left: 6rpx;
  2094. font-size: 26upx;
  2095. font-weight: bold;
  2096. font-family: PingFang SC;
  2097. color: #2a2b2e;
  2098. }
  2099. }
  2100. .doc-spec {
  2101. width: 100%;
  2102. display: flex;
  2103. align-items: center;
  2104. justify-content: flex-start;
  2105. margin-top: 15rpx;
  2106. .spec {
  2107. font-size: 26upx;
  2108. font-family: PingFang SC;
  2109. color: #626468;
  2110. }
  2111. }
  2112. .doc-count {
  2113. margin-top: 15rpx;
  2114. display: flex;
  2115. align-items: center;
  2116. justify-content: flex-start;
  2117. .name {
  2118. font-size: 24upx;
  2119. font-family: PingFang SC;
  2120. color: #9b9b9b;
  2121. }
  2122. .count {
  2123. margin: 0rpx 5rpx;
  2124. font-size: 24upx;
  2125. font-family: PingFang SC;
  2126. color: #2a2b2e;
  2127. }
  2128. }
  2129. .doc-price {
  2130. width: 100%;
  2131. margin-top: 15rpx;
  2132. display: flex;
  2133. align-items: center;
  2134. justify-content: flex-start;
  2135. .btn {
  2136. display: flex;
  2137. align-items: center;
  2138. justify-content: center;
  2139. background-color: #feefd7;
  2140. padding: 15rpx 30rpx;
  2141. border-radius: 30rpx;
  2142. font-size: 26upx;
  2143. font-family: PingFang SC;
  2144. color: #e69a22;
  2145. }
  2146. }
  2147. }
  2148. }
  2149. }
  2150. }
  2151. /*#endif*/
  2152. </style>
  2153. <style lang="less">
  2154. /*每个页面公共css */
  2155. // @import './assets/iconfont/iconfont.css';
  2156. @import './assets/css/common.less';
  2157. /* 全局flex样式 */
  2158. @import './common/css/flexCommon.css';
  2159. /*引入全局补充样式*/
  2160. @import './assets/css/czy/es.1.base.css';
  2161. @import './assets/css/czy/es.2.color.css';
  2162. @import './assets/css/czy/es.3.icon.css';
  2163. @import './assets/css/czy/es.4.view.css';
  2164. .textOne {
  2165. overflow: hidden;
  2166. white-space: nowrap;
  2167. text-overflow: ellipsis;
  2168. }
  2169. .textTwo {
  2170. overflow: hidden;
  2171. text-overflow: ellipsis;
  2172. display: -webkit-box;
  2173. -webkit-line-clamp: 2;
  2174. -webkit-box-orient: vertical;
  2175. }
  2176. </style>