login.vue 2.3 KB

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