WXL (wul)
6 天以前 130894e6743115fe924358292f8f1603bc665e89
src/views/login.vue
@@ -136,7 +136,7 @@
        smsCode: "",
        rememberMe: false,
        code: "",
        orgid: "1",
        orgid: "47255004333112711A1001",
      },
      options: [
        { value: "1", label: "景宁畲族自治县人民医院" },
@@ -145,7 +145,6 @@
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "请输入您的账号" },
          { validator: validatePhone, trigger: "blur", when: () => this.loginMethod === "sms" }
        ],
        password: [
          { required: true, trigger: "blur", message: "请输入您的密码", when: () => this.loginMethod === "password" },
@@ -181,8 +180,46 @@
  methods: {
    // 切换登录方式
    changeLoginMethod() {
      this.$refs.loginForm.clearValidate();
    },
    this.$refs.loginForm.clearValidate();
    // 动态更新验证规则
    this.loginRules = {
      username: [
        { required: true, trigger: "blur", message: this.loginMethod === 'password' ? '请输入您的账号' : '请输入手机号' },
        {
          validator: (rule, value, callback) => {
            if (this.loginMethod === 'sms' && !/^1[3-9]\d{9}$/.test(value)) {
              callback(new Error("请输入正确的手机号"));
            } else {
              callback();
            }
          },
          trigger: "blur"
        }
      ],
      password: [
        {
          required: true,
          trigger: "blur",
          message: "请输入您的密码",
          when: () => this.loginMethod === "password"
        },
      ],
      smsCode: [
        {
          required: true,
          trigger: "blur",
          message: "请输入验证码",
          when: () => this.loginMethod === "sms"
        },
        {
          pattern: /^\d{6}$/,
          message: "验证码为6位数字",
          trigger: "blur",
          when: () => this.loginMethod === "sms"
        }
      ],
    };
  },
    // 发送短信验证码
    phoneCode() {
@@ -259,7 +296,7 @@
          const loginData = {
            username: this.loginForm.username,
            orgid: "1",
            orgid: "47255004333112711A1001",
            loginType: this.loginMethod
          };
@@ -274,7 +311,7 @@
          this.$store
            .dispatch("Login", loginData)
            .then(() => {
              this.$router.push({ path: this.redirect || "/" }).catch(() => {});
              this.$router.push({ path: this.redirect || "/followvisit/discharge" }).catch(() => {});
            })
            .catch(() => {
              this.loading = false;