Merge branch 'light_v2'

This commit is contained in:
张成
2025-09-10 21:48:25 +08:00
12 changed files with 194 additions and 105 deletions

View File

@@ -3,7 +3,6 @@ import './nutui-theme.scss'
import './app.scss'
import { useDictionaryStore } from './store/dictionaryStore'
import { useGlobalStore } from './store/global'
import { check_login_status } from './services/loginService';
// import { getNavbarHeight } from "@/utils/getNavbarHeight";

View File

@@ -1,7 +1,8 @@
import React, { useEffect, useState } from "react";
import Taro from "@tarojs/taro";
import { View } from "@tarojs/components";
import { check_login_status } from "@/services/loginService";
import React, { useEffect, useState } from 'react'
import Taro from '@tarojs/taro'
import { check_login_status } from '@/services/loginService'
export function getCurrentFullPath(): string {
const pages = Taro.getCurrentPages();

View File

@@ -17,15 +17,14 @@ const envConfigs: Record<EnvType, EnvConfig> = {
// 开发环境
development: {
name: '开发环境',
apiBaseURL: 'https://sit.light120.com',
// apiBaseURL: 'http://localhost:9098',
//apiBaseURL: 'https://sit.light120.com',
apiBaseURL: 'http://localhost:9098',
timeout: 15000,
enableLog: true,
enableMock: true
},
// 生产环境
production: {
name: '生产环境',

View File

@@ -1,6 +1,8 @@
import { View, Text, Image } from "@tarojs/components";
import img from "@/config/images";
import { useGlobalState } from "@/store/global";
import { useUserInfo, } from '@/store/userStore'
import { useListState } from "@/store/listStore";
import CustomNavbar from "@/components/CustomNavbar";
import { Input } from "@nutui/nutui-react-taro";
@@ -32,9 +34,11 @@ const ListHeader = (props: IProps) => {
const { gamesNum, searchValue, isShowInputCustomerNavBar } = useListState();
const { statusBarHeight, navbarHeight } = statusNavbarHeightInfo;
const currentAddress = getLocationLoading
? getLocationText
: location?.address;
const { city,district } = useUserInfo()
console.log("useUserInfo",city,district )
const currentAddress = city + district
const handleInputClick = () => {
const pages = Taro.getCurrentPages();
@@ -69,9 +73,8 @@ const ListHeader = (props: IProps) => {
<View className="listNavWrapper">
{/* 首页logo 导航*/}
<View
className={`listNavContainer toggleElement firstElement hidden ${
(!isShowInputCustomerNavBar && !showInput) && "visible"
}`}
className={`listNavContainer toggleElement firstElement hidden ${(!isShowInputCustomerNavBar && !showInput) && "visible"
}`}
style={{
height: `${navbarHeight}px`,
paddingTop: `${statusBarHeight}px`,
@@ -94,16 +97,15 @@ const ListHeader = (props: IProps) => {
)}
</View>
<View className="listNavInfoWrapper">
<Text className="listNavInfo">${gamesNum}</Text>
<Text className="listNavInfo">{gamesNum}</Text>
</View>
</View>
</View>
</View>
{/* 搜索导航 */}
<View
className={`inputCustomerNavbarContainer toggleElement secondElement hidden ${
(isShowInputCustomerNavBar || showInput) && "visible"
} ${showInput && "inputCustomerNavbarShowInput"}`}
className={`inputCustomerNavbarContainer toggleElement secondElement hidden ${(isShowInputCustomerNavBar || showInput) && "visible"
} ${showInput && "inputCustomerNavbarShowInput"}`}
style={{
height: `${navbarHeight}px`,
paddingTop: `${statusBarHeight}px`,

View File

@@ -871,12 +871,14 @@ function Index() {
const updateLocation = async () => {
try {
const location = await getCurrentLocation();
setCurrentLocation([location.latitude, location.longitude]);
await updateUserInfo({
latitude: location.latitude,
longitude: location.longitude,
});
const location = await getCurrentLocation()
setCurrentLocation([location.latitude, location.longitude])
// 使用 userStore 中的统一位置更新方法
await updateUserInfo({ latitude: location.latitude, longitude: location.longitude })
// 位置更新后,重新获取详情页数据(因为距离等信息可能发生变化)
await fetchDetail()
} catch (error) {
console.error("用户位置更新失败", error);
}

View File

@@ -1,21 +1,40 @@
import React from 'react';
import React, { useEffect } from 'react';
import { View, } from '@tarojs/components';
import { check_login_status } from '../../services/loginService';
import { useUserActions } from '@/store/userStore';
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' })
}
const { fetchUserInfo } = useUserActions();
useEffect(() => {
const handleLoginRedirect = async () => {
const login_status = check_login_status();
if (login_status) {
try {
// 先获取用户信息
await fetchUserInfo();
// 用户信息获取成功后跳转到列表页
Taro.redirectTo({ url: '/pages/list/index' });
} catch (error) {
console.error('获取用户信息失败:', error);
// 如果获取用户信息失败,跳转到登录页
Taro.redirectTo({ url: '/pages/login/index/index' });
}
} else {
Taro.redirectTo({ url: '/pages/login/index/index' });
}
};
handleLoginRedirect();
}, [fetchUserInfo]);
return (
<View className="home_page">
</View>)
<View>...</View>
</View>
);
}
export default HomePage;

View File

@@ -11,6 +11,7 @@ import GuideBar from "@/components/GuideBar";
import ListContainer from "@/container/listContainer";
import DistanceQuickFilter from "@/components/DistanceQuickFilter";
import { withAuth } from "@/components";
import { updateUserLocation } from "@/services/userService";
// import img from "@/config/images";
// import ShareCardCanvas from "@/components/ShareCardCanvas/example";
@@ -62,11 +63,33 @@ const ListPage = () => {
getLocation()
}, []);
// 监听距离和排序方式变化,自动调用接口
useEffect(() => {
// 只有当 distanceQuickFilter 有值时才调用接口
if (distanceQuickFilter?.distance !== undefined || distanceQuickFilter?.quick !== undefined) {
if (distanceQuickFilter?.quick !== "0") {
getMatchesData();
}
}
}, [distanceQuickFilter?.distance, distanceQuickFilter?.quick]);
// 获取位置信息
const getLocation = async () => {
const location = await getCurrentLocationInfo()
// 保存位置
// 保存位置到全局状态
updateState({ location });
// 同时更新用户位置到后端和 store
if (location && location.latitude && location.longitude) {
try {
await updateUserLocation(location.latitude, location.longitude);
} catch (error) {
console.error('更新用户位置失败:', error);
}
}
// 页面加载时获取数据
getMatchesData();
return location;

View File

@@ -1,6 +1,7 @@
import Taro from "@tarojs/taro";
import httpService, { ApiResponse } from "./httpService";
import tokenManager from "../utils/tokenManager";
import tokenManager from '../utils/tokenManager';
import { useUser } from '@/store/userStore';
// 微信用户信息接口
export interface WechatUserInfo {
@@ -42,6 +43,13 @@ export interface UserStats {
participated_games_count: number;
}
// 手机号验证码登录接口参数
export interface PhoneLoginParams {
phone: string;
verification_code: string;
user_code: string
}
export interface UserInfoType {
subscribe_time: string;
last_login_time: string;
@@ -91,6 +99,13 @@ export const wechat_auth_login = async (
});
if (auth_response.code === 0) {
// 登录成功后,更新用户信息到 store
try {
await useUser.getState().fetchUserInfo();
} catch (error) {
console.error('更新用户信息到 store 失败:', error);
}
return {
success: true,
message: "微信登录成功",
@@ -132,6 +147,13 @@ export const phone_auth_login = async (
});
if (verify_response.code === 0) {
// 登录成功后,更新用户信息到 store
try {
await useUser.getState().fetchUserInfo();
} catch (error) {
console.error('更新用户信息到 store 失败:', error);
}
return {
success: true,
message: "登录成功",

View File

@@ -1,8 +1,8 @@
import { UserInfo } from '@/components/UserInfo';
import Taro from '@tarojs/taro';
import { API_CONFIG } from '@/config/api';
import httpService from './httpService';
import httpService, { ApiResponse } from './httpService';
import uploadFiles from './uploadFiles';
import Taro from '@tarojs/taro';
// 用户详情接口
@@ -35,55 +35,28 @@ interface UserDetailData {
};
}
// 更新用户信息参数接口
interface UpdateUserParams {
nickname: string;
avatar_url: string;
gender: string;
phone: string;
latitude?: string;
longitude?: string;
city: string;
province: string;
country: string;
// 用户详细信息接口(从 loginService 移过来)
export interface UserInfoType {
id: number
openid: string
unionid: string
session_key: string
nickname: string
avatar_url: string
gender: string
country: string
province: string
city: string
district:string
language: string
phone: string
is_subscribed: string
latitude: number
longitude: number
subscribe_time: string
last_login_time: string
}
// 上传响应接口
interface UploadResponseData {
create_time: string;
last_modify_time: string;
duration: string;
thumbnail_url: string;
view_count: string;
download_count: string;
is_delete: number;
id: number;
user_id: number;
resource_type: string;
file_name: string;
original_name: string;
file_path: string;
file_url: string;
file_size: number;
mime_type: string;
description: string;
tags: string;
is_public: string;
width: number;
height: number;
uploadInfo: {
success: boolean;
name: string;
path: string;
ossPath: string;
fileType: string;
fileSize: number;
originalName: string;
suffix: string;
storagePath: string;
};
}
// 后端球局数据接口
interface BackendGameData {
@@ -284,7 +257,7 @@ export class UserService {
}
}
// 更新用户信息
// 更新用户信息(简化版本,具体逻辑在 userStore 中处理)
static async update_user_info(update_data: Partial<UserInfo>): Promise<void> {
try {
// 过滤掉空字段
@@ -490,4 +463,55 @@ export class UserService {
return require('../static/userInfo/default_avatar.svg');
}
}
}
}
// 从 loginService 移过来的用户相关方法
// 获取用户详细信息
export const fetchUserProfile = async (): Promise<ApiResponse<UserInfoType>> => {
try {
const response = await httpService.post('user/detail');
return response;
} catch (error) {
console.error('获取用户信息失败:', error);
throw error;
}
};
// 更新用户信息
export const updateUserProfile = async (payload: Partial<UserInfoType>) => {
try {
const response = await httpService.post('/user/update', payload);
return response;
} catch (error) {
console.error('更新用户信息失败:', error);
throw error;
}
};
// 更新用户坐标位置
export const updateUserLocation = async (latitude: number, longitude: number) => {
try {
const response = await httpService.post('/user/update_location', {
latitude,
longitude,
});
return response;
} catch (error) {
console.error('更新用户坐标位置失败:', error);
throw error;
}
};
// 获取用户信息(从本地存储)
export const get_user_info = (): any | null => {
try {
let userinfo = Taro.getStorageSync('user_info')
if (userinfo) {
return JSON.parse(userinfo)
}
return null;
} catch (error) {
return null;
}
};

View File

@@ -16,7 +16,7 @@ interface GlobalState {
interface GlobalActions {
updateState: (payload: Record<string, any>) => void;
getNavbarHeightInfo: () => void;
getCurrentLocationInfo: () => void;
getCurrentLocationInfo: () => any;
}
// 完整的 Store 类型
type GlobalStore = GlobalState & GlobalActions;
@@ -50,14 +50,13 @@ export const useGlobalStore = create<GlobalStore>()((set, get) => ({
},
// 获取位置信息
getCurrentLocationInfo: () => {
return getCurrentLocation().then((res) => {
set({
getLocationLoading: false,
location: res || {},
});
return res;
getCurrentLocationInfo: async () => {
const res = await getCurrentLocation()
set({
getLocationLoading: false,
location: res || {},
});
return res;
},
// 更新store数据

View File

@@ -154,7 +154,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
},
// 获取列表数据(常规搜索)
fetchMatches: async (params) => {
fetchMatches: async (params, isFirstLoad = false) => {
set({ loading: true, error: null });
const { getSearchParams, setListData, distanceQuickFilter } = get();
@@ -172,6 +172,11 @@ export const useListStore = create<TennisStore>()((set, get) => ({
if (isIntegrate) {
reqParams.order = "";
fetchFn = getGamesIntegrateList;
// 第一次进入页面时传入 isRefresh 参数
if (isFirstLoad) {
reqParams.seachOption.isRefresh = true;
}
}
console.log("===fetchMatches 获取列表数据参数:", reqParams);
@@ -187,7 +192,6 @@ export const useListStore = create<TennisStore>()((set, get) => ({
}
const { count, rows } = data;
setListData({
// recommendList: rows || [],
error: '',
data: rows || [],
loading: false,
@@ -246,12 +250,7 @@ export const useListStore = create<TennisStore>()((set, get) => ({
// 获取列表数据
getMatchesData: () => {
const { fetchMatches } = get();
fetchMatches();
// if (distanceQuickFilter?.quick === "0") {
// getIntegrateListData();
// } else {
// fetchMatches();
// }
fetchMatches({}, true); // 第一次进入页面,传入 isFirstLoad = true
},
// 获取历史搜索数据

View File

@@ -61,7 +61,7 @@ export interface ListState {
}
export interface ListActions {
fetchMatches: (params?: Record<string, any>) => Promise<void>
fetchMatches: (params?: Record<string, any>,isFirstLoad?: Boolean) => Promise<void>
// getIntegrateListData: (params?: Record<string, any>) => Promise<void>
getMatchesData: () => void
clearError: () => void