uniapp调用sdk示例

``` <template> <view class="content"> <view> <text style="color:black;">当前状态:{{textStatus}}</text> <text style="color:black;">socket状态:{{socketStatus}}</text> </view> <view class="button" @click="initSdk"> <button>初始化sdk</button> </view> <view class="button" @click="login()"> <button>登录</button> </view> <view class="button"> <view class="text"> <button style="min-width: 200rpx;" @click="openChatMeesage">消息</button> <text style="color: red; width: 100rpx; display: flex; justify-content: center;"> {{unreadNum}} </text> </view> </view> <view class="button" @click="openChatMeeting"> <button>视频会议</button> </view> <view class="button" @click="sendChat"> <button>发起聊天</button> </view> <view class="button" @click="openChatContact()"> <button>通讯录</button> </view> <view class="button" @click="openWorkStation()()"> <button>工作台</button> </view> <view class="button" @click="logout()"> <button>退出登录</button> </view> <view class="button" @click="getCurLoginStatus()"> <button>获取当前登录状态</button> </view> </view> </template> <script> export default { data() { return { unreadNum: 0, textStatus: "", socketStatus: "", } }, methods: { async initSdk() { console.log('result initSdk()') this.textStatus = "点击初始化" const pluginImpl = uni.requireNativePlugin('dchtModule') pluginImpl.initHtImSdk({ "uprtcAppId": "dc44e4cb", "uprtcAppKey": "76ec10d1dba73485fc655570e0d51e5f" }, result => { console.log('initHtImSdk result ' + JSON.stringify(result)) if (result.message) { this.textStatus = result.message; } }); }, async login() { console.log('result login()') this.textStatus = "点击登录" const pluginImpl = uni.requireNativePlugin('dchtModule') pluginImpl.htImLogin({ "serverUrl": "http://192.168.1.96:90", "userSdkKey": "", "loginId": "admin", "password": "123456", "languageType": "CN", "vendorDeviceToken": "", "cidDeviceToken": "", "extra": "" }, result => { console.log('htImLogin result ' + JSON.stringify(result)) if (result.message) { this.textStatus = result.message; } if (result.code == 0) { this.addChatListener(); pluginImpl.htImSetRouteListener(result1 => { console.log('htImSetRouteListener result1 ' + JSON.stringify(result1)) }); pluginImpl.htImDataInit(result2 => { console.log('htImDataInit result2 ' + JSON.stringify(result2)) }); } }); }, async addChatListener() { const pluginImpl = uni.requireNativePlugin('dchtModule') pluginImpl.htImAddChatListener(result => { console.log('htImAddChatListener result ' + JSON.stringify(result)) if (result.code == 0) { var data = JSON.parse(result.data) if (data.type == 1) { //消息未读数监听 this.unreadNum = data.unreadNum; console.log('htImAddChatListener 消息未读数 = ' + data.unreadNum) } else if (data.type == 2) { //待办未读数监听 console.log('htImAddChatListener 待办数 = ' + data.unreadNum) } } else if (result.code === -1) { //登录失效 var data = JSON.parse(result.data) this.textStatus = data.type + " " + data.message; this.finishAllActivity(); } else if (result.code === -2) { //socket连接状态 var data = JSON.parse(result.data) this.socketStatus = data.type + " " + data.isConnect + " " + data.message; } }); }, async removeChatListener() { const pluginImpl = uni.requireNativePlugin('dchtModule') pluginImpl.htImRemoveChatListener(); console.log('removeChatListener ') }, async sendChat() { const pluginImpl = uni.requireNativePlugin('dchtModule') var res = pluginImpl.htImSendChat(); console.log('htImSendChat res ' + JSON.stringify(res)) }, async openChatMeeting() { const pluginImpl = uni.requireNativePlugin('dchtModule') var res = pluginImpl.htImOpenChatMeeting(); console.log('htImOpenChatMeeting res ' + JSON.stringify(res)) }, async openChatMeesage() { const pluginImpl = uni.requireNativePlugin('dchtModule') var res = pluginImpl.htImOpenChatMessage(); console.log('htImOpenChatMessage res ' + JSON.stringify(res)) }, async openChatContact() { const pluginImpl = uni.requireNativePlugin('dchtModule') var res = pluginImpl.htImOpenContact(); console.log('htImOpenContact res ' + JSON.stringify(res)) }, async openWorkStation() { const pluginImpl = uni.requireNativePlugin('dchtModule') var res = pluginImpl.htImOpenWorkStation(); console.log('htImOpenWorkStation res ' + JSON.stringify(res)) }, async logout() { this.textStatus = "点击退出登录" const pluginImpl = uni.requireNativePlugin('dchtModule') pluginImpl.htImLogout(result => { if (result.message) { this.textStatus = result.message; } console.log('htImLogout res ' + JSON.stringify(result)) this.removeChatListener(); }); }, async getCurLoginStatus() { const pluginImpl = uni.requireNativePlugin('dchtModule') var isLogin = pluginImpl.getLoginStatus() console.log('getCurLoginStatus res ' + isLogin) if (isLogin == true) { this.textStatus = "已登录"; } else { this.textStatus = "未登录"; } }, async finishAllActivity() { const pluginImpl = uni.requireNativePlugin('dchtModule') pluginImpl.htImFinishAllActivity() console.log('htImFinishAllActivity res ') } } } </script> <style> .content { display: flex; flex-direction: column; align-items: center; justify-content: center; } .text { display: flex; flex-direction: row; justify-content: center; align-items: center; } .button { min-width: 300rpx; padding-top: 10rpx; } </style> ```