添加登录注册接口
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# VITE_APP_URL = http://192.168.31.82:8771
|
||||
# VITE_APP_URL = http://18.167.251.121:10095
|
||||
VITE_APP_URL = http://192.168.31.118:8080
|
||||
VITE_APP_URL = http://18.167.251.121:10015
|
||||
# VITE_APP_URL = http://192.168.31.118:8080
|
||||
VITE_GOOGLE_CLIENT_ID = 216037134725-7q8vqp0ohtmohlosltkfg7bd2v29rm5a.apps.googleusercontent.com
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
VITE_APP_URL = https://www.lc-api.aida.com.hk
|
||||
# VITE_APP_URL = http://18.167.251.121:10095
|
||||
# VITE_APP_URL = https://www.lc-api.aida.com.hk
|
||||
VITE_APP_URL = http://18.167.251.121:10015
|
||||
VITE_GOOGLE_CLIENT_ID = 29310152396-nnsd3h533fld665oguu8ovrt1nukmt46.apps.googleusercontent.com
|
||||
|
||||
111
src/api/login.ts
111
src/api/login.ts
@@ -1,77 +1,48 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
interface LoginParamsType {
|
||||
name?: string // 姓名
|
||||
email: string // 邮箱
|
||||
password?: string // 密码
|
||||
operationType: 'REGISTER' | 'LOGIN' | 'FORGET_PWD'
|
||||
verifyCode?: string // 验证码
|
||||
/**
|
||||
*
|
||||
* 发送验证码
|
||||
* @param params 发送验证码的参数
|
||||
* @param params.email 邮箱
|
||||
* @returns 验证码发送成功的响应
|
||||
*/
|
||||
export const SendVerificationCode = (params) => {
|
||||
return request({
|
||||
url: '/api/user/send-verification-code',
|
||||
method: 'post',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
export const precheckEmail = (params: { email: string }): Promise<ApiResponse> => {
|
||||
return request({
|
||||
url: '/api/auth/precheckEmail',
|
||||
method: 'get',
|
||||
params
|
||||
})
|
||||
}
|
||||
|
||||
export const fetchRegisterOrLogin = (data: LoginParamsType): Promise<LoginResponse> => {
|
||||
return request({
|
||||
url: '/api/auth/registerOrLogin',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export const resetPassword = (data: LoginParamsType): Promise<ApiResponse> => {
|
||||
return request({
|
||||
url: '/api/auth/forgotPwd',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
export const checkLoginStatus = (): Promise<ApiResponse<LoginResponse>> => {
|
||||
return request({
|
||||
url: '/api/auth/checkLoginStatus',
|
||||
method: 'get',
|
||||
meta: { responseAll: true }
|
||||
})
|
||||
}
|
||||
|
||||
export const LogOut = (): Promise<ApiResponse> => {
|
||||
return request({
|
||||
url: '/api/auth/logout',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// Google登录/注册参数类型
|
||||
interface GoogleAuthParamsType {
|
||||
accessToken?: string // Google ID Token (用于One Tap登录)
|
||||
}
|
||||
export const googleAuth = (data: GoogleAuthParamsType): Promise<LoginResponse> => {
|
||||
return request({
|
||||
url: '/api/auth/parseGoogleAccessToken',
|
||||
method: 'get',
|
||||
params: data
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/** 更改用户信息
|
||||
* @param data 包含用户信息的对象
|
||||
* @param data.username 用户名
|
||||
* @param data.email 邮箱
|
||||
/**
|
||||
* 注册用户
|
||||
* @param data 注册用户的参数
|
||||
* @param data.username 姓名
|
||||
* @param data.password 密码
|
||||
* @returns 包含更新后的用户信息的对象
|
||||
* @param data.email 邮箱
|
||||
* @param data.verificationCode 验证码
|
||||
* @returns 注册成功后的token
|
||||
*/
|
||||
export const updateUserInfo = (data: any) => {
|
||||
return request({
|
||||
url: '/api/auth/updateUserInfo',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
export const Register = (data) => {
|
||||
return request({
|
||||
url: '/api/user/register',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 登录用户
|
||||
* @param data 登录用户的参数
|
||||
* @param data.username 姓名
|
||||
* @param data.password 密码
|
||||
* @param data.verificationCode 验证码
|
||||
* @returns 登录成功后的token
|
||||
*/
|
||||
export const Login = (data) => {
|
||||
return request({
|
||||
url: '/api/user/login',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
@@ -24,7 +24,7 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
||||
|
||||
const setToken = (data: string) => {
|
||||
state.value.token = data
|
||||
setLocal(data, 'token')
|
||||
// setLocal(data, 'token')
|
||||
}
|
||||
|
||||
const getGenerateParams = () => {
|
||||
|
||||
@@ -79,7 +79,7 @@ service.interceptors.response.use(
|
||||
const res = response.data
|
||||
// 处理异常的情况
|
||||
// console.log(res)
|
||||
if (res.code != 0) {
|
||||
if (res.code != 200) {
|
||||
// showToast({
|
||||
// message: res.errMsg || res.message,
|
||||
// // type: 'fail',
|
||||
|
||||
@@ -56,11 +56,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Login } from '@/api/login'
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { validateEmail, validatePass, validatePrivacy } from './tools'
|
||||
import OtherLogin from './other-login.vue'
|
||||
import VisibleCode from './visible-code.vue'
|
||||
import { useUserInfoStore } from '@/stores'
|
||||
const userInfoStore = useUserInfoStore()
|
||||
const router = useRouter()
|
||||
const ruleForm = reactive({
|
||||
email: [{ validator: validateEmail, trigger: 'blur' }],
|
||||
@@ -84,16 +87,29 @@
|
||||
const onSubmit = () => {
|
||||
formRef.value?.validate?.((valid) => {
|
||||
if (valid) {
|
||||
console.log('submit!')
|
||||
// console.log('submit!')
|
||||
isVisible.value = true
|
||||
} else {
|
||||
console.log('error submit!')
|
||||
console.warn('error submit!')
|
||||
}
|
||||
})
|
||||
}
|
||||
const onVerifyCode = (code: string) => {
|
||||
console.log(code)
|
||||
router.push({ name: 'mainInput' })
|
||||
// console.log(code)
|
||||
Login({
|
||||
email: formData.email,
|
||||
password: formData.password,
|
||||
verificationCode: code
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
userInfoStore.setToken(res)
|
||||
router.push({ name: 'mainInput' })
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.warn('error verify code!')
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -60,11 +60,14 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Register } from '@/api/login'
|
||||
import { computed, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { validateName, validateEmail, validatePass, validatePrivacy } from './tools'
|
||||
import OtherLogin from './other-login.vue'
|
||||
import VisibleCode from './visible-code.vue'
|
||||
import { useUserInfoStore } from '@/stores'
|
||||
const userInfoStore = useUserInfoStore()
|
||||
const router = useRouter()
|
||||
const ruleForm = reactive({
|
||||
name: [{ validator: validateName, trigger: 'blur' }],
|
||||
@@ -90,16 +93,31 @@
|
||||
const onSubmit = () => {
|
||||
formRef.value?.validate?.((valid) => {
|
||||
if (valid) {
|
||||
console.log('submit!')
|
||||
// console.log('submit!')
|
||||
isVisible.value = true
|
||||
} else {
|
||||
console.log('error submit!')
|
||||
console.warn('error submit!')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const onVerifyCode = (code: string) => {
|
||||
console.log(code)
|
||||
router.push({ name: 'nuic' })
|
||||
Register({
|
||||
username: formData.name,
|
||||
email: formData.email,
|
||||
password: formData.password,
|
||||
verificationCode: code
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
userInfoStore.setToken(res)
|
||||
router.push({ name: 'nuic' })
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.warn('error verify code!')
|
||||
})
|
||||
// router.push({ name: 'nuic' })
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { SendVerificationCode } from '@/api/login'
|
||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||
import { CountDown } from '@/utils/tools'
|
||||
import InputCode from '@/components/input-code.vue'
|
||||
@@ -44,11 +45,20 @@
|
||||
clearTime()
|
||||
})
|
||||
onMounted(() => {
|
||||
setTime()
|
||||
onSendCode()
|
||||
})
|
||||
const onSendCode = async () => {
|
||||
const email = props.email
|
||||
if (!email) {
|
||||
console.warn('请输入邮箱')
|
||||
return
|
||||
}
|
||||
setTime()
|
||||
await SendVerificationCode({ email })
|
||||
}
|
||||
const onResend = () => {
|
||||
if (time.value > 0) return
|
||||
setTime()
|
||||
onSendCode()
|
||||
}
|
||||
const onVerify = () => {
|
||||
if (code.value.length !== 6) return
|
||||
|
||||
Reference in New Issue
Block a user