lihang
2023-07-13 a3c868db4d017961be2d394eadb7d428045d5adc
Source/UBCS-WEB/dist/src/page/login/userlogin.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,291 @@
<template>
  <div>
    <el-form ref="loginForm"
             :model="loginForm"
             :rules="loginRules"
             class="login-form"
             label-width="0"
             status-icon
    >
      <el-form-item prop="selectInput">
        <el-select v-model="loginForm.value" placeholder="请选择组织" style="width: 326px" @change="selectchange">
          <i slot="prefix" class="el-icon-s-operation"/>
          <el-option
            v-for="(item,index) in loginForm.region"
            :key="index"
            :label="item.TENANT_NAME"
            :value="item.TENANT_ID">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item prop="username">
        <el-input v-model="loginForm.username"
                  :placeholder="$t('login.username')"
                  auto-complete="off"
                  size="small"
                  @keyup.enter.native="handleLogin">
          <i slot="prefix" class="icon-yonghu"/>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="loginForm.password"
                  :placeholder="$t('login.password')"
                  :type="passwordType"
                  auto-complete="off"
                  size="small"
                  @keyup.enter.native="handleLogin">
          <i slot="suffix" class="el-icon-view el-input__icon" @click="showPassword"/>
          <i slot="prefix" class="icon-mima"/>
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="login-submit"
                   size="small"
                   type="primary"
                   @click.native.prevent="handleLogin">{{ $t('login.submit') }}
        </el-button>
      </el-form-item>
      <!--密码修改弹出框-->
    </el-form>
    <el-dialog title="修改密码" :visible.sync="dialogFormVisible" append-to-body  @close="delok"  >
      <el-form :model="form"  :rules="rules">
        <el-form-item label="原密码" :label-width="formLabelWidth" prop="oldname">
          <el-input v-model="form.oldPassword" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="新密码" :label-width="formLabelWidth" prop="newname">
          <el-input v-model="form.newPassword" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" :label-width="formLabelWidth" prop="newname1">
          <el-input v-model="form.newPassword1" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="delok">取 æ¶ˆ</el-button>
        <el-button type="primary" @click="addok">ç¡® å®š</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {mapGetters} from "vuex";
import {info} from "@/api/system/tenant";
import {getTopUrl} from "@/util/util";
import {updatePassword} from "@/api/system/user.js"
import {removeToken} from "@/util/auth";
import md5 from "js-md5";
export default {
  name: "userlogin",
  data() {
    return {
      tenantMode: this.website.tenantMode,
      ButtonList: [],
      dialogFormVisible:false,
      form: {
        oldPassword: '',
        newPassword: '',
        newPassword1: '',
      },
      rules: {
        oldname: [
          { required: true, message: '请输入原密码', trigger: 'blur' }
        ],
        newname:[
          { required: true, message: '请输入新密码', trigger: 'blur' }
        ],
        newname1:[
          { required: true, message: '请输确认密码', trigger: 'blur' }
        ]
      },
      loginForm: {
        //租户ID
        tenantId: "000000",
        //部门ID
        deptId: "",
        //角色ID
        roleId: "",
        //用户名
        username: "admin",
        //密码
        password: "admin",
        selectInput: '',
        //下拉input数据
        value: '管理组',
        //下拉菜单
        region: [],
        //账号类型
        type: "account",
        //验证码的索引
        key: "",
        //预加载白色背景
        image: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
      },
      value: {
        selectInput: [
          {required: true, message: "请选择组织", trigger: "blur"}
        ],
        username: [
          {required: true, message: "请输入用户名", trigger: "blur"}
        ],
        password: [
          {required: true, message: "请输入密码", trigger: "blur"},
          {min: 1, message: "密码长度最少为6位", trigger: "blur"}
        ]
      },
      passwordType: "password",
      userBox: false,
      userForm: {
        deptId: '',
        roleId: ''
      },
      userinfo: []
    };
  },
  created() {
    this.getTenant();
  },
  mounted() {
    //在mounted获取首页下拉菜单数据
    this.$axios.get('/api/ubcs-system/tenant/tenant-map').then(res => {
      if (res.data.code == 200) {
        this.loginForm.region = res.data.data
      }
    })
  },
  watch: {
    'loginForm.deptId'() {
      const column = this.findObject(this.userOption.column, "deptId");
      if (this.loginForm.deptId.includes(",")) {
        column.dicUrl = `/api/ubcs-system/dept/select?deptId=${this.loginForm.deptId}`;
        column.display = true;
      } else {
        column.dicUrl = '';
      }
    },
    'loginForm.roleId'() {
      const column = this.findObject(this.userOption.column, "roleId");
      if (this.loginForm.roleId.includes(",")) {
        column.dicUrl = `/api/ubcs-system/role/select?roleId=${this.loginForm.roleId}`;
        column.display = true;
      } else {
        column.dicUrl = '';
      }
    }
  },
  computed: {
    ...mapGetters(["tagWel", "userInfo"])
  },
  props: [],
  methods: {
    aaa(){
      console.log(111)
    },
    delok(){
      //点击取消或者x æ¸…除token关闭弹窗 æ¸…除token后会自动重新获取用户信息
      this.dialogFormVisible = false;
      removeToken();
    },
    addok(){
      this.dialogFormVisible = false
      updatePassword(md5(this.form.oldPassword), this.form.newPassword, this.form.newPassword1).then(res=>{
        console.log(res)
        if(res.data.code==200){
          this.$message({
            type:"success",
            message:"修改成功!"
          })
          this.$router.push({path: this.tagWel.value})
        }
      })
    },
    // ç»‘定下拉菜单动态ID
    selectchange(value) {
      this.loginForm.tenantId = value
      console.log(this.loginForm.tenantId)
    },
    showPassword() {
      this.passwordType === ""
        ? (this.passwordType = "password")
        : (this.passwordType = "");
    },
    submitLogin(form, done) {
      if (form.deptId !== '') {
        this.loginForm.deptId = form.deptId;
      }
      if (form.roleId !== '') {
        this.loginForm.roleId = form.roleId;
      }
      this.handleLogin();
      done();
    },
    handleLogin: function () {
      this.userInfo = this.$store.state.upadatastatus
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: '登录中,请稍后。。。',
            spinner: "el-icon-loading"
          });
          this.$store.dispatch("LoginByUsername", this.loginForm).then(() => {
            //判断如果不等于0就是策略密码没有修改走下面逻辑
            if (this.userInfo.strategyUpdateStatus != 0) {
              if (this.website.switchMode) {
                const deptId = this.userInfo.dept_id;
                const roleId = this.userInfo.role_id;
                if (deptId.includes(",") || roleId.includes(",")) {
                  this.loginForm.deptId = deptId;
                  this.loginForm.roleId = roleId;
                  this.userBox = true;
                  this.$store.dispatch("LogOut").then(() => {
                    loading.close();
                  });
                }
              }
              this.$router.push({path: this.tagWel.value});
            } else {
              //等于0说明密码策略被修改,提示用户修改密码,给一个修改弹出框
              this.$message({
                type: "warning",
                message: "密码策略已被修改,请重新修改密码!"
              })
             // 1.5秒后执行 å¼¹å‡ºæ¡†æ˜¾ç¤º
             setTimeout(()=>{
               this.dialogFormVisible=true
             },1500)
            }
            console.log(this.userInfo)
            //把判断密码策略修改的值存进本地,然后再路由权限js文件里面获取再做判断,不然刷新会进入首页(因为在有id和token的情况下,刷新页面或者进入登录页会自动进入首页)
            localStorage.setItem("updataid",JSON.stringify(this.userInfo))
            loading.close();
          }).catch(() => {
            loading.close();
          });
        }
      });
    },
    getTenant() {
      let domain = getTopUrl();
      // ä¸´æ—¶æŒ‡å®šåŸŸåï¼Œæ–¹ä¾¿æµ‹è¯•
      //domain = "https://bladex.vip";
      info(domain).then(res => {
        const data = res.data;
        if (data.success && data.data.tenantId) {
          this.tenantMode = false;
          this.loginForm.tenantId = data.data.tenantId;
          this.$parent.$refs.login.style.backgroundImage = `url(${data.data.backgroundUrl})`;
        }
      })
    }
  }
};
</script>
<style>
</style>