• vue通过获取url中的信息登录页面


    在主界面获取到url的信息  html

     

    1. <script>
    2. let getRequest = function () {
    3. var url = location.href
    4. // 从 URL 中提取查询参数部分
    5. const queryParamsString = url.split('?')[1];
    6. // 使用 URLSearchParams 解析查询参数
    7. const queryParams = new URLSearchParams(queryParamsString);
    8. // 获取特定参数的值
    9. const userName = queryParams.get('userName');
    10. const loginMode = queryParams.get('loginMode');
    11. localStorage.setItem("userName",userName)
    12. localStorage.setItem("loginMode",loginMode)
    13. }
    14. getRequest()
    15. </script>

     将存储到localStorage中的信息发生请求   vue

     

    1. created() {
    2. this.loginInfo.userAcct = localStorage.getItem("userName") || "";
    3. this.loginInfo.loginMode = localStorage.getItem("loginMode") || "";
    4. if (this.loginInfo.userAcct !== "" && this.loginInfo.loginMode !== "") {
    5. // 直接在localstroage获取的信息 调用登录接口
    6. $login(this.loginInfo)
    7. .then((res) => {
    8. this.handleLoginInfo(res);
    9. })
    10. .catch((err) => {
    11. console.log(err);
    12. });
    13. }
    14. // this.getCode();
    15. // this.getSecretKey();
    16. // this.getRemInfo();
    17. this.enterEvent(); // 回车键登录
    18. },
    1. handleLoginInfo(res) {
    2. if (res.code === 200) {
    3. this.$message.success("登录成功!");
    4. //储存token,账号,密码
    5. this.$store.commit("set_token", res.data.token);
    6. this.$store.commit("set_userAcct", this.loginInfo.userAcct);
    7. this.$store.commit("set_password", this.loginInfo.password);
    8. this.$store.commit("set_tenantCode", this.loginInfo.tenantCode);
    9. this.$store.commit("set_userInfo", res.data.userInfo);
    10. let params = {
    11. userId: res.data.userInfo.sysUser.userId,
    12. };
    13. params = this.$qs.stringify(params);
    14. this.getMenuTreeSelect(res.data.userInfo.sysUser.userId);
    15. this.getDeptTreeSelect();
    16. //若用户选择记住密码
    17. if (this.isRemPwd) {
    18. this.$Cookie.set("userAcct", this.loginInfo.userAcct, {
    19. expires: 30,
    20. });
    21. this.$Cookie.set("tenantCode", this.loginInfo.tenantCode, {
    22. expires: 30,
    23. });
    24. //将密钥一起加密储存,后续解密时要用到
    25. this.$Cookie.set(
    26. "sk",
    27. CryptoJS.AES.encrypt(this.secretKey, "de43a68e4d184aa3"),
    28. {
    29. expires: 30, // 存储30天
    30. }
    31. );
    32. this.$Cookie.set(
    33. "thinglinkpwd",
    34. CryptoJS.AES.encrypt(this.loginInfo.password, this.secretKey),
    35. {
    36. expires: 30, // 存储30天
    37. }
    38. );
    39. // this.$router.go(0)
    40. } else {
    41. // 删除cookie
    42. this.$Cookie.remove("userAcct");
    43. this.$Cookie.remove("thinglinkpwd");
    44. this.$Cookie.remove("sk");
    45. this.$Cookie.remove("tenantCode");
    46. }
    47. // 去往首页
    48. this.$router.push("/index");
    49. //修改下首页默认的路径和菜单名称,确保一下侧边栏以及面包屑的正常展示,换首页了记得改下
    50. this.$store.commit("set_activeIndex", "/index");
    51. this.$store.commit("set_menuName", ["首页"]);
    52. }
    53. },

  • 相关阅读:
    UGUI交互组件ScrollBar
    Python:Jupyter:OSError: Initializing from file failed
    『SpringBoot 源码分析』run() 方法执行流程:(4)刷新应用上下文-处理 @Import 注解
    leetcode_1726 同积元组
    【云原生】多网络情况下,Kafka客户端如何选择合适的网络发起请求
    北京银行助力首批消费类公募REITs成功上市 担任嘉实物美消费REIT托监管行
    这个开源项目超哇塞,手写照片在线生成
    TouchGFX之文本和字体
    【LeetCode-中等题】347. 前 K 个高频元素
    基于springboot的个人博客管理系统
  • 原文地址:https://blog.csdn.net/Tel_17674647975/article/details/136170005