|
@@ -1,7 +1,81 @@
|
|
|
<template>
|
|
|
- <div>登录页面</div>
|
|
|
+ <div class="login-page">
|
|
|
+ <div class="login-container">
|
|
|
+ <div class="login-card">
|
|
|
+ <h2 class="login-title">卫星轨道仿真演示系统</h2>
|
|
|
+ <el-form ref="ruleFormRef" style="width: 400px" :model="loginForm" status-icon label-width="auto">
|
|
|
+ <el-form-item label="账号" prop="account">
|
|
|
+ <el-input v-model="loginForm.account" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="密码" prop="password">
|
|
|
+ <el-input v-model="loginForm.password" type="password" autocomplete="off" />
|
|
|
+ </el-form-item>
|
|
|
+ <el-button type="primary" @click="submitForm(ruleFormRef)"> 登录 </el-button>
|
|
|
+ <el-button @click="resetForm(ruleFormRef)">重置</el-button>
|
|
|
+ </el-form>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
-<script setup lang="ts"></script>
|
|
|
+<script lang="ts" setup>
|
|
|
+import { type FormInstance } from 'element-plus'
|
|
|
+import { useUserStore } from '@/stores'
|
|
|
+import router from '@/router'
|
|
|
+import { LocationQuery } from 'vue-router'
|
|
|
+const ruleFormRef = ref<FormInstance>()
|
|
|
+const route = useRoute()
|
|
|
+const userStore = useUserStore()
|
|
|
+const loginForm = reactive({
|
|
|
+ account: 'superadmin',
|
|
|
+ password: 'admin123',
|
|
|
+ grantType: 'password',
|
|
|
+ clientId: '7daa6e9b-8876-4918-8a12-b68cbfcdc680',
|
|
|
+ tenantId: '1'
|
|
|
+})
|
|
|
|
|
|
-<style scoped lang="scss"></style>
|
|
|
+/**
|
|
|
+ * 提交表单
|
|
|
+ *
|
|
|
+ * @param formEl 表单
|
|
|
+ */
|
|
|
+const submitForm = (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return
|
|
|
+ formEl.validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ userStore.userLogin({ ...loginForm }).then(res => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ const { path, queryParams } = parseRedirect()
|
|
|
+ router.push({ path: path, query: queryParams })
|
|
|
+ // ElMessage.success('提交成功')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 重置表单
|
|
|
+ *
|
|
|
+ * @param formEl 表单
|
|
|
+ */
|
|
|
+const resetForm = (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return
|
|
|
+ formEl.resetFields()
|
|
|
+}
|
|
|
+
|
|
|
+const parseRedirect = () => {
|
|
|
+ const query: LocationQuery = route.query
|
|
|
+ const redirect = (query.redirect as string) ?? '/home'
|
|
|
+ const url = new URL(redirect, window.location.origin)
|
|
|
+ const path = url.pathname
|
|
|
+ const queryParams: Record<string, string> = {}
|
|
|
+ url.searchParams.forEach((value, key) => {
|
|
|
+ queryParams[key] = value
|
|
|
+ })
|
|
|
+
|
|
|
+ return { path, queryParams }
|
|
|
+}
|
|
|
+</script>
|
|
|
+<style lang="scss"></style>
|