login.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 || userSigs.value,
  56. // userID: inputValue.value,
  57. // });
  58. const loginInfo = {
  59. SDKAppID: uni.$chat_SDKAppID,
  60. userID: inputValue.value,
  61. userSig: userSigs.value,
  62. useUploadPlugin: true,
  63. framework: `vue${vueVersion}`,
  64. TIMPush: uni.$TIMPush, // register TencentCloud-TIMPush
  65. pushConfig: {
  66. androidConfig: uni.$TIMPushConfigs, // Android timpush-configs.json
  67. iOSConfig: {
  68. iOSBusinessID: "", // iOS Certificate ID
  69. },
  70. },
  71. };
  72. login(loginInfo);
  73. };
  74. const login = (loginInfo: any) => {
  75. loginChat(loginInfo).catch(() => {
  76. uni.showToast({
  77. title: TUITranslateService.t("Login.登录失败"),
  78. icon: "none",
  79. });
  80. });
  81. };
  82. const openFullPlatformLink = (link: string) => {
  83. if (isPC || isH5) {
  84. window.open(link);
  85. } else if (isApp) {
  86. plus?.runtime?.openURL(link);
  87. }
  88. };
  89. </script>
  90. <style lang="scss" scoped>
  91. @import "../../styles/login";
  92. .icon {
  93. display: inline;
  94. }
  95. .btn {
  96. background: none;
  97. border: none;
  98. }
  99. .icon-unselected {
  100. display: inline-block;
  101. width: 12px;
  102. height: 12px;
  103. background: #fff;
  104. border: 1px solid #ddd;
  105. border-radius: 8px;
  106. }
  107. .selected-icon {
  108. width: 14px;
  109. height: 14px;
  110. }
  111. .icon-default {
  112. margin: 7px 6px 0 0;
  113. }
  114. .login-input-uniapp {
  115. border: 1px solid #ccc;
  116. border-radius: 4px;
  117. outline: none;
  118. height: 40px;
  119. padding: 0 0 0 14px;
  120. }
  121. .logo-back-png {
  122. width: 4.61rem;
  123. height: 3.23rem;
  124. }
  125. .private-content-link {
  126. display: inline-block;
  127. }
  128. </style>