signup.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <script setup>
  2. import { ref } from 'vue'
  3. import serverConfig from "../serverConfig"
  4. const router = useRouter()
  5. const username = ref('')
  6. const password = ref('')
  7. const schoolName = ref('')
  8. const isShowPassword = ref(true)
  9. const signup = async () => {
  10. let LoginState = await useFetch(serverConfig.host+'/api/user', {
  11. method: 'POST',
  12. credentials: 'include',
  13. mode: 'cors',
  14. body: {
  15. username: username.value.trim(),
  16. password: password.value.trim(),
  17. college: schoolName.value.trim(),
  18. geetest_challenge: "",
  19. geetest_validate: "",
  20. geetest_seccode: "",
  21. googleId: "",
  22. identity: 1,
  23. }
  24. }).then(r => {
  25. return r
  26. })
  27. console.log(LoginState.data.value)
  28. if (LoginState.data.value == "OK") {
  29. alert("注册成功")
  30. await useFetch(serverConfig.host+'/api/profile', {
  31. method: 'GET',
  32. credentials: 'include',
  33. mode: 'cors'
  34. }).then(r => {
  35. console.log(r)
  36. if (r.data.value) {
  37. router.push('/persion')
  38. let data = r.data.value
  39. let obj = {
  40. username: data.username,
  41. alias: data.alias,
  42. userid: data.userid,
  43. isLoading: true,
  44. googleId: data.gender,
  45. login: true,
  46. gender: data.gender,
  47. defaultSchool: data.defaultSchool,
  48. defaultAddress: data.defaultAddress,
  49. apiKey: data.apiKey
  50. }
  51. userInfo.value = obj
  52. try {
  53. window.parent.postMessage({ id: 'loginVerify', status: 'logged', data }, "*");
  54. } catch (error) {
  55. console.log(error);
  56. }
  57. }
  58. })
  59. }else if(LoginState.data.value.code === 11000){
  60. alert("用户名已注册")
  61. }else{
  62. alert("注册失败")
  63. }
  64. }
  65. </script>
  66. <template>
  67. <div class="signup">
  68. <div class="signup-box">
  69. <div class="box-item" style="min-height: 100px;">
  70. <p>电子邮箱</p>
  71. <input type="text" v-model="username">
  72. </div>
  73. <div class="box-item">
  74. <p>密码</p>
  75. <input :type="isShowPassword ? 'password' : 'text'" v-model="password" placeholder="至少6位数">
  76. <img :src="!isShowPassword ? './image/password.png' : './image/showPassword.png'" alt=""
  77. @click="isShowPassword = !isShowPassword">
  78. </div>
  79. <div class="box-item" style="min-height: 100px;">
  80. <p>学校名称</p>
  81. <input type="text" v-model="schoolName">
  82. </div>
  83. <div class="box-item flex-right" style="text-align: right;">
  84. <button @click="signup()">注册</button>
  85. </div>
  86. <div class="box-item flex-right">
  87. <nuxt-link to="/login" style="margin: 0 auto;">
  88. <button>返回</button>
  89. </nuxt-link>
  90. </div>
  91. </div>
  92. </div>
  93. </template>
  94. <style scoped>
  95. .signup {
  96. width: 100%;
  97. height: calc(100vh - 80px);
  98. position: relative;
  99. .signup-box {
  100. width: 30%;
  101. position: absolute;
  102. top: 50%;
  103. left: 50%;
  104. transform: translate(-50%, -50%);
  105. box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
  106. padding: 30px;
  107. border-radius: 10px;
  108. .box-item {
  109. width: 80%;
  110. margin: 10px auto;
  111. position: relative;
  112. img {
  113. position: absolute;
  114. bottom: 5px;
  115. right: 3px;
  116. width: 22px;
  117. cursor: pointer;
  118. }
  119. .error {
  120. color: red;
  121. animation-name: errorSide;
  122. animation: 1s;
  123. }
  124. p {
  125. color: #666;
  126. }
  127. input {
  128. width: 100%;
  129. padding: 10px 10px 10px 5px;
  130. font-size: 16px;
  131. outline: none;
  132. border: none;
  133. border-bottom: 2px solid #000;
  134. }
  135. button {
  136. width: 200px;
  137. font-size: 16px;
  138. padding: 10px 30px;
  139. margin: 10px auto;
  140. }
  141. }
  142. .flex-right {
  143. display: flex;
  144. justify-content: space-between;
  145. align-items: center;
  146. }
  147. }
  148. }
  149. </style>