| | |
| | | <script lang="ts" setup> |
| | | import {onMounted, onUnmounted, reactive, ref} from "vue" |
| | | import {onMounted, onUnmounted, reactive, ref} from 'vue' |
| | | import {useRoute, useRouter} from 'vue-router' |
| | | import type {FormInstance, FormRules} from 'element-plus' |
| | | import {ElMessage} from "element-plus"; |
| | | import {ElMessage} from 'element-plus' |
| | | import request from '@/utils/request' |
| | | import userInfo from '@/stores/userInfo' |
| | | |
| | | |
| | | const store=userInfo() |
| | | let ruleFormRef = ref<FormInstance>() |
| | | import { useI18n } from 'vue-i18n' |
| | | const store = userInfo() |
| | | let ruleFormRef = ref<FormInstance>() |
| | | const router = useRouter() |
| | | const route = useRoute() |
| | | |
| | | const { t } = useI18n() |
| | | let language = ref(localStorage.getItem('lang') || 'zh') |
| | | const changeLanguage = () =>{ |
| | | localStorage.setItem('lang',language.value) |
| | | location.reload() |
| | | } |
| | | const userForm = reactive({ |
| | | userId: '', |
| | | pass: '' |
| | | userName: '', |
| | | password: '', |
| | | }) |
| | | |
| | | if (typeof(route.query.id) != "undefined"){ |
| | | if (typeof route.query.id != 'undefined') { |
| | | userForm.userId = <string>route.query.id |
| | | } |
| | | |
| | | const validateUser = (rule: any, value: any, callback: any) => { |
| | | if (value === '') { |
| | | callback(new Error('请输入你的账号')) |
| | | callback(new Error(t('login.userErr'))) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | |
| | | const validatePass = (rule: any, value: any, callback: any) => { |
| | | if (value === '') { |
| | | callback(new Error('请输入你的密码')) |
| | | callback(new Error(t('login.pwErr'))) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | |
| | | const rules = reactive<FormRules<typeof userForm>>({ |
| | | userId: [{ validator: validateUser, trigger: 'blur' }], |
| | | pass: [{ validator: validatePass, trigger: 'blur' }] |
| | | userId: [{validator: validateUser, trigger: 'blur'}], |
| | | pass: [{validator: validatePass, trigger: 'blur'}], |
| | | }) |
| | | |
| | | //登陆方法 |
| | | const submitForm = (formEl: FormInstance | undefined) => { |
| | | store.$patch({ |
| | | user: null, |
| | | }) |
| | | if (!formEl) return |
| | | formEl.validate((valid) => { |
| | | if (valid) { |
| | | loginLoadings.value = true |
| | | request |
| | | .post('/userinfo/login', userForm) |
| | | // .post('/loadGlass/userinfo/login', userForm) |
| | | .post('/loadGlass/sys/user/login', userForm) |
| | | .then((res) => { |
| | | if (res['code'] == 200) { |
| | | store.$patch({user: res.data}) |
| | | console.log(res.data) |
| | | |
| | | router.push('/main') |
| | | ElMessage.success(`登录成功`) |
| | | ElMessage.success(t('login.loginSuccessful')) |
| | | } else { |
| | | ElMessage.error(res['msg']) |
| | | // ElMessage.error(res['msg']) |
| | | store.$patch({ |
| | | user: null, |
| | | }) |
| | | loginLoadings.value = false |
| | | return false |
| | | } |
| | | }).catch(error => { |
| | | ElMessage.error("服务器连接失败") |
| | | loginLoadings.value=false |
| | | return false |
| | | }) |
| | | }) |
| | | .catch((error) => { |
| | | ElMessage.error(t('main.connectErr')) |
| | | store.$patch({ |
| | | user: null, |
| | | }) |
| | | loginLoadings.value = false |
| | | return false |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | function register() { |
| | | |
| | | router.push({ |
| | | path:'/register', |
| | | path: '/register', |
| | | }) |
| | | } |
| | | |
| | | let loginLoadings= ref(false) |
| | | let registerLoadings= ref(false) |
| | | |
| | | let loginLoadings = ref(false) |
| | | let registerLoadings = ref(false) |
| | | const keyDown = (e) => { |
| | | // 回车则执行登录方法 enter键的ASCII是13 |
| | | if (e.keyCode == 13 || e.keyCode == 100) { |
| | | submitForm(ruleFormRef.value) |
| | | } |
| | | } |
| | | onMounted(()=>{ |
| | | onMounted(() => { |
| | | window.addEventListener('keydown', keyDown) |
| | | }) |
| | | onUnmounted(() => { |
| | | window.removeEventListener('keydown', keyDown) |
| | | }) |
| | | |
| | | </script> |
| | | |
| | | <template> |
| | | <div class="mainDiv" > |
| | | <div class="mainDiv"> |
| | | <div id="main-login"> |
| | | <!-- <img |
| | | style="width: 100%; height: 99vh" |
| | |
| | | <div style="position: absolute; left: 8vw; top: 6vw; "> |
| | | <img src="../../src/assets/3.png"> |
| | | </div> |
| | | <div style="position: absolute; left: 15vw; top: 22vw; font-size: 55px;color: rgba(29, 33, 41, 1);"> |
| | | 北玻MES系统 |
| | | </div> |
| | | </div> |
| | | <div id="div-login"> |
| | | <el-form |
| | | @submit.native.prevent |
| | | ref="ruleFormRef" |
| | | :model="userForm" |
| | | status-icon |
| | | :rules="rules" |
| | | > |
| | | <div id="center"> |
| | | <div style="color: rgba(78, 89, 105, 1);margin-bottom: 10px;">账号</div> |
| | | <el-form-item prop="userId"> |
| | | <el-input |
| | | style="width: 340px;" |
| | | v-model="userForm.userId" |
| | | type="text" |
| | | autocomplete="off" |
| | | :prefix-icon="Avatar" |
| | | placeholder="请输入账号" |
| | | /> |
| | | </el-form-item> |
| | | <div style="color: rgba(78, 89, 105, 1);margin-bottom: 10px;">密码</div> |
| | | <el-form-item prop="pass"> |
| | | <el-input |
| | | style="width: 340px;" |
| | | v-model="userForm.pass" |
| | | type="password" |
| | | autocomplete="off" |
| | | :prefix-icon="Lock" |
| | | show-password |
| | | placeholder="请输入密码" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item id="submitForm"> |
| | | <el-button |
| | | :loading="loginLoadings" |
| | | type="primary" |
| | | native-type="submit" |
| | | @click="submitForm(ruleFormRef)" |
| | | @keyup.enter.native="keyDown(e)" |
| | | plain |
| | | >登录 |
| | | </el-button> |
| | | <el-button |
| | | :loading="registerLoadings" |
| | | type="primary" |
| | | @click="register" |
| | | plain |
| | | >注册 |
| | | </el-button> |
| | | |
| | | </el-form-item> |
| | | <div style="position: absolute; left: 15vw; top: 22vw; font-size: 55px;color: rgba(29, 33, 41, 1);"> |
| | | {{ $t('northglassMESsystem') }} |
| | | </div> |
| | | </div> |
| | | <div id="div-login"> |
| | | <!--语言切换按钮--> |
| | | <el-select |
| | | @change="changeLanguage" |
| | | v-model="language" |
| | | placeholder=" " |
| | | style="float: right;width: 9rem"> |
| | | <el-option value="zh" label="中文" /> |
| | | <el-option value="py" label="Русский язык" /> |
| | | <el-option value="en" label="English" /> |
| | | </el-select> |
| | | <el-form @submit.native.prevent |
| | | ref="ruleFormRef" |
| | | :model="userForm" |
| | | status-icon |
| | | :rules="rules"> |
| | | <div id="center"> |
| | | <div style="color: rgba(78, 89, 105, 1);margin-bottom: 10px;">{{ $t('login.user') }}</div> |
| | | <el-form-item prop="userId"> |
| | | <el-input style="width: 340px;" |
| | | v-model="userForm.userName" |
| | | type="text" |
| | | autocomplete="off" |
| | | :prefix-icon="Avatar" |
| | | :placeholder="$t('login.userErr')"/> |
| | | </el-form-item> |
| | | <div style="color: rgba(78, 89, 105, 1);margin-bottom: 10px;">{{ $t('login.password') }}</div> |
| | | <el-form-item prop="pass"> |
| | | <el-input style="width: 340px;" |
| | | v-model="userForm.password" |
| | | type="password" |
| | | autocomplete="off" |
| | | :prefix-icon="Lock" |
| | | show-password |
| | | :placeholder="$t('login.pwErr')" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item id="submitForm"> |
| | | <el-button :loading="loginLoadings" |
| | | type="primary" |
| | | native-type="submit" |
| | | style="width: 80px;" |
| | | @click="submitForm(ruleFormRef)" |
| | | @keyup.enter.native="keyDown(e)" |
| | | plain>{{ $t('login.login') }} |
| | | </el-button> |
| | | <!-- <el-button :loading="registerLoadings" |
| | | type="primary" |
| | | @click="register" |
| | | plain>{{ $t('login.register') }} |
| | | </el-button> --> |
| | | </el-form-item> |
| | | </div> |
| | | </el-form> |
| | | </div> |
| | | </div> |
| | | |
| | | </div> |
| | | </template> |
| | | |
| | | <style scoped> |
| | | .mainDiv{ |
| | | .mainDiv { |
| | | overflow: hidden; |
| | | min-width: 718px; |
| | | background-image: url("../../src/assets/background.jpg"); |
| | | |
| | | background-image: url('../../src/assets/background.jpg'); |
| | | } |
| | | #main-login{ |
| | | #main-login { |
| | | margin: 150px auto 0 auto; |
| | | height: 70vh; |
| | | width: 80vw; |
| | | } |
| | | #img-div{ |
| | | #img-div { |
| | | width: 55%; |
| | | height: 100%; |
| | | display: flex; |
| | |
| | | align-items: center; |
| | | float: left; |
| | | } |
| | | #img-pic{ |
| | | #img-pic { |
| | | max-height: 90%; |
| | | max-width: 100%; |
| | | } |
| | | #div-login{ |
| | | #div-login { |
| | | margin-top: 5%; |
| | | /* margin-top: 20%; */ |
| | | /* margin-left: 650px; */ |
| | |
| | | height: 60%; |
| | | min-width: 318px; |
| | | border-radius: 4px; |
| | | box-shadow: 0 8px 16px 0 rgba(0,0,0,0), 0 6px 5px 0 rgba(0,0,0,0.19); |
| | | box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0), 0 6px 5px 0 rgba(0, 0, 0, 0.19); |
| | | } |
| | | #center{ |
| | | #center { |
| | | margin-top: -30px; |
| | | } |
| | | .el-form{ |
| | | .el-form { |
| | | width: 60%; |
| | | margin: 20% auto auto; |
| | | } |
| | |
| | | justify-content: space-evenly; |
| | | margin-top: 2rem; |
| | | } |
| | | :deep(.el-form-item__content){ |
| | | flex: unset |
| | | |
| | | :deep(.el-form-item__content) { |
| | | flex: unset; |
| | | } |
| | | </style> |