zhangzengfei
2022-07-31 85391dc1a2458202bdf0fb7a5394022aa17b9126
src/pages/login/index/App.vue
@@ -59,13 +59,13 @@
  </div> -->
  <div class="login">
    <div class="title">
      <div class="en">{{ data.title_firstLine }}</div>
      <div class="ch">{{ data.title_secondLine }}</div>
      <div class="en">{{ oem.title_firstLine }}</div>
      <div class="ch">{{ oem.title_secondLine }}</div>
    </div>
    <div class="left_footer">
      <img class="logo" src="/apps/loginData/LOGO.png" alt="" />
      <div class="web">{{ data.website }}</div>
      <div class="web">{{ oem.website }}</div>
    </div>
    <div class="login-form" :style="{ background: backgroundColor }">
@@ -115,17 +115,14 @@
</template>
<script>
import { tologin, getLoginUserData, getServerName } from "./api.ts";
import ParticleNetwork from "./ParticleNetwork";
import Licence from "@/components/licence";
import LangSelect from "@/components/langSelect";
import { getMenuListData } from "@/api/utils";
import loginData from "../../../../public/apps/loginData/login.json";
import { tologin, getLoginUserData, getServerName } from "./api.ts"
import { getVasystemInfo } from "@/api/system"
import { getMenuListData } from "@/api/utils"
export default {
  name: "login-pgae",
  metaInfo: {
    title: "登录页",
    title: "登录页"
  },
  components: {
    //  ParticleNetwork,
@@ -139,26 +136,26 @@
          {
            required: true,
            message: this.$t("placeholder.enterUsername"),
            trigger: "change",
          },
            trigger: "change"
          }
        ],
        password: [
          {
            required: true,
            message: this.$t("placeholder.enterPassword"),
            trigger: "change",
          },
        ],
      };
    },
            trigger: "change"
          }
        ]
      }
    }
  },
  data: () => ({
    data: {},
    oem: {},
    serverTitle: "",
    user: {
      loginName: "",
      password: "",
      rememberMe: false,
      rememberMe: false
    },
    nullRule: {},
@@ -167,61 +164,51 @@
    currentHeight: 1057,
    currentWidth: 1920,
    backgroundColor: "",
    backgroundList: [
      "#2A2344",
      "#342344",
      "#000000",
      "#233044",
      "#0B252E",
      "#150051",
      "#110040",
    ],
    backgroundList: ["#2A2344", "#342344", "#000000", "#233044", "#0B252E", "#150051", "#110040"]
  }),
  created() {
    this.getServerName();
    this.getScreenHeight();
    this.data = loginData;
    this.backgroundColor =
      this.backgroundList[
        Math.floor(Math.random() * this.backgroundList.length)
      ];
    this.getServerName()
    this.getScreenHeight()
    this.backgroundColor = this.backgroundList[Math.floor(Math.random() * this.backgroundList.length)]
  },
  mounted() {
    // 自动登录接口
    this.loginRobot();
    this.loginRobot()
    // oem 信息
    getVasystemInfo().then((rsp) => {
      this.oem = rsp
    })
  },
  watch: {},
  beforeDestroy() {
    window.onresize = null;
    window.onresize = null
  },
  methods: {
    loginRobot() {
      // 解析路由参数,并缓存
      let user = this.getQueryVariable("username");
      let passwd = this.getQueryVariable("password");
      let user = this.getQueryVariable("username")
      let passwd = this.getQueryVariable("password")
      if (user.length && passwd.length) {
        sessionStorage.setItem(
          "autoLogin",
          JSON.stringify({ username: user, passwd: passwd })
        );
        sessionStorage.setItem("autoLogin", JSON.stringify({ username: user, passwd: passwd }))
        this.user.loginName = user;
        this.user.password = passwd;
        this.systemLogin();
        return;
        this.user.loginName = user
        this.user.password = passwd
        this.systemLogin()
        return
      }
      // 登陆超时后的重新登陆
      let sessionInfo = sessionStorage.getItem("autoLogin");
      let sessionInfo = sessionStorage.getItem("autoLogin")
      if (sessionInfo) {
        let authority = JSON.parse(sessionInfo);
        this.user.loginName = authority.username;
        this.user.password = authority.passwd;
        this.systemLogin();
        let authority = JSON.parse(sessionInfo)
        this.user.loginName = authority.username
        this.user.password = authority.passwd
        this.systemLogin()
      }
    },
    systemLogin() {
      this.nullRule = this.rules;
      this.nullRule = this.rules
      this.$nextTick(() => {
        this.$refs["ruleForm"].validate((valid) => {
          if (valid) {
@@ -229,15 +216,15 @@
              lock: true,
              text: "Loading",
              spinner: "el-icon-loading",
              background: "rgba(0, 0, 0, 0.7)",
            });
            this.testLogin();
              background: "rgba(0, 0, 0, 0.7)"
            })
            this.testLogin()
          } else {
            this.nullRule = {};
            this.nullRule = {}
          }
        });
        this.nullRule = {};
      });
        })
        this.nullRule = {}
      })
    },
    async testLogin() {
      // location.assign("/view/desktop/")
@@ -245,89 +232,84 @@
        .then((json) => {
          const loginedInfo = {
            access_token: json.token_type + " " + json.access_token,
            refresh_token: json.refresh_token,
          };
          sessionStorage.setItem("expires_in", json.expires_in);
          sessionStorage.setItem("loginedInfo", JSON.stringify(loginedInfo));
          this.loading.close();
          this.getLoginUserData();
            refresh_token: json.refresh_token
          }
          sessionStorage.setItem("expires_in", json.expires_in)
          sessionStorage.setItem("loginedInfo", JSON.stringify(loginedInfo))
          this.loading.close()
          this.getLoginUserData()
        })
        .catch((err) => {
          this.loading.close();
          this.loading.close()
          this.$notify({
            title: "提示",
            type: "error",
            message: err.msg,
          });
          this.$refs.pwd.focus();
        });
            message: err.msg
          })
          this.$refs.pwd.focus()
        })
    },
    async getLoginUserData() {
      let res = await getLoginUserData();
      let res = await getLoginUserData()
      if (res.success) {
        sessionStorage.setItem("userInfo", JSON.stringify(res.data));
        this.$notify.success("登录成功!");
        sessionStorage.setItem("userInfo", JSON.stringify(res.data))
        this.$notify.success("登录成功!")
        // 获取权限
        await this.getMenuList();
        location.assign("/view/desktop/");
        return res.data;
        await this.getMenuList()
        location.assign("/view/desktop/")
        return res.data
      } else {
        this.$notify.error("登录失败!");
        this.$notify.error("登录失败!")
      }
    },
    getScreenHeight() {
      this.currentHeight = document.documentElement.clientHeight;
      this.currentWidth = document.documentElement.clientWidth;
      this.currentHeight = document.documentElement.clientHeight
      this.currentWidth = document.documentElement.clientWidth
      window.onresize = () => {
        this.currentHeight = document.documentElement.clientHeight;
        this.currentWidth = document.documentElement.clientWidth;
        this.$forceUpdate();
      };
        this.currentHeight = document.documentElement.clientHeight
        this.currentWidth = document.documentElement.clientWidth
        this.$forceUpdate()
      }
    },
    async getServerName() {
      let res = await getServerName();
      let res = await getServerName()
      if (res && res.success) {
        this.serverTitle = res.data.serverName;
        window.document.title = res.data.serverName
          ? res.data.serverName
          : "SmartAI";
        sessionStorage.setItem("title", res.data.serverName);
        this.serverTitle = res.data.serverName
        window.document.title = res.data.serverName ? res.data.serverName : "SmartAI"
        sessionStorage.setItem("title", res.data.serverName)
      }
    },
    async getMenuList() {
      let results = await getMenuListData({});
      let results = await getMenuListData({})
      if (results && results.success) {
        /* 存储权限 */
        let buttonAuthoritys = results.data;
        let buttonAuthoritys = results.data
        if (results && results.length && this.$route.query.is_login) {
          this.$router.replace(results[0].url);
          this.$router.replace(results[0].url)
        }
        sessionStorage.setItem(
          "buttonAuthoritys",
          "," + buttonAuthoritys + ","
        );
        sessionStorage.setItem("menuInfo", JSON.stringify(results));
        sessionStorage.setItem("buttonAuthoritys", "," + buttonAuthoritys + ",")
        sessionStorage.setItem("menuInfo", JSON.stringify(results))
      } else {
        this.$toast({
          type: "error",
          message: "菜单获取失败",
        });
          message: "菜单获取失败"
        })
      }
    },
    getQueryVariable(variable) {
      var query = window.location.search.substring(1);
      var vars = query.split("&");
      var query = window.location.search.substring(1)
      var vars = query.split("&")
      for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        var pair = vars[i].split("=")
        if (pair[0] == variable) {
          return pair[1];
          return pair[1]
        }
      }
      return false;
    },
  },
};
      return false
    }
  }
}
</script>
<style lang="scss">
html,