- 更新 package.json 中的依赖版本号,包括 element-plus、axios、pinia、vue-router 等 - 删除 HelloWorld 组件,替换为 router-view 以支持路由功能 - 添加 auth、category、customer、dashboard、medicine、role、stock、stockIn、stockOut、 supplier、user 等多个 API 接口文件 - 创建权限指令、主布局组件和全局样式 - 集成 Element Plus UI 框架并注册图标组件 - 实现应用状态管理和用户状态管理 Store - 配置 Vue Router 路由系统,支持动态菜单路由生成 - 移除旧的 CSS 样式文件,改用 SCSS 全局样式 ```
111 lines
2.6 KiB
Vue
111 lines
2.6 KiB
Vue
<script setup>
|
|
import { ref, reactive } from 'vue'
|
|
import { useRouter } from 'vue-router'
|
|
import { useUserStore } from '@/stores/user'
|
|
import { User, Lock } from '@element-plus/icons-vue'
|
|
|
|
const router = useRouter()
|
|
const userStore = useUserStore()
|
|
|
|
const loginFormRef = ref(null)
|
|
const loading = ref(false)
|
|
const loginForm = reactive({
|
|
username: 'admin',
|
|
password: 'admin123',
|
|
remember: false,
|
|
})
|
|
|
|
const rules = {
|
|
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
|
|
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
|
|
}
|
|
|
|
async function handleLogin() {
|
|
const valid = await loginFormRef.value.validate().catch(() => false)
|
|
if (!valid) return
|
|
|
|
loading.value = true
|
|
try {
|
|
await userStore.login({
|
|
username: loginForm.username,
|
|
password: loginForm.password,
|
|
})
|
|
router.push('/dashboard')
|
|
} catch {
|
|
// 错误已在拦截器中处理
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="login-page">
|
|
<div class="login-card">
|
|
<h2 class="login-title">药品管理系统</h2>
|
|
<el-form
|
|
ref="loginFormRef"
|
|
:model="loginForm"
|
|
:rules="rules"
|
|
size="large"
|
|
@keyup.enter="handleLogin"
|
|
>
|
|
<el-form-item prop="username">
|
|
<el-input
|
|
v-model="loginForm.username"
|
|
placeholder="用户名"
|
|
:prefix-icon="User"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item prop="password">
|
|
<el-input
|
|
v-model="loginForm.password"
|
|
type="password"
|
|
show-password
|
|
placeholder="密码"
|
|
:prefix-icon="Lock"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-checkbox v-model="loginForm.remember">记住我</el-checkbox>
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button
|
|
type="primary"
|
|
:loading="loading"
|
|
style="width: 100%"
|
|
@click="handleLogin"
|
|
>
|
|
{{ loading ? '登录中...' : '登 录' }}
|
|
</el-button>
|
|
</el-form-item>
|
|
</el-form>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<style lang="scss" scoped>
|
|
.login-page {
|
|
height: 100vh;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background: linear-gradient(135deg, #667eea 0%, #051f96 100%);
|
|
}
|
|
|
|
.login-card {
|
|
width: 420px;
|
|
padding: 40px;
|
|
background: #fff;
|
|
border-radius: 12px;
|
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
.login-title {
|
|
text-align: center;
|
|
margin-bottom: 32px;
|
|
color: #303133;
|
|
font-size: 24px;
|
|
}
|
|
</style>
|