| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842 |
- <script>
- //app.js
- const req = require("./utils/request.js");
- // // #ifndef H5
- // let livePlayer = requirePlugin('live-player-plugin')
- // // #endif
- // import _chunkArr from './hxChatSDK/utils/chunkArr';
- // let WebIM = (wx.WebIM = require("./hxChatSDK/utils/WebIM")["default"]);
- // let msgStorage = require("./chat/components/chat/msgstorage");
- // let msgType = require("./chat/components/chat/msgtype");
- // let disp = require("./hxChatSDK/utils/broadcast");
- // let logout = false;
- // import {
- // onGetSilentConfig
- // } from './chat/components/chat/pushStorage'
- export default {
- onLaunch: function(options) {
- //拉取模板配置自定义详细
- if (wx.getExtConfig) {
- wx.getExtConfig({
- success(res) {
- console.log(res.extConfig)
- if (res.extConfig && res.extConfig.NODE_ENV) {
- req.env.NODE_ENV = res.extConfig.NODE_ENV;
- }
- if (res.extConfig && res.extConfig.authAppId) {
- req.setStorage('appId', res.extConfig.authAppId)
- }
- }
- })
- }
- req.removeStorage('isShowUpdateMobile')
- req.removeStorage('isShowUpdateInfo')
- let scene = options.scene;
- req.setStorage('scene', scene)
- let arr = [1195, 1193, 1191, 1184, 1177, 1176, 1175, 1201, 1216, 10001]
- req.setStorage('isVideoScene', false)
- arr.some(it => {
- if (it === scene) {
- req.setStorage('isVideoScene', true)
- }
- })
- this.globalData.InitUpdateManager();
- this.globalData.getChatList();
- this.globalData.upColor()
- // #ifndef APP-PLUS
- uni.hideTabBar()
- // #endif
- // req.getWebchatAppId();
- // var me = this;
- // var logs = uni.getStorageSync("logs") || [];
- // logs.unshift(Date.now());
- // uni.setStorageSync("logs", logs);
- // disp.on("em.main.ready", function() {
- // calcUnReadSpot();
- // });
- // disp.on("em.chatroom.leave", function() {
- // calcUnReadSpot();
- // });
- // disp.on("em.chat.session.remove", function() {
- // calcUnReadSpot();
- // });
- // disp.on("em.chat.audio.fileLoaded", function() {
- // calcUnReadSpot();
- // });
- // disp.on("em.main.deleteFriend", function() {
- // calcUnReadSpot();
- // });
- // disp.on("em.chat.audio.fileLoaded", function() {
- // calcUnReadSpot();
- // }); //
- // disp.on("em.mian.profile.update", function() {
- // me.fetchUserInfoWithLoginId()
- // });
- // disp.on("em.mian.friendProfile.update", function() {
- // me.fetchFriendInfoFromServer()
- // });
- // WebIM.conn.listen({
- // onOpened(message) {
- // console.log('监听onOpened>>>>>', message);
- // if (
- // getCurrentRoute() == "pages/user/user" ||
- // getCurrentRoute() == "pages/login_token/login_token"
- // ) {
- // me.globalData.onLoginSuccess(
- // uni.getStorageSync("myUsername")
- // );
- // }
- // },
- // onReconnect() {
- // uni.showToast({
- // title: "重连中...",
- // duration: 2000,
- // });
- // },
- // onSocketConnected() {
- // uni.showToast({
- // title: "socket连接成功",
- // duration: 2000,
- // });
- // },
- // onClosed() {
- // // uni.showToast({
- // // title: "退出登录",
- // // icon: "none",
- // // duration: 2000,
- // // });
- // console.log('>>>>>>>>>>>IM被退出登录>>>>>>>>>>>>>>>>>')
- // // uni.redirectTo({
- // // url: "../login/login",
- // // });
- // me.globalData.conn.closed = true;
- // me.globalData.conn.isLoginIM = false;
- // WebIM.conn.close();
- // },
- // onInviteMessage(message) {
- // me.globalData.saveGroupInvitedList.push(message);
- // disp.fire("em.invite.joingroup", message);
- // },
- // onReadMessage(message) {
- // //console.log('已读', message)
- // },
- // //onPresence为旧版 ,建议参考最新增删好友api文档 :http://docs-im.easemob.com/im/web/basics/buddy
- // onPresence(message) {
- // switch (message.type) {
- // case "unsubscribe":
- // break;
- // // 好友邀请列表
- // case "subscribe":
- // for (let i = 0; i < me.globalData.saveFriendList.length; i++) {
- // if (me.globalData.saveFriendList[i].from === message.from) {
- // me.globalData.saveFriendList[i] = message;
- // disp.fire("em.subscribe");
- // return;
- // }
- // }
- // msgStorage.saveReceiveMsg(message, "INFORM"); //存添加好友消息,方便展示通知
- // me.globalData.saveFriendList.push(message);
- // disp.fire("em.subscribe");
- // break;
- // case "subscribed":
- // uni.showToast({
- // title: "添加成功",
- // duration: 1000,
- // });
- // disp.fire("em.subscribed");
- // break;
- // case "unsubscribed":
- // disp.fire("em.unsubscribed", message);
- // break;
- // case "direct_joined":
- // saveGroups();
- // uni.showToast({
- // title: "已进群",
- // duration: 1000,
- // });
- // break;
- // case "memberJoinPublicGroupSuccess":
- // saveGroups();
- // uni.showToast({
- // title: "已进群",
- // duration: 1000,
- // });
- // break;
- // case "invite":
- // // 防止重复添加
- // for (
- // let i = 0; i < me.globalData.saveGroupInvitedList.length; i++
- // ) {
- // if (me.globalData.saveGroupInvitedList[i].from === message.from) {
- // me.globalData.saveGroupInvitedList[i] = message;
- // disp.fire("em.invite.joingroup");
- // return;
- // }
- // }
- // me.globalData.saveGroupInvitedList.push(message);
- // msgStorage.saveReceiveMsg(message, "INFORM"); //存添加好友消息,方便展示通知
- // disp.fire("em.invite.joingroup");
- // break;
- // case "unavailable":
- // disp.fire("em.contacts.remove");
- // disp.fire("em.group.leaveGroup", message);
- // break;
- // case "deleteGroupChat":
- // disp.fire("em.invite.deleteGroup", message);
- // break;
- // case "leaveGroup":
- // disp.fire("em.group.leaveGroup", message);
- // break;
- // case "removedFromGroup":
- // disp.fire("em.group.leaveGroup", message);
- // break;
- // default:
- // break;
- // }
- // },
- // onRoster(message) {},
- // onVideoMessage(message) {
- // console.log("onVideoMessage: ", message);
- // if (message) {
- // msgStorage.saveReceiveMsg(message, msgType.VIDEO);
- // }
- // calcUnReadSpot(message);
- // ack(message);
- // onGetSilentConfig(message);
- // },
- // onAudioMessage(message) {
- // console.log("onAudioMessage", message);
- // if (message) {
- // if (onMessageError(message)) {
- // msgStorage.saveReceiveMsg(message, msgType.AUDIO);
- // }
- // calcUnReadSpot(message);
- // ack(message);
- // onGetSilentConfig(message);
- // }
- // },
- // onCmdMessage(message) {
- // console.log("onCmdMessage", message);
- // if (message) {
- // if (onMessageError(message)) {
- // msgStorage.saveReceiveMsg(message, msgType.CMD);
- // }
- // calcUnReadSpot(message);
- // ack(message);
- // onGetSilentConfig(message);
- // }
- // },
- // onTextMessage(message) {
- // console.log("onTextMessage", message);
- // if (message) {
- // if (onMessageError(message)) {
- // msgStorage.saveReceiveMsg(message, msgType.TEXT);
- // }
- // calcUnReadSpot(message);
- // ack(message);
- // onGetSilentConfig(message);
- // }
- // },
- // onEmojiMessage(message) {
- // console.log("onEmojiMessage", message);
- // if (message) {
- // if (onMessageError(message)) {
- // msgStorage.saveReceiveMsg(message, msgType.EMOJI);
- // }
- // calcUnReadSpot(message);
- // ack(message);
- // onGetSilentConfig(message);
- // }
- // },
- // onPictureMessage(message) {
- // console.log("onPictureMessage", message);
- // if (message) {
- // if (onMessageError(message)) {
- // msgStorage.saveReceiveMsg(message, msgType.IMAGE);
- // }
- // calcUnReadSpot(message);
- // ack(message);
- // onGetSilentConfig(message);
- // }
- // },
- // onFileMessage(message) {
- // console.log("onFileMessage", message);
- // if (message) {
- // if (onMessageError(message)) {
- // msgStorage.saveReceiveMsg(message, msgType.FILE);
- // }
- // calcUnReadSpot(message);
- // ack(message);
- // onGetSilentConfig(message);
- // }
- // },
- // // 各种异常
- // onError(error) {
- // console.log(error); // 16: server-side close the websocket connection
- // if (error.type == WebIM.statusCode.WEBIM_CONNCTION_OPEN_ERROR) {
- // uni.hideLoading();
- // disp.fire("em.error.passwordErr");
- // }
- // if (error.type == WebIM.statusCode.WEBIM_CONNCTION_AUTH_ERROR) {
- // uni.hideLoading();
- // disp.fire("em.error.tokenErr");
- // }
- // if (error.type == "socket_error") {
- // ///sendMsgError
- // console.log("socket_errorsocket_error", error);
- // uni.showToast({
- // title: "网络已断开",
- // icon: "none",
- // duration: 2000,
- // });
- // disp.fire("em.error.sendMsgErr", error);
- // }
- // },
- // });
- },
- onShow(options) {
- // #ifdef MP-WEIXIN
- uni.hideHomeButton();
- // #endif
- // // #ifndef H5
- // // 分享卡片/订阅消息/扫码二维码/广告/朋友圈等场景才能调用getShareParams接口获取以下参数
- // const sceneList = [1007, 1008, 1014, 1044, 1045, 1046, 1047, 1048, 1049, 1073, 1154, 1155]
- // if (sceneList.includes(options.scene)) {
- // livePlayer.getShareParams()
- // .then(res => {
- // // 房间号
- // console.log('get room id', res.room_id)
- // // 用户openid
- // console.log('get openid', res.openid)
- // // 分享者openid,分享卡片进入场景才有
- // console.log('get share openid', res.share_openid)
- // // 开发者在跳转进入直播间页面时,页面路径上携带的自定义参数,这里传回给开发者
- // console.log('get custom params', res.custom_params)
- // if(res.custom_params){
- // req.setStorage('pidCode',res.custom_params.userId)
- // }
- // }).catch(err => {
- // console.log('get share params', err)
- // })
- // }
- // // #endif
- // console.log('调用了this.globalData.conn.isLoginIM>>>>>', this.globalData.conn.isLoginIM);
- //记录已经是登录状态,并且检测到被断开
- let config = JSON.parse(req.getStorage('configRes'));
- // if (this.globalData.conn.isLoginIM && !WebIM.conn.isOpened()) {
- // console.log('执行重连逻辑>>>')
- // // WebIM.conn.close();
- // //增加延时目的是为了,确保连接完全断开再去执行重新openIM操作
- // setTimeout(() => {
- // if (config) {
- // if (config.is_not_open_im != 1) req.initIMChat();
- // } else {
- // req.getRequest('/api/config', {}, data => {
- // if (data.is_not_open_im != 1) req.initIMChat();
- // })
- // }
- // }, 500)
- // } else {
- // console.log('不需要执行重新登陆')
- // }
- },
- globalData: {
- phoneNumber: '',
- unReadMessageNum: 0,
- userInfo: null,
- // userInfoFromServer: null, //用户属性从环信服务器获取
- // friendUserInfoMap: new Map(), //好友属性
- // saveFriendList: [],
- // saveGroupInvitedList: [],
- // isIPX: false, //是否为iphone X
- // conn: {
- // isLoginIM: false,
- // closed: false,
- // curOpenOpt: {},
- // open(opt) {
- // // uni.showLoading({
- // // title: "加载中...",
- // // mask: true,
- // // });
- // this.curOpenOpt = opt;
- // const me = this;
- // WebIM.conn.open(opt).then(() => {
- // //token获取成功,即可开始请求用户属性。
- // disp.fire("em.mian.profile.update");
- // disp.fire("em.mian.friendProfile.update");
- // me.isLoginIM = true;
- // console.log('>>>>>token成功=', me.isLoginIM);
- // }).catch((err) => {
- // console.log('>>>>>token获取失败', err)
- // });
- // this.closed = false;
- // },
- // reopen() {
- // if (this.closed) {
- // //this.open(this.curOpenOpt);
- // WebIM.conn.open(this.curOpenOpt);
- // this.closed = false;
- // }
- // },
- // },
- // onLoginSuccess: function(myName) {
- // // uni.hideLoading();
- // uni.navigateTo({
- // url: "/chat/conversation/conversation?myName=" + myName,
- // });
- // },
- getUserInfo(cb) {
- var me = this;
- if (this.userInfo) {
- typeof cb == "function" && cb(this.userInfo);
- } else {
- // 调用登录接口
- uni.login({
- success() {
- uni.getUserInfo({
- success(res) {
- me.userInfo = res.userInfo;
- typeof cb == "function" && cb(me.userInfo);
- },
- });
- },
- });
- }
- },
- // 更新配色方案
- upColor(isUpdata) {
- return new Promise((r, j) => {
- let configRes = req.getStorage('configRes')
- if (configRes && !isUpdata) {
- configRes = JSON.parse(configRes)
- if (configRes && configRes.mainColor) {
- try {
- this.mainStyle = JSON.parse(configRes.mainColor)
- } catch (e) {
- this.mainStyle = null
- }
- } else {
- this.mainStyle = null
- }
- r()
- } else {
- req.getRequest('/api/config', {}, data => {
- if (data) req.setStorage('configRes', JSON.stringify(data));
- console.log('upColor', data)
- if (data && data.mainColor) {
- try {
- this.mainStyle = JSON.parse(data.mainColor)
- console.log('mainStyle', this.mainStyle)
- } catch (e) {
- //TODO handle the exception
- console.log('mainStyle catch', this.mainStyle)
- this.mainStyle = null
- }
- } else {
- this.mainStyle = null
- }
- r()
- });
- }
- })
- },
- //获取客服配置
- getChatList() {
- req.getRequest('/api/customer/list', {}, res => {
- req.setStorage('chatService', res);
- });
- },
- appInitData() {
- var getSysInfo = uni.getSystemInfoSync();
- this.isIPhone = getSysInfo.model.indexOf("iPhone") != -1;
- this.isIPhoneX = getSysInfo.model.indexOf("iPhone X") != -1 || getSysInfo.model.indexOf("iPhone 11") != -
- 1; // 是否为全面屏
- this.isFullScreen = getSysInfo.screenHeight / getSysInfo.screenWidth >= 2.1; // iPhoneX底部空白高度为68,全面屏为20
- this.bottomBlankHeignt = this.isIPhoneX ? 68 : this.isFullScreen ? 10 : 0;
- this.height = getSysInfo.statusBarHeight;
- this.screenHeight = getSysInfo.screenHeight;
- },
- InitUpdateManager() {
- const updateManager = uni.getUpdateManager();
- let that = this;
- updateManager.onCheckForUpdate(function(res) {
- // 请求完新版本信息的回调
- console.log(res.hasUpdate);
- });
- updateManager.onUpdateReady(function() {
- uni.showModal({
- title: '更新提示',
- content: '新版本已经准备好,是否重启应用?',
- success: function(res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- uni.clearStorage({
- success() {
- updateManager.applyUpdate();
- }
- });
- }
- }
- });
- });
- updateManager.onUpdateFailed(function() { // 新版本下载失败
- });
- },
- getCheckSessoin(success) {
- // var sessionKey = req.getStorage('SESSION_KEY');
- // let that = this;
- // wx.checkSession({
- // success() {
- // if (!sessionKey) {
- // that.getSessionKey(success);
- // } else {
- // success.call(this, sessionKey);
- // }
- // },
- // fail() {
- // that.getSessionKey(success);
- // }
- // })
- // #ifdef MP-WEIXIN
- this.getSessionKey(success);
- // #endif
- },
- getSessionKey(success) {
- let that = this;
- uni.login({
- success(res) {
- req.postRequest('/api/code', {
- code: res.code
- }, data => {
- that.SESSION_KEY = data.session_key;
- req.setStorage('SESSION_KEY', data.session_key);
- success.call(this, data);
- }, true);
- }
- });
- },
- userInfo: null,
- height: 0,
- isredenvelopes: true,
- isLayerAd: true,
- mainStyle: {},
- /**
- * 打开新页面
- */
- openPage(e) {
- let url
- if (e.indexOf("plugin-private:") != -1) {
- url = `${e}`
- } else {
- url = `/${e}`
- }
- uni.navigateTo({
- // url: `/${e}`
- url: url
- });
- // uni.navigateTo({
- // url: `/${e}`
- // });
- },
- /**
- *
- * 关闭当前页面,跳转到应用内的某个页面。
- */
- redirectTab(path) {
- uni.redirectTo({
- url: `/${path}`
- });
- },
- /**
- *
- * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
- */
- switchTab(path) {
- uni.switchTab({
- url: `/${path}`
- });
- },
- /**
- * 返回首页
- */
- openHome() {
- var url = '/pages/tabBar/index?appId=' + req.getStorage('appId');
- uni.reLaunch({
- url: url
- });
- },
- /**
- *
- * 关闭所有页面,打开到应用内的某个页面
- */
- reLaunchTo(path) {
- uni.reLaunch({
- url: `/${path}`
- });
- },
- /**
- *
- * 保留当前页面,跳转到应用内的某个页面
- */
- navigateTo(path) {
- uni.navigateTo({
- url: `/${path}`
- });
- },
- clickBanner(params) {
- console.log('params==', params.type)
- var dt = params
- var url = "";
- var id = "";
- var acid = "";
- if (dt.content != "") {
- let conunt = dt.content.split("_");
- id = conunt[1];
- acid = conunt[0];
- }
- if (dt.type * 1 == 2 && dt.content != "") {
- url = "product/detail/detail?id=" + dt.content;
- } else if (dt.type * 1 == 4) {
- url = "product/groupDetail/groupDetail?acid=" + acid + "&id=" + id;
- } else if (dt.type * 1 == 5) {
- url = "product/couponList/index";
- } else if (dt.type * 1 == 6) {
- url = "service/live/live";
- } else if (dt.type * 1 == 7) {
- url = "product/groupList/groupList";
- } else if (dt.type * 1 == 9 && dt.content != "") {
- url = "product/list/list?id=" + dt.content;
- } else if (dt.type * 1 == 10) {
- url = "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" + dt.content;
- // console.log(
- // url); // url=`plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${dt.content}`
- } else if (dt.type * 1 == 11) {
- url = "activity/group/index/index";
- } else if (dt.type * 1 == 12) {
- url = "activity/seckill/seckill";
- } else if (dt.type * 1 == 13) {
- url = "activity/bargain/index/index";
- } else if (dt.type * 1 == 14) {
- url = "activity/newbornZone/newbornZone";
- } else if (dt.type * 1 == 15 && dt.content != "") {
- url = "activity/newbornDetails/newbornDetails?acid=" + acid + "&id=" + id;
- } else if (dt.type * 1 == 16 && dt.content != "") {
- url = "activity/seckillDetails/seckillDetails?acid=" + acid + "&id=" + id;
- } else if (dt.type * 1 == 17 && dt.content != "") {
- url = "activity/bargain/detail/detail?acid=" + acid + "&id=" + id;
- } else if (dt.type * 1 == 18 && dt.content != "") {
- url = "activity/group/detail/detail?acid=" + acid + "&id=" + id;
- } else if (dt.type * 1 == 19 && dt.content != "") { //文章内容
- url = "activity/content/content?id=" + dt.content + "&type=" + 1; //1为普通文章内容
- } else if (dt.type * 1 == 3 && dt.content != "") { //外链类型
- url = dt.content; //1为普通文章内容
- } else if (dt.type * 1 == 22) { //团购广场
- url = "group/index/index";
- } else if (dt.type * 1 == 23 && dt.content != "") { //团购商品详情
- let content = JSON.parse(dt.content)
- url = "product/detail/detail?id=" + content.productId + '&groupId=' + content.groupId;
- } else if (dt.type * 1 == 24) { //课程列表
- url = "course/list/index";
- } else if (dt.type * 1 == 25 && dt.content != "") { //课程详情
- url = "course/detail/index?id=" + dt.content;
- } else {
- url = "";
- }
- if (dt.type * 1 == 6) this.switchTab(url);
- else this.openPage(url);
- }
- },
- methods: {
- async fetchUserInfoWithLoginId() {
- const userId = await uni.WebIM.conn.user;
- if (userId) {
- try {
- const {
- data
- } = await uni.WebIM.conn.fetchUserInfoById(userId)
- this.globalData.userInfoFromServer = Object.assign({}, data[userId]);
- } catch (error) {
- console.log(error)
- // uni.showToast({
- // title: "用户属性获取失败",
- // icon: "none",
- // duration: 2000,
- // })
- }
- }
- },
- async fetchFriendInfoFromServer() {
- let friendList = []
- try {
- const res = await uni.WebIM.conn.getContacts()
- friendList = Object.assign([], res?.data)
- if (friendList.length && friendList.length < 99) {
- const {
- data
- } = await uni.WebIM.conn.fetchUserInfoById(friendList)
- this.setFriendUserInfotoMap(data)
- } else {
- let newArr = _chunkArr(friendList, 99)
- for (let i = 0; i < newArr.length; i++) {
- const {
- data
- } = await uni.WebIM.conn.fetchUserInfoById(newArr[i])
- this.setFriendUserInfotoMap(data)
- }
- }
- } catch (error) {
- console.log(error)
- // uni.showToast({
- // title: "用户属性获取失败",
- // icon: "none"
- // })
- }
- },
- setFriendUserInfotoMap(data) {
- if (Object.keys(data).length) {
- for (const key in data) {
- if (Object.hasOwnProperty.call(data, key)) {
- const values = data[key];
- Object.values(values).length && this.globalData.friendUserInfoMap.set(key, values);
- }
- }
- }
- }
- }
- };
- /*--------环信SDK消息-----------------------*/
- function ack(receiveMsg) {
- // 处理未读消息回执
- var bodyId = receiveMsg.id; // 需要发送已读回执的消息id
- var ackMsg = new WebIM.message("read", WebIM.conn.getUniqueId());
- ackMsg.set({
- id: bodyId,
- to: receiveMsg.from,
- });
- WebIM.conn.send(ackMsg.body);
- }
- function onMessageError(err) {
- if (err.type === "error") {
- uni.showToast({
- title: err.errorText,
- });
- return false;
- }
- return true;
- }
- function getCurrentRoute() {
- let pages = getCurrentPages();
- if (pages.length > 0) {
- let currentPage = pages[pages.length - 1];
- return currentPage.route;
- }
- return "/";
- }
- // 包含陌生人版本
- //该方法用以计算本地存储消息的未读总数。
- function calcUnReadSpot(message) {
- // let myName = uni.getStorageSync("myUsername");
- // let pushObj = uni.getStorageSync("pushStorageData")
- // let pushAry = pushObj[myName] || []
- // uni.getStorageInfo({
- // success: function(res) {
- // let storageKeys = res.keys;
- // let newChatMsgKeys = [];
- // let historyChatMsgKeys = [];
- // storageKeys.forEach((item) => {
- // if (item.indexOf(myName) > -1 && item.indexOf("rendered_") == -1 && item.indexOf(
- // "imUserInfo_") == -1) {
- // newChatMsgKeys.push(item);
- // }
- // });
- // console.log('newChatMsgKeys》》》》》', newChatMsgKeys);
- // let count = newChatMsgKeys.reduce(function(result, curMember, idx) {
- // let newName = curMember.split(myName)[0]
- // let chatMsgs;
- // chatMsgs = uni.getStorageSync(curMember) || [];
- // console.log('chatMsgs>>>>>', chatMsgs);
- // //过滤消息来源与当前登录ID一致的消息,不计入总数中。
- // chatMsgs = chatMsgs.filter((msg) => msg.yourname !== myName);
- // if (pushAry.includes(newName)) return result
- // return result + chatMsgs.length;
- // }, 0);
- // getApp().globalData.unReadMessageNum = count;
- // disp.fire("em.unreadspot", message);
- // },
- // });
- }
- function saveGroups() {
- var me = this;
- return WebIM.conn.getGroup({
- limit: 50,
- success: function(res) {
- uni.setStorage({
- key: "listGroup",
- data: res.data,
- });
- },
- error: function(err) {
- console.log(err);
- },
- });
- }
- </script>
- <style>
- @import "./app.css";
- </style>
|