123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- <script>
- import amap from './common/amap-wx.130.js'
- var amapPlugin = new amap.AMapWX({
- key: 'bb69713f3c3d3c85e2662d313daa47b9'
- });
- import webIM from './utils/WebIM.js'
- export default {
- globalData: {
-
- getLoca: function() {
- var city = uni.getStorageSync('city')
- return new Promise((resolve, reject) => {
- if(!city) {
- uni.authorize({
- scope: 'scope.userLocation',
- success() {
- wx.getLocation({
- type: 'wgs84',
- success(res) {
- amapPlugin.getRegeo({
- success(data) {
- resolve(data)
- },
- fail(err) {
- console.log('err=',err)
- }
- })
- },
- fail(err){
- console.log('err=',err)
- }
- })
- },
- fail(err) {
- closeLoading('error',err)
- }
- })
- }
- })
-
- }
- },
- onLoad() {
-
- },
- onLaunch: function() {
- console.log('App Launch')
- this.HXlogin()
- this.HXlisten()
- },
- onShow: function() {
- console.log('App Show')
- },
- onHide: function() {
- console.log('App Hide')
- },
- methods: {
- HXlisten(){
- console.log('<<<<<<环信监听',uni.WebIM)
- uni.WebIM.conn.listen({
- onOpened: function () {
- console.log('>>>>>>环信登录成功啦')
- }, //连接成功回调
- onClosed: function () {
- console.log("<<<<<连接关闭");
- }, //连接关闭回调
- onTextMessage: function ( message ) {
- console.log("收到文本消息",message);
- }, //收到文本消息
- onEmojiMessage: function ( message ) {}, //收到表情消息
- onPictureMessage: function ( message ) {}, //收到图片消息
- onCmdMessage: function ( message ) {}, //收到命令消息
- onAudioMessage: function ( message ) {}, //收到音频消息
- onLocationMessage: function ( message ) {},//收到位置消息
- onFileMessage: function ( message ) {}, //收到文件消息
- onCustomMessage: function ( message ) {}, //收到自定义消息
- onVideoMessage: function (message) {
- var node = document.getElementById('privateVideo');
- var option = {
- url: message.url,
- headers: {
- 'Accept': 'audio/mp4'
- },
- onFileDownloadComplete: function (response) {
- var objectURL = uni.WebIM.utils.parseDownloadResponse.call(conn, response);
- node.src = objectURL;
- },
- onFileDownloadError: function () {
- console.log('File down load error.')
- }
- };
- uni.WebIM.utils.download.call(conn, option);
- }, //收到视频消息
- onPresence: function ( message ) {}, //处理“广播”或“发布-订阅”消息,如联系人订阅请求、处理群组、聊天室被踢解散等消息
- onRoster: function ( message ) {
- console.log('处理好友申请',message);
- }, //处理好友申请
- onInviteMessage: function ( message ) {}, //处理群组邀请
- onOnline: function () {
- console.log('本机网络连接成功');
- }, //本机网络连接成功
- onOffline: function () {
- console.log("本机网络掉线",message);
- }, //本机网络掉线
- onError: function ( message ) {
- console.log("失败回调:",message);
- }, //失败回调
- onBlacklistUpdate: function (list) { //黑名单变动
- // 查询黑名单,将好友拉黑,将好友从黑名单移除都会回调这个函数,list则是黑名单现有的所有好友信息
- console.log(list);
- },
- onRecallMessage: function(message){}, //收到撤回消息回调
- onReceivedMessage: function(message){
- console.log("收到消息送达服务器回执",message);
- }, //收到消息送达服务器回执
- onDeliveredMessage: function(message){
- console.log("收到消息送达客户端回执",message);
- }, //收到消息送达客户端回执
- onReadMessage: function(message){
- console.log("收到消息已读回执",message);
- }, //收到消息已读回执
- onCreateGroup: function(message){}, //创建群组成功回执(需调用createGroupNew)
- onMutedMessage: function(message){}, //如果用户在A群组被禁言,在A群发消息会走这个回调并且消息不会传递给群其它成员
- onChannelMessage: function(message){} //收到整个会话已读的回执,在对方发送channel ack时会在这个回调里收到消息
- });
- },
- HXlogin() {
- var HXtoken = uni.getStorageSync('HXtoken')
- if(HXtoken) {
- var userId = uni.getStorageSync('id')
- var options = {
- user: userId.toString(),
- pwd : '123456',
- appKey: uni.WebIM.config.appkey,
- success: function() {
- console.log("登录成功");
- var lianjie = uni.WebIM.conn.isOpened()
- console.log('链接',lianjie);
- },
- error: function() {
- console.log("登录失败");
- }
- }
- uni.WebIM.conn.open(options);
-
- }
-
- }
- }
- }
- </script>
- <style lang="scss">
- /*每个页面公共css */
- @import "uview-ui/index.scss";
-
- .content {
- background-color: #ffffff;
- width: 100%;
- min-height: 100vh;
- display: flex;
- flex-direction: column;
- font-size: 28rpx;
- color: #333;
- box-sizing: border-box;
- }
- .hflex {
- display: flex;
- flex-direction: row;
- flex-wrap: nowrap;
- }
- .vflex {
- display: flex;
- flex-direction: column;
- flex-wrap: nowrap;
- }
- .jbetween {
- justify-content: space-between;
- }
- .jaround {
- justify-content: space-around;
- }
- .jend {
- justify-content: flex-end;
- }
- .jcenter {
- justify-content: center;
- }
- .acenter {
- align-items: center;
- }
- .abetween {
- align-content: space-between;
- }
- .astart {
- align-items: flex-start;
- }
- .aend {
- align-items: flex-end;
- }
- .fwrap {
- flex-wrap: wrap;
- }
- .text_hide {
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- </style>
|