import Aegis from './TUIKit/lib/aegis'; import TIM from './TUIKit/lib/tim-wx-sdk'; import { genTestUserSig } from './TUIKit/debug/GenerateTestUserSig'; import TIMUploadPlugin from './TUIKit/lib/tim-upload-plugin'; import { API } from './utils/network/api' const api = new API() App({ onLaunch: function (options) { // 判断是否由分享进入小程序 if (options.scene != 1001) { this.globalData.share = true } else { this.globalData.share = false }; this.globalData.scene = options.scene //获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度) //这个最初我是在组件中获取,但是出现了一个问题,当第一次进入小程序时导航栏会把 //页面内容盖住一部分,当打开调试重新进入时就没有问题,这个问题弄得我是莫名其妙 //虽然最后解决了,但是花费了不少时间 wx.getSystemInfo({ success: (res) => { this.globalData.height = res.statusBarHeight } }) console.log("download fonts from oss "); let loadStatus = false; if (!loadStatus) { // wx.loadFontFace({ // global: true, // family: 'AlibabaPuHuiTi', // // source: 'url("https://oss.igandan.com/app/fonts/AlibabaPuHuiTi/STXINGKA.TTF")', // source: 'url("https://docwebsite.oss-cn-beijing.aliyuncs.com/app/fonts/AlibabaPuHuiTi/AlibabaPuHuiTi-2-65-Medium/AlibabaPuHuiTi-2-65-Medium.ttf")', // success() { // loadStatus = true; // console.log("download fonts from oss success"); // }, // fail(){ // console.log("download fonts from oss error"); // }, // complete(){ // console.log("download fonts from oss complete"); // } // }); } this.aegisInit() console.warn("app.js wx.aegis: ", wx.aegis); //监听网络状态变化事件 wx.onNetworkStatusChange(function (res) { console.log(res.isConnected) console.log(res.networkType) }) }, onShow(){ this.imInit(); }, imInit(){ let usertype = wx.getStorageSync('usertype'); let userID = wx.getStorageSync('user_id_'+usertype); if(usertype != 2){//只登录医师端 return; } if(userID == ""){ return; } this.globalData.config.userID = userID; let sign = genTestUserSig(this.globalData.config); console.log("sign: ", sign); // const userSig = sign.userSig; //获取im签名数据 api.getSignIM().then(response => { return response.data; }).then((userSig) => { console.log("userSig: ", userSig); wx.$TUIKit = TIM.create({ SDKAppID: this.globalData.config.SDKAPPID }); wx.$chat_userID = this.globalData.config.userID; wx.$chat_SDKAppID = this.globalData.config.SDKAPPID; wx.$chat_userSig = userSig; wx.$TUIKitTIM = TIM; wx.$TUIKit.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin }); let login_promise = wx.$TUIKit.login({ userID: this.globalData.config.userID, userSig }); login_promise.then(function(imResponse) { console.log(imResponse.data); // 登录成功 }).catch(function(imError) { console.warn('login error:', imError); // 登录失败的相关信息 }); wx.$TUIKit.setLogLevel(3);//设置日志级别 wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.SDK_READY, this.onSDKReady, this); }).then(()=>{ //初始化tab-bar角标 let index_info = wx.getStorageSync(userID+'_index_info'); let wenzhen_info = wx.getStorageSync(userID+'_wenzhen_info'); let my_info = wx.getStorageSync(userID+'_my_info'); if(!index_info) wx.setStorageSync(userID+'_index_info',""); if(!wenzhen_info) wx.setStorageSync(userID+'_wenzhen_info', ""); if(!my_info) wx.setStorageSync(userID+'_my_info', ""); }).catch(errors => {console.error(errors);}) }, onSDKReady(){ console.log("onSDKReady from app.js"); this.globalData.chat_sdk_ready = true; wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.MESSAGE_RECEIVED, this.$onSystemPushReceived, this); }, $onSystemPushReceived(e){ console.log("onSystemPushReceived from app.js"); console.log(e) let usertype = wx.getStorageSync('usertype'); let userID = wx.getStorageSync('user_id_'+usertype); let message = e.data[0]; console.log(message) let type = message.type; console.log(type); let unread_name = ""; if(type == TIM.TYPES.MSG_CUSTOM){ let payload = message.payload; let payloadData = payload.data; let payloadDataJson = JSON.parse(payloadData); let message_type = payloadDataJson.message_type; if(message_type == 3) unread_name = userID+"_system_notice_unreadnnum"; //医生端系统通知 if(message_type == 4) unread_name = userID+"_service_notice_unreadnnum"; //医生端服务通知 }else{ unread_name = userID+"_wenzhen_info";//tabbar 问诊角标 } this.formatUnReadNum(unread_name); }, formatUnReadNum(name){ let val = wx.getStorageSync(name); if(val == "") val = 0; if(val == "+99") val = 100; val = val + 1; if(val > 99) val = '+99'; wx.setStorageSync(name, val); }, aegisInit() { wx.aegis = new Aegis({ id: 'iHWefAYquFxvklBblC', // 项目key reportApiSpeed: true, // 接口测速 reportAssetSpeed: true, // 静态资源测速 pagePerformance: true, // 开启页面测速 }); }, globalData: { share: false, // 分享默认为false height: 0, scene: "",//场景值 login_url: "/Pages/login/index", chat_sdk_ready: false, jiesuan_dialog_show: false, config: { userID: "", SDKAPPID: 1400796919, // Your SDKAppID SECRETKEY: "a5bcd8c583181cf004e9d91a47687d719d4b5d2a10ce33fbee95d587889447d8", // Your secretKey EXPIRETIME: 604800, }, }, go(url, ...params){ wx.navigateTo({ url: url }) } })