From cab90aa1cba22a168d5eeaebae08b6ab3d83a01d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=88=90?= Date: Mon, 9 Feb 2026 13:25:13 +0800 Subject: [PATCH] 1 --- config/env.ts | 128 ++++++++++++++++++ project.config.json | 2 +- src/login_pages/index/index.tsx | 7 +- .../components/MyselfPageContent.tsx | 48 ++++--- src/other_pages/comment_reply/index.tsx | 2 +- src/services/userService.ts | 18 +-- 6 files changed, 164 insertions(+), 41 deletions(-) create mode 100644 config/env.ts diff --git a/config/env.ts b/config/env.ts new file mode 100644 index 0000000..2eb1e0b --- /dev/null +++ b/config/env.ts @@ -0,0 +1,128 @@ +import Taro from '@tarojs/taro' + +// 环境类型 +export type EnvType = 'development' | 'production' + +// 环境配置接口 +export interface EnvConfig { + name: string + apiBaseURL: string + timeout: number + enableLog: boolean + enableMock: boolean + // 客服配置 + customerService: { + corpId: string + serviceUrl: string + phoneNumber?: string + email?: string + } +} + +// 各环境配置 +const envConfigs: Record = { + + + // 开发环境 + development: { + name: '开发环境', + // apiBaseURL: 'https://tennis.bimwe.com', + apiBaseURL: 'http://localhost:9098', + timeout: 15000, + enableLog: true, + enableMock: false, + // 客服配置 + customerService: { + corpId: 'ww51fc969e8b76af82', // 企业ID + serviceUrl: 'https://work.weixin.qq.com/kfid/kfc64085b93243c5c91', + + } + }, + + + + // 生产环境1 + // production: { + // name: '生产环境1', + // apiBaseURL: 'https://tennis.bimwe.com', + // timeout: 10000, + // enableLog: false, + // enableMock: false, + // // 客服配置 + // customerService: { + // corpId: 'ww51fc969e8b76af82', // 企业ID + // serviceUrl: 'https://work.weixin.qq.com/kfid/kfc64085b93243c5c91', + + // } + // }, + + // 生产环境2 + production: { + name: '生产环境2', + apiBaseURL: 'https://youchang.qiongjingtiyu.com', + timeout: 10000, + enableLog: false, + enableMock: false, + // 客服配置 + customerService: { + corpId: 'ww9a2d9a5d9410c664', // 企业ID + serviceUrl: 'https://work.weixin.qq.com/kfid/kfcd355e162e0390684', + + } + } +} + +// 获取当前环境 +export const getCurrentEnv = (): EnvType => { + // 在小程序环境中,使用默认逻辑判断环境 + // 可以根据实际需要配置不同的判断逻辑 + + // 可以根据实际部署情况添加更多判断逻辑 + // 比如通过 Taro.getEnv() 获取当前平台环境 + + const isProd = process.env.NODE_ENV === 'production' + if (isProd) { + return 'production' + } else { + return 'development' + } +} + +// 获取当前环境配置 +export const getCurrentConfig = (): EnvConfig => { + const env = getCurrentEnv() + return envConfigs[env] +} + +// 获取指定环境配置 +export const getEnvConfig = (env: EnvType): EnvConfig => { + return envConfigs[env] +} + +// 是否为开发环境 +export const isDevelopment = (): boolean => { + return getCurrentEnv() === 'development' +} + +// 是否为生产环境 +export const isProduction = (): boolean => { + return getCurrentEnv() === 'production' +} + + + +// 环境配置调试信息 +export const getEnvInfo = () => { + const config = getCurrentConfig() + return { + env: getCurrentEnv(), + config, + taroEnv: Taro.getEnv(), + platform: Taro.getEnv() === Taro.ENV_TYPE.WEAPP ? '微信小程序' : + Taro.getEnv() === Taro.ENV_TYPE.WEB ? 'Web' : + Taro.getEnv() === Taro.ENV_TYPE.RN ? 'React Native' : '未知' + } +} + +// 导出当前环境配置(方便直接使用) +export default getCurrentConfig() \ No newline at end of file diff --git a/project.config.json b/project.config.json index 15d90c1..145631b 100644 --- a/project.config.json +++ b/project.config.json @@ -46,4 +46,4 @@ "simulatorType": "wechat", "simulatorPluginLibVersion": {}, "condition": {} -} +} \ No newline at end of file diff --git a/src/login_pages/index/index.tsx b/src/login_pages/index/index.tsx index d5c85e3..fa3ee27 100644 --- a/src/login_pages/index/index.tsx +++ b/src/login_pages/index/index.tsx @@ -1,6 +1,7 @@ import React, { useState } from "react"; import { View, Text, Button, Image } from "@tarojs/components"; import Taro, { useRouter } from "@tarojs/taro"; +import { GeneralNavbar } from "@/components"; import { wechat_auth_login, save_login_state, @@ -171,6 +172,8 @@ const LoginPage: React.FC = () => { + + {/* 主要内容 */} {/* 品牌区域 */} @@ -216,9 +219,9 @@ const LoginPage: React.FC = () => { 手机号快捷登录 - + {/* 返回首页 - + */} {/* 用户协议复选框 */} diff --git a/src/main_pages/components/MyselfPageContent.tsx b/src/main_pages/components/MyselfPageContent.tsx index 81a3296..fbffc5e 100644 --- a/src/main_pages/components/MyselfPageContent.tsx +++ b/src/main_pages/components/MyselfPageContent.tsx @@ -65,20 +65,22 @@ const MyselfPageContent: React.FC = ({ isActive = true } game_records: TennisMatch[] ): { notEndGames: TennisMatch[]; finishedGames: TennisMatch[] } => { const now = new Date().getTime(); - return game_records.reduce( - (result, cur) => { - let { end_time } = cur; - end_time = end_time.replace(/\s/, "T"); - new Date(end_time).getTime() > now - ? result.notEndGames.push(cur) - : result.finishedGames.push(cur); - return result; - }, - { - notEndGames: [] as TennisMatch[], - finishedGames: [] as TennisMatch[], - } - ); + + // 使用for + const notEndGames: TennisMatch[] = []; + const finishedGames: TennisMatch[] = []; + for (const game of game_records) { + const { end_time } = game; + const end_time_str = end_time.replace(/\s/, "T"); + new Date(end_time_str).getTime() > now + ? notEndGames.push(game) + : finishedGames.push(game); + } + + console.log("notEndGames", notEndGames); + + return { notEndGames, finishedGames }; + }, [] ); @@ -95,6 +97,8 @@ const MyselfPageContent: React.FC = ({ isActive = true } } else { games_data = await UserService.get_participated_games(user_info.id); } + + const sorted_games = games_data.sort((a, b) => { return ( new Date(a.original_start_time.replace(/\s/, "T")).getTime() - @@ -102,6 +106,8 @@ const MyselfPageContent: React.FC = ({ isActive = true } ); }); const { notEndGames, finishedGames } = classifyGameRecords(sorted_games); + console.log("notEndGames", notEndGames); + set_game_records(notEndGames); setEndedGameRecords(finishedGames); } catch (error) { @@ -250,17 +256,15 @@ const MyselfPageContent: React.FC = ({ isActive = true } setActiveTab("hosted")} > 我主办的 setActiveTab("participated")} > 我参与的 @@ -281,7 +285,7 @@ const MyselfPageContent: React.FC = ({ isActive = true } btnImg="ICON_ADD" reload={goPublish} isShowNoData={game_records.length === 0} - loadMoreMatches={() => {}} + loadMoreMatches={() => { }} collapse={true} style={{ paddingBottom: ended_game_records.length ? 0 : "90px", @@ -308,7 +312,7 @@ const MyselfPageContent: React.FC = ({ isActive = true } error={null} errorImg="ICON_LIST_EMPTY_CARD" isShowNoData={ended_game_records.length === 0} - loadMoreMatches={() => {}} + loadMoreMatches={() => { }} collapse={true} style={{ paddingBottom: "90px", overflow: "hidden" }} listLoadErrorWrapperHeight="fit-content" diff --git a/src/other_pages/comment_reply/index.tsx b/src/other_pages/comment_reply/index.tsx index 6a94d53..ef889cd 100644 --- a/src/other_pages/comment_reply/index.tsx +++ b/src/other_pages/comment_reply/index.tsx @@ -249,7 +249,7 @@ const CommentReply = () => { handleUserClick(e, item.user_id)} /> diff --git a/src/services/userService.ts b/src/services/userService.ts index e1bc150..4c7a7cc 100644 --- a/src/services/userService.ts +++ b/src/services/userService.ts @@ -151,6 +151,7 @@ interface BackendGameData { longitude: string; venue_type: string; surface_type: string; + distance_km: string; }; participants: { user: { @@ -206,7 +207,7 @@ export class UserService { latitude = parseFloat(game.venue_dtl.latitude) || latitude; longitude = parseFloat(game.venue_dtl.longitude) || longitude; } - const distance = this.calculate_distance(latitude, longitude); + // 处理地点信息 - 优先使用venue_dtl中的信息 let location = game.location_name || game.location || "未知地点"; @@ -227,7 +228,7 @@ export class UserService { original_start_time: game.start_time, end_time: game.end_time || "", location: location, - distance_km: parseFloat(distance.replace("km", "")) || 0, + distance_km: game.venue_dtl?.distance_km , current_players: registered_count, max_players: max_count, skill_level_min: parseInt(game.skill_level_min) || 0, @@ -303,20 +304,7 @@ export class UserService { return `${date_str} ${time_str}`; } - // 计算距离(模拟实现,实际需要根据用户位置计算) - private static calculate_distance( - latitude: number, - longitude: number - ): string { - if (latitude === 0 && longitude === 0) { - return "未知距离"; - } - // 这里应该根据用户当前位置计算实际距离 - // 暂时返回模拟距离 - const distances = ["1.2km", "2.5km", "3.8km", "5.1km", "7.3km"]; - return distances[Math.floor(Math.random() * distances.length)]; - } // 获取用户信息 static async get_user_info(user_id?: string): Promise { try {