App.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  1. <script>
  2. //app.js
  3. const req = require("./utils/request.js");
  4. // // #ifndef H5
  5. // let livePlayer = requirePlugin('live-player-plugin')
  6. // // #endif
  7. // import _chunkArr from './hxChatSDK/utils/chunkArr';
  8. // let WebIM = (wx.WebIM = require("./hxChatSDK/utils/WebIM")["default"]);
  9. // let msgStorage = require("./chat/components/chat/msgstorage");
  10. // let msgType = require("./chat/components/chat/msgtype");
  11. // let disp = require("./hxChatSDK/utils/broadcast");
  12. // let logout = false;
  13. // import {
  14. // onGetSilentConfig
  15. // } from './chat/components/chat/pushStorage'
  16. export default {
  17. onLaunch: function(options) {
  18. //拉取模板配置自定义详细
  19. if (wx.getExtConfig) {
  20. wx.getExtConfig({
  21. success(res) {
  22. console.log(res.extConfig)
  23. if (res.extConfig && res.extConfig.NODE_ENV) {
  24. req.env.NODE_ENV = res.extConfig.NODE_ENV;
  25. }
  26. if (res.extConfig && res.extConfig.authAppId) {
  27. req.setStorage('appId', res.extConfig.authAppId)
  28. }
  29. }
  30. })
  31. }
  32. req.removeStorage('isShowUpdateMobile')
  33. req.removeStorage('isShowUpdateInfo')
  34. let scene = options.scene;
  35. req.setStorage('scene', scene)
  36. let arr = [1195, 1193, 1191, 1184, 1177, 1176, 1175, 1201, 1216, 10001]
  37. req.setStorage('isVideoScene', false)
  38. arr.some(it => {
  39. if (it === scene) {
  40. req.setStorage('isVideoScene', true)
  41. }
  42. })
  43. this.globalData.InitUpdateManager();
  44. this.globalData.getChatList();
  45. this.globalData.upColor()
  46. // #ifndef APP-PLUS
  47. uni.hideTabBar()
  48. // #endif
  49. // req.getWebchatAppId();
  50. // var me = this;
  51. // var logs = uni.getStorageSync("logs") || [];
  52. // logs.unshift(Date.now());
  53. // uni.setStorageSync("logs", logs);
  54. // disp.on("em.main.ready", function() {
  55. // calcUnReadSpot();
  56. // });
  57. // disp.on("em.chatroom.leave", function() {
  58. // calcUnReadSpot();
  59. // });
  60. // disp.on("em.chat.session.remove", function() {
  61. // calcUnReadSpot();
  62. // });
  63. // disp.on("em.chat.audio.fileLoaded", function() {
  64. // calcUnReadSpot();
  65. // });
  66. // disp.on("em.main.deleteFriend", function() {
  67. // calcUnReadSpot();
  68. // });
  69. // disp.on("em.chat.audio.fileLoaded", function() {
  70. // calcUnReadSpot();
  71. // }); //
  72. // disp.on("em.mian.profile.update", function() {
  73. // me.fetchUserInfoWithLoginId()
  74. // });
  75. // disp.on("em.mian.friendProfile.update", function() {
  76. // me.fetchFriendInfoFromServer()
  77. // });
  78. // WebIM.conn.listen({
  79. // onOpened(message) {
  80. // console.log('监听onOpened>>>>>', message);
  81. // if (
  82. // getCurrentRoute() == "pages/user/user" ||
  83. // getCurrentRoute() == "pages/login_token/login_token"
  84. // ) {
  85. // me.globalData.onLoginSuccess(
  86. // uni.getStorageSync("myUsername")
  87. // );
  88. // }
  89. // },
  90. // onReconnect() {
  91. // uni.showToast({
  92. // title: "重连中...",
  93. // duration: 2000,
  94. // });
  95. // },
  96. // onSocketConnected() {
  97. // uni.showToast({
  98. // title: "socket连接成功",
  99. // duration: 2000,
  100. // });
  101. // },
  102. // onClosed() {
  103. // // uni.showToast({
  104. // // title: "退出登录",
  105. // // icon: "none",
  106. // // duration: 2000,
  107. // // });
  108. // console.log('>>>>>>>>>>>IM被退出登录>>>>>>>>>>>>>>>>>')
  109. // // uni.redirectTo({
  110. // // url: "../login/login",
  111. // // });
  112. // me.globalData.conn.closed = true;
  113. // me.globalData.conn.isLoginIM = false;
  114. // WebIM.conn.close();
  115. // },
  116. // onInviteMessage(message) {
  117. // me.globalData.saveGroupInvitedList.push(message);
  118. // disp.fire("em.invite.joingroup", message);
  119. // },
  120. // onReadMessage(message) {
  121. // //console.log('已读', message)
  122. // },
  123. // //onPresence为旧版 ,建议参考最新增删好友api文档 :http://docs-im.easemob.com/im/web/basics/buddy
  124. // onPresence(message) {
  125. // switch (message.type) {
  126. // case "unsubscribe":
  127. // break;
  128. // // 好友邀请列表
  129. // case "subscribe":
  130. // for (let i = 0; i < me.globalData.saveFriendList.length; i++) {
  131. // if (me.globalData.saveFriendList[i].from === message.from) {
  132. // me.globalData.saveFriendList[i] = message;
  133. // disp.fire("em.subscribe");
  134. // return;
  135. // }
  136. // }
  137. // msgStorage.saveReceiveMsg(message, "INFORM"); //存添加好友消息,方便展示通知
  138. // me.globalData.saveFriendList.push(message);
  139. // disp.fire("em.subscribe");
  140. // break;
  141. // case "subscribed":
  142. // uni.showToast({
  143. // title: "添加成功",
  144. // duration: 1000,
  145. // });
  146. // disp.fire("em.subscribed");
  147. // break;
  148. // case "unsubscribed":
  149. // disp.fire("em.unsubscribed", message);
  150. // break;
  151. // case "direct_joined":
  152. // saveGroups();
  153. // uni.showToast({
  154. // title: "已进群",
  155. // duration: 1000,
  156. // });
  157. // break;
  158. // case "memberJoinPublicGroupSuccess":
  159. // saveGroups();
  160. // uni.showToast({
  161. // title: "已进群",
  162. // duration: 1000,
  163. // });
  164. // break;
  165. // case "invite":
  166. // // 防止重复添加
  167. // for (
  168. // let i = 0; i < me.globalData.saveGroupInvitedList.length; i++
  169. // ) {
  170. // if (me.globalData.saveGroupInvitedList[i].from === message.from) {
  171. // me.globalData.saveGroupInvitedList[i] = message;
  172. // disp.fire("em.invite.joingroup");
  173. // return;
  174. // }
  175. // }
  176. // me.globalData.saveGroupInvitedList.push(message);
  177. // msgStorage.saveReceiveMsg(message, "INFORM"); //存添加好友消息,方便展示通知
  178. // disp.fire("em.invite.joingroup");
  179. // break;
  180. // case "unavailable":
  181. // disp.fire("em.contacts.remove");
  182. // disp.fire("em.group.leaveGroup", message);
  183. // break;
  184. // case "deleteGroupChat":
  185. // disp.fire("em.invite.deleteGroup", message);
  186. // break;
  187. // case "leaveGroup":
  188. // disp.fire("em.group.leaveGroup", message);
  189. // break;
  190. // case "removedFromGroup":
  191. // disp.fire("em.group.leaveGroup", message);
  192. // break;
  193. // default:
  194. // break;
  195. // }
  196. // },
  197. // onRoster(message) {},
  198. // onVideoMessage(message) {
  199. // console.log("onVideoMessage: ", message);
  200. // if (message) {
  201. // msgStorage.saveReceiveMsg(message, msgType.VIDEO);
  202. // }
  203. // calcUnReadSpot(message);
  204. // ack(message);
  205. // onGetSilentConfig(message);
  206. // },
  207. // onAudioMessage(message) {
  208. // console.log("onAudioMessage", message);
  209. // if (message) {
  210. // if (onMessageError(message)) {
  211. // msgStorage.saveReceiveMsg(message, msgType.AUDIO);
  212. // }
  213. // calcUnReadSpot(message);
  214. // ack(message);
  215. // onGetSilentConfig(message);
  216. // }
  217. // },
  218. // onCmdMessage(message) {
  219. // console.log("onCmdMessage", message);
  220. // if (message) {
  221. // if (onMessageError(message)) {
  222. // msgStorage.saveReceiveMsg(message, msgType.CMD);
  223. // }
  224. // calcUnReadSpot(message);
  225. // ack(message);
  226. // onGetSilentConfig(message);
  227. // }
  228. // },
  229. // onTextMessage(message) {
  230. // console.log("onTextMessage", message);
  231. // if (message) {
  232. // if (onMessageError(message)) {
  233. // msgStorage.saveReceiveMsg(message, msgType.TEXT);
  234. // }
  235. // calcUnReadSpot(message);
  236. // ack(message);
  237. // onGetSilentConfig(message);
  238. // }
  239. // },
  240. // onEmojiMessage(message) {
  241. // console.log("onEmojiMessage", message);
  242. // if (message) {
  243. // if (onMessageError(message)) {
  244. // msgStorage.saveReceiveMsg(message, msgType.EMOJI);
  245. // }
  246. // calcUnReadSpot(message);
  247. // ack(message);
  248. // onGetSilentConfig(message);
  249. // }
  250. // },
  251. // onPictureMessage(message) {
  252. // console.log("onPictureMessage", message);
  253. // if (message) {
  254. // if (onMessageError(message)) {
  255. // msgStorage.saveReceiveMsg(message, msgType.IMAGE);
  256. // }
  257. // calcUnReadSpot(message);
  258. // ack(message);
  259. // onGetSilentConfig(message);
  260. // }
  261. // },
  262. // onFileMessage(message) {
  263. // console.log("onFileMessage", message);
  264. // if (message) {
  265. // if (onMessageError(message)) {
  266. // msgStorage.saveReceiveMsg(message, msgType.FILE);
  267. // }
  268. // calcUnReadSpot(message);
  269. // ack(message);
  270. // onGetSilentConfig(message);
  271. // }
  272. // },
  273. // // 各种异常
  274. // onError(error) {
  275. // console.log(error); // 16: server-side close the websocket connection
  276. // if (error.type == WebIM.statusCode.WEBIM_CONNCTION_OPEN_ERROR) {
  277. // uni.hideLoading();
  278. // disp.fire("em.error.passwordErr");
  279. // }
  280. // if (error.type == WebIM.statusCode.WEBIM_CONNCTION_AUTH_ERROR) {
  281. // uni.hideLoading();
  282. // disp.fire("em.error.tokenErr");
  283. // }
  284. // if (error.type == "socket_error") {
  285. // ///sendMsgError
  286. // console.log("socket_errorsocket_error", error);
  287. // uni.showToast({
  288. // title: "网络已断开",
  289. // icon: "none",
  290. // duration: 2000,
  291. // });
  292. // disp.fire("em.error.sendMsgErr", error);
  293. // }
  294. // },
  295. // });
  296. },
  297. onShow(options) {
  298. // #ifdef MP-WEIXIN
  299. uni.hideHomeButton();
  300. // #endif
  301. // // #ifndef H5
  302. // // 分享卡片/订阅消息/扫码二维码/广告/朋友圈等场景才能调用getShareParams接口获取以下参数
  303. // const sceneList = [1007, 1008, 1014, 1044, 1045, 1046, 1047, 1048, 1049, 1073, 1154, 1155]
  304. // if (sceneList.includes(options.scene)) {
  305. // livePlayer.getShareParams()
  306. // .then(res => {
  307. // // 房间号
  308. // console.log('get room id', res.room_id)
  309. // // 用户openid
  310. // console.log('get openid', res.openid)
  311. // // 分享者openid,分享卡片进入场景才有
  312. // console.log('get share openid', res.share_openid)
  313. // // 开发者在跳转进入直播间页面时,页面路径上携带的自定义参数,这里传回给开发者
  314. // console.log('get custom params', res.custom_params)
  315. // if(res.custom_params){
  316. // req.setStorage('pidCode',res.custom_params.userId)
  317. // }
  318. // }).catch(err => {
  319. // console.log('get share params', err)
  320. // })
  321. // }
  322. // // #endif
  323. // console.log('调用了this.globalData.conn.isLoginIM>>>>>', this.globalData.conn.isLoginIM);
  324. //记录已经是登录状态,并且检测到被断开
  325. let config = JSON.parse(req.getStorage('configRes'));
  326. // if (this.globalData.conn.isLoginIM && !WebIM.conn.isOpened()) {
  327. // console.log('执行重连逻辑>>>')
  328. // // WebIM.conn.close();
  329. // //增加延时目的是为了,确保连接完全断开再去执行重新openIM操作
  330. // setTimeout(() => {
  331. // if (config) {
  332. // if (config.is_not_open_im != 1) req.initIMChat();
  333. // } else {
  334. // req.getRequest('/api/config', {}, data => {
  335. // if (data.is_not_open_im != 1) req.initIMChat();
  336. // })
  337. // }
  338. // }, 500)
  339. // } else {
  340. // console.log('不需要执行重新登陆')
  341. // }
  342. },
  343. globalData: {
  344. phoneNumber: '',
  345. unReadMessageNum: 0,
  346. userInfo: null,
  347. // userInfoFromServer: null, //用户属性从环信服务器获取
  348. // friendUserInfoMap: new Map(), //好友属性
  349. // saveFriendList: [],
  350. // saveGroupInvitedList: [],
  351. // isIPX: false, //是否为iphone X
  352. // conn: {
  353. // isLoginIM: false,
  354. // closed: false,
  355. // curOpenOpt: {},
  356. // open(opt) {
  357. // // uni.showLoading({
  358. // // title: "加载中...",
  359. // // mask: true,
  360. // // });
  361. // this.curOpenOpt = opt;
  362. // const me = this;
  363. // WebIM.conn.open(opt).then(() => {
  364. // //token获取成功,即可开始请求用户属性。
  365. // disp.fire("em.mian.profile.update");
  366. // disp.fire("em.mian.friendProfile.update");
  367. // me.isLoginIM = true;
  368. // console.log('>>>>>token成功=', me.isLoginIM);
  369. // }).catch((err) => {
  370. // console.log('>>>>>token获取失败', err)
  371. // });
  372. // this.closed = false;
  373. // },
  374. // reopen() {
  375. // if (this.closed) {
  376. // //this.open(this.curOpenOpt);
  377. // WebIM.conn.open(this.curOpenOpt);
  378. // this.closed = false;
  379. // }
  380. // },
  381. // },
  382. // onLoginSuccess: function(myName) {
  383. // // uni.hideLoading();
  384. // uni.navigateTo({
  385. // url: "/chat/conversation/conversation?myName=" + myName,
  386. // });
  387. // },
  388. getUserInfo(cb) {
  389. var me = this;
  390. if (this.userInfo) {
  391. typeof cb == "function" && cb(this.userInfo);
  392. } else {
  393. // 调用登录接口
  394. uni.login({
  395. success() {
  396. uni.getUserInfo({
  397. success(res) {
  398. me.userInfo = res.userInfo;
  399. typeof cb == "function" && cb(me.userInfo);
  400. },
  401. });
  402. },
  403. });
  404. }
  405. },
  406. // 更新配色方案
  407. upColor(isUpdata) {
  408. return new Promise((r, j) => {
  409. let configRes = req.getStorage('configRes')
  410. if (configRes && !isUpdata) {
  411. configRes = JSON.parse(configRes)
  412. if (configRes && configRes.mainColor) {
  413. try {
  414. this.mainStyle = JSON.parse(configRes.mainColor)
  415. } catch (e) {
  416. this.mainStyle = null
  417. }
  418. } else {
  419. this.mainStyle = null
  420. }
  421. r()
  422. } else {
  423. req.getRequest('/api/config', {}, data => {
  424. if (data) req.setStorage('configRes', JSON.stringify(data));
  425. console.log('upColor', data)
  426. if (data && data.mainColor) {
  427. try {
  428. this.mainStyle = JSON.parse(data.mainColor)
  429. console.log('mainStyle', this.mainStyle)
  430. } catch (e) {
  431. //TODO handle the exception
  432. console.log('mainStyle catch', this.mainStyle)
  433. this.mainStyle = null
  434. }
  435. } else {
  436. this.mainStyle = null
  437. }
  438. r()
  439. });
  440. }
  441. })
  442. },
  443. //获取客服配置
  444. getChatList() {
  445. req.getRequest('/api/customer/list', {}, res => {
  446. req.setStorage('chatService', res);
  447. });
  448. },
  449. appInitData() {
  450. var getSysInfo = uni.getSystemInfoSync();
  451. this.isIPhone = getSysInfo.model.indexOf("iPhone") != -1;
  452. this.isIPhoneX = getSysInfo.model.indexOf("iPhone X") != -1 || getSysInfo.model.indexOf("iPhone 11") != -
  453. 1; // 是否为全面屏
  454. this.isFullScreen = getSysInfo.screenHeight / getSysInfo.screenWidth >= 2.1; // iPhoneX底部空白高度为68,全面屏为20
  455. this.bottomBlankHeignt = this.isIPhoneX ? 68 : this.isFullScreen ? 10 : 0;
  456. this.height = getSysInfo.statusBarHeight;
  457. this.screenHeight = getSysInfo.screenHeight;
  458. },
  459. InitUpdateManager() {
  460. const updateManager = uni.getUpdateManager();
  461. let that = this;
  462. updateManager.onCheckForUpdate(function(res) {
  463. // 请求完新版本信息的回调
  464. console.log(res.hasUpdate);
  465. });
  466. updateManager.onUpdateReady(function() {
  467. uni.showModal({
  468. title: '更新提示',
  469. content: '新版本已经准备好,是否重启应用?',
  470. success: function(res) {
  471. if (res.confirm) {
  472. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  473. uni.clearStorage({
  474. success() {
  475. updateManager.applyUpdate();
  476. }
  477. });
  478. }
  479. }
  480. });
  481. });
  482. updateManager.onUpdateFailed(function() { // 新版本下载失败
  483. });
  484. },
  485. getCheckSessoin(success) {
  486. // var sessionKey = req.getStorage('SESSION_KEY');
  487. // let that = this;
  488. // wx.checkSession({
  489. // success() {
  490. // if (!sessionKey) {
  491. // that.getSessionKey(success);
  492. // } else {
  493. // success.call(this, sessionKey);
  494. // }
  495. // },
  496. // fail() {
  497. // that.getSessionKey(success);
  498. // }
  499. // })
  500. // #ifdef MP-WEIXIN
  501. this.getSessionKey(success);
  502. // #endif
  503. },
  504. getSessionKey(success) {
  505. let that = this;
  506. uni.login({
  507. success(res) {
  508. req.postRequest('/api/code', {
  509. code: res.code
  510. }, data => {
  511. that.SESSION_KEY = data.session_key;
  512. req.setStorage('SESSION_KEY', data.session_key);
  513. success.call(this, data);
  514. }, true);
  515. }
  516. });
  517. },
  518. userInfo: null,
  519. height: 0,
  520. isredenvelopes: true,
  521. isLayerAd: true,
  522. mainStyle: {},
  523. /**
  524. * 打开新页面
  525. */
  526. openPage(e) {
  527. let url
  528. if (e.indexOf("plugin-private:") != -1) {
  529. url = `${e}`
  530. } else {
  531. url = `/${e}`
  532. }
  533. uni.navigateTo({
  534. // url: `/${e}`
  535. url: url
  536. });
  537. // uni.navigateTo({
  538. // url: `/${e}`
  539. // });
  540. },
  541. /**
  542. *
  543. * 关闭当前页面,跳转到应用内的某个页面。
  544. */
  545. redirectTab(path) {
  546. uni.redirectTo({
  547. url: `/${path}`
  548. });
  549. },
  550. /**
  551. *
  552. * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
  553. */
  554. switchTab(path) {
  555. uni.switchTab({
  556. url: `/${path}`
  557. });
  558. },
  559. /**
  560. * 返回首页
  561. */
  562. openHome() {
  563. var url = '/pages/tabBar/index?appId=' + req.getStorage('appId');
  564. uni.reLaunch({
  565. url: url
  566. });
  567. },
  568. /**
  569. *
  570. * 关闭所有页面,打开到应用内的某个页面
  571. */
  572. reLaunchTo(path) {
  573. uni.reLaunch({
  574. url: `/${path}`
  575. });
  576. },
  577. /**
  578. *
  579. * 保留当前页面,跳转到应用内的某个页面
  580. */
  581. navigateTo(path) {
  582. uni.navigateTo({
  583. url: `/${path}`
  584. });
  585. },
  586. clickBanner(params) {
  587. console.log('params==', params.type)
  588. var dt = params
  589. var url = "";
  590. var id = "";
  591. var acid = "";
  592. if (dt.content != "") {
  593. let conunt = dt.content.split("_");
  594. id = conunt[1];
  595. acid = conunt[0];
  596. }
  597. if (dt.type * 1 == 2 && dt.content != "") {
  598. url = "product/detail/detail?id=" + dt.content;
  599. } else if (dt.type * 1 == 4) {
  600. url = "product/groupDetail/groupDetail?acid=" + acid + "&id=" + id;
  601. } else if (dt.type * 1 == 5) {
  602. url = "product/couponList/index";
  603. } else if (dt.type * 1 == 6) {
  604. url = "service/live/live";
  605. } else if (dt.type * 1 == 7) {
  606. url = "product/groupList/groupList";
  607. } else if (dt.type * 1 == 9 && dt.content != "") {
  608. url = "product/list/list?id=" + dt.content;
  609. } else if (dt.type * 1 == 10) {
  610. url = "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" + dt.content;
  611. // console.log(
  612. // url); // url=`plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${dt.content}`
  613. } else if (dt.type * 1 == 11) {
  614. url = "activity/group/index/index";
  615. } else if (dt.type * 1 == 12) {
  616. url = "activity/seckill/seckill";
  617. } else if (dt.type * 1 == 13) {
  618. url = "activity/bargain/index/index";
  619. } else if (dt.type * 1 == 14) {
  620. url = "activity/newbornZone/newbornZone";
  621. } else if (dt.type * 1 == 15 && dt.content != "") {
  622. url = "activity/newbornDetails/newbornDetails?acid=" + acid + "&id=" + id;
  623. } else if (dt.type * 1 == 16 && dt.content != "") {
  624. url = "activity/seckillDetails/seckillDetails?acid=" + acid + "&id=" + id;
  625. } else if (dt.type * 1 == 17 && dt.content != "") {
  626. url = "activity/bargain/detail/detail?acid=" + acid + "&id=" + id;
  627. } else if (dt.type * 1 == 18 && dt.content != "") {
  628. url = "activity/group/detail/detail?acid=" + acid + "&id=" + id;
  629. } else if (dt.type * 1 == 19 && dt.content != "") { //文章内容
  630. url = "activity/content/content?id=" + dt.content + "&type=" + 1; //1为普通文章内容
  631. } else if (dt.type * 1 == 3 && dt.content != "") { //外链类型
  632. url = dt.content; //1为普通文章内容
  633. } else if (dt.type * 1 == 22) { //团购广场
  634. url = "group/index/index";
  635. } else if (dt.type * 1 == 23 && dt.content != "") { //团购商品详情
  636. let content = JSON.parse(dt.content)
  637. url = "product/detail/detail?id=" + content.productId + '&groupId=' + content.groupId;
  638. } else if (dt.type * 1 == 24) { //课程列表
  639. url = "course/list/index";
  640. } else if (dt.type * 1 == 25 && dt.content != "") { //课程详情
  641. url = "course/detail/index?id=" + dt.content;
  642. } else {
  643. url = "";
  644. }
  645. if (dt.type * 1 == 6) this.switchTab(url);
  646. else this.openPage(url);
  647. }
  648. },
  649. methods: {
  650. async fetchUserInfoWithLoginId() {
  651. const userId = await uni.WebIM.conn.user;
  652. if (userId) {
  653. try {
  654. const {
  655. data
  656. } = await uni.WebIM.conn.fetchUserInfoById(userId)
  657. this.globalData.userInfoFromServer = Object.assign({}, data[userId]);
  658. } catch (error) {
  659. console.log(error)
  660. // uni.showToast({
  661. // title: "用户属性获取失败",
  662. // icon: "none",
  663. // duration: 2000,
  664. // })
  665. }
  666. }
  667. },
  668. async fetchFriendInfoFromServer() {
  669. let friendList = []
  670. try {
  671. const res = await uni.WebIM.conn.getContacts()
  672. friendList = Object.assign([], res?.data)
  673. if (friendList.length && friendList.length < 99) {
  674. const {
  675. data
  676. } = await uni.WebIM.conn.fetchUserInfoById(friendList)
  677. this.setFriendUserInfotoMap(data)
  678. } else {
  679. let newArr = _chunkArr(friendList, 99)
  680. for (let i = 0; i < newArr.length; i++) {
  681. const {
  682. data
  683. } = await uni.WebIM.conn.fetchUserInfoById(newArr[i])
  684. this.setFriendUserInfotoMap(data)
  685. }
  686. }
  687. } catch (error) {
  688. console.log(error)
  689. // uni.showToast({
  690. // title: "用户属性获取失败",
  691. // icon: "none"
  692. // })
  693. }
  694. },
  695. setFriendUserInfotoMap(data) {
  696. if (Object.keys(data).length) {
  697. for (const key in data) {
  698. if (Object.hasOwnProperty.call(data, key)) {
  699. const values = data[key];
  700. Object.values(values).length && this.globalData.friendUserInfoMap.set(key, values);
  701. }
  702. }
  703. }
  704. }
  705. }
  706. };
  707. /*--------环信SDK消息-----------------------*/
  708. function ack(receiveMsg) {
  709. // 处理未读消息回执
  710. var bodyId = receiveMsg.id; // 需要发送已读回执的消息id
  711. var ackMsg = new WebIM.message("read", WebIM.conn.getUniqueId());
  712. ackMsg.set({
  713. id: bodyId,
  714. to: receiveMsg.from,
  715. });
  716. WebIM.conn.send(ackMsg.body);
  717. }
  718. function onMessageError(err) {
  719. if (err.type === "error") {
  720. uni.showToast({
  721. title: err.errorText,
  722. });
  723. return false;
  724. }
  725. return true;
  726. }
  727. function getCurrentRoute() {
  728. let pages = getCurrentPages();
  729. if (pages.length > 0) {
  730. let currentPage = pages[pages.length - 1];
  731. return currentPage.route;
  732. }
  733. return "/";
  734. }
  735. // 包含陌生人版本
  736. //该方法用以计算本地存储消息的未读总数。
  737. function calcUnReadSpot(message) {
  738. // let myName = uni.getStorageSync("myUsername");
  739. // let pushObj = uni.getStorageSync("pushStorageData")
  740. // let pushAry = pushObj[myName] || []
  741. // uni.getStorageInfo({
  742. // success: function(res) {
  743. // let storageKeys = res.keys;
  744. // let newChatMsgKeys = [];
  745. // let historyChatMsgKeys = [];
  746. // storageKeys.forEach((item) => {
  747. // if (item.indexOf(myName) > -1 && item.indexOf("rendered_") == -1 && item.indexOf(
  748. // "imUserInfo_") == -1) {
  749. // newChatMsgKeys.push(item);
  750. // }
  751. // });
  752. // console.log('newChatMsgKeys》》》》》', newChatMsgKeys);
  753. // let count = newChatMsgKeys.reduce(function(result, curMember, idx) {
  754. // let newName = curMember.split(myName)[0]
  755. // let chatMsgs;
  756. // chatMsgs = uni.getStorageSync(curMember) || [];
  757. // console.log('chatMsgs>>>>>', chatMsgs);
  758. // //过滤消息来源与当前登录ID一致的消息,不计入总数中。
  759. // chatMsgs = chatMsgs.filter((msg) => msg.yourname !== myName);
  760. // if (pushAry.includes(newName)) return result
  761. // return result + chatMsgs.length;
  762. // }, 0);
  763. // getApp().globalData.unReadMessageNum = count;
  764. // disp.fire("em.unreadspot", message);
  765. // },
  766. // });
  767. }
  768. function saveGroups() {
  769. var me = this;
  770. return WebIM.conn.getGroup({
  771. limit: 50,
  772. success: function(res) {
  773. uni.setStorage({
  774. key: "listGroup",
  775. data: res.data,
  776. });
  777. },
  778. error: function(err) {
  779. console.log(err);
  780. },
  781. });
  782. }
  783. </script>
  784. <style>
  785. @import "./app.css";
  786. </style>