login.vue 3.2 KB

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