石墨仪设备 前端仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
3.7 KiB

6 months ago
5 months ago
5 months ago
6 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
5 months ago
6 months ago
5 months ago
6 months ago
5 months ago
6 months ago
5 months ago
6 months ago
  1. <template>
  2. <div class="main">
  3. <div class="login-form">
  4. <img :src="logo" class="logo" alt=""/>
  5. <div class="title">长春黄金研究院有限公司</div>
  6. <el-form :model="form" :rules="rules" ref="formRef" style="width: 100%">
  7. <div class="input-title">用户名</div>
  8. <el-form-item prop="username">
  9. <el-input
  10. v-model="form.username"
  11. placeholder="请输入用户名"
  12. prefix-icon="userIconSvg"
  13. style="width: 100%"
  14. size="large"
  15. >
  16. <template #prefix>
  17. <img :src="userIconSvg" alt="" class="icon" />
  18. </template>
  19. </el-input>
  20. </el-form-item>
  21. <div class="input-title">密码</div>
  22. <el-form-item prop="password">
  23. <el-input
  24. v-model="form.password"
  25. placeholder="请输入密码"
  26. prefix-icon="pwdIconSvg"
  27. type="password"
  28. style="width: 100%"
  29. size="large"
  30. >
  31. <template #prefix>
  32. <img :src="pwdIconSvg" alt="" class="icon"/>
  33. </template>
  34. </el-input>
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button style="width: 100%; margin-top: 10px" type="primary" @click="loginHandle" :loading="loading">登录</el-button>
  38. </el-form-item>
  39. </el-form>
  40. <span class="info">Changchun Gold Research Institute Co.,Ltd.</span>
  41. </div>
  42. </div>
  43. </template>
  44. <script setup lang="ts">
  45. import { ref } from "vue";
  46. import { useRouter } from "vue-router";
  47. import logo from '@/assets/logo.svg'
  48. import userIconSvg from '@/assets/user_icon.svg'
  49. import pwdIconSvg from '@/assets/pwdw_icon.svg'
  50. import { getCurrentUser, login, type User } from "@/services/user/userManager";
  51. import { useUserStore } from "@/stores/user";
  52. import {ElMessage} from "element-plus";
  53. const form = ref({
  54. username: "",
  55. password: "",
  56. });
  57. const formRef = ref();
  58. const rules = {
  59. username: [
  60. { required: true, message: "请输入用户名", trigger: "blur" },
  61. { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" },
  62. ],
  63. password: [
  64. { required: true, message: "请输入密码", trigger: "blur" },
  65. { min: 3, max: 10, message: "长度在 3 到 10 个字符", trigger: "blur" },
  66. ]
  67. }
  68. const loading = ref(false);
  69. const userStore = useUserStore();
  70. const router = useRouter();
  71. const loginHandle = () => {
  72. formRef.value.validate(async(valid: any) => {
  73. if (!valid) {
  74. return;
  75. }
  76. loading.value = true;
  77. const res = await login(form.value);
  78. if(res.success) {
  79. sessionStorage.setItem("token", res.data);
  80. const response = await getCurrentUser();
  81. if (response.success) {
  82. const { username, nickname, role } = response.data;
  83. userStore.setUser({ username, nickname, role } as User);
  84. }
  85. await router.push("/home");
  86. loading.value = false;
  87. }else {
  88. ElMessage.error(res.msg);
  89. loading.value = false;
  90. }
  91. })
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. @media screen and (max-width: 1000px) {
  96. .main {
  97. .login-form {
  98. width: 80%;
  99. }
  100. }
  101. }
  102. .main {
  103. width: 100%;
  104. height: 100vh;
  105. background: #BDE2FE;
  106. display: flex;
  107. justify-content: center;
  108. align-items: center;
  109. .login-form {
  110. width: 30%;
  111. display: flex;
  112. flex-direction: column;
  113. justify-content: center;
  114. align-items: center;
  115. padding: 50px 50px 10px;
  116. border-radius: 10px;
  117. background: linear-gradient(180deg, rgba(250, 252, 255, 0.51) 0%, rgba(255, 255, 255, 0.52) 100%);
  118. .logo {
  119. width: 50px;
  120. }
  121. .title {
  122. color: #8799AB;
  123. margin: 20px 0 30px 0;
  124. }
  125. .info {
  126. margin-top: 10px;
  127. color: #8799AB;
  128. font-size: 10px;
  129. }
  130. }
  131. }
  132. .icon {
  133. width: 15px;
  134. }
  135. .input-title {
  136. font-size: 14px;
  137. color: #2C3E59;
  138. margin-bottom: 10px;
  139. }
  140. </style>