login.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template></template>
  2. <script lang="ts" setup>
  3. import { ref, vueVersion } from "../../TUIKit/adapter-vue";
  4. import { onLoad, onShow } from "@dcloudio/uni-app";
  5. import { TUITranslateService } from "@tencentcloud/chat-uikit-engine";
  6. import Link from "../../utils/link";
  7. import { genTestUserSig } from "../../TUIKit/debug";
  8. import { isPC, isH5, isApp } from "../../TUIKit/utils/env";
  9. import Icon from "../../TUIKit/components/common/Icon.vue";
  10. import logo from "../../static/logo-back.svg";
  11. import { loginChat } from "../../loginChat";
  12. const privateAgree = ref(false);
  13. const inputValue = ref("");
  14. onLoad((options) => {
  15. let personId = getQueryString("personId");
  16. let type = getQueryString("type");
  17. let openid = getQueryString("openid");
  18. // 获取跳转的token和userId
  19. let token = getQueryString("token");
  20. let id = getQueryString("id");
  21. uni.setStorageSync("personId", personId);
  22. uni.setStorageSync("type", type);
  23. uni.setStorageSync("token", token);
  24. uni.setStorageSync("userId", id);
  25. uni.setStorageSync("openid", openid);
  26. let params = {
  27. token: token,
  28. id: id,
  29. };
  30. init(params);
  31. });
  32. function getQueryString(name) {
  33. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  34. var r = window.location.search.substr(1).match(reg);
  35. if (r != null) {
  36. return unescape(r[2]);
  37. }
  38. return null;
  39. }
  40. function init(params) {
  41. inputValue.value = params.id;
  42. handleLoginInfo();
  43. }
  44. const onAgreePrivateProtocol = () => {
  45. privateAgree.value = !privateAgree.value;
  46. };
  47. const handleLoginInfo = () => {
  48. const options = genTestUserSig({
  49. SDKAppID: uni.$chat_SDKAppID,
  50. secretKey: uni.$chat_secretKey,
  51. userID: inputValue.value,
  52. });
  53. const loginInfo = {
  54. SDKAppID: uni.$chat_SDKAppID,
  55. userID: inputValue.value,
  56. userSig: options.userSig,
  57. useUploadPlugin: true,
  58. framework: `vue${vueVersion}`,
  59. TIMPush: uni.$TIMPush, // register TencentCloud-TIMPush
  60. pushConfig: {
  61. androidConfig: uni.$TIMPushConfigs, // Android timpush-configs.json
  62. iOSConfig: {
  63. iOSBusinessID: "", // iOS Certificate ID
  64. },
  65. },
  66. };
  67. login(loginInfo);
  68. };
  69. const login = (loginInfo: any) => {
  70. loginChat(loginInfo).catch(() => {
  71. uni.showToast({
  72. title: TUITranslateService.t("Login.登录失败"),
  73. icon: "none",
  74. });
  75. });
  76. };
  77. const openFullPlatformLink = (link: string) => {
  78. if (isPC || isH5) {
  79. window.open(link);
  80. } else if (isApp) {
  81. plus?.runtime?.openURL(link);
  82. }
  83. };
  84. </script>
  85. <style lang="scss" scoped>
  86. @import "../../styles/login";
  87. .icon {
  88. display: inline;
  89. }
  90. .btn {
  91. background: none;
  92. border: none;
  93. }
  94. .icon-unselected {
  95. display: inline-block;
  96. width: 12px;
  97. height: 12px;
  98. background: #fff;
  99. border: 1px solid #ddd;
  100. border-radius: 8px;
  101. }
  102. .selected-icon {
  103. width: 14px;
  104. height: 14px;
  105. }
  106. .icon-default {
  107. margin: 7px 6px 0 0;
  108. }
  109. .login-input-uniapp {
  110. border: 1px solid #ccc;
  111. border-radius: 4px;
  112. outline: none;
  113. height: 40px;
  114. padding: 0 0 0 14px;
  115. }
  116. .logo-back-png {
  117. width: 4.61rem;
  118. height: 3.23rem;
  119. }
  120. .private-content-link {
  121. display: inline-block;
  122. }
  123. </style>