李达明 2 months ago
parent
commit
69fb1eb859
  1. 147
      src/views/login/components/LoginForm.vue

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

@ -30,15 +30,10 @@
<el-col :span="24" style="padding-right: 10px; padding-left: 10px"> <el-col :span="24" style="padding-right: 10px; padding-left: 10px">
<el-form-item prop="password"> <el-form-item prop="password">
<el-input v-model="loginData.loginForm.password" :placeholder="t('login.passwordPlaceholder')" <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-form-item>
</el-col> </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">
<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-form-item prop="code"> <el-form-item prop="code">
<div class="flex w-[100%]"> <div class="flex w-[100%]">
<el-input v-model="loginData.loginForm.code" :placeholder="t('login.codePlaceholder')" <el-input v-model="loginData.loginForm.code" :placeholder="t('login.codePlaceholder')"
@ -52,14 +47,14 @@
</div> </div>
</div> </div>
</el-form-item> </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-col :span="24" style="padding-right: 10px; padding-left: 10px; margin-top: -20px; margin-bottom: -20px">
<el-form-item> <el-form-item>
<el-row justify="space-between" style="width: 100%"> <el-row justify="space-between" style="width: 100%">
<el-col :span="6"> <el-col :span="6">
<!-- <el-checkbox v-model="loginData.loginForm.rememberMe"> <el-checkbox v-model="loginData.loginForm.rememberMe">
{{ t('login.remember') }} {{ t('login.remember') }}
</el-checkbox> --> </el-checkbox>
</el-col> </el-col>
<el-col :offset="6" :span="12"> <el-col :offset="6" :span="12">
<el-link style="float: right" type="primary" <el-link style="float: right" type="primary"
@ -74,8 +69,14 @@
<XButton :loading="loginLoading" :title="t('login.login')" class="w-[100%]" type="primary" <XButton :loading="loginLoading" :title="t('login.login')" class="w-[100%]" type="primary"
@click="handleLogin()" /> @click="handleLogin()" />
</el-form-item> </el-form-item>
</el-col> </el-col>
<!-- <Verify
ref="verify"
:captchaType="captchaType"
:imgSize="{ width: '400px', height: '200px' }"
mode="pop"
@success="handleLogin"
/> -->
</el-row> </el-row>
</el-form> </el-form>
</template> </template>
@ -89,18 +90,13 @@
import * as authUtil from '@/utils/auth' import * as authUtil from '@/utils/auth'
import { usePermissionStore } from '@/store/modules/permission' import { usePermissionStore } from '@/store/modules/permission'
import * as LoginApi from '@/api/login' import * as LoginApi from '@/api/login'
import * as PassWordApi from '@/api/system/password'
import { LoginStateEnum, useFormValid, useLoginState } from './useLogin' import { LoginStateEnum, useFormValid, useLoginState } from './useLogin'
import { getCodeImg } from "@/api/login"; import { getCodeImg } from "@/api/login";
import router from "@/router"; import router from "@/router";
import { CACHE_KEY, useCache } from '@/hooks/web/useCache' import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
import * as DeptApi from '@/api/system/dept' import * as DeptApi from '@/api/system/dept'
import { getTenant } from '@/utils/systemParam' import { getTenant } from '@/utils/systemParam'
import { getSystermUpdateAlert,getSystermUpdateUrl,getNeedCode } from '@/utils/systemParam' import { getSystermUpdateAlert,getSystermUpdateUrl } from '@/utils/systemParam'
import {validateResetTime} from "@/api/system/password";
import { Verify } from '@/components/Verifition'
const needCode = ref(getNeedCode()==true||getNeedCode()=='true')
defineOptions({ name: 'LoginForm' }) defineOptions({ name: 'LoginForm' })
@ -116,7 +112,8 @@
const permissionStore = usePermissionStore() const permissionStore = usePermissionStore()
const redirect = ref<string>('') const redirect = ref<string>('')
const loginLoading = ref(false) const loginLoading = ref(false)
const VerifySlide = ref() const verify = ref()
const captchaType = ref('blockPuzzle') // blockPuzzle clickWord
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN) const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
@ -148,8 +145,8 @@
tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE, tenantEnable: import.meta.env.VITE_APP_TENANT_ENABLE,
loginForm: { loginForm: {
tenantName: tenantArray.value[0].name, tenantName: tenantArray.value[0].name,
username: '', username: 'admin',
password: '', password: '123456',
captchaVerification: '', captchaVerification: '',
rememberMe: false, rememberMe: false,
code: '', code: '',
@ -175,27 +172,14 @@
// verify.value.show() // verify.value.show()
// } // }
// } // }
const passwordEnter = ()=>{
if(!needCode.value){
handleLogin()
return
}else{
getCode()
}
}
function getCode() { function getCode() {
console.log('getCode') getCodeImg().then(res => {
if(!needCode.value){ captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled;
return if (captchaEnabled.value) {
codeUrl.value = "data:image/gif;base64," + res.img;
loginData.loginForm.uuid = res.uuid;
} }
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 //ID
const getTenantId = async () => { const getTenantId = async () => {
@ -223,75 +207,29 @@
name: 'ForgetPassword', 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 loading = ref() // ElLoading.service
// //
const handleLogin = async () => { const handleLogin = async (params) => {
console.log('登录-185') console.log('登录-185')
loginLoading.value = true if(getSystermUpdateAlert()=='true'||getSystermUpdateAlert()===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:
await ElMessageBox.alert( await ElMessageBox.alert(
'<strong>密码到期,请立即修改</strong>', '<strong>系统迁移,请移步至</strong>' +
`<a href=${getSystermUpdateUrl()} target="_blank">${getSystermUpdateUrl()}</a>`,
'重要提示', '重要提示',
{ {
dangerouslyUseHTMLString: true, dangerouslyUseHTMLString: true,
} }
) )
router.push({path:"/updatePasswordNewTips",query:{username:loginData.loginForm.username}})
return
case 1:
await ElMessageBox.alert(
'<strong>密码到期,请立即修改</strong>',
'重要提示',
{
dangerouslyUseHTMLString: true,
} }
) loginLoading.value = true
router.push({path:"/updatePasswordNewTips",query:{username:loginData.loginForm.username}}) try {
await getTenantId()
const data = await validForm()
if (!data) {
return return
default:
await ElMessageBox.alert(
'密码'+differenceDays+'到期,请尽快修改。',
'重要提示',
{
dangerouslyUseHTMLString: true,
}
)
break
} }
const res = await LoginApi.login(loginData.loginForm)
if (!res) { if (!res) {
console.log('登录-195') console.log('登录-195')
getCode() getCode()
@ -308,16 +246,6 @@
authUtil.removeLoginForm() authUtil.removeLoginForm()
} }
authUtil.setToken(res) 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) { if (!redirect.value) {
redirect.value = '/' redirect.value = '/'
} }
@ -331,19 +259,14 @@
// //
const { wsCache } = useCache() const { wsCache } = useCache()
wsCache.set(CACHE_KEY.DEPT, await DeptApi.getSimpleDeptList()) 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') console.log('登录-224')
getCode()
loginLoading.value = false loginLoading.value = false
loading?.value?.close() loading?.value?.close()
getCode()
} }
} }
// //
const doSocialLogin = async (type : number) => { const doSocialLogin = async (type : number) => {
if (type === 0) { if (type === 0) {

Loading…
Cancel
Save