2023-03-06 17:57:39 +08:00

64 lines
1.9 KiB
JavaScript

// index.js
import TIM from '../../../TUIKit/lib/tim-wx-sdk';
import { genTestUserSig } from '../../../TUIKit/debug/GenerateTestUserSig';
import TIMUploadPlugin from '../../../TUIKit/lib/tim-upload-plugin';
const app = getApp()
Page({
data: {
config: {
userID: "xiaobeibei", //User ID
SDKAPPID: 1400793692, // Your SDKAppID
SECRETKEY: "44d97cf741fc758be98cdad100015582b6ad1dc5a3b6676c1997a57279eecfa9", // Your secretKey
EXPIRETIME: 604800,
},
patient_account: "ayu",
title: '患者姓名',
height: app.globalData.height,
},
onLoad() {
console.log("chat onload");
let sign = genTestUserSig(this.data.config);
console.log("sign: ", sign);
const userSig = sign.userSig;
console.log("userSig: ", userSig);
wx.$TUIKit = TIM.create({
SDKAppID: this.data.config.SDKAPPID
});
wx.$chat_SDKAppID = this.data.config.SDKAPPID;
wx.$chat_userID = this.data.config.userID;
wx.$chat_userSig = userSig;
wx.$TUIKitTIM = TIM;
wx.$TUIKit.registerPlugin({ 'tim-upload-plugin': TIMUploadPlugin });
wx.$TUIKit.login({
userID: this.data.config.userID,
userSig
});
wx.$TUIKit.setLogLevel(3);//设置日志级别
wx.setStorage({
key: 'currentUserID',
data: [],
});
wx.$TUIKit.on(wx.$TUIKitTIM.EVENT.SDK_READY, this.onSDKReady,this);
},
onUnload() {
console.log("chat onUnload");
wx.$TUIKit.off(wx.$TUIKitTIM.EVENT.SDK_READY, this.onSDKReady,this);
},
onShow(){
let _this = this;
let interval = setInterval(() => {
if(app.globalData.chat_sdk_ready){
_this.onSDKReady();
clearInterval(interval);
}
}, 100);
},
onSDKReady() {
console.error("chat js: onSDKReady")
const TUIChat = this.selectComponent('#TUIChat');
TUIChat.init();
app.globalData.chat_sdk_ready = true
}
})