From 50e5775dc8820ce6fc828950cc4d386cd7669992 Mon Sep 17 00:00:00 2001 From: toom1996 <23cm.cn@gmail.com> Date: Tue, 1 Sep 2026 00:08:05 +0800 Subject: [PATCH] update --- src/components/RunwayLooks.astro | 3 +- src/components/StreetSnaps.astro | 1 + src/i18n/dictionary.ts | 2 + src/layouts/Layout.astro | 69 ++++++++++---- src/lib/api.ts | 28 ++++-- src/pages/cn/account.astro | 88 +++++++++++------- src/pages/cn/login.astro | 148 +++++++++++++++++++++++++------ src/pages/en/account.astro | 88 +++++++++++------- src/pages/en/login.astro | 148 +++++++++++++++++++++++++------ 9 files changed, 434 insertions(+), 141 deletions(-) diff --git a/src/components/RunwayLooks.astro b/src/components/RunwayLooks.astro index 5a4a4bd..b5d3e2f 100644 --- a/src/components/RunwayLooks.astro +++ b/src/components/RunwayLooks.astro @@ -347,6 +347,7 @@ const seasonOptions: { value: string; label: string }[] = [ const ct = new URLSearchParams(window.location.search).get('collection') const ALLOWED = ['rtw', 'menswear', 'womenswear', 'couture', 'resort', 'pre_fall', 'bridal', 'swimwear'] if (ct && ALLOWED.includes(ct)) this.selectedCt = ct + // 首页(含筛选后的首页)公开:未登录也直接加载首屏,不弹登录框 this.loadPage(1) }, @@ -393,7 +394,7 @@ const seasonOptions: { value: string; label: string }[] = [ }, refreshFilter() { - if (!this.requireLogin()) return + // 首页公开:筛选切换后重新加载第 1 页,未登录也可查看 this.loadPage(1) }, diff --git a/src/components/StreetSnaps.astro b/src/components/StreetSnaps.astro index 003d3fc..45a8f9a 100644 --- a/src/components/StreetSnaps.astro +++ b/src/components/StreetSnaps.astro @@ -296,6 +296,7 @@ const cityOptions: { value: string; label: string }[] = [ const city = new URLSearchParams(window.location.search).get('city') const allowed = (this.cityOptions || []).map((c: any) => c.value) if (city && allowed.includes(city)) this.selectedCity = city + // 首页公开:未登录也直接加载首屏,不弹登录框 this.loadPage(1) }, diff --git a/src/i18n/dictionary.ts b/src/i18n/dictionary.ts index b1c281d..e51648d 100644 --- a/src/i18n/dictionary.ts +++ b/src/i18n/dictionary.ts @@ -51,6 +51,8 @@ export const dict: Record = { 'please log in': { cn: '请先登录' }, 'login to continue': { cn: '登录以继续使用筛选与翻页' }, 'login prompt': { cn: '登录后可筛选与翻页浏览全部档案' }, + 'members': { cn: '会员专区' }, + 'back to site': { cn: '返回网站' }, 'email': { cn: '邮箱' }, 'my collections': { cn: '我的收藏' }, 'my history': { cn: '浏览历史' }, diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index cd114fa..565aecc 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -2,7 +2,7 @@ import '@/styles/global.css' import { href, ROUTES } from '@/lib/routes' import { getI18n } from '@/i18n/utils' -import { LOCALES, LOCALE_NAMES } from '@/i18n/config' +import { LOCALE_NAMES } from '@/i18n/config' import { setApiLocale } from '@/lib/api' import { i18n } from 'astro:config/client'; import { toCodes } from 'astro:i18n'; @@ -17,8 +17,7 @@ const { locale, t, getRelativeLocaleUrl } = getI18n(Astro) setApiLocale(locale) // 经 data-* 属性把已翻译字符串传入打包型 {/* Top Footer Grid */}
diff --git a/src/lib/api.ts b/src/lib/api.ts index 25901b2..f49d0b0 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -177,13 +177,27 @@ async function request(path: string, params?: URLSearchParams): Promise { const fullPath = "/api/v1" + path const { sig, ts, nonce } = await clientSign("GET", fullPath, p.toString()) const url = getBase() + fullPath + qs - const res = await fetch(url, { - headers: { - "X-Sign": sig, - "X-Sign-Ts": ts, - "X-Sign-Nonce": nonce, - }, - }) + const headers: Record = { + "X-Sign": sig, + "X-Sign-Ts": ts, + "X-Sign-Nonce": nonce, + } + // 已登录则自动附带 Bearer(翻页/筛选等需鉴权的列表请求才能通过后端校验)。 + // 未登录时不带,首页(page<=1)仍可直接公开访问。 + const token = getAccessToken() + if (token) headers["Authorization"] = `Bearer ${token}` + let res = await fetch(url, { headers }) + // 登录态下 access 过期:用 refresh 续期一次后重试(与 authedFetch 行为一致)。 + if (res.status === 401 && getRefreshToken()) { + try { + await refreshSession() + const newToken = getAccessToken() + if (newToken) headers["Authorization"] = `Bearer ${newToken}` + res = await fetch(url, { headers }) + } catch { + /* 刷新失败:保留原 401,下面统一抛出,由调用方处理 */ + } + } if (!res.ok) throw new Error(`API ${res.status} ${url}`) return (await res.json()) as T } diff --git a/src/pages/cn/account.astro b/src/pages/cn/account.astro index 9435a8d..3b8172f 100644 --- a/src/pages/cn/account.astro +++ b/src/pages/cn/account.astro @@ -2,7 +2,9 @@ import Layout from '@/layouts/Layout.astro' import { getI18n } from '@/i18n/utils' import { href, ROUTES } from '@/lib/routes' + const { locale, t } = getI18n(Astro) + const titleLabel = t('my account') const pleaseLabel = t('please log in') const loginLabel = t('login') @@ -14,46 +16,72 @@ const historyLabel = t('my history') const soonLabel = t('coming soon') --- -
-

{titleLabel}

- -
-

{pleaseLabel}

- +
+ +
+
+

{collectionsLabel}

+

{soonLabel}

+
+
+

{historyLabel}

+

{soonLabel}

+
+
+
+ - + diff --git a/src/pages/en/account.astro b/src/pages/en/account.astro index 9435a8d..3b8172f 100644 --- a/src/pages/en/account.astro +++ b/src/pages/en/account.astro @@ -2,7 +2,9 @@ import Layout from '@/layouts/Layout.astro' import { getI18n } from '@/i18n/utils' import { href, ROUTES } from '@/lib/routes' + const { locale, t } = getI18n(Astro) + const titleLabel = t('my account') const pleaseLabel = t('please log in') const loginLabel = t('login') @@ -14,46 +16,72 @@ const historyLabel = t('my history') const soonLabel = t('coming soon') --- -
-

{titleLabel}

- -
+ +
+
+

{collectionsLabel}

+

{soonLabel}

+
+
+

{historyLabel}

+

{soonLabel}

+
+
+ +
- +