main.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import Vue from 'vue';
  2. import App from './App';
  3. //import GoEasy from '@/uni_modules/GOEASY-IM/js_sdk/goeasy-2.13.21.esm.min.js'
  4. import GoEasy from '@/uni_modules/GOEASY-IM/js_sdk/goeasy-2.13.24-0.esm.min.js'
  5. import GRTC from './lib/goeasy-rtc-0.3.7.esm.min.js'
  6. //import GRTC from './lib/goeasy-2.13.24-0.esm.min.js'
  7. import request from '@/utils/request.js'
  8. Vue.prototype.$http = request.http
  9. Vue.prototype.$http2 = request.http2
  10. Vue.prototype.$request =request
  11. console.log("main.js")
  12. console.log(request.baseUrl)
  13. var header={};
  14. header['Content-Type']='application/x-www-form-urlencoded';
  15. uni.request({
  16. method: "POST",
  17. url: request.baseUrl + 'imSys/imAppKey',
  18. data: {},
  19. header: header,
  20. dataType: 'json',
  21. }).then((response) => {
  22. let [error, res] = response;
  23. var appKey=res.data.data.appKey
  24. console.log(res.data.data.appKey)
  25. GoEasy.init({
  26. host:"hangzhou.goeasy.io",//应用所在的区域地址: 【hangzhou.goeasy.io |singapore.goeasy.io】
  27. appkey:appKey,//"BC-729fefdf1ad7417daea8e62b9fce3f74",// common key
  28. modules: ['im'],
  29. // true表示支持通知栏提醒,false则表示不需要通知栏提醒
  30. allowNotification: true //仅有效于app,小程序和H5将会被自动忽略
  31. });
  32. GRTC.init(GoEasy);
  33. uni.$GoEasy = GoEasy;
  34. uni.$GRTC = GRTC;
  35. Vue.config.productionTip = false;
  36. App.mpType = 'app';
  37. const app = new Vue({
  38. ...App
  39. });
  40. app.$mount();
  41. })
  42. GoEasy.onClickNotification((message) => {
  43. let currentUrl;
  44. const routes = getCurrentPages();
  45. if (routes && routes.length) {
  46. const curRoute = routes[routes.length - 1].route;
  47. const curParam = routes[routes.length - 1].options;
  48. currentUrl = '/' + curRoute + `?to=${curParam.to}`;
  49. }
  50. let newUrl;
  51. switch (message.toType) {
  52. case GoEasy.IM_SCENE.PRIVATE:
  53. newUrl = '/pages/privateChat?to=' + message.senderId;
  54. break;
  55. case GoEasy.IM_SCENE.GROUP:
  56. newUrl = '/pages/groupChat?to=' + message.groupId;
  57. break;
  58. }
  59. if (currentUrl !== newUrl) {
  60. uni.navigateTo({
  61. url: newUrl,
  62. });
  63. }
  64. });