自动登录
parent
3a116f78c0
commit
3f3bc6bf93
|
|
@ -84,12 +84,12 @@
|
||||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
},
|
},
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": "explicit"
|
||||||
},
|
},
|
||||||
"[vue]": {
|
"[vue]": {
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true,
|
"source.fixAll.eslint": "explicit",
|
||||||
"source.fixAll.stylelint": true
|
"source.fixAll.stylelint": "explicit"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"i18n-ally.localesPaths": ["src/locales/lang"],
|
"i18n-ally.localesPaths": ["src/locales/lang"],
|
||||||
|
|
|
||||||
|
|
@ -108,16 +108,10 @@
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import Security from '/@/components/Security/index.vue'
|
import Security from '/@/components/Security/index.vue'
|
||||||
import { reactive, ref, unref, computed } from 'vue'
|
import { reactive, ref, unref, computed, onBeforeMount } from 'vue'
|
||||||
import md5 from 'js-md5'
|
import md5 from 'js-md5'
|
||||||
import { Checkbox, Form, Input, Row, Col, Button, Divider } from 'ant-design-vue'
|
import { Form, Input, Button } from 'ant-design-vue'
|
||||||
import {
|
|
||||||
GithubFilled,
|
|
||||||
WechatFilled,
|
|
||||||
AlipayCircleFilled,
|
|
||||||
GoogleCircleFilled,
|
|
||||||
TwitterCircleFilled,
|
|
||||||
} from '@ant-design/icons-vue'
|
|
||||||
import LoginFormTitle from './LoginFormTitle.vue'
|
import LoginFormTitle from './LoginFormTitle.vue'
|
||||||
|
|
||||||
import { useI18n } from '/@/hooks/web/useI18n'
|
import { useI18n } from '/@/hooks/web/useI18n'
|
||||||
|
|
@ -126,10 +120,11 @@
|
||||||
import { useUserStore } from '/@/store/modules/user'
|
import { useUserStore } from '/@/store/modules/user'
|
||||||
import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin'
|
import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from './useLogin'
|
||||||
import { useDesign } from '/@/hooks/web/useDesign'
|
import { useDesign } from '/@/hooks/web/useDesign'
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
//import { onKeyStroke } from '@vueuse/core';
|
//import { onKeyStroke } from '@vueuse/core';
|
||||||
|
|
||||||
const ACol = Col
|
const route = useRoute()
|
||||||
const ARow = Row
|
|
||||||
const FormItem = Form.Item
|
const FormItem = Form.Item
|
||||||
const InputPassword = Input.Password
|
const InputPassword = Input.Password
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
@ -153,8 +148,43 @@
|
||||||
const { validForm } = useFormValid(formRef)
|
const { validForm } = useFormValid(formRef)
|
||||||
|
|
||||||
//onKeyStroke('Enter', handleLogin);
|
//onKeyStroke('Enter', handleLogin);
|
||||||
|
const { username, userpwd, userToken } = route.query
|
||||||
|
|
||||||
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
|
const getShow = computed(() => unref(getLoginState) === LoginStateEnum.LOGIN)
|
||||||
|
|
||||||
|
const autoLogin = ref(!!userToken || (!!username && !!userpwd))
|
||||||
|
onBeforeMount(() => {
|
||||||
|
if (userToken) {
|
||||||
|
autoLoginByToken(userToken)
|
||||||
|
}
|
||||||
|
if (username && userpwd) {
|
||||||
|
autoLoginByUser(username, userpwd)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
function autoLoginByToken(token) {
|
||||||
|
try {
|
||||||
|
userStore.setToken(token)
|
||||||
|
userStore.afterLoginAction()
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function autoLoginByUser(username, userpwd) {
|
||||||
|
const { redirect } = route.query
|
||||||
|
let e = redirect
|
||||||
|
if (!e) {
|
||||||
|
e = '/'
|
||||||
|
}
|
||||||
|
userStore.login({
|
||||||
|
password: md5(userpwd),
|
||||||
|
username: username,
|
||||||
|
mode: 'none', //不要默认的错误提示
|
||||||
|
homeRouter: e,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function randomNum(min, max) {
|
function randomNum(min, max) {
|
||||||
return Math.floor(Math.random() * (max - min) + min)
|
return Math.floor(Math.random() * (max - min) + min)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue