设置页面修改昵称和头像,修改后端数据成功
This commit is contained in:
parent
1e9088bf2b
commit
72e7bd790f
|
|
@ -123,6 +123,8 @@ export function updateNickName(nickName) {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
params: { nickName },
|
params: { nickName },
|
||||||
showLoading: true,
|
showLoading: true,
|
||||||
|
// 强制将params作为查询参数发送
|
||||||
|
useQueryParams: true,
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
console.warn('更新昵称API调用失败:', error)
|
console.warn('更新昵称API调用失败:', error)
|
||||||
throw error
|
throw error
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ export const DEV_CONFIG = {
|
||||||
// 临时token,用于开发测试
|
// 临时token,用于开发测试
|
||||||
TEMP_TOKEN:
|
TEMP_TOKEN:
|
||||||
'\n' +
|
'\n' +
|
||||||
'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjIyMzRmNTVlLTQ4NTEtNDQwOS05MjIwLWQ0M2M0NzMwZDgzMiJ9.yWNuS7YH_MTYW5Tf3VjzEHki0z4erEwHkb6CVO7Ix7p_zvbfMyc9XHsP80DRczWEuXlglfMQV8EbYtkTBLj8Rg',
|
'eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjY2M2UzOWVkLTg4N2MtNGUxOS1iZDBiLWFmZTY1ZmI3Mjk2YiJ9.nMIcrWJK3l5itjQH-okwKL2X4Tresr_sKmgMQ66nHsjYGHK9Xyz5YHO2oDeF-sPt1BxHbz4fyBXcSWhr1HwWTQ',
|
||||||
|
|
||||||
// 是否使用临时token
|
// 是否使用临时token
|
||||||
USE_TEMP_TOKEN: true,
|
USE_TEMP_TOKEN: true,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<view class="page">
|
<view class="page">
|
||||||
<view class="info">
|
<view class="info">
|
||||||
<view v-for="(item, index) in userInfoSettings" :key="index" class="info-row" @click="handleItemClick(item)">
|
<view
|
||||||
|
v-for="(item, index) in userInfoSettings"
|
||||||
|
:key="index"
|
||||||
|
class="info-row"
|
||||||
|
@click="handleItemClick(item)"
|
||||||
|
>
|
||||||
<view class="label">{{ item.label }}</view>
|
<view class="label">{{ item.label }}</view>
|
||||||
<view class="value">
|
<view class="value">
|
||||||
<image
|
<image
|
||||||
|
|
@ -94,7 +99,6 @@ export default {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('用户信息加载成功')
|
console.log('用户信息加载成功')
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('加载用户信息时发生错误:', error)
|
console.error('加载用户信息时发生错误:', error)
|
||||||
this.setDefaultValues()
|
this.setDefaultValues()
|
||||||
|
|
@ -126,7 +130,7 @@ export default {
|
||||||
// 头像修改逻辑可以在这里添加
|
// 头像修改逻辑可以在这里添加
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '头像修改功能开发中',
|
title: '头像修改功能开发中',
|
||||||
icon: 'none'
|
icon: 'none',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -137,12 +141,12 @@ export default {
|
||||||
|
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '修改昵称',
|
title: '修改昵称',
|
||||||
content: '请输入新的昵称',
|
content: '',
|
||||||
editable: true,
|
editable: true,
|
||||||
placeholderText: '请输入昵称',
|
placeholderText: '请输入昵称',
|
||||||
confirmText: '确定',
|
confirmText: '确定',
|
||||||
cancelText: '取消',
|
cancelText: '取消',
|
||||||
success: async (res) => {
|
success: async res => {
|
||||||
if (res.confirm && res.content) {
|
if (res.confirm && res.content) {
|
||||||
const newNickname = res.content.trim()
|
const newNickname = res.content.trim()
|
||||||
if (newNickname) {
|
if (newNickname) {
|
||||||
|
|
@ -150,11 +154,11 @@ export default {
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '昵称不能为空',
|
title: '昵称不能为空',
|
||||||
icon: 'none'
|
icon: 'none',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -162,7 +166,7 @@ export default {
|
||||||
async updateNickname(newNickname) {
|
async updateNickname(newNickname) {
|
||||||
try {
|
try {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '更新中...'
|
title: '更新中...',
|
||||||
})
|
})
|
||||||
|
|
||||||
const response = await updateNickName(newNickname)
|
const response = await updateNickName(newNickname)
|
||||||
|
|
@ -187,7 +191,7 @@ export default {
|
||||||
|
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '昵称更新成功',
|
title: '昵称更新成功',
|
||||||
icon: 'success'
|
icon: 'success',
|
||||||
})
|
})
|
||||||
|
|
||||||
// 通知个人中心页面更新用户信息
|
// 通知个人中心页面更新用户信息
|
||||||
|
|
@ -195,13 +199,13 @@ export default {
|
||||||
const userInfo = uni.getStorageSync('userInfo') || {}
|
const userInfo = uni.getStorageSync('userInfo') || {}
|
||||||
uni.$emit('userInfoUpdated', {
|
uni.$emit('userInfoUpdated', {
|
||||||
nickName: newNickname,
|
nickName: newNickname,
|
||||||
avatar: userInfo.avatar || ''
|
avatar: userInfo.avatar || '',
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取用户信息失败:', error)
|
console.error('获取用户信息失败:', error)
|
||||||
uni.$emit('userInfoUpdated', {
|
uni.$emit('userInfoUpdated', {
|
||||||
nickName: newNickname,
|
nickName: newNickname,
|
||||||
avatar: ''
|
avatar: '',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -212,7 +216,7 @@ export default {
|
||||||
console.error('更新昵称失败:', error)
|
console.error('更新昵称失败:', error)
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: error.message || '更新失败',
|
title: error.message || '更新失败',
|
||||||
icon: 'none'
|
icon: 'none',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -228,7 +232,7 @@ export default {
|
||||||
confirmText: '确定',
|
confirmText: '确定',
|
||||||
cancelText: '取消',
|
cancelText: '取消',
|
||||||
success: resolve,
|
success: resolve,
|
||||||
fail: reject
|
fail: reject,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -250,13 +254,13 @@ export default {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: '退出成功',
|
title: '退出成功',
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
duration: 1500
|
duration: 1500,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 延迟跳转到登录页
|
// 延迟跳转到登录页
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/pages/login/login'
|
url: '/pages/login/login',
|
||||||
})
|
})
|
||||||
}, 1500)
|
}, 1500)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -267,10 +271,10 @@ export default {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: error.message || '退出失败',
|
title: error.message || '退出失败',
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
duration: 2000
|
duration: 2000,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -246,7 +246,16 @@ export function request(options = {}) {
|
||||||
|
|
||||||
// 处理请求参数
|
// 处理请求参数
|
||||||
if (options.params && Object.keys(options.params).length > 0) {
|
if (options.params && Object.keys(options.params).length > 0) {
|
||||||
|
// 对于GET请求或明确指定使用查询参数的请求,params作为查询参数
|
||||||
|
if (requestOptions.method === 'GET' || options.useQueryParams) {
|
||||||
|
const queryString = Object.keys(options.params)
|
||||||
|
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(options.params[key])}`)
|
||||||
|
.join('&')
|
||||||
|
requestOptions.url += (requestOptions.url.includes('?') ? '&' : '?') + queryString
|
||||||
|
} else {
|
||||||
|
// 对于其他请求方法,params作为请求体数据
|
||||||
requestOptions.data = { ...options.params }
|
requestOptions.data = { ...options.params }
|
||||||
|
}
|
||||||
} else if (options.data && Object.keys(options.data).length > 0) {
|
} else if (options.data && Object.keys(options.data).length > 0) {
|
||||||
requestOptions.data = { ...options.data }
|
requestOptions.data = { ...options.data }
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -277,6 +286,8 @@ export function request(options = {}) {
|
||||||
data: requestOptions.data,
|
data: requestOptions.data,
|
||||||
timeout: requestOptions.timeout,
|
timeout: requestOptions.timeout,
|
||||||
baseUrl: BASE_URL,
|
baseUrl: BASE_URL,
|
||||||
|
useQueryParams: options.useQueryParams,
|
||||||
|
hasParams: !!(options.params && Object.keys(options.params).length > 0),
|
||||||
})
|
})
|
||||||
|
|
||||||
// 显示loading(默认显示,但减少延迟)
|
// 显示loading(默认显示,但减少延迟)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user