fix: 完善登录相关逻辑

This commit is contained in:
fanpeng 2025-06-10 14:23:50 +08:00
parent 3c4d229d23
commit 592a3ec7f5
7 changed files with 55 additions and 43 deletions

View File

@ -4,12 +4,6 @@ export const myRequest = async (option = {}) => {
const envConfig = getApp().globalData.getEnvConfig()
const baseConfig = env[envConfig]
console.log('=== 请求入参 ===')
console.log('URL:', baseConfig.baseUrl + option.url)
console.log('Data:', JSON.stringify(option.data || {}, null, 2))
console.log('Method:', option.method || 'GET')
console.log('================')
return new Promise((resolve, reject) => {
uni.request({
url: baseConfig.baseUrl + option.url,
@ -21,10 +15,14 @@ export const myRequest = async (option = {}) => {
...option.header
},
success: result => {
console.log('=== 请求出参 ===')
console.log('StatusCode:', result.statusCode)
console.log('Response:', JSON.stringify(result.data, null, 2))
console.log('================')
console.log({
url: baseConfig.baseUrl + option.url,
request: option.data,
response: result.data,
statusCode: result.statusCode,
method: option.method,
header: option.header
})
if (result.statusCode === 200) {
resolve(result)

View File

@ -323,31 +323,14 @@
xWidth: Math.round(moveLeftDistance)
}
console.log('=== 滑动验证请求参数 ===')
console.log('params:', JSON.stringify(_this.params, null, 2))
console.log('moveLeftDistance:', moveLeftDistance)
console.log('captchaVerification:', captchaVerification)
console.log('token:', _this.backToken)
console.log('data:', JSON.stringify(data, null, 2))
console.log('=====================')
myRequest({
url: `/user/sendValidationCode`,
data,
method: 'POST'
})
.then(result => {
console.log('=== 滑动验证响应数据 ===')
console.log('result:', JSON.stringify(result, null, 2))
console.log('=====================')
if (result && result.data) {
let res = result.data
console.log('=== 验证结果详情 ===')
console.log('errorCode:', res.errorCode)
console.log('errorMsg:', res.errorMsg)
console.log('res.data:', JSON.stringify(res.data, null, 2))
console.log('==================')
if (res.errorCode === 0) {
this.moveBlockBackgroundColor = '#5cb85c'
@ -377,9 +360,8 @@
}
})
.catch(error => {
console.log('=== 滑动验证请求错误 ===')
console.log('error:', error)
console.log('=====================')
this.handleValidationError('网络错误,请重试')
})
}
@ -455,11 +437,6 @@
captchaType: this.captchaType || 'blockPuzzle'
}
console.log('=== getPictrue 请求参数 ===')
console.log('params:', JSON.stringify(this.params, null, 2))
console.log('data:', JSON.stringify(data, null, 2))
console.log('========================')
myRequest({
url: '/user/getSliderVerifyImg',
data,
@ -469,9 +446,6 @@
this.loading = false
if (result && result.data) {
let res = result.data
console.log('=== getPictrue 响应数据 ===')
console.log('res:', JSON.stringify(res, null, 2))
console.log('========================')
if (res.errorCode === 0 && res.data) {
this.backImgBase = res.data.bigImg

View File

@ -172,10 +172,10 @@
return result
}
const weChatTickets = async (snTicket, sn) => {
let ticket = snTicket
let snResult = sn
if (!snTicket) {
const weChatTickets = async () => {
let ticket = null
let snResult = null
if (!ticket) {
const result = await getInfo()
ticket = result.data.WXIoTDeviceInfo.SNTicket
snResult = result.data.WXIoTDeviceInfo.SN

View File

@ -131,6 +131,8 @@
const seconds = ref(120)
const uCodeRef = ref(null)
const pending = ref(false)
const codeChange = text => {
tips.value = text
}
@ -142,7 +144,8 @@
const params = {
account: username.value,
codeType: 2,
countryCode: country.value.code
countryCode: country.value.code,
channel: EMAIL_REG.test(username.value) ? 2 : 1
}
$basic.routeJump({
name: 'safeVerify',
@ -202,14 +205,28 @@
if (!canResetPassword.value) {
return
}
if (pending.value) {
return
}
pending.value = true
uni.showLoading({
title: '重置中'
})
const res = await resetPasswordRequest({
account: username.value,
newPassword: password.value,
countryCode: country.value.code,
verificationCode: code.value
})
if (res) {
pending.value = false
uni.hideLoading()
if (res.code === 0) {
$basic.backAndToast('密码重置成功')
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
}

View File

@ -99,6 +99,8 @@
const select = ref(false)
const pending = ref(false)
const isValidUsername = computed(() => {
if (!username.value) return false
return PHONE_REG.test(username.value) || EMAIL_REG.test(username.value)
@ -155,11 +157,16 @@
})
return
}
if (pending.value) {
return
}
pending.value = true
const res = await $user.passwordLogin({
username: username.value,
password: password.value,
countryCode: country.value.code
})
pending.value = false
if (res) {
$basic.routeJump({
name: 'home',

View File

@ -170,6 +170,8 @@
const uCodeRef = ref(null)
const select = ref(false)
const pending = ref(false)
onMounted(async () => {
const res = await $basic.getDeviceInfo()
if (res.language !== 'zh-CN') {
@ -263,6 +265,11 @@
})
return
}
if (pending.value) {
return
}
pending.value = true
const res = await $user.register({
account: username.value,
password: password.value,
@ -270,6 +277,7 @@
countryCode: country.value.code,
verificationCode: code.value
})
pending.value = false
if (res) {
$basic.routeJump({
name: 'home',

View File

@ -43,6 +43,9 @@ export const useUserStore = defineStore('user', {
return code
},
async register(params) {
uni.showLoading({
title: '注册中'
})
const { account, password, receiverType, countryCode, verificationCode } = params
const $basic = useBasicStore()
const deviceInfo = await $basic.getDeviceInfo()
@ -62,6 +65,7 @@ export const useUserStore = defineStore('user', {
platId: 2,
deviceInfo: info
})
uni.hideLoading()
if (code === 0) {
setStorage('token', data.accessToken)
return true
@ -73,6 +77,9 @@ export const useUserStore = defineStore('user', {
return false
},
async passwordLogin(params) {
uni.showLoading({
title: '登录中'
})
const { username, password, countryCode } = params
const $basic = useBasicStore()
const deviceInfo = await $basic.getDeviceInfo()
@ -91,6 +98,7 @@ export const useUserStore = defineStore('user', {
platId: 2,
deviceInfo: info
})
uni.hideLoading()
if (code === 0) {
setStorage('token', data.accessToken)
return true