diff --git a/src/pages/detail/index.tsx b/src/pages/detail/index.tsx
index b9784fe..8be0e4c 100644
--- a/src/pages/detail/index.tsx
+++ b/src/pages/detail/index.tsx
@@ -4,11 +4,11 @@ import { Cell, Avatar, Progress, Popover } from '@nutui/nutui-react-taro'
import Taro, { useRouter, useShareAppMessage, useShareTimeline, useDidShow } from '@tarojs/taro'
// 导入API服务
import DetailService from '../../services/detailService'
-import { updateUserProfile } from '../../services/loginService'
+import { updateUserProfile, get_user_info } from '../../services/loginService'
import { getCurrentLocation } from '../../utils/locationUtils'
import {
- useUserStats,
- useUserActions
+ useUserInfo,
+ useUserActions,
} from '../../store/userStore'
import img from '../../config/images'
import { getTextColorOnImage } from '../../utils'
@@ -25,6 +25,7 @@ function insertDotInTags(tags: string[]) {
return tags.join('-·-').split('-')
}
+// 分享弹窗
const SharePopup = forwardRef(({ id, from }: { id: string, from: string }, ref) => {
const [visible, setVisible] = useState(false)
@@ -90,6 +91,39 @@ const SharePopup = forwardRef(({ id, from }: { id: string, from: string }, ref)
)
})
+// 底部操作栏
+function StickyButton(props) {
+ const { handleShare, handleJoinGame, detail } = props
+ const userInfo = useUserInfo()
+ const { id } = userInfo
+ const { publisher_id, status } = detail || {}
+
+ const role = Number(publisher_id) === id ? 'ownner' : 'visitor'
+ console.log(status, role)
+ return (
+
+
+
+
+ 分享
+
+
+ { Taro.showToast({ title: 'To be continued', icon: 'none' }) }}>
+
+ 32
+
+
+
+ 🎾
+ 立即加入
+
+ ¥ 65
+
+
+
+ )
+}
+
function Index() {
// 使用Zustand store
// const userStats = useUserStats()
@@ -99,7 +133,9 @@ function Index() {
// const [textColor, setTextColor] = useState([])
const [detail, setDetail] = useState(null)
const { params } = useRouter()
+ const [currentLocation, setCurrentLocation] = useState([0, 0])
const { id, autoShare, from } = params
+ const { fetchUserInfo, updateUserInfo } = useUserActions()
console.log('from', from)
@@ -115,6 +151,7 @@ function Index() {
useDidShow(async () => {
await updateLocation()
+ await fetchUserInfo()
await fetchDetail()
// calcBgMainColors()
})
@@ -122,7 +159,8 @@ function Index() {
const updateLocation = async () => {
try {
const location = await getCurrentLocation()
- await updateUserProfile({ latitude: location.latitude, longitude: location.longitude })
+ setCurrentLocation([location.latitude, location.longitude])
+ await updateUserInfo({ latitude: location.latitude, longitude: location.longitude })
console.log('用户位置更新成功')
} catch (error) {
console.error('用户位置更新失败', error)
@@ -130,7 +168,7 @@ function Index() {
}
const fetchDetail = async () => {
- const res = await DetailService.getDetail(Number(id))
+ const res = await DetailService.getDetail(242/* Number(id) */)
if (res.code === 0) {
console.log(res.data)
setDetail(res.data)
@@ -156,8 +194,8 @@ function Index() {
const openMap = () => {
Taro.openLocation({
- latitude: detail?.latitude, // 纬度(必填)
- longitude: detail?.longitude, // 经度(必填)
+ latitude: detail?.longitude, // 纬度(必填)
+ longitude: detail?.latitude, // 经度(必填)
name: '上海体育场', // 位置名(可选)
address: '上海市徐汇区肇嘉浜路128号', // 地址详情(可选)
scale: 15, // 地图缩放级别(1-28)
@@ -188,6 +226,8 @@ function Index() {
const { title, longitude, latitude } = detail || {}
+ console.log(longitude, latitude, 2222)
+
const requirements = [{
title: 'NTRP水平要求',
desc: '2.0 - 4.5 之间',
@@ -245,6 +285,7 @@ function Index() {
},
]
+ console.log('detail', detail)
return (
{/* custom navbar */}
@@ -376,15 +417,20 @@ function Index() {
{/* venue map */}
-
@@ -565,26 +611,7 @@ function Index() {
{/* sticky bottom action bar */}
-
-
-
-
- 分享
-
-
- { Taro.showToast({ title: 'To be continued', icon: 'none' }) }}>
-
- 32
-
-
-
- 🎾
- 立即加入
-
- ¥ 65
-
-
-
+
{/* share popup */}
diff --git a/src/services/loginService.ts b/src/services/loginService.ts
index 3d1dc3f..b44544b 100644
--- a/src/services/loginService.ts
+++ b/src/services/loginService.ts
@@ -1,5 +1,5 @@
import Taro from '@tarojs/taro';
-import httpService from './httpService';
+import httpService, { ApiResponse } from './httpService';
import tokenManager from '../utils/tokenManager';
// 微信用户信息接口
@@ -34,8 +34,26 @@ export interface VerifyCodeResponse {
token?: string;
user_info?: WechatUserInfo;
}
-
-
+// 用户详细信息
+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
+ language: string
+ phone: string
+ is_subscribed: string
+ latitude: number
+ longitude: number
+ subscribe_time: string
+ last_login_time: string
+}
// 微信授权登录
@@ -332,8 +350,19 @@ export const refresh_login_status = async (): Promise => {
}
};
+// 获取用户详细信息
+export const fetchUserProfile = async (): Promise> => {
+ try {
+ const response = await httpService.post('/user/detail');
+ return response;
+ } catch (error) {
+ console.error('获取用户信息失败:', error);
+ throw error;
+ }
+};
+
// 更新用户信息
-export const updateUserProfile = async (payload: Partial & { latitude?: number; longitude?: number; }) => {
+export const updateUserProfile = async (payload: Partial) => {
try {
const response = await httpService.post('user/update', payload);
return response;
diff --git a/src/static/detail/icon-stark.svg b/src/static/detail/icon-stark.svg
new file mode 100644
index 0000000..76f6d2e
--- /dev/null
+++ b/src/static/detail/icon-stark.svg
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/src/store/userStore.ts b/src/store/userStore.ts
index fecedc8..07ebb81 100644
--- a/src/store/userStore.ts
+++ b/src/store/userStore.ts
@@ -1,58 +1,47 @@
import { create } from 'zustand'
+import { fetchUserProfile, updateUserProfile, UserInfoType } from '@/services/loginService'
-// 用户统计信息
-export interface UserStats {
- requestCount: number
- matchesCreated: number
- matchesJoined: number
- lastActiveTime: string
+export interface UserState {
+ user: UserInfoType
+ fetchUserInfo: () => Promise
+ updateUserInfo: (userInfo: Partial) => void
}
-// Store 状态接口
-interface UserState {
- userStats: UserStats
- incrementRequestCount: () => void
- resetUserStats: () => void
-}
-
-// 创建适配 Zustand 4.x 的 store
-export const useUserStore = create()((set) => ({
- // 初始状态
- userStats: {
- requestCount: 0,
- matchesCreated: 0,
- matchesJoined: 0,
- lastActiveTime: new Date().toISOString()
+export const useUser = create()((set) => ({
+ user: {
+ id: 0,
+ "openid": "",
+ "unionid": "",
+ "session_key": "",
+ "nickname": "张三",
+ "avatar_url": "https://example.com/avatar.jpg",
+ "gender": "",
+ "country": "",
+ "province": "",
+ "city": "",
+ "language": "",
+ "phone": "13800138000",
+ "is_subscribed": "0",
+ "latitude": 0,
+ "longitude": 0,
+ "subscribe_time": "2024-06-15 14:00:00",
+ "last_login_time": "2024-06-15 14:00:00"
},
-
- // Actions
- incrementRequestCount: () => {
- console.log('store: incrementRequestCount 被调用')
- set((state) => ({
- userStats: {
- ...state.userStats,
- requestCount: state.userStats.requestCount + 1,
- lastActiveTime: new Date().toISOString()
- }
- }))
+ fetchUserInfo: async () => {
+ const res = await fetchUserProfile()
+ console.log(res)
+ set({ user: res.data })
},
-
- resetUserStats: () => {
- console.log('store: resetUserStats 被调用')
- set({
- userStats: {
- requestCount: 0,
- matchesCreated: 0,
- matchesJoined: 0,
- lastActiveTime: new Date().toISOString()
- }
- })
+ updateUserInfo: async(userInfo: Partial) => {
+ const res = await updateUserProfile(userInfo)
+ console.log(res)
+ set({ user: res.data })
}
}))
-// 简单的 hooks
-export const useUserStats = () => useUserStore((state) => state.userStats)
-export const useUserActions = () => useUserStore((state) => ({
- incrementRequestCount: state.incrementRequestCount,
- resetUserStats: state.resetUserStats
-}))
\ No newline at end of file
+export const useUserInfo = () => useUser((state) => state.user)
+
+export const useUserActions = () => useUser((state) => ({
+ fetchUserInfo: state.fetchUserInfo,
+ updateUserInfo: state.updateUserInfo
+}))