login.vue 3.6 KB

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