App.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <script lang="ts">
  2. import { TUIChatKit } from "./TUIKit";
  3. import { TUITranslateService } from "@tencentcloud/chat-uikit-engine";
  4. // #ifndef MP-WEIXIN
  5. import { locales } from "./locales";
  6. // #endif
  7. import TIMPushConfigs from "./timpush-configs.json";
  8. // #ifdef APP-PLUS
  9. // register TencentCloud-TIMPush
  10. import { IEnterChatConfig, loginFromStorage, openChat } from "./loginChat";
  11. import TUIChatEngine from "@tencentcloud/chat-uikit-engine";
  12. import { getNotificationAuth } from "./utils/getNotificationAuth";
  13. const TIMPush: any = uni.requireNativePlugin("TencentCloud-TIMPush");
  14. console.warn(
  15. `TencentCloud-TIMPush: uni.requireNativePlugin ${TIMPush ? "success" : "fail"}`
  16. );
  17. uni.$TIMPush = TIMPush;
  18. uni.$TIMPushConfigs = TIMPushConfigs;
  19. const enterChatConfig: IEnterChatConfig = {
  20. isLoginChat: false,
  21. conversationID: "",
  22. };
  23. // register TencentCloud-TUICallKit
  24. const TUICallKit: any = uni.requireNativePlugin("TencentCloud-TUICallKit");
  25. console.warn(
  26. `TencentCloud-TUICallKit: uni.requireNativePlugin ${TUICallKit ? "success" : "fail"}`
  27. );
  28. uni.$TUICallKit = TUICallKit;
  29. // #endif
  30. // #ifdef APP-ANDROID
  31. const notificationChannelInfo = {
  32. notificationChannelList: [
  33. {
  34. channelID: "tuikit", // 控制台配置 oppo 的 channelID
  35. channelName: "tuikit", // 自定义名称
  36. channelDesc: "自定义铃音", // 自定义描述
  37. channelSound: "private_ring", // 自定义铃音的名称且不需要后缀名
  38. },
  39. ],
  40. };
  41. uni.$TIMPush.createNotificationChannels(notificationChannelInfo);
  42. // #endif
  43. // #ifndef MP-WEIXIN
  44. TUITranslateService.provideLanguages(locales);
  45. TUITranslateService.useI18n();
  46. // #endif
  47. TUIChatKit.init();
  48. const SDKAppID = 1600005199; // Your SDKAppID
  49. const secretKey = "82f8b45664eb3252cf02f939aaac43cd81ba25b7c7f94f45be4f05e173e1ab2d"; // Your secretKey
  50. uni.$chat_SDKAppID = SDKAppID;
  51. uni.$chat_secretKey = secretKey;
  52. export default {
  53. onLaunch: function () {
  54. // #ifdef APP-PLUS
  55. // 在 App.vue, 生命钩子 onLaunch 中监听
  56. if (typeof uni.$TIMPush === "undefined") {
  57. console.warn(
  58. "如果您使用推送功能,需集成 TIMPush 插件,使用真机运行并且自定义基座调试,请参考官网文档:https://cloud.tencent.com/document/product/269/103522"
  59. );
  60. } else {
  61. getNotificationAuth();
  62. uni.$on("uikitLogin", () => {
  63. enterChatConfig.isLoginChat = true;
  64. openChat(enterChatConfig);
  65. });
  66. uni.$TIMPush.setOfflinePushListener((data) => {
  67. const { notification = "" } = data?.data || {};
  68. if (!notification) {
  69. return;
  70. }
  71. const { entity } = JSON.parse(notification);
  72. const type =
  73. entity.chatType === 1
  74. ? TUIChatEngine.TYPES.CONV_C2C
  75. : TUIChatEngine.TYPES.CONV_GROUP;
  76. enterChatConfig.conversationID = `${type}${entity.sender}`;
  77. if (enterChatConfig.isLoginChat && entity.sender) {
  78. openChat(enterChatConfig);
  79. }
  80. });
  81. loginFromStorage();
  82. }
  83. // #endif
  84. },
  85. onShow: function () {},
  86. onHide: function () {},
  87. };
  88. </script>
  89. <style>
  90. /* 每个页面公共css */
  91. uni-page-body,
  92. html,
  93. body,
  94. page {
  95. width: 100% !important;
  96. height: 100% !important;
  97. overflow: hidden;
  98. }
  99. </style>