LoginBox.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <!-- 登录box -->
  3. <div class="login_box">
  4. <!-- 账号/手机号登录 -->
  5. <Login v-if="showInner == ''" @showInnerControl="showInnerControl" />
  6. <!-- 选择登录方式 -->
  7. <SelectLogin
  8. v-if="showInner == 'selectLogin'"
  9. @showInnerControl="showInnerControl"
  10. />
  11. <!-- 联系客服 -->
  12. <MenuService
  13. v-if="showInner == 'service'"
  14. @showInnerControl="showInnerControl"
  15. />
  16. </div>
  17. </template>
  18. <script>
  19. import SelectLogin from "@/views/Login/SelectLogin"; // 选择登录方式页
  20. import Login from "@/views/Login/Login"; // 账号/手机号登录页
  21. import MenuService from "@/components/Menu/MenuService"; // 联系客服
  22. import { mapActions, mapState } from "vuex";
  23. export default {
  24. name: "LoginBox",
  25. components: {
  26. SelectLogin,
  27. Login,
  28. MenuService,
  29. },
  30. provide() {
  31. return {
  32. // 游客登录工具函数
  33. onQuickHandler: this.onQuickHandler,
  34. // 登录成功工具函数
  35. loginUtil: this.loginUtil,
  36. };
  37. },
  38. data() {
  39. return {
  40. showInner: "", // 控制显示哪个组件
  41. canQucikLogin: true, // 是否能够快速登录
  42. };
  43. },
  44. inject: ["checkCode", "getFinance", "routeLink"],
  45. computed: {
  46. ...mapState(["platform"]),
  47. },
  48. watch: {},
  49. created() {},
  50. mounted() {
  51. // const jhremember = JSON.parse(localStorage.getItem("jhremember"));
  52. let jhremember = this.$utils.readStorage("", "jhremember");
  53. jhremember = jhremember && JSON.parse(jhremember);
  54. const isRemember = jhremember && jhremember.length > 0;
  55. // 没有登录, 并且记住了密码 显示账号/手机号登录页面
  56. this.showInner = !this.isLogin && isRemember ? "" : "selectLogin";
  57. },
  58. methods: {
  59. ...mapActions(["userInfoAction"]),
  60. // 控制显示哪个组件
  61. showInnerControl(showInner) {
  62. this.showInner = showInner;
  63. },
  64. // 游客登录工具函数
  65. onQuickHandler() {
  66. const { canQucikLogin } = this;
  67. if (!canQucikLogin) {
  68. return;
  69. }
  70. this.canQucikLogin = false;
  71. const promoCode = this.$utils.getQueryString("promoCode");
  72. const { appid } = this;
  73. return this.$api.quickRegist({ promoCode, appId: appid }).then((res) => {
  74. this.canQucikLogin = true;
  75. this.checkCode(res);
  76. const { data, code } = res.data;
  77. // 错误
  78. if (code) {
  79. return;
  80. }
  81. // 成功
  82. // 记住密码
  83. const jhremember = this.$utils.rememberFun(
  84. data.passport,
  85. data.password
  86. );
  87. if (window.android) {
  88. this.getFinance();
  89. }
  90. // 存储用户信息
  91. // localStorage.setItem("userInfo", JSON.stringify(data));
  92. this.$utils.writeStorage("", "userInfo", JSON.stringify(data));
  93. this.userInfoAction(data);
  94. this.routeLink("Visitor", {
  95. userInfo: data,
  96. jhremember,
  97. });
  98. });
  99. },
  100. // 登录工具函数
  101. loginUtil(data, routeName, params) {
  102. if (window.android) {
  103. this.androidLogin(routeName, params);
  104. }
  105. if (this.platform === "wcfml") {
  106. this.wcfmlLogin(data);
  107. }
  108. },
  109. // android 安卓登录工具函数
  110. androidLogin(routeName, params) {
  111. // 获取鸿币余额
  112. this.getFinance();
  113. this.routeLink(routeName, params);
  114. },
  115. // wcfml 忘川伏魔录登录工具函数
  116. wcfmlLogin(data) {
  117. // 记住密码 todo
  118. const savedata = this.$utils.getQueryString("data");
  119. // 跳转对应登录链接
  120. const query = this.$utils.queryStringUtil({
  121. uid: data.uid,
  122. data: encodeURIComponent(savedata),
  123. });
  124. // window.open(`${this.$CONFIG.wcfmlLoginUrl}?${query}`); 这个没法
  125. window.location.href = `${this.$CONFIG.wcfmlLoginUrl}?${query}`;
  126. },
  127. },
  128. };
  129. </script>
  130. <style lang='less' scoped>
  131. </style>