login.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 { loginChat } from "../../loginChat";
  7. const inputValue: any = ref("");
  8. const userSigs = ref();
  9. onLoad(() => {
  10. const paramsToFetch = [
  11. "type",
  12. "token",
  13. "id",
  14. "userSig",
  15. "loginType",
  16. "companyUserId",
  17. "postId",
  18. "recruitUserId",
  19. "userId",
  20. "link",
  21. "Identity",
  22. "shopUserId",
  23. "houseId",
  24. "refId",
  25. "demandId",
  26. "userLoginType",
  27. "userType",
  28. "agentType",
  29. ];
  30. // 批量获取参数并存储到storage
  31. const params: any = {};
  32. paramsToFetch.forEach((key) => {
  33. const value = getQueryString(key);
  34. if (value !== undefined && value !== "undefined") {
  35. uni.setStorageSync(key, value);
  36. params[key] = value;
  37. } else {
  38. uni.removeStorageSync(key);
  39. }
  40. });
  41. console.log("params", params);
  42. // 单独处理userSig
  43. userSigs.value = params.userSig || "";
  44. inputValue.value = params;
  45. handleLoginInfo();
  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. const handleLoginInfo = () => {
  56. const loginInfo = {
  57. SDKAppID: uni.$chat_SDKAppID,
  58. userID: inputValue.value.id,
  59. userSig: inputValue.value.userSig,
  60. useUploadPlugin: true,
  61. framework: `vue${vueVersion}`,
  62. };
  63. login(loginInfo);
  64. };
  65. const login = (loginInfo: any) => {
  66. loginChat(loginInfo).catch(() => {
  67. uni.showToast({
  68. title: TUITranslateService.t("Login.登录失败"),
  69. icon: "none",
  70. });
  71. });
  72. };
  73. </script>
  74. <style lang="scss" scoped>
  75. @import "../../styles/login";
  76. .icon {
  77. display: inline;
  78. }
  79. .btn {
  80. background: none;
  81. border: none;
  82. }
  83. .icon-unselected {
  84. display: inline-block;
  85. width: 12px;
  86. height: 12px;
  87. background: #fff;
  88. border: 1px solid #ddd;
  89. border-radius: 8px;
  90. }
  91. .selected-icon {
  92. width: 14px;
  93. height: 14px;
  94. }
  95. .icon-default {
  96. margin: 7px 6px 0 0;
  97. }
  98. .login-input-uniapp {
  99. border: 1px solid #ccc;
  100. border-radius: 4px;
  101. outline: none;
  102. height: 40px;
  103. padding: 0 0 0 14px;
  104. }
  105. .logo-back-png {
  106. width: 4.61rem;
  107. height: 3.23rem;
  108. }
  109. .private-content-link {
  110. display: inline-block;
  111. }
  112. </style>