存储用户id
This commit is contained in:
parent
63c22f9811
commit
bd7f74c346
|
|
@ -11,10 +11,23 @@ export function getUserInfo() {
|
|||
url: '/app/user/getUser',
|
||||
method: 'GET',
|
||||
showLoading: false,
|
||||
}).then(response => {
|
||||
// 如果API调用成功,将用户ID存入本地存储
|
||||
if (response.code === 200 && response.data && response.data.userId) {
|
||||
uni.setStorageSync('userId', response.data.userId)
|
||||
console.log('用户ID已存入本地存储:', response.data.userId)
|
||||
}
|
||||
return response
|
||||
}).catch(error => {
|
||||
console.warn('用户信息API调用失败,使用模拟数据:', error)
|
||||
// 如果API调用失败,返回模拟数据
|
||||
return createMockResponse(mockUserInfo)
|
||||
const mockResponse = createMockResponse(mockUserInfo)
|
||||
// 模拟数据中如果有用户ID,也存入本地存储
|
||||
if (mockResponse.data && mockResponse.data.userId) {
|
||||
uni.setStorageSync('userId', mockResponse.data.userId)
|
||||
console.log('模拟数据用户ID已存入本地存储:', mockResponse.data.userId)
|
||||
}
|
||||
return mockResponse
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -203,4 +216,20 @@ export function uploadAvatar(filePath) {
|
|||
console.error('头像上传失败:', error)
|
||||
throw error
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地存储的用户ID
|
||||
* @returns {string|null} 返回用户ID,如果不存在则返回null
|
||||
*/
|
||||
export function getLocalUserId() {
|
||||
return uni.getStorageSync('userId') || null
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除本地存储的用户ID
|
||||
*/
|
||||
export function clearLocalUserId() {
|
||||
uni.removeStorageSync('userId')
|
||||
console.log('本地用户ID已清除')
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
<!-- 主要内容区域 -->
|
||||
<view class="main-content">
|
||||
<view class="qrcode-container">
|
||||
<uv-qrcode :options="qrcodeOptions" :value="qrcodeValue" size="300rpx"></uv-qrcode>
|
||||
<uv-qrcode :options="qrcodeOptions" :value="qrcodeValue" size="500rpx"></uv-qrcode>
|
||||
</view>
|
||||
|
||||
<!-- 按钮区域 -->
|
||||
|
|
@ -36,7 +36,6 @@ export default {
|
|||
components: { UvQrcode },
|
||||
data() {
|
||||
return {
|
||||
inviteCode: '1114514',
|
||||
qrcodeValue: '123456',
|
||||
qrcodeOptions: {
|
||||
errorCorrectLevel: 'Q',
|
||||
|
|
@ -114,7 +113,7 @@ export default {
|
|||
background: white;
|
||||
border-radius: 20rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||
margin-bottom: 60rpx;
|
||||
margin-bottom: 200rpx;
|
||||
}
|
||||
|
||||
.button-container {
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -1 +0,0 @@
|
|||
|
||||
Loading…
Reference in New Issue
Block a user