-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc2c3f7
commit bf8c77d
Showing
4 changed files
with
114 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ node_modules | |
.nuxt | ||
.nitro | ||
.cache | ||
.vscode | ||
.output | ||
.env | ||
dist | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<template> | ||
<div id="checkbox" class="form-item"> | ||
<input :id="id ?? label" v-model="selected" type="checkbox" /> | ||
<label :for="id ?? label">{{ label }}</label> | ||
<slot v-if="modelValue" name="active" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
const props = defineProps({ | ||
label: { | ||
type: String, | ||
required: true, | ||
default: '', | ||
}, | ||
id: { | ||
type: String, | ||
required: false, | ||
default: undefined, | ||
}, | ||
modelValue: { | ||
type: Boolean, | ||
required: true, | ||
default: false, | ||
}, | ||
}); | ||
const emit = defineEmits<{ | ||
(e: 'update:modelValue', value: boolean): void; | ||
}>(); | ||
const selected = ref(false); | ||
watch(selected, (value) => { | ||
emit('update:modelValue', value); | ||
}); | ||
</script> | ||
|
||
<style> | ||
This comment has been minimized.
Sorry, something went wrong. |
||
#checkbox { | ||
display: flex; | ||
gap: 20px; | ||
align-items: center; | ||
* { | ||
margin: 0; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<template> | ||
<div id="radio" class="form-item"> | ||
<input :id="id ?? label" type="radio" name="radio" @change="onChange" /> | ||
<label :for="id ?? label">{{ label }}</label> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
const props = defineProps({ | ||
label: { | ||
type: String, | ||
required: true, | ||
default: '', | ||
}, | ||
id: { | ||
type: String, | ||
required: false, | ||
default: undefined, | ||
}, | ||
modelValue: { | ||
type: null, | ||
required: true, | ||
default: '', | ||
}, | ||
value: { | ||
type: null, | ||
required: true, | ||
}, | ||
}); | ||
const emit = defineEmits<{ | ||
(e: 'update:modelValue', value: unknown): void; | ||
}>(); | ||
function onChange() { | ||
emit('update:modelValue', props.value); | ||
} | ||
</script> | ||
|
||
<style> | ||
#radio { | ||
display: flex; | ||
gap: 20px; | ||
align-items: center; | ||
* { | ||
margin: 0; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,12 @@ | |
<nuxt-link to="/reset">忘记密码?</nuxt-link> | ||
</template> | ||
</z-input> | ||
<z-checkbox id="auto-login" v-model="isAutoLogin" label="自动登录"> | ||
<template #active> | ||
<z-radio v-model="expireTimeLocal" label="7天" :value="7" /> | ||
<z-radio v-model="expireTimeLocal" label="14天" :value="14" /> | ||
</template> | ||
</z-checkbox> | ||
<button type="submit"> | ||
<z-loading v-if="isLoading" /> | ||
登录<template v-if="isLoading">中...</template> | ||
|
@@ -57,6 +63,8 @@ import { API_PREFIX } from '@/utils/request'; | |
const username = ref(''); | ||
const password = ref(''); | ||
const isAutoLogin = ref(false); | ||
const expireTimeLocal = ref(7); // 以天为单位 | ||
const router = useRouter(); | ||
const route = useRoute(); | ||
|
@@ -137,7 +145,13 @@ onMounted(() => { | |
/** | ||
* 自动登录,当仅验证学生时,获取用户信息并返回 | ||
*/ | ||
if (!manually && typeof localStorage.getItem('access') === 'string' && !isLoading.value) { | ||
if ( | ||
!manually && | ||
isAutoLogin && | ||
This comment has been minimized.
Sorry, something went wrong. |
||
typeof localStorage.getItem('access') === 'string' && | ||
Date.parse(localStorage.getItem('exp-local') ?? Date()) > Date.now() && | ||
This comment has been minimized.
Sorry, something went wrong. |
||
!isLoading.value | ||
) { | ||
isLoading.value = true; | ||
if (isCertifyOnly) { | ||
|
@@ -146,6 +160,7 @@ onMounted(() => { | |
console.warn('自动登录失败', err); | ||
localStorage.removeItem('access'); | ||
localStorage.removeItem('exp'); | ||
localStorage.removeItem('exp-local'); | ||
localStorage.removeItem('refresh'); | ||
}) | ||
.finally(() => { | ||
|
@@ -157,6 +172,7 @@ onMounted(() => { | |
console.warn('自动登录失败', err); | ||
localStorage.removeItem('access'); | ||
localStorage.removeItem('exp'); | ||
localStorage.removeItem('exp-local'); | ||
localStorage.removeItem('refresh'); | ||
}) | ||
.finally(() => { | ||
|
@@ -190,6 +206,7 @@ function submit(e: Event) { | |
localStorage.setItem('access', res.data.access); | ||
localStorage.setItem('exp', res.data.expire_time); | ||
localStorage.setItem('refresh', res.data.refresh); | ||
localStorage.setItem('exp-local', new Date(Date.now() + expireTimeLocal.value * 24 * 60 * 60 * 1000).toString()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Saltro
Contributor
|
||
if (isCertifyOnly) { | ||
if (res.data.is_certified) { | ||
|
建议都用scoped