| | |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <div class="pc-login items-center justify-center" style="display:flex" v-show="state.isShowLogin"> |
| | | <div class="pc-login items-center justify-center" style="display: flex" v-show="state.isShowLogin"> |
| | | <div class="login_box"> |
| | | <div class="sign_in"> |
| | | <i class="ywicon icon-guanbi closes" @click="handleClose"></i> |
| | | <h1><span>登录 WI 水务</span></h1> |
| | | <el-form ref="loginFormRef" :model="state.loginForm" :rules="loginRules" class="demo-ruleForm mt-[24px]" size="large"> |
| | | <el-form-item label="账号" prop="account"> |
| | | <el-input v-model="state.loginForm.account" clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="密码" prop="pwd"> |
| | | <el-input v-model="state.loginForm.pwd" type="password" autocomplete="off" clearable /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <h1><span>登录 WI 水务智能</span></h1> |
| | | <el-tabs v-model="state.activeLoginName" class="mt-[24px]" @tab-change="handleUserClick"> |
| | | <el-tab-pane label="账户密码登录" name="accountUser"> |
| | | <el-form |
| | | ref="loginFormRef" |
| | | :model="state.loginForm" |
| | | :rules="loginRules" |
| | | class="demo-ruleForm mt-[24px] min-h-[140px]" |
| | | size="large" |
| | | > |
| | | <el-form-item label="账号" prop="account"> |
| | | <el-input v-model="state.loginForm.account" clearable /> |
| | | </el-form-item> |
| | | <el-form-item label="密码" prop="pwd"> |
| | | <el-input v-model="state.loginForm.pwd" type="password" autocomplete="off" clearable /> |
| | | </el-form-item> |
| | | </el-form> |
| | | </el-tab-pane> |
| | | <el-tab-pane label="手机号登录" name="phoneUser"> |
| | | <el-form |
| | | ref="formPhoneRef" |
| | | :rules="loginPhoneRules" |
| | | :model="state.loginPhoneForm" |
| | | size="large" |
| | | class="mt-[24px] min-h-[140px]" |
| | | > |
| | | <el-form-item label="手机号" prop="phoneUser"> |
| | | <el-input v-model="state.loginPhoneForm.phoneUser" placeholder="请输入手机号码" clearable> |
| | | <template #prepend>+86</template> |
| | | </el-input> |
| | | </el-form-item> |
| | | <el-form-item prop="verifyCode" label="验证码"> |
| | | <el-input v-model="state.loginPhoneForm.verifyCode" placeholder="请输入四位验证码" maxlength="6" clearable> |
| | | <template #append> |
| | | <el-button type="primary" @click="handleSendVerifyCode" :disabled="countdown > 0">{{ |
| | | countdown > 0 ? `${countdown}秒后重试` : '获取验证码' |
| | | }}</el-button> |
| | | </template> |
| | | </el-input> |
| | | </el-form-item> |
| | | </el-form> |
| | | </el-tab-pane> |
| | | </el-tabs> |
| | | |
| | | <div class="mt-[24px]"> |
| | | <el-button type="primary" @click="onSubmit" class="set-login_btn">登录</el-button> |
| | | </div> |
| | |
| | | </template> |
| | | |
| | | <script setup lang="ts"> |
| | | import type { FormInstance } from 'element-plus'; |
| | | import { ElMessage, type FormInstance } from 'element-plus'; |
| | | import { computed, onMounted, reactive, ref, watchEffect } from 'vue'; |
| | | import { PostLogin } from '/@/api/ai/user'; |
| | | import { PostLogin, loginMessageUser, loginVerifyMessage } from '/@/api/ai/user'; |
| | | import router from '/@/router'; |
| | | import emitter from '/@/utils/mitt'; |
| | | import { accessSessionKey, userNameKey } from '/@/utils/request'; |
| | | import { gotoRoute } from '/@/utils/route'; |
| | | import { Local } from '/@/utils/storage'; |
| | | |
| | | const loginFormRef = ref<FormInstance>(null); |
| | | import { Local, LoginInfo } from '/@/utils/storage'; |
| | | const loginFormRef = ref<FormInstance>(null); //账户密码登录 |
| | | const formPhoneRef = ref(); //手机号登录 |
| | | const isLoginStatus = ref(!!Local.get(accessSessionKey)); |
| | | |
| | | const userName = ref(''); |
| | | const countdown = ref(0); |
| | | const firstUserCharacter = computed(() => userName.value?.[0]?.toUpperCase()); |
| | | watchEffect(() => { |
| | | if (!isLoginStatus.value) return; |
| | |
| | | id: 1, |
| | | icon: '/static/images/wave/AsideIcon.png', |
| | | title: '应用场景', |
| | | routerName: 'Scenario', |
| | | routerName: 'AllScenario', |
| | | }, |
| | | { |
| | | id: 2, |
| | |
| | | account: '', |
| | | pwd: '', |
| | | }, |
| | | loginPhoneForm: { |
| | | phoneUser: '', |
| | | verifyCode: '', |
| | | }, |
| | | activeLoginName: 'accountUser', |
| | | }); |
| | | const loginRules = reactive({ |
| | | account: [{ required: true, message: '请输入账号', trigger: 'blur' }], |
| | | pwd: [{ required: true, message: '请输入密码', trigger: 'blur' }], |
| | | }); |
| | | const loginPhoneRules = { |
| | | phoneUser: [ |
| | | { required: true, message: '请输入手机号码', trigger: 'blur' }, |
| | | { pattern: /^1\d{10}$/, message: '请输入正确的手机号码', trigger: 'blur' }, |
| | | ], |
| | | verifyCode: [{ required: true, message: '请输入验证码', trigger: 'blur' }], |
| | | }; |
| | | const handleClick = (item) => { |
| | | gotoRoute({ name: item.routerName }); |
| | | }; |
| | |
| | | }; |
| | | //登录 |
| | | const onSubmit = async () => { |
| | | const isValid = await loginFormRef.value.validate().catch(() => {}); |
| | | if (!isValid) return; |
| | | const res = await PostLogin({ |
| | | user: state.loginForm.account, |
| | | pass: state.loginForm.pwd, |
| | | }); |
| | | Local.set(accessSessionKey, res.hswatersession); |
| | | Local.set(userNameKey, state.loginForm.account); |
| | | if (state.activeLoginName === 'accountUser') { |
| | | //账户密码登录 |
| | | const isValid = await loginFormRef.value.validate().catch(() => {}); |
| | | if (!isValid) return; |
| | | const res = await PostLogin({ |
| | | user: state.loginForm.account, |
| | | pass: state.loginForm.pwd, |
| | | }); |
| | | |
| | | LoginInfo.set(res.hswatersession, state.loginForm.account); |
| | | } else if (state.activeLoginName === 'phoneUser') { |
| | | //手机登录 |
| | | const isValid = await formPhoneRef.value.validate().catch(() => {}); |
| | | if (!isValid) return; |
| | | const res = await loginMessageUser({ |
| | | phone: state.loginPhoneForm.phoneUser, |
| | | code: state.loginPhoneForm.verifyCode, |
| | | }); |
| | | if (!res.json_ok) { |
| | | return ElMessage.warning(res.json_msg); |
| | | } |
| | | LoginInfo.set(res.hswatersession, state.loginPhoneForm.phoneUser); |
| | | } |
| | | state.isShowLogin = false; |
| | | isLoginStatus.value = true; |
| | | window.location.reload(); |
| | |
| | | const logoutClick = () => { |
| | | state.isShowExitLogin = false; |
| | | isLoginStatus.value = false; |
| | | Local.remove(accessSessionKey); |
| | | LoginInfo.remove(); |
| | | }; |
| | | const toggleExitLoginBtnRef = ref<HTMLDivElement>(null); |
| | | |
| | |
| | | state.isShowExitLogin = false; |
| | | } |
| | | }; |
| | | |
| | | //切换用户登录页面 |
| | | const handleUserClick = (item) => { |
| | | state.activeLoginName = item; |
| | | // formPhoneRef?.value?.resetFields(); |
| | | // loginFormRef.value.resetFields(); |
| | | }; |
| | | //获取验证码 |
| | | const handleSendVerifyCode = async () => { |
| | | formPhoneRef.value.validateField('phoneUser', async (valid: boolean) => { |
| | | if (valid) { |
| | | const res = await loginVerifyMessage({ |
| | | phone: state.loginPhoneForm.phoneUser, |
| | | }); |
| | | if (res.json_ok) { |
| | | countdown.value = 60; //开启倒计时 |
| | | // 倒计时逻辑 |
| | | const intervalId = setInterval(() => { |
| | | if (countdown.value > 0) { |
| | | countdown.value--; |
| | | } else { |
| | | clearInterval(intervalId); |
| | | } |
| | | }, 1000); |
| | | } |
| | | } |
| | | }); |
| | | }; |
| | | onMounted(() => { |
| | | emitter.on('openLoginDlg', () => { |
| | | if (state.isShowLogin || isLoginStatus.value) return; |
| | |
| | | -ms-flex-pack: center; |
| | | justify-content: center; |
| | | } |
| | | |
| | | .pc-login { |
| | | position: fixed; |
| | | top: 0; |
| | |
| | | background-color: #fff; |
| | | border-radius: 5px; |
| | | } |
| | | :deep(.el-form-item--large .el-form-item__error) { |
| | | padding: unset !important; |
| | | } |
| | | } |
| | | .set-pwd { |
| | | text-align: right; |