From c54af2a4b3d2d771fe516acb561a5afe155acc69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9D=B0?= Date: Wed, 3 Sep 2025 20:49:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E8=BF=9B=E5=85=A5=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E6=9B=B4=E6=96=B0=E7=94=A8=E6=88=B7=E5=9D=90?= =?UTF-8?q?=E6=A0=87=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/detail/index.tsx | 17 +++++++++++++++-- src/services/loginService.ts | 33 ++++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/pages/detail/index.tsx b/src/pages/detail/index.tsx index 5565e69..b8f1ae1 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 @@ -114,8 +116,19 @@ function Index() { useDidShow(() => { fetchDetail() calcBgMainColors() + updateLocation() }) + 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) { @@ -552,10 +565,10 @@ function Index() { {/* share popup */} - + ) } -export default Index +export default Index \ No newline at end of file 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 From 1e9b40c208308be4d1161eb73831d23f557fd5f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9D=B0?= Date: Wed, 3 Sep 2025 22:59:04 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E4=B8=8A=E4=BC=A0=E5=B0=81?= =?UTF-8?q?=E9=9D=A2=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UploadCover/upload-from-wx.tsx | 4 +- .../UploadCover/upload-source-popup.tsx | 23 ++++------- src/services/httpService.ts | 2 +- src/services/publishService.ts | 38 ++++++++++++++++++- 4 files changed, 47 insertions(+), 20 deletions(-) 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..7ceff4b 100644 --- a/src/components/UploadCover/upload-source-popup.tsx +++ b/src/components/UploadCover/upload-source-popup.tsx @@ -57,27 +57,18 @@ 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 => { + console.log(res, 1122) + 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/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/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, + }) + } + } } // 导出认证服务实例 From 1012f75eac553d48f8f36d3809454690a8576cc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9D=B0?= Date: Thu, 4 Sep 2025 18:58:59 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E8=AF=A6=E6=83=85=E9=A1=B5?= =?UTF-8?q?=E8=BD=AE=E6=92=AD=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UploadCover/upload-source-popup.tsx | 1 - src/pages/detail/index.scss | 32 +++++++++++ src/pages/detail/index.tsx | 53 +++++++++++++------ 3 files changed, 69 insertions(+), 17 deletions(-) diff --git a/src/components/UploadCover/upload-source-popup.tsx b/src/components/UploadCover/upload-source-popup.tsx index 7ceff4b..5b02ad0 100644 --- a/src/components/UploadCover/upload-source-popup.tsx +++ b/src/components/UploadCover/upload-source-popup.tsx @@ -63,7 +63,6 @@ export default forwardRef(function UploadImage(props: UploadImageProps, ref) { function fetchImages(st: SourceType) { publishService.getPictures({ type: st }).then(res => { - console.log(res, 1122) if (res.code === 0) { let start = 0 setImages(res.data.rows.map(item => ({ 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 b8f1ae1..b9784fe 100644 --- a/src/pages/detail/index.tsx +++ b/src/pages/detail/index.tsx @@ -96,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 @@ -113,10 +113,10 @@ function Index() { // calcBgMainColors() // }, []) - useDidShow(() => { - fetchDetail() - calcBgMainColors() - updateLocation() + useDidShow(async () => { + await updateLocation() + await fetchDetail() + // calcBgMainColors() }) const updateLocation = async () => { @@ -137,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() @@ -254,10 +258,27 @@ function Index() { - + {/* swiper */} - + + { + detail?.image_list?.length > 0 && detail?.image_list.map((item, index) => { + return ( + + + + ) + }) + } + + + {/* ))} - + */} {/* content */} {/* avatar and tags */}