|
|
@ -38,7 +38,7 @@ |
|
|
|
</a-input-password> |
|
|
|
</a-form-item> |
|
|
|
|
|
|
|
<a-form-item name="code" :rules="[{ validator }]"> |
|
|
|
<a-form-item name="code"> |
|
|
|
<!-- 验证码 --> |
|
|
|
<a-input v-model:value="code" placeholder="验证码" class="loginInfo"> |
|
|
|
<template #prefix> |
|
|
@ -49,7 +49,7 @@ |
|
|
|
style="margin-right: 20px" /> |
|
|
|
</template> |
|
|
|
<template #addonAfter> |
|
|
|
<ns-verify @get-code="onGetCode" /> |
|
|
|
<ns-verify @get-code="onGetCode" ref="verifyRef" /> |
|
|
|
</template> |
|
|
|
</a-input> |
|
|
|
</a-form-item> |
|
|
@ -78,6 +78,7 @@ |
|
|
|
import { authorizationService } from '/nerv-base/store/modules/authorization-service'; |
|
|
|
import { Cookies } from '/nerv-lib/util/cookie'; |
|
|
|
import { storeToRefs } from 'pinia'; |
|
|
|
import { NsMessage } from '/nerv-lib/component'; |
|
|
|
|
|
|
|
export default defineComponent({ |
|
|
|
name: 'UserLogin', |
|
|
@ -94,6 +95,7 @@ |
|
|
|
const initUrl = ref(''); |
|
|
|
const verifyCode = ref(''); |
|
|
|
const code = ref(); |
|
|
|
const verifyRef = ref(); |
|
|
|
const isRemember = ref(false); |
|
|
|
title.value = '账号登录'; |
|
|
|
// title.value = appConfig.title ? appConfig.title : '账号登录'; |
|
|
@ -123,102 +125,89 @@ |
|
|
|
const submit = (value): void => { |
|
|
|
console.log(value); |
|
|
|
|
|
|
|
// if (password.value === '') { |
|
|
|
// errorMsg.value = '请输入密码'; |
|
|
|
// errorShow.value = true; |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// if (userName.value === '') { |
|
|
|
// errorMsg.value = '请输入账号'; |
|
|
|
// errorShow.value = true; |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// if (!code.value) { |
|
|
|
// // errorMsg.value = '请输入验证码'; |
|
|
|
// // errorShow.value = true; |
|
|
|
// return; |
|
|
|
// } |
|
|
|
// if (code.value.toLocaleLowerCase() !== verifyCode.value.toLocaleLowerCase()) { |
|
|
|
// errorMsg.value = '请输入正确的验证码'; |
|
|
|
// errorShow.value = true; |
|
|
|
// return; |
|
|
|
// } |
|
|
|
if (userName.value !== '' && password.value !== '') { |
|
|
|
errorShow.value = false; |
|
|
|
let data = JSON.stringify({ |
|
|
|
accountNo: userName.value.trim(), |
|
|
|
password: password.value.trim(), |
|
|
|
}); |
|
|
|
|
|
|
|
// 记住密码 |
|
|
|
rememberFunc(data); |
|
|
|
loading.value = true; |
|
|
|
async function logins() { |
|
|
|
try { |
|
|
|
const res = await configStore.userLogin(JSON.parse(data)); |
|
|
|
|
|
|
|
if (res.data?.token) { |
|
|
|
let data = JSON.stringify({ |
|
|
|
accountNo: userName.value.trim(), |
|
|
|
password: password.value.trim(), |
|
|
|
}); |
|
|
|
validator(null, value.code) |
|
|
|
.then(() => { |
|
|
|
// 记住密码 |
|
|
|
rememberFunc(data); |
|
|
|
loading.value = true; |
|
|
|
async function logins() { |
|
|
|
try { |
|
|
|
const res = await configStore.userLogin(JSON.parse(data)); |
|
|
|
verifyRef.value?.reload(); |
|
|
|
if (res.data?.token) { |
|
|
|
Cookies.set('nervsid', res.data?.token); |
|
|
|
} |
|
|
|
const info = await configStore.userInfo(); |
|
|
|
info.data |
|
|
|
? window.sessionStorage.setItem('userInfo', JSON.stringify(info.data)) |
|
|
|
: ''; |
|
|
|
loading.value = false; |
|
|
|
if (configStore.enablePermissions) { |
|
|
|
const res = await configStore.userResource(info); |
|
|
|
res?.data.sort((a, b) => { |
|
|
|
return a.sort - b.sort; |
|
|
|
}); |
|
|
|
console.log(res.data); |
|
|
|
|
|
|
|
if (configStore.customApplication) { |
|
|
|
await useAuthorization.initMenuResource(); |
|
|
|
if (res.data?.token) { |
|
|
|
Cookies.set('nervsid', res.data?.token); |
|
|
|
} |
|
|
|
const info = await configStore.userInfo(); |
|
|
|
info.data |
|
|
|
? window.sessionStorage.setItem('userInfo', JSON.stringify(info.data)) |
|
|
|
: ''; |
|
|
|
loading.value = false; |
|
|
|
if (configStore.enablePermissions) { |
|
|
|
const res = await configStore.userResource(info); |
|
|
|
res?.data.sort((a, b) => { |
|
|
|
return a.sort - b.sort; |
|
|
|
}); |
|
|
|
console.log(res.data); |
|
|
|
|
|
|
|
initUrl.value = ''; |
|
|
|
const dealInitUrl = (item) => { |
|
|
|
if (item.type === 'menus' && item.menus && item.menus?.length !== 0) { |
|
|
|
dealInitUrl(item.menus[0]); |
|
|
|
} else { |
|
|
|
if (item.type === 'noChildrenMenu') { |
|
|
|
initUrl.value = configStore.resourceName |
|
|
|
? item.code.replace(configStore.resourceName, '') |
|
|
|
: item.code; |
|
|
|
} |
|
|
|
if (configStore.customApplication) { |
|
|
|
await useAuthorization.initMenuResource(); |
|
|
|
} |
|
|
|
}; |
|
|
|
if (configStore.resourceName) { |
|
|
|
const initResource = []; |
|
|
|
res.data.forEach((item) => { |
|
|
|
if (item.code.includes(configStore.resourceName)) { |
|
|
|
initResource.push(item); |
|
|
|
|
|
|
|
initUrl.value = ''; |
|
|
|
const dealInitUrl = (item) => { |
|
|
|
if (item.type === 'menus' && item.menus && item.menus?.length !== 0) { |
|
|
|
dealInitUrl(item.menus[0]); |
|
|
|
} else { |
|
|
|
if (item.type === 'noChildrenMenu') { |
|
|
|
initUrl.value = configStore.resourceName |
|
|
|
? item.code.replace(configStore.resourceName, '') |
|
|
|
: item.code; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
if (configStore.resourceName) { |
|
|
|
const initResource = []; |
|
|
|
res.data.forEach((item) => { |
|
|
|
if (item.code.includes(configStore.resourceName)) { |
|
|
|
initResource.push(item); |
|
|
|
} |
|
|
|
}); |
|
|
|
dealInitUrl(initResource[0]); |
|
|
|
} else { |
|
|
|
dealInitUrl(res.data[0]); |
|
|
|
} |
|
|
|
// dealInitUrl(res.data[0]); |
|
|
|
useAuthorization.updateUserResource(res.data); |
|
|
|
const initRouterList = useAuthorization.getInitRouterList; |
|
|
|
|
|
|
|
router.push({ |
|
|
|
name: initRouterList.length === 0 ? 'error403' : res.data[0]['code'], |
|
|
|
}); |
|
|
|
dealInitUrl(initResource[0]); |
|
|
|
} else { |
|
|
|
dealInitUrl(res.data[0]); |
|
|
|
router.replace({ name: 'root' }); |
|
|
|
} |
|
|
|
// dealInitUrl(res.data[0]); |
|
|
|
useAuthorization.updateUserResource(res.data); |
|
|
|
const initRouterList = useAuthorization.getInitRouterList; |
|
|
|
|
|
|
|
router.push({ |
|
|
|
name: initRouterList.length === 0 ? 'error403' : res.data[0]['code'], |
|
|
|
}); |
|
|
|
} else { |
|
|
|
router.replace({ name: 'root' }); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
console.log(err); |
|
|
|
} catch (err) { |
|
|
|
console.log(err); |
|
|
|
|
|
|
|
loading.value = false; |
|
|
|
loading.value = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
logins(); |
|
|
|
} |
|
|
|
logins(); |
|
|
|
}) |
|
|
|
.catch((flag) => { |
|
|
|
if (flag) { |
|
|
|
NsMessage.error('请输入正确的验证码'); |
|
|
|
verifyRef.value?.reload(); |
|
|
|
} else { |
|
|
|
NsMessage.error('请输入验证码'); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
const checkoutLogo = (): void => { |
|
|
|
logUrl.value = ''; |
|
|
@ -232,10 +221,11 @@ |
|
|
|
verifyCode.value = res; |
|
|
|
}; |
|
|
|
|
|
|
|
const validator = async (rule, value) => { |
|
|
|
if (!value) return Promise.reject('请输入验证码'); |
|
|
|
const validator = (rule, value) => { |
|
|
|
if (!value) return Promise.reject(false); |
|
|
|
if (value?.toLocaleLowerCase() !== verifyCode.value.toLocaleLowerCase()) |
|
|
|
return Promise.reject('请输入正确的验证码'); |
|
|
|
return Promise.reject(true); |
|
|
|
return Promise.resolve(); |
|
|
|
}; |
|
|
|
return { |
|
|
|
validator, |
|
|
@ -258,6 +248,7 @@ |
|
|
|
errorShow, |
|
|
|
configStore, |
|
|
|
isRemember, |
|
|
|
verifyRef, |
|
|
|
}; |
|
|
|
}, |
|
|
|
created() { |
|
|
|