RegisterView.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <script setup lang="ts">
  2. import CommonView from "@/components/CommonView.vue"
  3. import { ref } from "vue"
  4. import { Lock, Phone, 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 pwd2 = ref("")
  14. const phone = ref("")
  15. const code = ref("")
  16. const open = () => {
  17. router.push("/login")
  18. }
  19. const register = () => {
  20. if (email.value.length === 0) {
  21. ElMessage.error("请输入正确的邮箱地址")
  22. return
  23. }
  24. if (pwd.value.length === 0) {
  25. ElMessage.error("请输入密码")
  26. return
  27. }
  28. if (pwd2.value.length === 0) {
  29. ElMessage.error("请输入确认密码")
  30. return
  31. }
  32. if (pwd2.value !== pwd.value) {
  33. ElMessage.error("两次输入的密码不一致")
  34. return
  35. }
  36. if (phone.value.length === 0) {
  37. ElMessage.error("请输入正确手机号")
  38. return
  39. }
  40. if (code.value.length === 0) {
  41. ElMessage.error("请输入验证吗")
  42. return
  43. }
  44. if (code.value !== "123456") {
  45. ElMessage.error("验证码错误")
  46. return
  47. }
  48. Api.register({
  49. userEmail: email.value,
  50. userPhone: phone.value,
  51. userPwd: pwd.value
  52. }).then(() => {
  53. ElMessage.success("注册成功")
  54. open()
  55. })
  56. }
  57. </script>
  58. <template>
  59. <CommonView title="注册">
  60. <div style="display: flex; place-content: center">
  61. <el-card style="max-width: 480px">
  62. <template #header>
  63. <div class="card-header" style="display: flex; flex-direction: row-reverse">
  64. <el-button type="primary" @click="open">登录</el-button>
  65. </div>
  66. </template>
  67. <div class="flex gap-4 mb-4">
  68. <el-input
  69. class="text item"
  70. v-model="email"
  71. style="width: 440px"
  72. placeholder="请输入邮箱地址"
  73. :prefix-icon="User"
  74. :clearable="true"
  75. />
  76. <el-input
  77. v-model="pwd"
  78. style="width: 440px; margin-top: 18px"
  79. placeholder="请输入密码"
  80. :prefix-icon="Lock"
  81. :clearable="true"
  82. :show-password="true"
  83. />
  84. <el-input
  85. v-model="pwd2"
  86. style="width: 440px; margin-top: 18px"
  87. placeholder="请输入确认密码"
  88. :prefix-icon="Lock"
  89. :show-password="true"
  90. :clearable="true"
  91. />
  92. <el-input
  93. v-model="phone"
  94. style="width: 440px; margin-top: 18px"
  95. placeholder="请输入手机号"
  96. :prefix-icon="Phone"
  97. :clearable="true"
  98. />
  99. <el-input
  100. v-model="code"
  101. style="width: 440px; margin-top: 18px"
  102. placeholder="请输入验证码"
  103. :prefix-icon="Lock"
  104. :show-password="true"
  105. :clearable="true"
  106. >
  107. <template #append>
  108. <el-button>获取验证码</el-button>
  109. </template>
  110. </el-input>
  111. <el-button style="width: 440px; margin-top: 28px" type="primary" @click="register"
  112. >注册
  113. </el-button>
  114. </div>
  115. </el-card>
  116. </div>
  117. </CommonView>
  118. </template>
  119. <style scoped></style>