App.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <script>
  2. import amap from './common/amap-wx.130.js'
  3. var amapPlugin = new amap.AMapWX({
  4. key: 'bb69713f3c3d3c85e2662d313daa47b9'
  5. });
  6. import webIM from './utils/WebIM.js'
  7. export default {
  8. globalData: {
  9. getLoca: function() {
  10. var city = uni.getStorageSync('city')
  11. return new Promise((resolve, reject) => {
  12. if(!city) {
  13. uni.authorize({
  14. scope: 'scope.userLocation',
  15. success() {
  16. wx.getLocation({
  17. type: 'wgs84',
  18. success(res) {
  19. amapPlugin.getRegeo({
  20. success(data) {
  21. resolve(data)
  22. },
  23. fail(err) {
  24. console.log('err=',err)
  25. }
  26. })
  27. },
  28. fail(err){
  29. console.log('err=',err)
  30. }
  31. })
  32. },
  33. fail(err) {
  34. closeLoading('error',err)
  35. }
  36. })
  37. }
  38. })
  39. }
  40. },
  41. onLoad() {
  42. },
  43. onLaunch: function() {
  44. console.log('App Launch')
  45. this.HXlogin()
  46. this.HXlisten()
  47. },
  48. onShow: function() {
  49. console.log('App Show')
  50. },
  51. onHide: function() {
  52. console.log('App Hide')
  53. },
  54. methods: {
  55. HXlisten(){
  56. console.log('<<<<<<环信监听',uni.WebIM)
  57. uni.WebIM.conn.listen({
  58. onOpened: function () {
  59. console.log('>>>>>>环信登录成功啦')
  60. }, //连接成功回调
  61. onClosed: function () {
  62. console.log("<<<<<连接关闭");
  63. }, //连接关闭回调
  64. onTextMessage: function ( message ) {
  65. console.log("收到文本消息",message);
  66. }, //收到文本消息
  67. onEmojiMessage: function ( message ) {}, //收到表情消息
  68. onPictureMessage: function ( message ) {}, //收到图片消息
  69. onCmdMessage: function ( message ) {}, //收到命令消息
  70. onAudioMessage: function ( message ) {}, //收到音频消息
  71. onLocationMessage: function ( message ) {},//收到位置消息
  72. onFileMessage: function ( message ) {}, //收到文件消息
  73. onCustomMessage: function ( message ) {}, //收到自定义消息
  74. onVideoMessage: function (message) {
  75. var node = document.getElementById('privateVideo');
  76. var option = {
  77. url: message.url,
  78. headers: {
  79. 'Accept': 'audio/mp4'
  80. },
  81. onFileDownloadComplete: function (response) {
  82. var objectURL = uni.WebIM.utils.parseDownloadResponse.call(conn, response);
  83. node.src = objectURL;
  84. },
  85. onFileDownloadError: function () {
  86. console.log('File down load error.')
  87. }
  88. };
  89. uni.WebIM.utils.download.call(conn, option);
  90. }, //收到视频消息
  91. onPresence: function ( message ) {}, //处理“广播”或“发布-订阅”消息,如联系人订阅请求、处理群组、聊天室被踢解散等消息
  92. onRoster: function ( message ) {
  93. console.log('处理好友申请',message);
  94. }, //处理好友申请
  95. onInviteMessage: function ( message ) {}, //处理群组邀请
  96. onOnline: function () {
  97. console.log('本机网络连接成功');
  98. }, //本机网络连接成功
  99. onOffline: function () {
  100. console.log("本机网络掉线",message);
  101. }, //本机网络掉线
  102. onError: function ( message ) {
  103. console.log("失败回调:",message);
  104. }, //失败回调
  105. onBlacklistUpdate: function (list) { //黑名单变动
  106. // 查询黑名单,将好友拉黑,将好友从黑名单移除都会回调这个函数,list则是黑名单现有的所有好友信息
  107. console.log(list);
  108. },
  109. onRecallMessage: function(message){}, //收到撤回消息回调
  110. onReceivedMessage: function(message){
  111. console.log("收到消息送达服务器回执",message);
  112. }, //收到消息送达服务器回执
  113. onDeliveredMessage: function(message){
  114. console.log("收到消息送达客户端回执",message);
  115. }, //收到消息送达客户端回执
  116. onReadMessage: function(message){
  117. console.log("收到消息已读回执",message);
  118. }, //收到消息已读回执
  119. onCreateGroup: function(message){}, //创建群组成功回执(需调用createGroupNew)
  120. onMutedMessage: function(message){}, //如果用户在A群组被禁言,在A群发消息会走这个回调并且消息不会传递给群其它成员
  121. onChannelMessage: function(message){} //收到整个会话已读的回执,在对方发送channel ack时会在这个回调里收到消息
  122. });
  123. },
  124. HXlogin() {
  125. var HXtoken = uni.getStorageSync('HXtoken')
  126. if(HXtoken) {
  127. var userId = uni.getStorageSync('id')
  128. var options = {
  129. user: userId.toString(),
  130. pwd : '123456',
  131. appKey: uni.WebIM.config.appkey,
  132. success: function() {
  133. console.log("登录成功");
  134. var lianjie = uni.WebIM.conn.isOpened()
  135. console.log('链接',lianjie);
  136. },
  137. error: function() {
  138. console.log("登录失败");
  139. }
  140. }
  141. uni.WebIM.conn.open(options);
  142. }
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss">
  148. /*每个页面公共css */
  149. @import "uview-ui/index.scss";
  150. .content {
  151. background-color: #ffffff;
  152. width: 100%;
  153. min-height: 100vh;
  154. display: flex;
  155. flex-direction: column;
  156. font-size: 28rpx;
  157. color: #333;
  158. box-sizing: border-box;
  159. }
  160. .hflex {
  161. display: flex;
  162. flex-direction: row;
  163. flex-wrap: nowrap;
  164. }
  165. .vflex {
  166. display: flex;
  167. flex-direction: column;
  168. flex-wrap: nowrap;
  169. }
  170. .jbetween {
  171. justify-content: space-between;
  172. }
  173. .jaround {
  174. justify-content: space-around;
  175. }
  176. .jend {
  177. justify-content: flex-end;
  178. }
  179. .jcenter {
  180. justify-content: center;
  181. }
  182. .acenter {
  183. align-items: center;
  184. }
  185. .abetween {
  186. align-content: space-between;
  187. }
  188. .astart {
  189. align-items: flex-start;
  190. }
  191. .aend {
  192. align-items: flex-end;
  193. }
  194. .fwrap {
  195. flex-wrap: wrap;
  196. }
  197. .text_hide {
  198. overflow: hidden;
  199. white-space: nowrap;
  200. text-overflow: ellipsis;
  201. }
  202. </style>