283 lines
9.4 KiB
Vue
283 lines
9.4 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import { useRouter } from 'vue-router'
|
|
import http, { apiErrorMessage } from '../api/http'
|
|
import { branding } from '../config/branding'
|
|
import LocaleSwitcher from '../components/LocaleSwitcher.vue'
|
|
|
|
const router = useRouter()
|
|
const { t } = useI18n()
|
|
const loading = ref(false)
|
|
const submitting = ref(false)
|
|
const colleges = ref<any[]>([])
|
|
const majors = ref<any[]>([])
|
|
const classes = ref<any[]>([])
|
|
const form = reactive({
|
|
name: '',
|
|
studentNumber: '',
|
|
collegeId: '',
|
|
majorId: '',
|
|
grade: undefined as number | undefined,
|
|
administrativeClassId: '',
|
|
password: '',
|
|
confirmPassword: '',
|
|
activationTicket: '',
|
|
})
|
|
|
|
const availableMajors = computed(() =>
|
|
majors.value.filter((item) => item.collegeId === form.collegeId),
|
|
)
|
|
const availableGrades = computed(() => {
|
|
const values = classes.value
|
|
.filter((item) => item.majorId === form.majorId)
|
|
.map((item) => Number(item.grade))
|
|
return [...new Set(values)].sort((a, b) => b - a)
|
|
})
|
|
const availableClasses = computed(() =>
|
|
classes.value.filter((item) =>
|
|
item.majorId === form.majorId && Number(item.grade) === form.grade,
|
|
),
|
|
)
|
|
|
|
watch(() => form.collegeId, () => {
|
|
form.majorId = ''
|
|
form.grade = undefined
|
|
form.administrativeClassId = ''
|
|
})
|
|
watch(() => form.majorId, () => {
|
|
form.grade = undefined
|
|
form.administrativeClassId = ''
|
|
})
|
|
watch(() => form.grade, () => {
|
|
form.administrativeClassId = ''
|
|
})
|
|
|
|
function validate() {
|
|
if (
|
|
!form.name.trim() ||
|
|
!form.studentNumber.trim() ||
|
|
!form.collegeId ||
|
|
!form.majorId ||
|
|
!form.grade ||
|
|
!form.administrativeClassId ||
|
|
!form.activationTicket.trim()
|
|
) {
|
|
ElMessage.warning(t('auth.activation.incomplete'))
|
|
return false
|
|
}
|
|
if (
|
|
form.password.length < 8 ||
|
|
!/[a-z]/.test(form.password) ||
|
|
!/[A-Z]/.test(form.password) ||
|
|
!/\d/.test(form.password) ||
|
|
!/[^A-Za-z0-9]/.test(form.password)
|
|
) {
|
|
ElMessage.warning(t('auth.activation.passwordRule'))
|
|
return false
|
|
}
|
|
if (form.password !== form.confirmPassword) {
|
|
ElMessage.warning(t('auth.activation.mismatch'))
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
async function activate() {
|
|
if (!validate()) return
|
|
submitting.value = true
|
|
try {
|
|
const { data } = await http.post('/auth/activate-student', {
|
|
name: form.name.trim(),
|
|
studentNumber: form.studentNumber.trim(),
|
|
collegeId: form.collegeId,
|
|
majorId: form.majorId,
|
|
grade: form.grade,
|
|
administrativeClassId: form.administrativeClassId,
|
|
password: form.password,
|
|
activationTicket: form.activationTicket.trim(),
|
|
})
|
|
ElMessage.success(t('auth.activation.success'))
|
|
await router.replace({
|
|
name: 'login',
|
|
query: { userName: data.userName, activated: '1' },
|
|
})
|
|
} catch (error) {
|
|
ElMessage.error(apiErrorMessage(error))
|
|
} finally {
|
|
submitting.value = false
|
|
}
|
|
}
|
|
|
|
onMounted(async () => {
|
|
loading.value = true
|
|
try {
|
|
const { data } = await http.get('/auth/activation-options')
|
|
colleges.value = data.colleges
|
|
majors.value = data.majors
|
|
classes.value = data.classes
|
|
} catch (error) {
|
|
ElMessage.error(apiErrorMessage(error))
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
})
|
|
</script>
|
|
|
|
<template>
|
|
<main class="activation-page">
|
|
<header class="activation-header">
|
|
<router-link to="/login">{{ branding.shortName }}</router-link>
|
|
<div class="activation-header-actions">
|
|
<LocaleSwitcher />
|
|
<router-link to="/timetable">{{ t('auth.activation.timetable') }}</router-link>
|
|
</div>
|
|
</header>
|
|
|
|
<section class="activation-card" v-loading="loading">
|
|
<div class="activation-intro">
|
|
<span>STUDENT ACCOUNT ACTIVATION</span>
|
|
<h1>{{ t('auth.activation.title') }}</h1>
|
|
<p>{{ t('auth.activation.intro') }}</p>
|
|
</div>
|
|
|
|
<el-alert
|
|
type="info"
|
|
:closable="false"
|
|
:title="t('auth.activation.notice')"
|
|
/>
|
|
|
|
<el-form label-position="top" class="activation-form" @submit.prevent="activate">
|
|
<div class="activation-grid">
|
|
<el-form-item :label="t('auth.activation.name')" required>
|
|
<el-input v-model="form.name" autocomplete="name" :placeholder="t('auth.activation.matchingName')" />
|
|
</el-form-item>
|
|
<el-form-item :label="t('auth.activation.studentNumber')" required>
|
|
<el-input v-model="form.studentNumber" autocomplete="username" :placeholder="t('auth.activation.fullNumber')" />
|
|
</el-form-item>
|
|
</div>
|
|
<div class="activation-grid">
|
|
<el-form-item :label="t('auth.activation.college')" required>
|
|
<el-select v-model="form.collegeId" filterable :placeholder="t('auth.activation.selectCollege')">
|
|
<el-option
|
|
v-for="item in colleges"
|
|
:key="item.id"
|
|
:label="item.name"
|
|
:value="item.id"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item :label="t('auth.activation.major')" required>
|
|
<el-select
|
|
v-model="form.majorId"
|
|
filterable
|
|
:disabled="!form.collegeId"
|
|
:placeholder="t('auth.activation.selectMajor')"
|
|
>
|
|
<el-option
|
|
v-for="item in availableMajors"
|
|
:key="item.id"
|
|
:label="item.name"
|
|
:value="item.id"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
</div>
|
|
<div class="activation-grid">
|
|
<el-form-item :label="t('auth.activation.grade')" required>
|
|
<el-select
|
|
v-model="form.grade"
|
|
:disabled="!form.majorId"
|
|
:placeholder="t('auth.activation.selectGrade')"
|
|
>
|
|
<el-option
|
|
v-for="grade in availableGrades"
|
|
:key="grade"
|
|
:label="t('auth.activation.gradeOption', { grade })"
|
|
:value="grade"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item :label="t('auth.activation.class')" required>
|
|
<el-select
|
|
v-model="form.administrativeClassId"
|
|
filterable
|
|
:disabled="!form.grade"
|
|
:placeholder="t('auth.activation.selectClass')"
|
|
>
|
|
<el-option
|
|
v-for="item in availableClasses"
|
|
:key="item.id"
|
|
:label="item.name"
|
|
:value="item.id"
|
|
/>
|
|
</el-select>
|
|
</el-form-item>
|
|
</div>
|
|
<el-form-item :label="t('auth.activation.ticket')" required>
|
|
<el-input v-model="form.activationTicket" type="password" show-password autocomplete="off" />
|
|
</el-form-item>
|
|
<div class="activation-grid">
|
|
<el-form-item :label="t('auth.activation.password')" required>
|
|
<el-input
|
|
v-model="form.password"
|
|
type="password"
|
|
show-password
|
|
autocomplete="new-password"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item :label="t('auth.activation.confirmPassword')" required>
|
|
<el-input
|
|
v-model="form.confirmPassword"
|
|
type="password"
|
|
show-password
|
|
autocomplete="new-password"
|
|
@keyup.enter="activate"
|
|
/>
|
|
</el-form-item>
|
|
</div>
|
|
<p class="password-rule">{{ t('auth.activation.passwordRule') }}</p>
|
|
<el-button
|
|
class="activation-submit"
|
|
type="primary"
|
|
size="large"
|
|
native-type="submit"
|
|
:loading="submitting"
|
|
>
|
|
{{ t('auth.activation.submit') }}
|
|
</el-button>
|
|
</el-form>
|
|
|
|
<footer>
|
|
{{ t('auth.activation.hasAccount') }}
|
|
<router-link to="/login">{{ t('auth.activation.back') }}</router-link>
|
|
</footer>
|
|
</section>
|
|
</main>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.activation-page { min-height: 100vh; padding: 0 24px 48px; background: #eef3f6; color:var(--ink); }
|
|
.activation-header { max-width: 920px; height: 68px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #d7e0e7; }
|
|
.activation-header a { color:var(--ink); font-weight: 700; text-decoration: none; }
|
|
.activation-header a:last-child { color: #176b87; font-size: 13px; }
|
|
.activation-header-actions { display: flex; align-items: center; gap: 16px; }
|
|
.activation-card { max-width: 760px; margin: 44px auto 0; padding: 36px 42px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
|
|
.activation-intro { margin-bottom: 22px; }
|
|
.activation-intro span { color: #176b87; font-size: 11px; font-weight: 750; letter-spacing: .12em; }
|
|
.activation-intro h1 { margin: 8px 0; font-size: 28px; }
|
|
.activation-intro p { margin: 0; color: #687b8c; }
|
|
.activation-form { margin-top: 24px; }
|
|
.activation-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
|
|
.activation-form :deep(.el-select) { width: 100%; }
|
|
.password-rule { margin: -4px 0 18px; color: #5d7185; font-size: 12px; }
|
|
.activation-submit { width: 100%; }
|
|
footer { margin-top: 22px; color:var(--muted); font-size: 13px; text-align: center; }
|
|
footer a { color: #176b87; font-weight: 700; text-decoration: none; }
|
|
@media (max-width: 640px) {
|
|
.activation-page { padding: 0 14px 28px; }
|
|
.activation-card { margin-top: 22px; padding: 26px 20px; }
|
|
.activation-grid { grid-template-columns: 1fr; gap: 0; }
|
|
}
|
|
</style>
|