login.vue 2.2 KB

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