App.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <script>
  2. import TIM from 'tim-wx-sdk';
  3. import COS from 'cos-wx-sdk-v5';
  4. import Aegis from 'aegis-weex-sdk';
  5. import {
  6. genTestUserSig
  7. } from './debug/GenerateTestUserSig.js';
  8. const aegis = new Aegis({
  9. id: 'iHWefAYqKznuxWjLnr', // 项目key
  10. reportApiSpeed: true, // 接口测速
  11. });
  12. uni.$aegis = aegis
  13. const TUICalling = uni.requireNativePlugin('TUICallingUniPlugin-TUICallingModule');
  14. export default {
  15. onLaunch() {
  16. const SDKAppID = genTestUserSig('').sdkAppID;
  17. uni.$aegis.reportEvent({
  18. name: 'onLaunch',
  19. ext1: 'onLaunch-success',
  20. ext2: 'uniTuikitExternal',
  21. ext3: `${SDKAppID}`,
  22. })
  23. uni.setStorageSync(`TIM_${SDKAppID}_isTUIKit`, true);
  24. // 重点注意: 为了 uni-app 更好地接入使用 tim,快速定位和解决问题,请勿修改 uni.$TUIKit 命名。
  25. // 如果您已经接入 tim ,请将 uni.tim 修改为 uni.$TUIKit。
  26. uni.$TUIKit = TIM.create({
  27. SDKAppID: SDKAppID
  28. });
  29. // #ifndef H5
  30. uni.$TUIKit.registerPlugin({
  31. 'cos-wx-sdk': COS
  32. });
  33. // #endif
  34. // #ifdef H5
  35. uni.$TUIKit.registerPlugin({ 'tim-upload-plugin':TIMUploadPlugin })
  36. // #endif
  37. // 将原生插件挂载在 uni 上
  38. // #ifdef APP-PLUS
  39. uni.$TUICalling = TUICalling;
  40. // #endif
  41. // 如果您已创建了 tim,请将 tim 实例挂载在 wx 上,且不可以修改 wx.$TIM(修改变量可能导致 TUICalling 组件无法正常使用), 完成 TUICalling 初始化,
  42. // 如果您没有创建,可以不传
  43. // #ifdef MP-WEIXIN
  44. wx.$TIM = uni.$TUIKit;
  45. // #endif
  46. uni.$TUIKitTIM = TIM;
  47. uni.$TUIKitEvent = TIM.EVENT;
  48. uni.$TUIKitVersion = TIM.VERSION;
  49. uni.$TUIKitTypes = TIM.TYPES; // 监听系统级事件
  50. uni.$resetLoginData = this.resetLoginData();
  51. uni.$TUIKit.on(uni.$TUIKitEvent.SDK_READY, this.onSDKReady);
  52. uni.$TUIKit.on(uni.$TUIKitEvent.SDK_NOT_READY, this.onSdkNotReady);
  53. uni.$TUIKit.on(uni.$TUIKitEvent.KICKED_OUT, this.onKickedOut);
  54. uni.$TUIKit.on(uni.$TUIKitEvent.ERROR, this.onTIMError);
  55. uni.$TUIKit.on(uni.$TUIKitEvent.NET_STATE_CHANGE, this.onNetStateChange);
  56. uni.$TUIKit.on(uni.$TUIKitEvent.SDK_RELOAD, this.onSDKReload);
  57. },
  58. globalData: {
  59. // userInfo: userID userSig token phone
  60. userInfo: null,
  61. // 个人信息
  62. userProfile: null,
  63. isTUIKit: true,
  64. headerHeight: 0,
  65. statusBarHeight: 0,
  66. SDKAppID: genTestUserSig('').sdkAppID
  67. },
  68. methods: {
  69. // TODO:
  70. resetLoginData() {
  71. this.globalData.expiresIn = '';
  72. this.globalData.sessionID = '';
  73. this.globalData.userInfo = {
  74. userID: '',
  75. userSig: '',
  76. token: '',
  77. phone: ''
  78. };
  79. this.globalData.userProfile = null;
  80. },
  81. onTIMError() {},
  82. onSDKReady({name}) {
  83. const isSDKReady = name === uni.$TUIKitEvent.SDK_READY ? true : false
  84. uni.$emit('isSDKReady', {
  85. isSDKReady: true
  86. });
  87. },
  88. onNetStateChange() {},
  89. onSDKReload() {},
  90. onSdkNotReady() {},
  91. onKickedOut() {
  92. uni.showToast({
  93. title: '您被踢下线',
  94. icon: 'error'
  95. });
  96. uni.navigateTo({
  97. url: './pages/TUI-Login/login'
  98. });
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="less">
  104. @import '~@/commons/commons.less';
  105. @import "@/static/font/iconfont.css";
  106. /*每个页面公共css */
  107. </style>