干燥机配套车间生产管理系统/云平台服务端
baoshiwei
2023-05-24 beca65f4d01ca07c358102a35b949c2a4f277afe
src/views/system/loginmini/MiniLogin.vue
@@ -91,7 +91,8 @@
                <div class="aui-formButton">
                  <div class="aui-flex">
                    <a-button :loading="loginLoading" class="aui-link-login aui-flex-box" type="primary" @click="loginHandleClick">
                      {{ t('sys.login.loginButton') }}</a-button>
                                 {{ t('sys.login.loginButton') }}</a-button
                              >
                  </div>
                  <div class="aui-flex">
                    <a class="aui-linek-code aui-flex-box" @click="codeHandleClick">{{ t('sys.login.qrSignInFormTitle') }}</a>
@@ -145,101 +146,101 @@
      <MiniCodelogin ref="codeRef" @go-back="goBack" @success="handleSuccess" />
    </div>
    <!-- 第三方登录相关弹框 -->
    <ThirdModal ref="thirdModalRef"></ThirdModal>
      <ThirdModal ref="thirdModalRef" />
  </div>
</template>
<script lang="ts" setup name="login-mini">
  import { getCaptcha, getCodeInfo } from '/@/api/sys/user';
  import { computed, onMounted, reactive, ref, toRaw, unref } from 'vue';
  import codeImg from '/@/assets/images/checkcode.png';
  import { Rule } from '/@/components/Form';
  import { useUserStore } from '/@/store/modules/user';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { SmsEnum } from '/@/views/sys/login/useLogin';
  import ThirdModal from '/@/views/sys/login/ThirdModal.vue';
  import MiniForgotpad from './MiniForgotpad.vue';
  import MiniRegister from './MiniRegister.vue';
  import MiniCodelogin from './MiniCodelogin.vue';
  import logoImg from '/@/assets/loginmini/icon/lanpu_logo.png';
  import adTextImg from '/@/assets/loginmini/icon/jeecg_ad_text.png';
  import { AppLocalePicker, AppDarkModeToggle } from '/@/components/Application';
  import { useLocaleStore } from '/@/store/modules/locale';
  import { useDesign } from "/@/hooks/web/useDesign";
  import { useAppInject } from "/@/hooks/web/useAppInject";
  import { GithubFilled, WechatFilled, DingtalkCircleFilled, createFromIconfontCN } from '@ant-design/icons-vue';
   import { getCaptcha, getCodeInfo } from '/@/api/sys/user'
   import { computed, onMounted, reactive, ref, toRaw, unref } from 'vue'
   import codeImg from '/@/assets/images/checkcode.png'
   import { Rule } from '/@/components/Form'
   import { useUserStore } from '/@/store/modules/user'
   import { useMessage } from '/@/hooks/web/useMessage'
   import { useI18n } from '/@/hooks/web/useI18n'
   import { SmsEnum } from '/@/views/sys/login/useLogin'
   import ThirdModal from '/@/views/sys/login/ThirdModal.vue'
   import MiniForgotpad from './MiniForgotpad.vue'
   import MiniRegister from './MiniRegister.vue'
   import MiniCodelogin from './MiniCodelogin.vue'
   import logoImg from '/@/assets/loginmini/icon/lanpu_logo.png'
   import adTextImg from '/@/assets/loginmini/icon/jeecg_ad_text.png'
   import { AppLocalePicker, AppDarkModeToggle } from '/@/components/Application'
   import { useLocaleStore } from '/@/store/modules/locale'
   import { useDesign } from '/@/hooks/web/useDesign'
   import { useAppInject } from '/@/hooks/web/useAppInject'
   import { GithubFilled, WechatFilled, DingtalkCircleFilled, createFromIconfontCN } from '@ant-design/icons-vue'
  const IconFont = createFromIconfontCN({
    scriptUrl: '//at.alicdn.com/t/font_2316098_umqusozousr.js',
  });
  const { prefixCls } = useDesign('mini-login');
  const { notification, createMessage } = useMessage();
  const userStore = useUserStore();
  const { t } = useI18n();
  const localeStore = useLocaleStore();
  const showLocale = localeStore.getShowPicker;
   })
   const { prefixCls } = useDesign('mini-login')
   const { notification, createMessage } = useMessage()
   const userStore = useUserStore()
   const { t } = useI18n()
   const localeStore = useLocaleStore()
   const showLocale = localeStore.getShowPicker
  const randCodeData = reactive<any>({
    randCodeImage: '',
    requestCodeSuccess: false,
    checkKey: null,
  });
  const rememberMe = ref<string>('0');
   })
   const rememberMe = ref<string>('0')
  //手机号登录还是账号登录
  const activeIndex = ref<string>('accountLogin');
  const type = ref<string>('login');
   const activeIndex = ref<string>('accountLogin')
   const type = ref<string>('login')
  //账号登录表单字段
  const formData = reactive<any>({
    inputCode: '',
    username: '',
    password: '',
  });
   })
  //手机登录表单字段
  const phoneFormData = reactive<any>({
    mobile: '',
    smscode: '',
  });
  const loginRef = ref();
   })
   const loginRef = ref()
  //第三方登录弹窗
  const thirdModalRef = ref();
   const thirdModalRef = ref()
  //扫码登录
  const codeRef = ref();
   const codeRef = ref()
  //是否显示获取验证码
  const showInterval = ref<boolean>(true);
   const showInterval = ref<boolean>(true)
  //60s
  const timeRuning = ref<number>(60);
   const timeRuning = ref<number>(60)
  //定时器
  const timer = ref<any>(null);
   const timer = ref<any>(null)
  //忘记密码
  const forgotRef = ref();
   const forgotRef = ref()
  //注册
  const registerRef = ref();
  const loginLoading = ref<boolean>(false);
  const { getIsMobile } = useAppInject();
   const registerRef = ref()
   const loginLoading = ref<boolean>(false)
   const { getIsMobile } = useAppInject()
  defineProps({
    sessionTimeout: {
      type: Boolean,
    },
  });
   })
  /**
   * 获取验证码
   */
  function handleChangeCheckCode() {
    formData.inputCode = '';
      formData.inputCode = ''
    randCodeData.checkKey = 1629428467008;
      randCodeData.checkKey = 1629428467008
    getCodeInfo(randCodeData.checkKey).then((res) => {
      randCodeData.randCodeImage = res;
      randCodeData.requestCodeSuccess = true;
    });
         randCodeData.randCodeImage = res
         randCodeData.requestCodeSuccess = true
      })
  }
  /**
   * 切换登录方式
   */
  function loginClick(type) {
    activeIndex.value = type;
      activeIndex.value = type
  }
  /**
@@ -247,24 +248,24 @@
   */
  async function loginHandleClick() {
    if (unref(activeIndex) === 'accountLogin') {
      accountLogin();
         accountLogin()
    } else {
      //手机号登录
      phoneLogin();
         phoneLogin()
    }
  }
  async function accountLogin() {
    if (!formData.username) {
      createMessage.warn(t('sys.login.accountPlaceholder'));
      return;
         createMessage.warn(t('sys.login.accountPlaceholder'))
         return
    }
    if (!formData.password) {
      createMessage.warn(t('sys.login.passwordPlaceholder'));
      return;
         createMessage.warn(t('sys.login.passwordPlaceholder'))
         return
    }
    try {
      loginLoading.value = true;
         loginLoading.value = true
      const { userInfo } = await userStore.login(
        toRaw({
          password: formData.password,
@@ -273,23 +274,23 @@
          checkKey: randCodeData.checkKey,
          mode: 'none', //不要默认的错误提示
        })
      );
         )
      if (userInfo) {
        notification.success({
          message: t('sys.login.loginSuccessTitle'),
          description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realname}`,
          duration: 3,
        });
            })
      }
    } catch (error) {
      notification.error({
        message: t('sys.api.errorTip'),
        description: error.message || t('sys.login.networkExceptionMsg'),
        duration: 3,
      });
      handleChangeCheckCode();
         })
         handleChangeCheckCode()
    } finally {
      loginLoading.value = false;
         loginLoading.value = false
    }
  }
@@ -298,35 +299,35 @@
   */
  async function phoneLogin() {
    if (!phoneFormData.mobile) {
      createMessage.warn(t('sys.login.mobilePlaceholder'));
      return;
         createMessage.warn(t('sys.login.mobilePlaceholder'))
         return
    }
    if (!phoneFormData.smscode) {
      createMessage.warn(t('sys.login.smsPlaceholder'));
      return;
         createMessage.warn(t('sys.login.smsPlaceholder'))
         return
    }
    try {
      loginLoading.value = true;
         loginLoading.value = true
      const { userInfo }: any = await userStore.phoneLogin({
        mobile: phoneFormData.mobile,
        captcha: phoneFormData.smscode,
        mode: 'none', //不要默认的错误提示
      });
         })
      if (userInfo) {
        notification.success({
          message: t('sys.login.loginSuccessTitle'),
          description: `${t('sys.login.loginSuccessDesc')}: ${userInfo.realname}`,
          duration: 3,
        });
            })
      }
    } catch (error) {
      notification.error({
        message: t('sys.api.errorTip'),
        description: error.message || t('sys.login.networkExceptionMsg'),
        duration: 3,
      });
         })
    } finally {
      loginLoading.value = false;
         loginLoading.value = false
    }
  }
@@ -335,24 +336,24 @@
   */
  async function getLoginCode() {
    if (!phoneFormData.mobile) {
      createMessage.warn(t('sys.login.mobilePlaceholder'));
      return;
         createMessage.warn(t('sys.login.mobilePlaceholder'))
         return
    }
    const result = await getCaptcha({ mobile: phoneFormData.mobile, smsmode: SmsEnum.FORGET_PASSWORD });
      const result = await getCaptcha({ mobile: phoneFormData.mobile, smsmode: SmsEnum.FORGET_PASSWORD })
    if (result) {
      const TIME_COUNT = 60;
         const TIME_COUNT = 60
      if (!unref(timer)) {
        timeRuning.value = TIME_COUNT;
        showInterval.value = false;
            timeRuning.value = TIME_COUNT
            showInterval.value = false
        timer.value = setInterval(() => {
          if (unref(timeRuning) > 0 && unref(timeRuning) <= TIME_COUNT) {
            timeRuning.value = timeRuning.value - 1;
                  timeRuning.value = timeRuning.value - 1
          } else {
            showInterval.value = true;
            clearInterval(unref(timer));
            timer.value = null;
                  showInterval.value = true
                  clearInterval(unref(timer))
                  timer.value = null
          }
        }, 1000);
            }, 1000)
      }
    }
  }
@@ -362,25 +363,25 @@
   * @param type
   */
  function onThirdLogin(type) {
    thirdModalRef.value.onThirdLogin(type);
      thirdModalRef.value.onThirdLogin(type)
  }
  /**
   * 忘记密码
   */
  function forgetHandelClick() {
    type.value = 'forgot';
      type.value = 'forgot'
    setTimeout(() => {
      forgotRef.value.initForm();
    }, 300);
         forgotRef.value.initForm()
      }, 300)
  }
  /**
   * 返回登录页面
   */
  function goBack() {
    activeIndex.value = 'accountLogin';
    type.value = 'login';
      activeIndex.value = 'accountLogin'
      type.value = 'login'
  }
  /**
@@ -388,37 +389,37 @@
   * @param value
   */
  function handleSuccess(value) {
    Object.assign(formData, value);
    Object.assign(phoneFormData, { mobile: "", smscode: "" });
    type.value = 'login';
    activeIndex.value = 'accountLogin';
    handleChangeCheckCode();
      Object.assign(formData, value)
      Object.assign(phoneFormData, { mobile: '', smscode: '' })
      type.value = 'login'
      activeIndex.value = 'accountLogin'
      handleChangeCheckCode()
  }
  /**
   * 注册
   */
  function registerHandleClick() {
    type.value = 'register';
      type.value = 'register'
    setTimeout(() => {
      registerRef.value.initForm();
    }, 300);
         registerRef.value.initForm()
      }, 300)
  }
  /**
   * 注册
   */
  function codeHandleClick() {
    type.value = 'codeLogin';
      type.value = 'codeLogin'
    setTimeout(() => {
      codeRef.value.initFrom();
    }, 300);
         codeRef.value.initFrom()
      }, 300)
  }
  onMounted(() => {
    //加载验证码
    handleChangeCheckCode();
  });
      handleChangeCheckCode()
   })
</script>
<style lang="less" scoped>
@@ -505,7 +506,9 @@
    .app-iconify {
      color: #fff !important;
    }
    .aui-inputClear input,.aui-input-line input,.aui-choice{
         .aui-inputClear input,
         .aui-input-line input,
         .aui-choice {
      color: #c9d1d9 !important;
    }
@@ -526,7 +529,8 @@
    .aui-code-line{
      border-left: none !important;
    }
    .ant-checkbox-inner,.aui-success h3{
         .ant-checkbox-inner,
         .aui-success h3 {
      border-color: #c9d1d9;
    }
  }