feat: 添加请求打印
This commit is contained in:
parent
122d400e4c
commit
0e38f5ab4c
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
const tab = ref<number>(0)
|
const tab = ref<number>(0)
|
||||||
|
|
||||||
const props = defineProps({
|
defineProps({
|
||||||
list: {
|
list: {
|
||||||
type: Array<HomeTab>,
|
type: Array<HomeTab>,
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
@ -150,6 +150,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useBasicStore } from '@/store'
|
import { useBasicStore } from '@/store'
|
||||||
import { passwordRegExp, phoneRegExp } from '@/constants/regular-expressions'
|
import { passwordRegExp, phoneRegExp } from '@/constants/regular-expressions'
|
||||||
|
import { getCodeApi, UserGetCodeRequest } from '@/service/user'
|
||||||
|
import { AccountChannel, CodeType, IResData } from '@/typings'
|
||||||
|
import { Result } from '@/constants/result'
|
||||||
|
|
||||||
const $basic = useBasicStore()
|
const $basic = useBasicStore()
|
||||||
|
|
||||||
@ -188,7 +191,7 @@
|
|||||||
console.log('登录')
|
console.log('登录')
|
||||||
}
|
}
|
||||||
|
|
||||||
const codeLogin = () => {
|
const codeLogin = async () => {
|
||||||
if (!phonePass.value) {
|
if (!phonePass.value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -197,9 +200,35 @@
|
|||||||
agreementModal.value.showModal()
|
agreementModal.value.showModal()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uni.navigateTo({
|
await uni.showLoading({
|
||||||
url: `/pages/code/code?phone=${phone.value}&type=login`
|
title: '加载中',
|
||||||
|
mask: true
|
||||||
})
|
})
|
||||||
|
try {
|
||||||
|
const result: IResData = await getCodeApi<UserGetCodeRequest>({
|
||||||
|
account: phone.value,
|
||||||
|
channel: AccountChannel.phone,
|
||||||
|
codeType: CodeType.login
|
||||||
|
})
|
||||||
|
uni.hideLoading()
|
||||||
|
if (result.errorCode === Result.Success.code) {
|
||||||
|
await uni.navigateTo({
|
||||||
|
url: `/pages/code/code?phone=${phone.value}&type=login`
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await uni.showToast({
|
||||||
|
title: result.errorMsg,
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
uni.hideLoading()
|
||||||
|
await uni.showToast({
|
||||||
|
title: '获取验证码失败,请稍后再试',
|
||||||
|
icon: 'none'
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resetPassword = () => {
|
const resetPassword = () => {
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
import { http } from '@/utils/http'
|
|
||||||
export interface IFooItem {
|
|
||||||
id: string
|
|
||||||
name: string
|
|
||||||
}
|
|
||||||
|
|
||||||
/** GET 请求 */
|
|
||||||
export const getFooAPI = (name: string) => {
|
|
||||||
return http.get<IFooItem>('/foo', { name })
|
|
||||||
}
|
|
||||||
|
|
||||||
/** POST 请求 */
|
|
||||||
export const postFooAPI = (name: string) => {
|
|
||||||
return http.post<IFooItem>('/foo', { name }, { name })
|
|
||||||
}
|
|
||||||
13
src/service/user.ts
Normal file
13
src/service/user.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { http } from '@/utils/http'
|
||||||
|
|
||||||
|
export interface UserGetCodeRequest {
|
||||||
|
account: string
|
||||||
|
channel: string
|
||||||
|
codeType: string
|
||||||
|
countryCode?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取验证码
|
||||||
|
export const getCodeApi = (params: UserGetCodeRequest) => {
|
||||||
|
return http.post('/v1/common/sendValidationCode', params)
|
||||||
|
}
|
||||||
@ -1,6 +1,6 @@
|
|||||||
// 全局要用的类型放到这里
|
// 全局要用的类型放到这里
|
||||||
|
|
||||||
type IResData<T> = {
|
export type IResData<T> = {
|
||||||
errorCode: number
|
errorCode: number
|
||||||
errorMsg: string
|
errorMsg: string
|
||||||
data: T
|
data: T
|
||||||
@ -39,3 +39,20 @@ type HomeTab = {
|
|||||||
title: string
|
title: string
|
||||||
list: HomeTabItem[]
|
list: HomeTabItem[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum AccountChannel {
|
||||||
|
phone = '1',
|
||||||
|
email = '2'
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum CodeType {
|
||||||
|
login = '1',
|
||||||
|
reset = '2',
|
||||||
|
bindPhone = '3',
|
||||||
|
unbindPhone = '4',
|
||||||
|
deleteAccount = '5',
|
||||||
|
bindEmail = '6',
|
||||||
|
unbindEmail = '7',
|
||||||
|
deleteLock = '8',
|
||||||
|
updatePassword = '9'
|
||||||
|
}
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import { CustomRequestOptions } from '@/interceptors/request'
|
import { CustomRequestOptions } from '@/interceptors/request'
|
||||||
|
|
||||||
export const http = <T>(options: CustomRequestOptions) => {
|
export const http = <T>(options: CustomRequestOptions) => {
|
||||||
// 1. 返回 Promise 对象
|
|
||||||
return new Promise<IResData<T>>((resolve, reject) => {
|
return new Promise<IResData<T>>((resolve, reject) => {
|
||||||
|
const timestamp = new Date().getTime()
|
||||||
|
|
||||||
uni.request({
|
uni.request({
|
||||||
...options,
|
...options,
|
||||||
dataType: 'json',
|
dataType: 'json',
|
||||||
@ -22,7 +23,6 @@ export const http = <T>(options: CustomRequestOptions) => {
|
|||||||
resolve(res.data as IResData<T>)
|
resolve(res.data as IResData<T>)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 其他错误 -> 根据后端错误信息轻提示
|
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
title: '网络错误,请重试'
|
title: '网络错误,请重试'
|
||||||
@ -37,6 +37,19 @@ export const http = <T>(options: CustomRequestOptions) => {
|
|||||||
title: '网络错误,请重试'
|
title: '网络错误,请重试'
|
||||||
})
|
})
|
||||||
reject(err)
|
reject(err)
|
||||||
|
},
|
||||||
|
complete(res) {
|
||||||
|
console.log(options.url, {
|
||||||
|
env: import.meta.env.VITE_APP_ENV,
|
||||||
|
statusCode: res?.statusCode,
|
||||||
|
code: res?.data?.errorCode,
|
||||||
|
baseUrl: import.meta.env.VITE_SERVER_BASEURL,
|
||||||
|
url: options.url,
|
||||||
|
req: options.data,
|
||||||
|
res: res?.data?.data,
|
||||||
|
message: res?.data?.errorMsg,
|
||||||
|
duration: new Date().getTime() - timestamp
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -124,28 +124,7 @@ export const needLoginPages: string[] = getAllPages('needLogin').map(page => pag
|
|||||||
*/
|
*/
|
||||||
export const getEnvBaseUrl = () => {
|
export const getEnvBaseUrl = () => {
|
||||||
// 请求基准地址
|
// 请求基准地址
|
||||||
let baseUrl = import.meta.env.VITE_SERVER_BASEURL
|
return import.meta.env.VITE_SERVER_BASEURL
|
||||||
|
|
||||||
// 小程序端环境区分
|
|
||||||
if (isMp) {
|
|
||||||
const {
|
|
||||||
miniProgram: { envVersion }
|
|
||||||
} = uni.getAccountInfoSync()
|
|
||||||
|
|
||||||
switch (envVersion) {
|
|
||||||
case 'develop':
|
|
||||||
baseUrl = 'https://ukw0y1.laf.run'
|
|
||||||
break
|
|
||||||
case 'trial':
|
|
||||||
baseUrl = 'https://ukw0y1.laf.run'
|
|
||||||
break
|
|
||||||
case 'release':
|
|
||||||
baseUrl = 'https://ukw0y1.laf.run'
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return baseUrl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user