From a084780180857d52056ae67d854b807072a05ca6 Mon Sep 17 00:00:00 2001 From: ivan Date: Sat, 28 Feb 2026 20:17:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9AUI=E4=BC=98=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/components/TradeComponent.md | 5 +- docs/composables/useAuthError.md | 36 ++++ docs/views/TradeDetail.md | 1 + docs/views/Wallet.md | 1 + sdk/clobSocket.ts | 5 +- src/components/TradeComponent.vue | 319 ++++++++++++++++++++++-------- src/composables/useAuthError.ts | 20 ++ src/locales/en.json | 4 +- src/locales/ja.json | 4 +- src/locales/ko.json | 4 +- src/locales/zh-CN.json | 4 +- src/locales/zh-TW.json | 4 +- src/stores/user.ts | 16 +- src/views/EventMarkets.vue | 10 + src/views/Home.vue | 15 +- src/views/TradeDetail.vue | 134 +++++++++++-- src/views/Wallet.vue | 19 +- 17 files changed, 492 insertions(+), 109 deletions(-) create mode 100644 docs/composables/useAuthError.md create mode 100644 src/composables/useAuthError.ts diff --git a/docs/components/TradeComponent.md b/docs/components/TradeComponent.md index 0d04c25..87bdc4f 100644 --- a/docs/components/TradeComponent.md +++ b/docs/components/TradeComponent.md @@ -32,7 +32,9 @@ interface TradePositionItem { - Buy/Sell Tab 切换 - Market/Limit 类型、Merge/Split 菜单 -- **Buy 模式 Amount 区**:无论余额是否充足,均显示 Amount 标签、Balance、金额输入、+$1/+$20/+$100/Max 快捷按钮(桌面端、嵌入弹窗、移动端弹窗一致) +- **Buy 模式 Amount 区**:无论余额是否充足,均显示 Amount 标签、Balance、**可编辑金额输入框**(v-text-field,带 $ 前缀,variant="outlined")、+$1/+$20/+$100/Max 快捷按钮(桌面端、嵌入弹窗、移动端弹窗一致) + - 输入框支持直接输入金额(>= 0,支持小数) + - 事件处理:`onAmountInput`、`onAmountKeydown`、`onAmountPaste` - 余额不足时 Buy 显示 Deposit 按钮 - 25%/50%/Max 快捷份额 - **Sell 模式 UI 优化**: @@ -42,6 +44,7 @@ interface TradePositionItem { - 整体布局更清晰:`Shares Max: 2` → `[输入框]` → `[25%][50%][Max]` - 调用 market API 下单、Split、Merge - **合并/拆分成功后触发事件**:`mergeSuccess`、`splitSuccess`,父组件监听后可刷新持仓列表 +- **401 权限错误提示**:通过 `useAuthError().formatAuthError` 统一处理,未登录显示「请先登录」,已登录显示「权限不足」 ## 使用方式 diff --git a/docs/composables/useAuthError.md b/docs/composables/useAuthError.md new file mode 100644 index 0000000..03e4fea --- /dev/null +++ b/docs/composables/useAuthError.md @@ -0,0 +1,36 @@ +# useAuthError.ts + +**路径**:`src/composables/useAuthError.ts` + +## 功能用途 + +统一处理 HTTP 401(Unauthorized)等权限相关错误,根据登录状态返回用户友好的提示文案:未登录时提示「请先登录」,已登录时提示「权限不足」。 + +## 核心能力 + +- `formatAuthError(err, fallback)`:将异常转换为展示文案 + - 若错误信息包含 `401` 或 `Unauthorized`:根据 `userStore.isLoggedIn` 返回 `error.pleaseLogin` 或 `error.insufficientPermission` + - 否则返回原始错误信息或 `fallback` + +## 使用方式 + +```typescript +import { useAuthError } from '@/composables/useAuthError' + +const { formatAuthError } = useAuthError() + +try { + await someApiCall() +} catch (e) { + errorMessage.value = formatAuthError(e, t('error.requestFailed')) +} +``` + +## 国际化 + +依赖 `error.pleaseLogin`、`error.insufficientPermission`,在各 `locales/*.json` 的 `error` 下配置。 + +## 扩展方式 + +1. **扩展状态码**:在 `formatAuthError` 中增加对 403 等的判断 +2. **统一拦截**:在 `request.ts` 层统一处理 401,自动跳转登录或弹 toast diff --git a/docs/views/TradeDetail.md b/docs/views/TradeDetail.md index ea597f8..f709dfe 100644 --- a/docs/views/TradeDetail.md +++ b/docs/views/TradeDetail.md @@ -16,6 +16,7 @@ - 限价订单:通过 `getOrderList` 获取当前市场未成交限价单,支持撤单 - 移动端:底部栏 + `v-bottom-sheet` 嵌入 `TradeComponent` - Merge/Split:通过 `TradeComponent` 或底部菜单触发,成功后监听 `mergeSuccess`/`splitSuccess` 事件刷新持仓 +- **401 权限错误**:加载详情失败时,通过 `useAuthError().formatAuthError` 统一提示「请先登录」或「权限不足」 ## 使用方式 diff --git a/docs/views/Wallet.md b/docs/views/Wallet.md index fb32835..0bd1755 100644 --- a/docs/views/Wallet.md +++ b/docs/views/Wallet.md @@ -13,6 +13,7 @@ - Profit/Loss 卡片:时间范围切换、ECharts 图表 - Tab:Positions、Open orders、History - DepositDialog、WithdrawDialog 组件 +- **401 权限错误**:取消订单等接口失败时,通过 `useAuthError().formatAuthError` 统一提示「请先登录」或「权限不足」 ## 使用方式 diff --git a/sdk/clobSocket.ts b/sdk/clobSocket.ts index fcdfbc0..e18fcd5 100644 --- a/sdk/clobSocket.ts +++ b/sdk/clobSocket.ts @@ -126,7 +126,10 @@ export class ClobSdk { console.log(`[ClobSdk] 已连接到 ${this.url}`); this.reconnectAttempts = 0; this.notifyConnect(event); - this.subscribe(); + setTimeout(() => { + this.subscribe(); + }, 1000); + // this.subscribe(); }; this.ws.onmessage = (event: any) => { diff --git a/src/components/TradeComponent.vue b/src/components/TradeComponent.vue index e45710f..f6c86c3 100644 --- a/src/components/TradeComponent.vue +++ b/src/components/TradeComponent.vue @@ -42,6 +42,7 @@ class="yes-btn" :class="{ active: selectedOption === 'yes' }" text + :title="`${yesLabel} ${yesPriceCents}¢`" @click="handleOptionChange('yes')" > {{ yesLabel }} {{ yesPriceCents }}¢ @@ -50,6 +51,7 @@ class="no-btn" :class="{ active: selectedOption === 'no' }" text + :title="`${noLabel} ${noPriceCents}¢`" @click="handleOptionChange('no')" > {{ noLabel }} {{ noPriceCents }}¢ @@ -58,19 +60,32 @@ @@ -107,7 +122,7 @@