Login.vue 2.18 KB
<template>
  <div class="login-wrap">
    <a-card title="外卖管理系统" style="width:400px">
      <a-form :model="form" @finish="onSubmit" layout="vertical">
        <a-form-item name="role" label="登录身份">
          <a-radio-group v-model:value="form.role" button-style="solid">
            <a-radio-button value="substation">分站管理员</a-radio-button>
            <a-radio-button value="admin">超级管理员</a-radio-button>
          </a-radio-group>
        </a-form-item>
        <a-form-item name="account" :rules="[{ required: true, message: '请输入账号' }]">
          <a-input v-model:value="form.account" placeholder="登录账号" size="large">
            <template #prefix><user-outlined /></template>
          </a-input>
        </a-form-item>
        <a-form-item name="pass" :rules="[{ required: true, message: '请输入密码' }]">
          <a-input-password v-model:value="form.pass" placeholder="密码" size="large">
            <template #prefix><lock-outlined /></template>
          </a-input-password>
        </a-form-item>
        <a-form-item>
          <a-button type="primary" html-type="submit" block size="large" :loading="loading">
            登录
          </a-button>
        </a-form-item>
      </a-form>
    </a-card>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { message } from 'ant-design-vue'
import { UserOutlined, LockOutlined } from '@ant-design/icons-vue'
import { useAuthStore } from '@/stores/auth'
import request from '@/utils/request'

const router = useRouter()
const auth = useAuthStore()
const loading = ref(false)
const form = reactive({ account: '', pass: '', role: 'substation' })

async function onSubmit() {
  loading.value = true
  try {
    const res: any = await request.post('/api/admin/auth/login', form)
    auth.setToken(res.data.token)
    auth.setUserInfo(res.data)
    router.push('/')
  } catch {
    // 错误已由 request 拦截器处理
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f2f5;
}
</style>