接口配置
This commit is contained in:
@@ -1,3 +1 @@
|
||||
# VITE_APP_URL = http://192.168.31.82:8771
|
||||
# VITE_APP_URL = http://18.167.251.121:10095
|
||||
VITE_APP_URL = https://www.lc-api.aida.com.hk
|
||||
VITE_APP_URL = http://192.168.31.82:10094
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
VITE_APP_URL = https://www.lc-api.aida.com.hk
|
||||
# VITE_APP_URL = http://18.167.251.121:10095
|
||||
VITE_APP_URL = http://192.168.31.82:10094
|
||||
|
||||
63
src/api/account.ts
Normal file
63
src/api/account.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 登录发送验证码
|
||||
* @param data - 包含邮箱的参数
|
||||
* @param data.email - 邮箱
|
||||
* @param data.password - 密码
|
||||
*/
|
||||
export const AccountSendLoginCode = (data) => {
|
||||
return request({
|
||||
url: '/buyer/account/preLogin',
|
||||
method: 'post',
|
||||
data,
|
||||
loading: true
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 登录
|
||||
* @param data - 包含邮箱的参数
|
||||
* @param data.email - 邮箱
|
||||
* @param data.password - 密码
|
||||
* @param data.emailVerifyCode - 验证码
|
||||
*/
|
||||
export const AccountLogin = (data) => {
|
||||
return request({
|
||||
url: '/buyer/account/login',
|
||||
method: 'post',
|
||||
data,
|
||||
loading: true
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注册
|
||||
* @param data - 包含注册信息的参数
|
||||
* @param data.email - 邮箱
|
||||
* @param data.password - 密码
|
||||
* @param data.username - 用户名
|
||||
* @param data.emailVerifyCode - 验证码
|
||||
*/
|
||||
export const AccountRegister = (data) => {
|
||||
return request({
|
||||
url: '/buyer/account/register',
|
||||
method: 'post',
|
||||
data,
|
||||
loading: true
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 注册||忘记密码:发送邮箱验证码
|
||||
* @param data - 包含邮箱的参数
|
||||
* @param data.email - 邮箱
|
||||
* @param data.operationType - 操作类型:FORGET_PWD, REGISTER
|
||||
*/
|
||||
export const AccountSendVerifyCode = (data) => {
|
||||
return request({
|
||||
url: '/buyer/account/sendCode',
|
||||
method: 'post',
|
||||
data,
|
||||
loading: true
|
||||
})
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
interface LoginParamsType {
|
||||
name?: string // 姓名
|
||||
email: string // 邮箱
|
||||
password?: string // 密码
|
||||
operationType: 'REGISTER' | 'LOGIN' | 'FORGET_PWD'
|
||||
verifyCode?: string // 验证码
|
||||
}
|
||||
|
||||
// 发送验证码
|
||||
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.password 密码
|
||||
* @returns 包含更新后的用户信息的对象
|
||||
*/
|
||||
export const updateUserInfo = (data: any) => {
|
||||
return request({
|
||||
url: '/api/auth/updateUserInfo',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
@@ -20,6 +20,7 @@ export const useUserInfoStore = defineStore('userInfo', () => {
|
||||
// actions
|
||||
const setUserInfo = (data: any) => {
|
||||
state.value.userInfo = data
|
||||
state.value.token = data.accessToken
|
||||
}
|
||||
|
||||
const setToken = (data: string) => {
|
||||
|
||||
@@ -75,7 +75,7 @@ service.interceptors.response.use(
|
||||
const res = response.data
|
||||
// 处理异常的情况
|
||||
// console.log(res)
|
||||
if (res.code != 200) {
|
||||
if (res.errCode != 0) {
|
||||
ElMessage.error(res.message)
|
||||
return Promise.reject(new Error(res.errMsg || res.message || 'error'))
|
||||
} else {
|
||||
|
||||
@@ -55,6 +55,12 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
AccountSendLoginCode,
|
||||
AccountLogin,
|
||||
AccountRegister,
|
||||
AccountSendVerifyCode
|
||||
} from '@/api/account'
|
||||
import { computed, ref, markRaw, watch, onBeforeUnmount } from 'vue'
|
||||
import md5 from 'md5'
|
||||
import login from './login.vue'
|
||||
@@ -63,6 +69,8 @@
|
||||
import registerSuccess from './register-success.vue'
|
||||
import retrievePassword from './retrieve-password.vue'
|
||||
import myEvent from '@/utils/myEvent'
|
||||
import { useUserInfoStore } from '@/stores/userInfo'
|
||||
const userStore = useUserInfoStore()
|
||||
const data = ref({
|
||||
name: '',
|
||||
email: '',
|
||||
@@ -121,22 +129,42 @@
|
||||
})
|
||||
|
||||
const onLogin = (res: any) => {
|
||||
AccountSendLoginCode({
|
||||
email: res.email,
|
||||
password: md5(res.password)
|
||||
}).then((v) => {
|
||||
data.value = res
|
||||
data.value.type = TabNames.login
|
||||
currentTab.value = TabNames.email_verify
|
||||
})
|
||||
}
|
||||
const onRegister = (res: any) => {
|
||||
const value = {
|
||||
email: res.email,
|
||||
operationType: 'REGISTER'
|
||||
}
|
||||
AccountSendVerifyCode(value).then((v) => {
|
||||
data.value = res
|
||||
data.value.type = TabNames.register
|
||||
currentTab.value = TabNames.email_verify
|
||||
})
|
||||
}
|
||||
const onSubmitEmailCode = (code: string) => {
|
||||
const value = {
|
||||
email: data.value.email,
|
||||
password: md5(data.value.password),
|
||||
emailVerifyCode: code
|
||||
}
|
||||
if (data.value.type === TabNames.login) {
|
||||
console.log('登录', code)
|
||||
AccountLogin(value).then((v) => {
|
||||
userStore.setUserInfo(v)
|
||||
show.value = false
|
||||
})
|
||||
} else {
|
||||
console.log('注册', code)
|
||||
value['username'] = data.value.name
|
||||
AccountRegister(value).then((v) => {
|
||||
currentTab.value = TabNames.register_success
|
||||
})
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -66,11 +66,10 @@ export default defineConfig(({ mode }) => {
|
||||
overlay: true
|
||||
},
|
||||
proxy: {
|
||||
'/api': {
|
||||
//'/api'是自行设置的请求前缀
|
||||
'/buyer': {
|
||||
target: env.VITE_APP_URL,
|
||||
changeOrigin: true, //用于控制请求头中的host值
|
||||
rewrite: (path) => path.replace(/^\/api/, '/api') //路径重写,(正则)匹配以api开头的路径为空(将请求前缀删除)
|
||||
rewrite: (path) => path.replace(/^\/buyer/, '/buyer') //路径重写,(正则)匹配以api开头的路径为空(将请求前缀删除)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user