|
@@ -1,12 +1,12 @@
|
|
|
<script setup>
|
|
|
-import {apiSystemCommon,apiSystemRole} from '@/api/system'
|
|
|
+import { apiSystemCommon, apiSystemRole } from '@/api/system'
|
|
|
import md5 from 'js-md5'
|
|
|
-import {Base64 } from 'js-base64'
|
|
|
+import { Base64 } from 'js-base64'
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
|
-const router=useRouter()
|
|
|
+const router = useRouter()
|
|
|
|
|
|
-const ruleFormRef=ref(null)
|
|
|
+const ruleFormRef = ref(null)
|
|
|
const formRules = {
|
|
|
account: [{ required: true, message: '请输入用户名', trigger: 'blur' },],
|
|
|
pwd: [{ required: true, message: '请输入密码', trigger: 'blur' },]
|
|
@@ -16,28 +16,28 @@ const formState = reactive({
|
|
|
pwd: '',
|
|
|
checked: false
|
|
|
})
|
|
|
-async function submitForm(formEl){
|
|
|
+async function submitForm(formEl) {
|
|
|
if (!formEl) return
|
|
|
await formEl.validate((valid, fields) => {
|
|
|
if (valid) {
|
|
|
console.log('submit!')
|
|
|
- const t=new Date().getTime()
|
|
|
- const md5key='MiQM9YUdf89T2uIH'
|
|
|
+ const t = new Date().getTime()
|
|
|
+ const md5key = 'MiQM9YUdf89T2uIH'
|
|
|
apiSystemCommon.login({
|
|
|
- Username:formState.account,
|
|
|
- password:md5(md5(formState.pwd)+md5key+`${t}`),
|
|
|
- ReqTime:`${t}`,
|
|
|
- }).then(res=>{
|
|
|
- if(res.Ret===200){
|
|
|
- if(formState.checked){
|
|
|
- localStorage.setItem('account',Base64.encode(formState.account))
|
|
|
- localStorage.setItem('pwd',Base64.encode(formState.pwd))
|
|
|
- }else{
|
|
|
+ Username: formState.account,
|
|
|
+ password: md5(md5(formState.pwd) + md5key + `${t}`),
|
|
|
+ ReqTime: `${t}`,
|
|
|
+ }).then(res => {
|
|
|
+ if (res.Ret === 200) {
|
|
|
+ if (formState.checked) {
|
|
|
+ localStorage.setItem('account', Base64.encode(formState.account))
|
|
|
+ localStorage.setItem('pwd', Base64.encode(formState.pwd))
|
|
|
+ } else {
|
|
|
localStorage.removeItem('account')
|
|
|
localStorage.removeItem('pwd')
|
|
|
}
|
|
|
- localStorage.setItem('token',res.Data.Authorization)
|
|
|
- localStorage.setItem('userName',res.Data.SysRealName)
|
|
|
+ localStorage.setItem('token', res.Data.Authorization)
|
|
|
+ localStorage.setItem('userName', res.Data.SysRealName)
|
|
|
getMenuList()
|
|
|
}
|
|
|
})
|
|
@@ -48,15 +48,15 @@ async function submitForm(formEl){
|
|
|
}
|
|
|
|
|
|
// 获取菜单跳转到第一个菜单
|
|
|
-function getMenuList(){
|
|
|
- apiSystemRole.menuData().then(res=>{
|
|
|
- if(res.Ret===200){
|
|
|
- const arr=res.Data||[]
|
|
|
- let path=''
|
|
|
- if(arr[0]?.Children[0]){
|
|
|
- path=arr[0].Children[0].Path
|
|
|
- }else{
|
|
|
- path=arr[0].Path
|
|
|
+function getMenuList() {
|
|
|
+ apiSystemRole.menuData().then(res => {
|
|
|
+ if (res.Ret === 200) {
|
|
|
+ const arr = res.Data || []
|
|
|
+ let path = ''
|
|
|
+ if (arr[0]?.Children[0]) {
|
|
|
+ path = arr[0].Children[0].Path
|
|
|
+ } else {
|
|
|
+ path = arr[0].Path
|
|
|
}
|
|
|
router.replace(path)
|
|
|
}
|
|
@@ -64,17 +64,26 @@ function getMenuList(){
|
|
|
}
|
|
|
|
|
|
//获取用户记住的账号密码 如果有
|
|
|
-function getRememberedInfo(){
|
|
|
- const account=localStorage.getItem('account')||null
|
|
|
- const pwd=localStorage.getItem('pwd')||null
|
|
|
- if(account){
|
|
|
- formState.account=Base64.decode(account)
|
|
|
- formState.pwd=Base64.decode(pwd)
|
|
|
- formState.checked=true
|
|
|
+function getRememberedInfo() {
|
|
|
+ const account = localStorage.getItem('account') || null
|
|
|
+ const pwd = localStorage.getItem('pwd') || null
|
|
|
+ if (account) {
|
|
|
+ formState.account = Base64.decode(account)
|
|
|
+ formState.pwd = Base64.decode(pwd)
|
|
|
+ formState.checked = true
|
|
|
}
|
|
|
}
|
|
|
getRememberedInfo()
|
|
|
|
|
|
+onMounted(() => {
|
|
|
+ document.onkeydown = (e) => {
|
|
|
+ let keyval = window.event.keyCode;
|
|
|
+ if (keyval === 13) {
|
|
|
+ submitForm(ruleFormRef.value)
|
|
|
+ }
|
|
|
+ };
|
|
|
+})
|
|
|
+
|
|
|
|
|
|
</script>
|
|
|
|
|
@@ -109,7 +118,7 @@ getRememberedInfo()
|
|
|
</el-form-item>
|
|
|
<el-form-item>
|
|
|
<el-button
|
|
|
- style="width: 100%;margin-top:50px"
|
|
|
+ style="width: 100%; margin-top: 50px"
|
|
|
type="primary"
|
|
|
@click="submitForm(ruleFormRef)"
|
|
|
>登录</el-button
|