马宇豪
2023-10-31 c7bd1a3fd46b5d5f887ce4f674387294ee1e8ccd
src/views/Login.vue
@@ -15,9 +15,10 @@
    >
      <a-form-model-item ref="name" prop="name">
        <a-input
            placeholder="请输入用户"
            placeholder="请输入用户名"
            size="large"
            v-model="form.name"
            autocomplete="new-password"
        >
          <a-icon slot="prefix" type="user" style="color:rgba(0,0,0,.25)" />
        </a-input>
@@ -28,6 +29,7 @@
            placeholder="请输入密码"
            size="large"
            v-model="form.pwd"
            autocomplete="new-password"
        >
          <a-icon slot="prefix" type="lock" style="color:rgba(0,0,0,.25)" />
        </a-input-password>
@@ -78,8 +80,8 @@
<!--        </a-tab-pane>-->
<!--      </a-tabs>-->
      <div style="margin-bottom: 20px">
        <a-checkbox :checked="true" style="color:#fff;">自动登录</a-checkbox>
        <a style="float: right">忘记密码</a>
        <a-checkbox :checked="saveAccount" style="color:#fff;" @change="isSave">记住密码</a-checkbox>
<!--        <a style="float: right">忘记密码</a>-->
      </div>
      <a-form-item style="text-align: center">
        <a-button
@@ -88,6 +90,7 @@
          style="width: 100%"
          size="large"
          @click="handleSubmit"
          :loading="isLoading"
        >
          登录
        </a-button>
@@ -100,12 +103,16 @@
<script>
import { Login, getMenuAdmin } from "@/api/login";
import { login, getMenuAdmin } from "@/api/login";
import Cookies from 'js-cookie';
import {Base64} from "js-base64";
export default {
  name: "login",
  data() {
    return {
      isLoading: false,
      saveAccount: false,
      // hasErrors,
      // form: this.$form.createForm(this),
      form: {
@@ -119,24 +126,47 @@
      menu: []
    };
  },
  mounted() {
  created() {
    // this.$nextTick(() => {
    //   this.form.validateFields();
    // });
    this.hasUserCodeOrPassword()
  },
  methods: {
    hasUserCodeOrPassword(){
      if (localStorage.getItem('userName') && localStorage.getItem('userPassword')) {
        this.form.name = localStorage.getItem('userName')
        this.form.pwd = Base64.decode(localStorage.getItem('userPassword'))//解密
        this.saveAccount = true
      }
    },
    isSave(e){
      const t = this
      t.saveAccount = !t.saveAccount
    },
    handleSubmit() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          const res = await Login(this.form)
          this.isLoading = true
          const res = await login(this.form)
          if (res.data.code === 100) {
            Cookies.set('resTk', res.data.data.tk);
            Cookies.set('resUid', res.data.data.uid);
            Cookies.set('userInfo',JSON.stringify(res.data.data),{expires: 7})
            if (this.saveAccount) {
              localStorage.setItem('userName', this.form.name)
              localStorage.setItem('userPassword', Base64.encode(this.form.pwd))
            } else {
              localStorage.removeItem('userName')
              localStorage.removeItem('userPassword')
            }
            this.$router.push('/home')
          } else {
            console.log(res.data.msg)
            this.$message.warning(res.data.msg);
          }
          this.isLoading = false
        } else {
          console.log('error submit!!');
          return false;
@@ -170,7 +200,7 @@
}
  .hedaer {
    margin: 0px auto;
   padding-top:100px;
   padding-top:200px;
    width: 1000px;
    text-align: center;
   text-shadow:0 0 1px #000;