LoginView.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <script setup lang="ts">
  2. import CommonView from "@/components/CommonView.vue"
  3. import { ref } from "vue"
  4. import { Lock, User } from "@element-plus/icons-vue"
  5. import { useRouter } from "vue-router"
  6. import { ElMessage } from "element-plus"
  7. // @ts-ignore
  8. import API from "@/api/index.js"
  9. const router = useRouter()
  10. const Api = API
  11. const email = ref("")
  12. const pwd = ref("")
  13. const register = () => {
  14. router.push("/register")
  15. }
  16. const login = () => {
  17. if (email.value.length === 0) {
  18. ElMessage.error("请输入正确的邮箱地址")
  19. return
  20. }
  21. if (pwd.value.length === 0) {
  22. ElMessage.error("请输入密码")
  23. return
  24. }
  25. Api.login({
  26. email: email.value,
  27. password: pwd.value
  28. }).then((res) => {
  29. ElMessage.success("登录成功")
  30. console.log(">>>>", JSON.stringify(res))
  31. sessionStorage.setItem("szyxToken", res)
  32. router.push("/main")
  33. })
  34. }
  35. </script>
  36. <template>
  37. <CommonView title="登录">
  38. <div style="display: flex; place-content: center">
  39. <el-card style="max-width: 480px">
  40. <template #header>
  41. <div class="card-header" style="display: flex; flex-direction: row-reverse">
  42. <el-button type="primary" @click="register">注册</el-button>
  43. </div>
  44. </template>
  45. <div class="flex gap-4 mb-4">
  46. <el-input
  47. class="text item"
  48. v-model="email"
  49. style="width: 440px"
  50. placeholder="请输入邮箱地址"
  51. :prefix-icon="User"
  52. :clearable="true"
  53. />
  54. <el-input
  55. v-model="pwd"
  56. style="width: 440px; margin-top: 18px"
  57. placeholder="请输入密码"
  58. :prefix-icon="Lock"
  59. :clearable="true"
  60. :show-password="true"
  61. />
  62. <el-button style="width: 440px; margin-top: 28px" type="primary" @click="login"
  63. >登录
  64. </el-button>
  65. </div>
  66. </el-card>
  67. </div>
  68. </CommonView>
  69. </template>
  70. <style scoped></style>