123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <script setup>
- import { ref } from 'vue'
- import serverConfig from "../serverConfig"
- const router = useRouter()
- const username = ref('')
- const password = ref('')
- const schoolName = ref('')
- const isShowPassword = ref(true)
- const signup = async () => {
- let LoginState = await useFetch(serverConfig.host+'/api/user', {
- method: 'POST',
- credentials: 'include',
- mode: 'cors',
- body: {
- username: username.value.trim(),
- password: password.value.trim(),
- college: schoolName.value.trim(),
- geetest_challenge: "",
- geetest_validate: "",
- geetest_seccode: "",
- googleId: "",
- identity: 1,
- }
- }).then(r => {
- return r
- })
- console.log(LoginState.data.value)
- if (LoginState.data.value == "OK") {
- alert("注册成功")
- await useFetch(serverConfig.host+'/api/profile', {
- method: 'GET',
- credentials: 'include',
- mode: 'cors'
- }).then(r => {
- console.log(r)
- if (r.data.value) {
- router.push('/persion')
- let data = r.data.value
- let obj = {
- username: data.username,
- alias: data.alias,
- userid: data.userid,
- isLoading: true,
- googleId: data.gender,
- login: true,
- gender: data.gender,
- defaultSchool: data.defaultSchool,
- defaultAddress: data.defaultAddress,
- apiKey: data.apiKey
- }
- userInfo.value = obj
- try {
- window.parent.postMessage({ id: 'loginVerify', status: 'logged', data }, "*");
- } catch (error) {
- console.log(error);
- }
- }
- })
- }else if(LoginState.data.value.code === 11000){
- alert("用户名已注册")
- }else{
- alert("注册失败")
- }
- }
- </script>
- <template>
- <div class="signup">
- <div class="signup-box">
- <div class="box-item" style="min-height: 100px;">
- <p>电子邮箱</p>
- <input type="text" v-model="username">
- </div>
- <div class="box-item">
- <p>密码</p>
- <input :type="isShowPassword ? 'password' : 'text'" v-model="password" placeholder="至少6位数">
- <img :src="!isShowPassword ? './image/password.png' : './image/showPassword.png'" alt=""
- @click="isShowPassword = !isShowPassword">
- </div>
- <div class="box-item" style="min-height: 100px;">
- <p>学校名称</p>
- <input type="text" v-model="schoolName">
- </div>
- <div class="box-item flex-right" style="text-align: right;">
- <button @click="signup()">注册</button>
- </div>
- <div class="box-item flex-right">
- <nuxt-link to="/login" style="margin: 0 auto;">
- <button>返回</button>
- </nuxt-link>
- </div>
- </div>
- </div>
- </template>
- <style scoped>
- .signup {
- width: 100%;
- height: calc(100vh - 80px);
- position: relative;
- .signup-box {
- width: 30%;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
- padding: 30px;
- border-radius: 10px;
- .box-item {
- width: 80%;
- margin: 10px auto;
- position: relative;
- img {
- position: absolute;
- bottom: 5px;
- right: 3px;
- width: 22px;
- cursor: pointer;
- }
- .error {
- color: red;
- animation-name: errorSide;
- animation: 1s;
- }
- p {
- color: #666;
- }
- input {
- width: 100%;
- padding: 10px 10px 10px 5px;
- font-size: 16px;
- outline: none;
- border: none;
- border-bottom: 2px solid #000;
- }
- button {
- width: 200px;
- font-size: 16px;
- padding: 10px 30px;
- margin: 10px auto;
- }
- }
- .flex-right {
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- }
- }
- </style>
|