You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
OneAuth/oaf/src/views/login.vue

99 lines
2.7 KiB
Vue

<template>
<div class="flex items-center justify-center">
4 years ago
<div
:style="{background:Theme.me.lightBox, 'box-shadow': Theme.me.lightBoxShadow}"
class="px-10 pb-9 pt-28 rounded-xl w-96">
<n-form label-width="70px" label-align="left" :model="data" ref="form_ref" label-placement="left" :rules="rules">
<n-form-item required label="用户名" path="username">
<n-input @keydown.enter="divs[1].focus()" :ref="el => {if (el)divs[0]=el}"
v-model:value="data.username"></n-input>
</n-form-item>
4 years ago
<n-form-item required label="密码" path="password">
<n-input @keydown.enter="login" :ref="el => {if (el) divs[1]=el}" v-model:value="data.password"
type="password"></n-input>
</n-form-item>
4 years ago
<div class="flex justify-around mt-4">
<n-button @click="login"></n-button>
<n-button @click="router.push({name:'register'})"></n-button>
</div>
</n-form>
</div>
</div>
</template>
<script lang="ts" setup>
4 years ago
import {computed, onMounted, ref} from "vue";
import {Theme} from "@/theme";
4 years ago
import {useMessage} from 'naive-ui'
import api from "@/api"
4 years ago
import {useRoute, useRouter} from "vue-router";
import {store} from "@/store";
4 years ago
let msg = useMessage()
const route = useRoute()
const router = useRouter()
4 years ago
const divs = ref([])
let form_ref = ref(null)
let data = ref({
4 years ago
username: '',
password: ''
})
4 years ago
let rules = {
username: [
4 years ago
{
required: true,
validator(r: any, v: any) {
return (v && v.length >= 3 && v.length <= 16) || new Error('长度要求3~16')
},
trigger: ['input', 'blur']
}
],
4 years ago
password: [{
required: true,
validator(r: any, v: any) {
return (v && v.length >= 6 && v.length <= 16) || new Error('长度要求6~16')
}
4 years ago
}]
}
4 years ago
let uuid = computed(() => {
return route.params.uuid || store.state.oauuid
})
function login() {
4 years ago
// @ts-ignore
form_ref.value.validate((e:any) => {
if (!e) {
api.user.login(data.value.username, data.value.password, uuid.value as string).Start((url: string) => {
msg.success('登录成功')
store.dispatch('user/fetchUserData')
let target = url
if (route.query.redirect) {
target = route.query.redirect as string
}
if (target && target.startsWith('http')) {
window.location.href = target
} else if (target) {
router.push(target)
} else {
router.push({name: 'home'})
}
}, e => {
console.log(e)
msg.warning('登录失败:' + e)
})
}
})
}
4 years ago
onMounted(() => {
if (divs.value[0]) {
// @ts-ignore
divs.value[0].focus()
}
})
</script>
<style scoped>
</style>