李达明 1 month ago
parent
commit
69fb1eb859
  1. 305
      src/views/login/components/LoginForm.vue

305
src/views/login/components/LoginForm.vue

@ -30,15 +30,10 @@
<el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item prop="password">
<el-input v-model="loginData.loginForm.password" :placeholder="t('login.passwordPlaceholder')"
:prefix-icon="iconLock" show-password type="password" @keyup.enter="passwordEnter" style="height: 42px;" />
:prefix-icon="iconLock" show-password type="password" @keyup.enter="getCode()" style="height: 42px;" />
</el-form-item>
</el-col>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px" v-if="needCode">
<el-form-item prop="code">
<Verify ref="VerifySlide" captchaType="blockPuzzle" mode="" :imgSize="{ width: '450px', height: '225px' }" @success="capctchaCheckSuccess" @error="capctchaCheckError"></Verify>
</el-form-item>
</el-col>
<!-- <el-col :span="24" style="padding-right: 10px; padding-left: 10px" v-if="needCode">
<el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item prop="code">
<div class="flex w-[100%]">
<el-input v-model="loginData.loginForm.code" :placeholder="t('login.codePlaceholder')"
@ -52,14 +47,14 @@
</div>
</div>
</el-form-item>
</el-col> -->
</el-col>
<el-col :span="24" style="padding-right: 10px; padding-left: 10px; margin-top: -20px; margin-bottom: -20px">
<el-form-item>
<el-row justify="space-between" style="width: 100%">
<el-col :span="6">
<!-- <el-checkbox v-model="loginData.loginForm.rememberMe">
<el-checkbox v-model="loginData.loginForm.rememberMe">
{{ t('login.remember') }}
</el-checkbox> -->
</el-checkbox>
</el-col>
<el-col :offset="6" :span="12">
<el-link style="float: right" type="primary"
@ -74,138 +69,127 @@
<XButton :loading="loginLoading" :title="t('login.login')" class="w-[100%]" type="primary"
@click="handleLogin()" />
</el-form-item>
</el-col>
<!-- <Verify
ref="verify"
:captchaType="captchaType"
:imgSize="{ width: '400px', height: '200px' }"
mode="pop"
@success="handleLogin"
/> -->
</el-row>
</el-form>
</template>
<script lang="ts" setup>
import { ElLoading } from 'element-plus'
import LoginFormTitle from './LoginFormTitle.vue'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import { useIcon } from '@/hooks/web/useIcon'
import { ElLoading } from 'element-plus'
import LoginFormTitle from './LoginFormTitle.vue'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import * as authUtil from '@/utils/auth'
import { usePermissionStore } from '@/store/modules/permission'
import * as LoginApi from '@/api/login'
import * as PassWordApi from '@/api/system/password'
import { LoginStateEnum, useFormValid, useLoginState } from './useLogin'
import { getCodeImg } from "@/api/login";
import router from "@/router";
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import * as DeptApi from '@/api/system/dept'
import { getTenant } from '@/utils/systemParam'
import { getSystermUpdateAlert,getSystermUpdateUrl,getNeedCode } from '@/utils/systemParam'
import {validateResetTime} from "@/api/system/password";
import { Verify } from '@/components/Verifition'
import { useIcon } from '@/hooks/web/useIcon'
const needCode = ref(getNeedCode()==true||getNeedCode()=='true')
import * as authUtil from '@/utils/auth'
import { usePermissionStore } from '@/store/modules/permission'
import * as LoginApi from '@/api/login'
import { LoginStateEnum, useFormValid, useLoginState } from './useLogin'
import { getCodeImg } from "@/api/login";
import router from "@/router";
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import * as DeptApi from '@/api/system/dept'
import { getTenant } from '@/utils/systemParam'
import { getSystermUpdateAlert,getSystermUpdateUrl } from '@/utils/systemParam'
defineOptions({ name: 'LoginForm' })
defineOptions({ name: 'LoginForm' })
const { t } = useI18n()
const message = useMessage()
const iconHouse = useIcon({ icon: 'ep:house' })
const iconAvatar = useIcon({ icon: 'ep:avatar' })
const iconLock = useIcon({ icon: 'ep:lock' })
const formLogin = ref()
const { validForm } = useFormValid(formLogin)
const { setLoginState, getLoginState } = useLoginState()
const { currentRoute, push, replace } = useRouter()
const permissionStore = usePermissionStore()
const redirect = ref<string>('')
const loginLoading = ref(false)
const VerifySlide = ref()
const { t } = useI18n()
const message = useMessage()
const iconHouse = useIcon({ icon: 'ep:house' })
const iconAvatar = useIcon({ icon: 'ep:avatar' })
const iconLock = useIcon({ icon: 'ep:lock' })
const formLogin = ref()
const { validForm } = useFormValid(formLogin)
const { setLoginState, getLoginState } = useLoginState()
const { currentRoute, push, replace } = useRouter()
const permissionStore = usePermissionStore()
const redirect = ref<string>('')
const loginLoading = ref(false)
const verify = ref()
const captchaType = ref('blockPuzzle') // blockPuzzle clickWord
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
//
const captchaEnabled = ref(true)
const codeUrl = ref("")
const tenantArray = ref(JSON.parse(getTenant()))
const { wsCache } = useCache()
const language = wsCache.get('lang')
if('en-US'==language){
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
//
const captchaEnabled = ref(true)
const codeUrl = ref("")
const tenantArray = ref(JSON.parse(getTenant()))
const { wsCache } = useCache()
const language = wsCache.get('lang')
if('en-US'==language){
tenantArray.value = tenantArray.value.map(item => ({
name: item,
aliasName:item.replace('长春','ChangChun').replace('成都','ChengDu')
}));
}else{
}else{
tenantArray.value = tenantArray.value.map(item => ({
name: item,
aliasName:item
}));
}
const LoginRules = {
}
const LoginRules = {
tenantName: [required],
username: [required],
password: [required]
}
const loginData = reactive({
}
const loginData = reactive({
isShowPassword: false,
captchaEnable: import.meta.env.VITE_APP_CAPTCHA_ENABLE,
tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE,
loginForm: {
tenantName: tenantArray.value[0].name,
username: '',
password: '',
username: 'admin',
password: '123456',
captchaVerification: '',
rememberMe: false,
code: '',
uuid: ''
}
})
})
const socialList = [
const socialList = [
{ icon: 'ant-design:github-filled', type: 0 },
{ icon: 'ant-design:wechat-filled', type: 30 },
{ icon: 'ant-design:alipay-circle-filled', type: 0 },
{ icon: 'ant-design:dingtalk-circle-filled', type: 20 }
]
]
//
// const getCode = async () => {
// //
// if (loginData.captchaEnable === 'false') {
// await handleLogin({})
// } else {
// //
// //
// verify.value.show()
// }
// }
const passwordEnter = ()=>{
if(!needCode.value){
handleLogin()
return
}else{
getCode()
}
}
function getCode() {
console.log('getCode')
if(!needCode.value){
return
}
VerifySlide.value.refresh()
// getCodeImg().then(res => {
// captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
// if (captchaEnabled.value) {
// codeUrl.value = "data:image/gif;base64," + res.img;
// loginData.loginForm.uuid = res.uuid;
// }
// });
}
//ID
const getTenantId = async () => {
//
// const getCode = async () => {
// //
// if (loginData.captchaEnable === 'false') {
// await handleLogin({})
// } else {
// //
// //
// verify.value.show()
// }
// }
function getCode() {
getCodeImg().then(res => {
captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
if (captchaEnabled.value) {
codeUrl.value = "data:image/gif;base64," + res.img;
loginData.loginForm.uuid = res.uuid;
}
});
}
//ID
const getTenantId = async () => {
if (loginData.tenantEnable === 'true') {
const res = await LoginApi.getTenantIdByName(loginData.loginForm.tenantName)
authUtil.setTenantId(res)
}
}
//
const getCookie = () => {
}
//
const getCookie = () => {
const loginForm = authUtil.getLoginForm()
if (loginForm) {
loginData.loginForm = {
@ -216,82 +200,36 @@
tenantName: loginForm.tenantName ? loginForm.tenantName : loginData.loginForm.tenantName
}
}
}
}
const handleUpdate = () => {
const handleUpdate = () => {
router.push({
name: 'ForgetPassword',
})
};
//
const capctchaCheckSuccess = async ({captchaVerification})=>{
console.log('capctchaCheckSuccess',captchaVerification)
if(captchaVerification){
loginData.loginForm.code = captchaVerification
await handleLogin()
}
}
//
const capctchaCheckError = ()=>{
console.log('capctchaCheckError')
}
};
const loading = ref() // ElLoading.service
//
const handleLogin = async () => {
const loading = ref() // ElLoading.service
//
const handleLogin = async (params) => {
console.log('登录-185')
loginLoading.value = true
try {
await getTenantId()
const data = await validForm()
if (!data) {
return
}
let res = null
if(!needCode.value){
res = await LoginApi.loginNoCode(loginData.loginForm)
}else{
res = await LoginApi.login(loginData.loginForm)
}
console.log('登陆res',res)
const differenceDays = await PassWordApi.validateResetTime(res.userId)
switch (differenceDays){
case null:
break
case 0:
if(getSystermUpdateAlert()=='true'||getSystermUpdateAlert()===true){
await ElMessageBox.alert(
'<strong>密码到期,请立即修改</strong>',
'<strong>系统迁移,请移步至</strong>' +
`<a href=${getSystermUpdateUrl()} target="_blank">${getSystermUpdateUrl()}</a>`,
'重要提示',
{
dangerouslyUseHTMLString: true,
}
)
router.push({path:"/updatePasswordNewTips",query:{username:loginData.loginForm.username}})
return
case 1:
await ElMessageBox.alert(
'<strong>密码到期,请立即修改</strong>',
'重要提示',
{
dangerouslyUseHTMLString: true,
}
)
router.push({path:"/updatePasswordNewTips",query:{username:loginData.loginForm.username}})
loginLoading.value = true
try {
await getTenantId()
const data = await validForm()
if (!data) {
return
default:
await ElMessageBox.alert(
'密码'+differenceDays+'到期,请尽快修改。',
'重要提示',
{
dangerouslyUseHTMLString: true,
}
)
break
}
const res = await LoginApi.login(loginData.loginForm)
if (!res) {
console.log('登录-195')
getCode()
@ -308,16 +246,6 @@
authUtil.removeLoginForm()
}
authUtil.setToken(res)
if(getSystermUpdateAlert()=='true'||getSystermUpdateAlert()===true){
await ElMessageBox.alert(
'<strong>系统迁移,请移步至</strong>' +
`<a href=${getSystermUpdateUrl()} target="_blank">${getSystermUpdateUrl()}</a>`,
'重要提示',
{
dangerouslyUseHTMLString: true,
}
)
}
if (!redirect.value) {
redirect.value = '/'
}
@ -331,21 +259,16 @@
//
const { wsCache } = useCache()
wsCache.set(CACHE_KEY.DEPT, await DeptApi.getSimpleDeptList())
}catch (e){
if(e.code === 1002000008){
setTimeout(function (){
router.push({path:"/updatePasswordNewTips",query:{username:loginData.loginForm.username}})
},1500)
}
}finally {
} finally {
console.log('登录-224')
getCode()
loginLoading.value = false
loading?.value?.close()
getCode()
}
}
//
const doSocialLogin = async (type : number) => {
}
//
const doSocialLogin = async (type : number) => {
if (type === 0) {
message.error('此方式未配置')
} else {
@ -364,8 +287,8 @@
console.log(33)
window.location.href = res
}
}
watch(
}
watch(
() => currentRoute.value,
(route : RouteLocationNormalizedLoaded) => {
redirect.value = route?.query?.redirect as string
@ -373,21 +296,21 @@
{
immediate: true
}
)
onMounted(() => {
)
onMounted(() => {
getCode();
getCookie()
})
})
</script>
<style lang="scss" scoped>
:deep(.anticon) {
:deep(.anticon) {
&:hover {
color: var(--el-color-primary) !important;
}
}
}
.login-code {
.login-code {
float: right;
width: 100%;
height: 38px;
@ -399,5 +322,5 @@
vertical-align: middle;
cursor: pointer;
}
}
}
</style>

Loading…
Cancel
Save