login.vue 3.6 KB

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