修改用户信息保存是否完善
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
export default defineAppConfig({
|
||||
pages: [
|
||||
|
||||
'pages/home/index', //中转页
|
||||
|
||||
'pages/login/index/index',
|
||||
'pages/login/verification/index',
|
||||
'pages/login/terms/index',
|
||||
|
||||
@@ -22,8 +22,8 @@ export interface UserInfo {
|
||||
phone?: string;
|
||||
gender?: string;
|
||||
|
||||
latitude?: number,
|
||||
longitude?: number,
|
||||
latitude?: string,
|
||||
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) {
|
||||
save_login_state(result.token!, result.user_info!)
|
||||
debugger
|
||||
|
||||
setTimeout(() => {
|
||||
Taro.redirectTo({
|
||||
url: '/pages/list/index'
|
||||
|
||||
@@ -4,6 +4,7 @@ import Taro from '@tarojs/taro';
|
||||
import './index.scss';
|
||||
import { UserInfo } from '@/components/UserInfo';
|
||||
import { UserService } from '@/services/userService';
|
||||
import {clear_login_state} from '@/services/loginService';
|
||||
import { EditModal } from '@/components';
|
||||
|
||||
const EditProfilePage: React.FC = () => {
|
||||
@@ -210,8 +211,8 @@ const EditProfilePage: React.FC = () => {
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
// 清除用户数据
|
||||
Taro.removeStorageSync('user_token');
|
||||
Taro.removeStorageSync('user_info');
|
||||
clear_login_state();
|
||||
|
||||
Taro.reLaunch({
|
||||
url: '/pages/login/index/index'
|
||||
});
|
||||
|
||||
@@ -4,8 +4,8 @@ import tokenManager from '../utils/tokenManager';
|
||||
|
||||
// 微信用户信息接口
|
||||
export interface WechatUserInfo {
|
||||
user_id: string;
|
||||
username: string;
|
||||
id: string;
|
||||
nickname: string;
|
||||
avatar: string;
|
||||
gender: number;
|
||||
city: string;
|
||||
@@ -79,8 +79,8 @@ export const wechat_auth_login = async (phone_code?: string): Promise<LoginRespo
|
||||
return {
|
||||
success: true,
|
||||
message: '微信登录成功',
|
||||
token: auth_response.data?.token || 'wx_token_' + Date.now(),
|
||||
user_info: auth_response.data?.user_info
|
||||
token: auth_response.data?.token || '',
|
||||
user_info: auth_response.data?.userInfo
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
@@ -114,12 +114,13 @@ export const phone_auth_login = async (params: PhoneLoginParams): Promise<LoginR
|
||||
user_code: params.user_code
|
||||
});
|
||||
|
||||
|
||||
if (verify_response.code === 0) {
|
||||
return {
|
||||
success: true,
|
||||
message: '登录成功',
|
||||
token: verify_response.data?.token,
|
||||
user_info: verify_response.data?.user_info
|
||||
user_info: verify_response.data?.userInfo
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
@@ -176,7 +177,7 @@ export const verify_sms_code = async (phone: string, code: string): Promise<Veri
|
||||
success: response.success,
|
||||
message: response.message || '验证失败',
|
||||
token: response.data?.token,
|
||||
user_info: response.data?.user_info
|
||||
user_info: response.data?.userInfo
|
||||
};
|
||||
} catch (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) => {
|
||||
@@ -220,8 +199,9 @@ export const save_login_state = (token: string, user_info: WechatUserInfo) => {
|
||||
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('login_time', Date.now());
|
||||
} catch (error) {
|
||||
@@ -248,6 +228,8 @@ export const clear_login_state = () => {
|
||||
export const check_login_status = (): boolean => {
|
||||
try {
|
||||
// 使用 tokenManager 检查令牌有效性
|
||||
|
||||
|
||||
if (!tokenManager.hasValidToken()) {
|
||||
clear_login_state();
|
||||
return false;
|
||||
@@ -297,7 +279,11 @@ export const get_token_status = () => {
|
||||
// 获取用户信息
|
||||
export const get_user_info = (): WechatUserInfo | null => {
|
||||
try {
|
||||
return Taro.getStorageSync('user_info') || null;
|
||||
let userinfo = Taro.getStorageSync('user_info')
|
||||
if (userinfo) {
|
||||
return JSON.parse(userinfo)
|
||||
}
|
||||
return null;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -20,8 +20,8 @@ interface UserDetailData {
|
||||
language: string;
|
||||
phone: string;
|
||||
is_subscribed: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
latitude: string;
|
||||
longitude: string;
|
||||
subscribe_time: string;
|
||||
last_login_time: string;
|
||||
create_time: string;
|
||||
@@ -40,11 +40,12 @@ interface UpdateUserParams {
|
||||
avatar_url: string;
|
||||
gender: string;
|
||||
phone: string;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
latitude?: string;
|
||||
longitude?: string;
|
||||
city: string;
|
||||
province: string;
|
||||
country: string;
|
||||
|
||||
}
|
||||
|
||||
// 上传响应接口
|
||||
@@ -105,8 +106,8 @@ interface BackendGameData {
|
||||
end_time: string;
|
||||
location_name: string | null;
|
||||
location: string;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
latitude?: string;
|
||||
longitude?: string;
|
||||
image_list?: string[];
|
||||
description_tag?: string[];
|
||||
venue_description_tag?: string[];
|
||||
|
||||
Reference in New Issue
Block a user