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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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