feat(web): add login, auth store and router guard

This commit is contained in:
2026-07-07 15:25:47 +08:00
parent bcef04a8cc
commit e731ee7a2e
9 changed files with 227 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
<template>
<div>
<h2>流程追踪</h2>
</div>
</template>

View File

@@ -0,0 +1,110 @@
<template>
<div class="login-page">
<el-card class="login-card" shadow="always">
<template #header>
<div class="login-title">Sino MCI 管理后台</div>
</template>
<el-form
ref="formRef"
:model="form"
:rules="rules"
label-position="top"
@keyup.enter="handleSubmit"
>
<el-form-item label="租户编码" prop="tenantCode">
<el-input v-model="form.tenantCode" placeholder="请输入租户编码" />
</el-form-item>
<el-form-item label="用户名" prop="username">
<el-input v-model="form.username" placeholder="请输入用户名" />
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input
v-model="form.password"
type="password"
show-password
placeholder="请输入密码"
/>
</el-form-item>
<el-button
type="primary"
class="login-btn"
:loading="loading"
@click="handleSubmit"
>
登录
</el-button>
</el-form>
</el-card>
</div>
</template>
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import { login } from '@/api/account'
import { useAuthStore } from '@/stores/auth'
const router = useRouter()
const authStore = useAuthStore()
const formRef = ref<FormInstance>()
const loading = ref(false)
const form = reactive({
tenantCode: '',
username: '',
password: '',
})
const rules: FormRules = {
tenantCode: [{ required: true, message: '请输入租户编码', trigger: 'blur' }],
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
}
async function handleSubmit() {
const valid = await formRef.value?.validate().catch(() => false)
if (!valid) return
loading.value = true
try {
const res: any = await login(form)
const userInfo = res.data?.userInfo || res.data
authStore.setAuth(
res.data?.token || '',
userInfo.tenantCode,
userInfo.username,
userInfo.roleCodes || []
)
ElMessage.success('登录成功')
router.push('/dashboard')
} catch (err: any) {
ElMessage.error(err?.message || '登录失败')
} finally {
loading.value = false
}
}
</script>
<style scoped>
.login-page {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #f5f7fa;
}
.login-card {
width: 400px;
}
.login-title {
text-align: center;
font-size: 18px;
font-weight: bold;
}
.login-btn {
width: 100%;
margin-top: 8px;
}
</style>

View File

@@ -0,0 +1,5 @@
<template>
<div>
<h2>消息测试</h2>
</div>
</template>

View File

@@ -0,0 +1,5 @@
<template>
<div>
<h2>租户管理</h2>
</div>
</template>

View File

@@ -0,0 +1,5 @@
<template>
<div>
<h2>用户管理</h2>
</div>
</template>