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.

92 lines
2.4 KiB
Vue

<template>
<ch-flex justify="center" class="page login-page" items="center">
<ch-flex class="login-win" items="center">
<image class="login-img" src="@/assets/images/logo/ghlogo.png" mode="aspectFit"></image>
<uni-forms ref="formRef" err-show-type="toast" :modelValue="form" :rules="rules">
<!-- <uni-forms-item name="schoolId">
<uni-data-select v-model="form.schoolId" :localdata="schoolList" prefixIcon="home-filled" placeholder="请选择学校">
</uni-data-select>
</uni-forms-item> -->
<uni-forms-item name="studentno">
<uni-easyinput v-model="form.studentno" placeholder="学生学号" prefixIcon="person-filled"></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="studentpwd">
<uni-easyinput v-model="form.studentpwd" type="password" placeholder="登录密码" prefixIcon="locked-filled"></uni-easyinput>
</uni-forms-item>
<uni-forms-item>
<button type="primary" size="mini" :disabled="loading" @click="login">{{ loading ? ' ...' : ' ' }}</button>
</uni-forms-item>
</uni-forms>
</ch-flex>
</ch-flex>
</template>
<script setup>
import { ref, reactive, toRefs } from 'vue';
import useForm from '@/useModules/useForm.js';
import ChFlex from '@/components/ch-flex/ch-flex.vue';
import { useSystemStore } from '@/store/system.js';
const defaultForm = {
studentno: '',
studentpwd: '',
// schoolId: '',
}
const systemStore = useSystemStore();
const formRef = ref();
const { form, validateForm, resetForm } = useForm(formRef, defaultForm);
const data = reactive({
loading: false,
rules: {
schoolId: {
rules: [{ required: false, errorMessage: '请选择学校' }]
},
studentno: {
rules: [{ required: true, errorMessage: '请输入学生编号' }]
},
studentpwd: {
rules: [{ required: true, errorMessage: '请输入密码' }]
}
},
schoolList: [
{
value: '001',
text: '学校1'
},
{
value: '002',
text: '学校2'
}
]
})
const { rules, schoolList, loading } = toRefs(data);
function login () {
validateForm().then(status => {
if(!status) return false;
loading.value = true;
systemStore.Login(form).then(res => {
uni.navigateTo({
url: '/pages/index/index'
})
}).catch(error => {
uni.showToast({
icon: 'fail',
title: '登录失败'
})
}).finally(() => {
loading.value = false;
})
})
}
</script>
<style lang="scss" scoped>
@import 'login.scss'
</style>