diff --git a/src/components/UploadCover/upload-from-wx.tsx b/src/components/UploadCover/upload-from-wx.tsx index 841c27b..33e23fe 100644 --- a/src/components/UploadCover/upload-from-wx.tsx +++ b/src/components/UploadCover/upload-from-wx.tsx @@ -27,8 +27,8 @@ export default function UploadFromWx(props: UploadFromWxProps) { let count = 0 const files = res.tempFiles.map(item => ({ filePath: item.path, - description: 'test', - tags: 'test', + description: '封面图', + tags: 'cover', is_public: 1 as unknown as 0 | 1, id: (Date.now() + count++).toString(), })) diff --git a/src/components/UploadCover/upload-source-popup.tsx b/src/components/UploadCover/upload-source-popup.tsx index dc72e44..5b02ad0 100644 --- a/src/components/UploadCover/upload-source-popup.tsx +++ b/src/components/UploadCover/upload-source-popup.tsx @@ -57,27 +57,17 @@ export default forwardRef(function UploadImage(props: UploadImageProps, ref) { setVisible(true) setSourceType(sourceType) setMaxCount(maxCount) - fetchImages() + fetchImages(sourceType) } })) - function fetchImages() { - publishService.getPictures({ - pageOption: { - page: 1, - pageSize: 100, - }, - seachOption: { - tag: '', - resource_type: 'image', - dateRange: [], - }, - }).then(res => { - if (res.success) { + function fetchImages(st: SourceType) { + publishService.getPictures({ type: st }).then(res => { + if (res.code === 0) { let start = 0 - setImages(res.data.data.rows.map(item => ({ + setImages(res.data.rows.map(item => ({ id: (Date.now() + start++).toString(), - url: item.thumbnail_url, + url: item.file_url, }))) } else { // TODO: 显示错误信息 diff --git a/src/pages/detail/index.scss b/src/pages/detail/index.scss index 495151a..92a3ec6 100644 --- a/src/pages/detail/index.scss +++ b/src/pages/detail/index.scss @@ -81,6 +81,38 @@ background-color: rgba(0, 0, 0, 0.3); } + .detail-swiper-container { + height: 240px; + margin-top: 15px; + margin-left: 15px; + margin-right: 15px; + overflow-x: scroll; + + .detail-swiper-scroll-container { + display: flex; + height: 240px; + width: auto; + align-items: center; + justify-content: flex-start; + flex-wrap: nowrap; + gap: 12px; + + .detail-swiper-item { + flex: 0 0 auto; + max-width: calc(100vw - 30px); + max-height: 240px; + &-image { + max-width: 100%; + max-height: 100%; + width: 300px; + height: 300px; + border-radius: 12px; + transition: transform 0.5s; + } + } + } + } + .detail-swiper { height: 240px; margin-top: 15px; diff --git a/src/pages/detail/index.tsx b/src/pages/detail/index.tsx index 5565e69..b9784fe 100644 --- a/src/pages/detail/index.tsx +++ b/src/pages/detail/index.tsx @@ -4,6 +4,8 @@ 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 { getCurrentLocation } from '../../utils/locationUtils' import { useUserStats, useUserActions @@ -94,7 +96,7 @@ function Index() { // const { incrementRequestCount, resetUserStats } = useUserActions() const [current, setCurrent] = useState(0) - const [colors, setColors] = useState([]) + // const [textColor, setTextColor] = useState([]) const [detail, setDetail] = useState(null) const { params } = useRouter() const { id, autoShare, from } = params @@ -111,11 +113,22 @@ function Index() { // calcBgMainColors() // }, []) - useDidShow(() => { - fetchDetail() - calcBgMainColors() + useDidShow(async () => { + await updateLocation() + await fetchDetail() + // calcBgMainColors() }) + const updateLocation = async () => { + try { + const location = await getCurrentLocation() + await updateUserProfile({ latitude: location.latitude, longitude: location.longitude }) + console.log('用户位置更新成功') + } catch (error) { + console.error('用户位置更新失败', error) + } + } + const fetchDetail = async () => { const res = await DetailService.getDetail(Number(id)) if (res.code === 0) { @@ -124,14 +137,18 @@ function Index() { } } - const calcBgMainColors = async () => { - const textcolors: string[] = [] - for (const index in images) { - const { textColor } = await getTextColorOnImage(images[index]) - textcolors[index] = textColor - } - setColors(textcolors) - } + // const calcBgMainColors = async () => { + // const textcolors: string[] = [] + // // for (const index in images) { + // // const { textColor } = await getTextColorOnImage(images[index]) + // // textcolors[index] = textColor + // // } + // if (detail?.image_list?.length > 0) { + // const { textColor } = await getTextColorOnImage(detail.image_list[0]) + // textcolors[0] = textColor + // } + // setColors(textcolors) + // } function handleShare() { sharePopupRef.current.show() @@ -241,10 +258,27 @@ function Index() { - + {/* swiper */} - + + { + detail?.image_list?.length > 0 && detail?.image_list.map((item, index) => { + return ( + + + + ) + }) + } + + + {/* ))} - + */} {/* content */} {/* avatar and tags */} @@ -552,10 +586,10 @@ function Index() { {/* share popup */} - + ) } -export default Index +export default Index \ No newline at end of file diff --git a/src/services/httpService.ts b/src/services/httpService.ts index fcee8f3..4c356fa 100644 --- a/src/services/httpService.ts +++ b/src/services/httpService.ts @@ -58,7 +58,7 @@ class HttpService { // 构建完整URL private buildUrl(url: string, params?: Record): string { - const fullUrl = url.startsWith('http') ? url : `${this.baseURL}${url}` + const fullUrl = url.startsWith('http') ? url : `${this.baseURL}${url.startsWith('/') ? url.slice(1) : url}` if (params) { const searchParams = new URLSearchParams() diff --git a/src/services/loginService.ts b/src/services/loginService.ts index d0807b3..3d1dc3f 100644 --- a/src/services/loginService.ts +++ b/src/services/loginService.ts @@ -43,7 +43,7 @@ export const wechat_auth_login = async (phone_code?: string): Promise => { const response = await httpService.post('user/sms/send', { phone: phone }); - + // 修复响应检查逻辑:检查 code === 0 或 success === true if (response.code === 0 || response.success === true) { return { @@ -159,7 +159,7 @@ export const verify_sms_code = async (phone: string, code: string): Promise { accessToken: token, expiresAt: expires_at }); - + // 保存用户信息 Taro.setStorageSync('user_info', user_info); Taro.setStorageSync('is_logged_in', true); @@ -222,7 +222,7 @@ export const clear_login_state = () => { try { // 使用 tokenManager 清除令牌 tokenManager.clearTokens(); - + // 清除其他登录状态 Taro.removeStorageSync('user_info'); Taro.removeStorageSync('is_logged_in'); @@ -240,7 +240,7 @@ export const check_login_status = (): boolean => { clear_login_state(); return false; } - + const is_logged_in = Taro.getStorageSync('is_logged_in'); return !!is_logged_in; } catch (error) { @@ -265,7 +265,7 @@ export const get_token_status = () => { const is_valid = tokenManager.hasValidToken(); const remaining_time = tokenManager.getTokenRemainingTime(); const is_expired = tokenManager.isTokenExpired(); - + return { is_valid, remaining_time, @@ -317,17 +317,28 @@ export const refresh_login_status = async (): Promise => { try { // 检查微信登录状态 const is_valid = await check_wechat_login(); - + if (!is_valid) { // 微信登录已过期,需要重新登录 clear_login_state(); return false; } - + // 检查本地存储的登录状态 return check_login_status(); } catch (error) { console.error('刷新登录状态失败:', error); return false; } -}; \ No newline at end of file +}; + +// 更新用户信息 +export const updateUserProfile = async (payload: Partial & { latitude?: number; longitude?: number; }) => { + try { + const response = await httpService.post('user/update', payload); + return response; + } catch (error) { + console.error('更新用户信息失败:', error); + throw error; + } +}; \ No newline at end of file diff --git a/src/services/publishService.ts b/src/services/publishService.ts index 24d55d9..8d88261 100644 --- a/src/services/publishService.ts +++ b/src/services/publishService.ts @@ -129,12 +129,48 @@ class PublishService { loadingText: '发布中...' }) } - async getPictures(req: getPicturesReq): Promise> { + async getHistoryImageList(req: getPicturesReq): Promise { + return httpService.post('/gallery/list', req, { + showLoading: false, + showToast: false, + }) + } + async getPresetImageList(req: getPicturesReq): Promise { return httpService.post('/gallery/sys_img_list', req, { showLoading: false, showToast: false, }) } + async getPictures(req) { + const { type, otherReq = {} } = req + if (type === 'history') { + return this.getHistoryImageList({ + pageOption: { + page: 1, + pageSize: 100, + }, + seachOption: { + tag: 'cover', + resource_type: 'image', + dateRange: [], + }, + ...otherReq, + }) + } else { + return this.getPresetImageList({ + pageOption: { + page: 1, + pageSize: 100, + }, + seachOption: { + tag: '', + resource_type: 'image', + dateRange: [], + }, + ...otherReq, + }) + } + } } // 导出认证服务实例