修改用户信息保存是否完善
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
export default defineAppConfig({
|
export default defineAppConfig({
|
||||||
pages: [
|
pages: [
|
||||||
|
|
||||||
|
'pages/home/index', //中转页
|
||||||
|
|
||||||
'pages/login/index/index',
|
'pages/login/index/index',
|
||||||
'pages/login/verification/index',
|
'pages/login/verification/index',
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ export interface UserInfo {
|
|||||||
phone?: string;
|
phone?: string;
|
||||||
gender?: string;
|
gender?: string;
|
||||||
|
|
||||||
latitude?: number,
|
latitude?: string,
|
||||||
longitude?: number,
|
longitude?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
7
src/pages/home/index.config.ts
Normal file
7
src/pages/home/index.config.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export default definePageConfig({
|
||||||
|
navigationBarTitleText: '请等待',
|
||||||
|
enablePullDownRefresh: true,
|
||||||
|
backgroundTextStyle: 'dark',
|
||||||
|
navigationStyle: 'custom',
|
||||||
|
})
|
||||||
|
|
||||||
21
src/pages/home/index.tsx
Normal file
21
src/pages/home/index.tsx
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { View, } from '@tarojs/components';
|
||||||
|
import { check_login_status } from '../../services/loginService';
|
||||||
|
import Taro from '@tarojs/taro';
|
||||||
|
const HomePage: React.FC = () => {
|
||||||
|
let login_status = check_login_status()
|
||||||
|
if (login_status) {
|
||||||
|
Taro.redirectTo({ url: '/pages/list/index' })
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Taro.redirectTo({ url: '/pages/login/index/index' })
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View className="home_page">
|
||||||
|
|
||||||
|
</View>)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default HomePage;
|
||||||
@@ -134,7 +134,7 @@ const VerificationPage: React.FC = () => {
|
|||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
save_login_state(result.token!, result.user_info!)
|
save_login_state(result.token!, result.user_info!)
|
||||||
debugger
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
Taro.redirectTo({
|
Taro.redirectTo({
|
||||||
url: '/pages/list/index'
|
url: '/pages/list/index'
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import Taro from '@tarojs/taro';
|
|||||||
import './index.scss';
|
import './index.scss';
|
||||||
import { UserInfo } from '@/components/UserInfo';
|
import { UserInfo } from '@/components/UserInfo';
|
||||||
import { UserService } from '@/services/userService';
|
import { UserService } from '@/services/userService';
|
||||||
|
import {clear_login_state} from '@/services/loginService';
|
||||||
import { EditModal } from '@/components';
|
import { EditModal } from '@/components';
|
||||||
|
|
||||||
const EditProfilePage: React.FC = () => {
|
const EditProfilePage: React.FC = () => {
|
||||||
@@ -210,8 +211,8 @@ const EditProfilePage: React.FC = () => {
|
|||||||
success: (res) => {
|
success: (res) => {
|
||||||
if (res.confirm) {
|
if (res.confirm) {
|
||||||
// 清除用户数据
|
// 清除用户数据
|
||||||
Taro.removeStorageSync('user_token');
|
clear_login_state();
|
||||||
Taro.removeStorageSync('user_info');
|
|
||||||
Taro.reLaunch({
|
Taro.reLaunch({
|
||||||
url: '/pages/login/index/index'
|
url: '/pages/login/index/index'
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import tokenManager from '../utils/tokenManager';
|
|||||||
|
|
||||||
// 微信用户信息接口
|
// 微信用户信息接口
|
||||||
export interface WechatUserInfo {
|
export interface WechatUserInfo {
|
||||||
user_id: string;
|
id: string;
|
||||||
username: string;
|
nickname: string;
|
||||||
avatar: string;
|
avatar: string;
|
||||||
gender: number;
|
gender: number;
|
||||||
city: string;
|
city: string;
|
||||||
@@ -79,8 +79,8 @@ export const wechat_auth_login = async (phone_code?: string): Promise<LoginRespo
|
|||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: '微信登录成功',
|
message: '微信登录成功',
|
||||||
token: auth_response.data?.token || 'wx_token_' + Date.now(),
|
token: auth_response.data?.token || '',
|
||||||
user_info: auth_response.data?.user_info
|
user_info: auth_response.data?.userInfo
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
@@ -113,13 +113,14 @@ export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginR
|
|||||||
code: params.verification_code,
|
code: params.verification_code,
|
||||||
user_code: params.user_code
|
user_code: params.user_code
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (verify_response.code === 0) {
|
if (verify_response.code === 0) {
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: '登录成功',
|
message: '登录成功',
|
||||||
token: verify_response.data?.token,
|
token: verify_response.data?.token,
|
||||||
user_info: verify_response.data?.user_info
|
user_info: verify_response.data?.userInfo
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
@@ -176,7 +177,7 @@ export const verify_sms_code = async (phone: string, code: string): Promise<Veri
|
|||||||
success: response.success,
|
success: response.success,
|
||||||
message: response.message || '验证失败',
|
message: response.message || '验证失败',
|
||||||
token: response.data?.token,
|
token: response.data?.token,
|
||||||
user_info: response.data?.user_info
|
user_info: response.data?.userInfo
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('验证验证码失败:', error);
|
console.error('验证验证码失败:', error);
|
||||||
@@ -187,28 +188,6 @@ export const verify_sms_code = async (phone: string, code: string): Promise<Veri
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 获取用户信息
|
|
||||||
export const get_user_profile = (): Promise<WechatUserInfo> => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
Taro.getUserProfile({
|
|
||||||
desc: '用于完善用户资料',
|
|
||||||
success: (res) => {
|
|
||||||
const profile = res.userInfo;
|
|
||||||
const user_data: WechatUserInfo = {
|
|
||||||
user_id: 'wx_' + Date.now(),
|
|
||||||
username: profile.nickName || '微信用户',
|
|
||||||
avatar: profile.avatarUrl || '',
|
|
||||||
gender: profile.gender || 0,
|
|
||||||
city: profile.city || '',
|
|
||||||
province: profile.province || '',
|
|
||||||
country: profile.country || ''
|
|
||||||
};
|
|
||||||
resolve(user_data);
|
|
||||||
},
|
|
||||||
fail: reject
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// 保存用户登录状态
|
// 保存用户登录状态
|
||||||
export const save_login_state = (token: string, user_info: WechatUserInfo) => {
|
export const save_login_state = (token: string, user_info: WechatUserInfo) => {
|
||||||
@@ -220,8 +199,9 @@ export const save_login_state = (token: string, user_info: WechatUserInfo) => {
|
|||||||
expiresAt: expires_at
|
expiresAt: expires_at
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// 保存用户信息
|
// 保存用户信息
|
||||||
Taro.setStorageSync('user_info', user_info);
|
Taro.setStorageSync('user_info', JSON.stringify(user_info));
|
||||||
Taro.setStorageSync('is_logged_in', true);
|
Taro.setStorageSync('is_logged_in', true);
|
||||||
Taro.setStorageSync('login_time', Date.now());
|
Taro.setStorageSync('login_time', Date.now());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -248,6 +228,8 @@ export const clear_login_state = () => {
|
|||||||
export const check_login_status = (): boolean => {
|
export const check_login_status = (): boolean => {
|
||||||
try {
|
try {
|
||||||
// 使用 tokenManager 检查令牌有效性
|
// 使用 tokenManager 检查令牌有效性
|
||||||
|
|
||||||
|
|
||||||
if (!tokenManager.hasValidToken()) {
|
if (!tokenManager.hasValidToken()) {
|
||||||
clear_login_state();
|
clear_login_state();
|
||||||
return false;
|
return false;
|
||||||
@@ -297,7 +279,11 @@ export const get_token_status = () => {
|
|||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
export const get_user_info = (): WechatUserInfo | null => {
|
export const get_user_info = (): WechatUserInfo | null => {
|
||||||
try {
|
try {
|
||||||
return Taro.getStorageSync('user_info') || null;
|
let userinfo = Taro.getStorageSync('user_info')
|
||||||
|
if (userinfo) {
|
||||||
|
return JSON.parse(userinfo)
|
||||||
|
}
|
||||||
|
return null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ interface UserDetailData {
|
|||||||
language: string;
|
language: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
is_subscribed: string;
|
is_subscribed: string;
|
||||||
latitude: number;
|
latitude: string;
|
||||||
longitude: number;
|
longitude: string;
|
||||||
subscribe_time: string;
|
subscribe_time: string;
|
||||||
last_login_time: string;
|
last_login_time: string;
|
||||||
create_time: string;
|
create_time: string;
|
||||||
@@ -40,11 +40,12 @@ interface UpdateUserParams {
|
|||||||
avatar_url: string;
|
avatar_url: string;
|
||||||
gender: string;
|
gender: string;
|
||||||
phone: string;
|
phone: string;
|
||||||
latitude?: number;
|
latitude?: string;
|
||||||
longitude?: number;
|
longitude?: string;
|
||||||
city: string;
|
city: string;
|
||||||
province: string;
|
province: string;
|
||||||
country: string;
|
country: string;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 上传响应接口
|
// 上传响应接口
|
||||||
@@ -105,8 +106,8 @@ interface BackendGameData {
|
|||||||
end_time: string;
|
end_time: string;
|
||||||
location_name: string | null;
|
location_name: string | null;
|
||||||
location: string;
|
location: string;
|
||||||
latitude?: number;
|
latitude?: string;
|
||||||
longitude?: number;
|
longitude?: string;
|
||||||
image_list?: string[];
|
image_list?: string[];
|
||||||
description_tag?: string[];
|
description_tag?: string[];
|
||||||
venue_description_tag?: string[];
|
venue_description_tag?: string[];
|
||||||
|
|||||||
Reference in New Issue
Block a user