App.vue 63 KB

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