diff --git a/docs/components/TradeComponent.md b/docs/components/TradeComponent.md index a5039d9..a07a4e6 100644 --- a/docs/components/TradeComponent.md +++ b/docs/components/TradeComponent.md @@ -37,6 +37,7 @@ interface TradePositionItem { - 事件处理:`onAmountInput`、`onAmountKeydown`、`onAmountPaste` - 余额不足时 Buy 显示 Deposit 按钮 - 25%/50%/Max 快捷份额 +- **Sell 模式份额默认取最大可卖**:切换至 Sell 或 maxAvailableShares 变化时自动调用 `setMaxShares()`,将 shares 设为最大可卖数量(无可卖时为 0) - **Sell 模式 UI 优化**: - Shares 标签与 Max shares 提示同行显示(`max-shares-inline`) - 输入框独占一行(`shares-input-wrapper`) diff --git a/docs/views/TradeDetail.md b/docs/views/TradeDetail.md index 4d970f5..a7b1092 100644 --- a/docs/views/TradeDetail.md +++ b/docs/views/TradeDetail.md @@ -17,6 +17,8 @@ - 移动端:底部栏 + `v-bottom-sheet` 嵌入 `TradeComponent` - Merge/Split:通过 `TradeComponent` 或底部菜单触发,成功后监听 `mergeSuccess`/`splitSuccess` 事件刷新持仓 - **401 权限错误**:加载详情失败时,通过 `useAuthError().formatAuthError` 统一提示「请先登录」或「权限不足」 +- **Sell 弹窗 emitsOptions 竞态**:`sellDialogRenderContent` 延迟 350ms 卸载 TradeComponent,等 v-dialog transition 完成,避免 Vue patch 时组件实例为 null 的 `emitsOptions` 错误 +- **底部栏 slot 竞态**:`tradeSheetRenderContent` 延迟 50ms 挂载、350ms 卸载 TradeComponent,避免 v-bottom-sheet transition 期间 VTextField 触发「Slot default invoked outside of the render function」警告 ## 使用方式 diff --git a/src/components/TradeComponent.vue b/src/components/TradeComponent.vue index 9657884..21dadc3 100644 --- a/src/components/TradeComponent.vue +++ b/src/components/TradeComponent.vue @@ -1748,6 +1748,18 @@ const maxAvailableShares = computed(() => { return Math.floor(currentOptionPositionShares.value) }) +/** 将 shares 限制为正整数(>= 1) */ +function clampShares(v: number): number { + const n = Math.floor(Number.isFinite(v) ? v : 1) + return Math.max(1, n) +} + +// 设置最大份额(基于当前选项的持仓);Sell 模式下份额默认取最大可卖数量 +const setMaxShares = () => { + const maxShares = currentOptionPositionShares.value + shares.value = maxShares > 0 ? clampShares(maxShares) : 0 +} + function applyInitialOption(option: 'yes' | 'no') { selectedOption.value = option syncLimitPriceFromMarket() @@ -1769,6 +1781,7 @@ onMounted(() => { if (props.initialOption) applyInitialOption(props.initialOption) else if (props.market) syncLimitPriceFromMarket() if (props.initialTab) activeTab.value = props.initialTab + if (activeTab.value === 'sell') setMaxShares() }) watch( () => props.initialOption, @@ -1810,14 +1823,18 @@ watch( watch( () => [activeTab.value, maxAvailableShares.value] as const, ([tab, max]) => { - if (tab === 'sell' && (!Number.isFinite(max) || max <= 0)) { - orderError.value = t('activity.noAvailableSharesToSell') - isNoAvailableSharesError.value = true - } else if (tab !== 'sell' || (Number.isFinite(max) && max > 0)) { - if (isNoAvailableSharesError.value) { + if (tab === 'sell') { + setMaxShares() + if (!Number.isFinite(max) || max <= 0) { + orderError.value = t('activity.noAvailableSharesToSell') + isNoAvailableSharesError.value = true + } else if (isNoAvailableSharesError.value) { orderError.value = '' isNoAvailableSharesError.value = false } + } else if (isNoAvailableSharesError.value) { + orderError.value = '' + isNoAvailableSharesError.value = false } }, { immediate: true }, @@ -1885,12 +1902,6 @@ const increasePrice = () => { limitPrice.value = ALLOWED_LIMIT_PRICES[nextIdx] ?? limitPrice.value } -/** 将 shares 限制为正整数(>= 1) */ -function clampShares(v: number): number { - const n = Math.floor(Number.isFinite(v) ? v : 1) - return Math.max(1, n) -} - /** 仅在值为正整数时更新 shares */ function onSharesInput(v: unknown) { const num = v == null ? NaN : Number(v) @@ -1979,14 +1990,6 @@ const setMaxAmount = () => { amount.value = balance.value } -// 设置最大份额(基于当前选项的持仓) -const setMaxShares = () => { - const maxShares = currentOptionPositionShares.value - if (maxShares > 0) { - shares.value = clampShares(maxShares) - } -} - /** Buy 模式:余额是否足够(>= 所需金额且不为 0)。cost:balance>0 时用 totalPrice,否则用 amount */ const canAffordBuy = computed(() => { const bal = balance.value diff --git a/src/views/EventMarkets.vue b/src/views/EventMarkets.vue index ee84214..0d8a847 100644 --- a/src/views/EventMarkets.vue +++ b/src/views/EventMarkets.vue @@ -192,6 +192,7 @@