| New file |
| | |
| | | <script lang="ts" setup> |
| | | import {onMounted, onUnmounted, reactive, ref} from "vue" |
| | | import {useRouter,useRoute } from 'vue-router' |
| | | import type {FormInstance, FormRules} from 'element-plus' |
| | | import { ElMessage } from "element-plus"; |
| | | import { Lock,Avatar } from '@element-plus/icons-vue' |
| | | import request from '@/utils/request' |
| | | import userInfo from '@/stores/userInfo' |
| | | import { sendSock, createWebSocket, closeSock,global_callback1 } from "@/utils/webSocket" |
| | | import userOrderInfo from '@/stores/sd/order/orderInfo' |
| | | import { useI18n } from 'vue-i18n' |
| | | import i18n from "@/lang/index" |
| | | //语言获取 |
| | | const { t } = useI18n() |
| | | let language = ref(localStorage.getItem('lang') || 'zh') |
| | | const store=userInfo() |
| | | let ruleFormRef = ref<FormInstance>() |
| | | const router = useRouter() |
| | | const route = useRoute() |
| | | const orderInfo = userOrderInfo() |
| | | |
| | | |
| | | const userForm = reactive({ |
| | | userId: '', |
| | | pass: '' |
| | | }) |
| | | |
| | | 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(t('login.userErr'))) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | |
| | | const validatePass = (rule: any, value: any, callback: any) => { |
| | | if (value === '') { |
| | | callback(new Error( t('login.pwErr') )) |
| | | } else { |
| | | callback() |
| | | } |
| | | } |
| | | |
| | | const rules = reactive<FormRules<typeof userForm>>({ |
| | | userId: [{ validator: validateUser, trigger: 'blur' }], |
| | | pass: [{ validator: validatePass, trigger: 'blur' }] |
| | | }) |
| | | |
| | | //登陆方法 |
| | | const submitForm = (formEl: FormInstance | undefined) => { |
| | | if (!formEl) return |
| | | formEl.validate((valid) => { |
| | | if (valid) { |
| | | loginLoadings.value=true |
| | | userForm.pass = btoa(userForm.pass) |
| | | request.post('/userInfo/login', |
| | | userForm).then((res) => { |
| | | if(res['code']==200 && res['data']){ |
| | | store.$patch({user:res.data}) |
| | | orderInfo.clearSelectDate() |
| | | router.push('/main') |
| | | ElMessage.success(t('login.loginSuccessful')) |
| | | } else { |
| | | ElMessage.error(t('login.loginErr')) |
| | | loginLoadings.value=false |
| | | return false |
| | | } |
| | | }).catch(error => { |
| | | ElMessage.error(t('login.connectErr')) |
| | | loginLoadings.value=false |
| | | return false |
| | | }).then(() => { |
| | | userForm.pass = atob(userForm.pass) |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | function register() { |
| | | |
| | | router.push({ |
| | | path:'/register', |
| | | }) |
| | | } |
| | | |
| | | let loginLoadings= ref(false) |
| | | let registerLoadings= ref(false) |
| | | |
| | | const keyDown = (e) => { |
| | | // 回车则执行登录方法 enter键的ASCII是13 |
| | | if (e.keyCode == 13 ) { |
| | | submitForm(ruleFormRef.value) |
| | | } |
| | | } |
| | | onMounted(()=>{ |
| | | window.addEventListener('keydown', keyDown) |
| | | }) |
| | | onUnmounted(() => { |
| | | window.removeEventListener('keydown', keyDown) |
| | | }) |
| | | const changeLanguage = () =>{ |
| | | localStorage.setItem('lang',language.value) |
| | | location.reload() |
| | | } |
| | | </script> |
| | | |
| | | <template> |
| | | <div class="mainDiv" > |
| | | <div id="main-login"> |
| | | <div id="img-div"> |
| | | <img id="img-pic" src="@/assets/img.png" alt=""> |
| | | </div> |
| | | <div id="div-login"> |
| | | <el-select |
| | | @change="changeLanguage" |
| | | v-model="language" |
| | | placeholder=" " |
| | | style="float: right;width: 6rem"> |
| | | <el-option value="zh" label="中文" /> |
| | | <el-option value="en" label="English" /> |
| | | <el-option value="ru" label="Русский язык" /> |
| | | </el-select> |
| | | <h2>{{$t('login.SysName')}}</h2> |
| | | <el-form |
| | | @submit.native.prevent |
| | | ref="ruleFormRef" |
| | | :model="userForm" |
| | | status-icon |
| | | :rules="rules" |
| | | > |
| | | <el-form-item :label="$t('login.user')+':'" prop="userId"> |
| | | <el-input |
| | | v-model="userForm.userId" |
| | | type="text" |
| | | autocomplete="off" |
| | | :prefix-icon="Avatar" |
| | | :placeholder="$t('login.userErr')" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item :label="$t('login.password')+':'" prop="pass"> |
| | | <el-input |
| | | v-model="userForm.pass" |
| | | type="password" |
| | | autocomplete="off" |
| | | :prefix-icon="Lock" |
| | | :placeholder="$t('login.pwErr')" |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item id="submitForm"> |
| | | <el-button |
| | | :loading="registerLoadings" |
| | | type="primary" |
| | | @click="register" |
| | | >{{$t('login.register')}} |
| | | </el-button> |
| | | <el-button |
| | | :loading="loginLoadings" |
| | | type="primary" |
| | | native-type="submit" |
| | | @click="submitForm(ruleFormRef)" |
| | | @keyup.enter.native="keyDown(e)" |
| | | >{{$t('login.login')}} |
| | | </el-button> |
| | | |
| | | </el-form-item> |
| | | </el-form> |
| | | </div> |
| | | </div> |
| | | |
| | | </div> |
| | | </template> |
| | | |
| | | <style scoped> |
| | | .mainDiv{ |
| | | //background-color: #1890FF; |
| | | overflow: hidden; |
| | | min-width: 718px; |
| | | } |
| | | #main-login{ |
| | | margin: 150px auto 0 auto; |
| | | height: 60vh; |
| | | width: 70vw; |
| | | |
| | | //background-color: #f2f2f2; |
| | | } |
| | | #img-div{ |
| | | width: 55%; |
| | | height: 100%; |
| | | display: flex; |
| | | justify-content: center; |
| | | align-items: center; |
| | | float: left; |
| | | } |
| | | #img-pic{ |
| | | max-height: 90%; |
| | | max-width: 100%; |
| | | } |
| | | #div-login{ |
| | | margin-top: 5%; |
| | | background-color: #fff; |
| | | float: right; |
| | | width: 40%; |
| | | height: 80%; |
| | | border-radius: 12px; |
| | | min-width: 318px; |
| | | box-shadow: 0 8px 16px 0 rgba(0,0,0,0), 0 6px 5px 0 rgba(0,0,0,0.19); |
| | | } |
| | | h2{ |
| | | color: #1890FF; |
| | | width: 100%; |
| | | text-align: center; |
| | | margin-top: 20%; |
| | | } |
| | | .el-form{ |
| | | width: 50%; |
| | | margin: 5% auto auto; |
| | | } |
| | | #submitForm { |
| | | display: flex; |
| | | justify-content: space-evenly; |
| | | margin-top: 2rem; |
| | | } |
| | | :deep(.el-form-item__content){ |
| | | flex: unset |
| | | |
| | | } |
| | | </style> |