login.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. ];
  29. // 批量获取参数并存储到storage
  30. const params: any = {};
  31. paramsToFetch.forEach((key) => {
  32. const value = getQueryString(key);
  33. if (value !== undefined && value !== "undefined") {
  34. uni.setStorageSync(key, value);
  35. params[key] = value;
  36. } else {
  37. uni.removeStorageSync(key);
  38. }
  39. });
  40. console.log("params", params);
  41. // 单独处理userSig
  42. userSigs.value = params.userSig || "";
  43. inputValue.value = params;
  44. handleLoginInfo();
  45. });
  46. function getQueryString(name) {
  47. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  48. var r = window.location.search.substr(1).match(reg);
  49. if (r != null) {
  50. return unescape(r[2]);
  51. }
  52. return null;
  53. }
  54. const handleLoginInfo = () => {
  55. const loginInfo = {
  56. SDKAppID: uni.$chat_SDKAppID,
  57. userID: inputValue.value.id,
  58. userSig: inputValue.value.userSig,
  59. useUploadPlugin: true,
  60. framework: `vue${vueVersion}`,
  61. };
  62. login(loginInfo);
  63. };
  64. const login = (loginInfo: any) => {
  65. loginChat(loginInfo).catch(() => {
  66. uni.showToast({
  67. title: TUITranslateService.t("Login.登录失败"),
  68. icon: "none",
  69. });
  70. });
  71. };
  72. </script>
  73. <style lang="scss" scoped>
  74. @import "../../styles/login";
  75. .icon {
  76. display: inline;
  77. }
  78. .btn {
  79. background: none;
  80. border: none;
  81. }
  82. .icon-unselected {
  83. display: inline-block;
  84. width: 12px;
  85. height: 12px;
  86. background: #fff;
  87. border: 1px solid #ddd;
  88. border-radius: 8px;
  89. }
  90. .selected-icon {
  91. width: 14px;
  92. height: 14px;
  93. }
  94. .icon-default {
  95. margin: 7px 6px 0 0;
  96. }
  97. .login-input-uniapp {
  98. border: 1px solid #ccc;
  99. border-radius: 4px;
  100. outline: none;
  101. height: 40px;
  102. padding: 0 0 0 14px;
  103. }
  104. .logo-back-png {
  105. width: 4.61rem;
  106. height: 3.23rem;
  107. }
  108. .private-content-link {
  109. display: inline-block;
  110. }
  111. </style>