App.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 = 1600037650; // 测试appid
  49. // const secretKey =
  50. // "2f6c61ac073596b399d7605460e3dc3aba5edec16c2b8196a33464cc3caaa1f7"; // 测试key
  51. uni.$chat_SDKAppID = SDKAppID;
  52. // uni.$chat_secretKey = secretKey;
  53. export default {
  54. onLaunch: function () {
  55. // #ifdef APP-PLUS
  56. // 在 App.vue, 生命钩子 onLaunch 中监听
  57. if (typeof uni.$TIMPush === "undefined") {
  58. console.warn(
  59. "如果您使用推送功能,需集成 TIMPush 插件,使用真机运行并且自定义基座调试,请参考官网文档:https://cloud.tencent.com/document/product/269/103522"
  60. );
  61. } else {
  62. getNotificationAuth();
  63. uni.$on("uikitLogin", () => {
  64. enterChatConfig.isLoginChat = true;
  65. openChat(enterChatConfig);
  66. });
  67. uni.$TIMPush.setOfflinePushListener((data) => {
  68. const { notification = "" } = data?.data || {};
  69. if (!notification) {
  70. return;
  71. }
  72. const { entity } = JSON.parse(notification);
  73. const type =
  74. entity.chatType === 1
  75. ? TUIChatEngine.TYPES.CONV_C2C
  76. : TUIChatEngine.TYPES.CONV_GROUP;
  77. enterChatConfig.conversationID = `${type}${entity.sender}`;
  78. if (enterChatConfig.isLoginChat && entity.sender) {
  79. openChat(enterChatConfig);
  80. }
  81. });
  82. loginFromStorage();
  83. }
  84. // #endif
  85. },
  86. onShow: function () {},
  87. onHide: function () {},
  88. };
  89. </script>
  90. <style lang="scss">
  91. $main-color: #12ae85;
  92. /* 每个页面公共css */
  93. @import "@/uni_modules/uview-ui/index.scss";
  94. @import "./static/css/common.scss";
  95. @import "./static/css/qzy.scss";
  96. uni-page-body,
  97. html,
  98. body,
  99. page {
  100. width: 100% !important;
  101. height: 100% !important;
  102. overflow: hidden;
  103. }
  104. </style>