存储用户id
This commit is contained in:
parent
63c22f9811
commit
bd7f74c346
|
|
@ -11,10 +11,23 @@ export function getUserInfo() {
|
||||||
url: '/app/user/getUser',
|
url: '/app/user/getUser',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
showLoading: false,
|
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 => {
|
}).catch(error => {
|
||||||
console.warn('用户信息API调用失败,使用模拟数据:', error)
|
console.warn('用户信息API调用失败,使用模拟数据:', error)
|
||||||
// 如果API调用失败,返回模拟数据
|
// 如果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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,3 +217,19 @@ export function uploadAvatar(filePath) {
|
||||||
throw 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="main-content">
|
||||||
<view class="qrcode-container">
|
<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>
|
</view>
|
||||||
|
|
||||||
<!-- 按钮区域 -->
|
<!-- 按钮区域 -->
|
||||||
|
|
@ -36,7 +36,6 @@ export default {
|
||||||
components: { UvQrcode },
|
components: { UvQrcode },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
inviteCode: '1114514',
|
|
||||||
qrcodeValue: '123456',
|
qrcodeValue: '123456',
|
||||||
qrcodeOptions: {
|
qrcodeOptions: {
|
||||||
errorCorrectLevel: 'Q',
|
errorCorrectLevel: 'Q',
|
||||||
|
|
@ -114,7 +113,7 @@ export default {
|
||||||
background: white;
|
background: white;
|
||||||
border-radius: 20rpx;
|
border-radius: 20rpx;
|
||||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
|
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
|
||||||
margin-bottom: 60rpx;
|
margin-bottom: 200rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button-container {
|
.button-container {
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user