Merge pull request #9254 from Sjeary/fix/users-mobile-layout

fix: 修复手机端用户管理页面溢出和菜单裁切的问题
This commit is contained in:
Wesley Liddick authored and GitHub committed 2026-12-04 23:41:19 +08:00
commit 3f99496496
5 files changed
+58 -19

No files matched your search

+1 -1
View File
@@ -76,7 +76,7 @@
<span class="text-xs font-medium uppercase tracking-wider text-gray-500 dark:text-dark-400">
{{ column.label }}
</span>
<div class="min-w-0 max-w-full text-right text-sm text-gray-900 dark:text-gray-100">
<div class="min-w-0 max-w-full [overflow-wrap:anywhere] text-right text-sm text-gray-900 dark:text-gray-100">
<slot :name="`cell-${column.key}`" :row="row" :value="row[column.key]" :expanded="actionsExpanded">
{{ column.formatter ? column.formatter(row[column.key], row) : row[column.key] }}
</slot>
@@ -1,23 +1,30 @@
<template>
<div class="group/usage relative text-sm">
<div class="flex items-center gap-1.5">
<div class="flex flex-wrap items-center gap-1.5">
<span class="text-gray-500 dark:text-gray-400">{{ t('admin.users.today') }}:</span>
<span class="font-medium text-gray-900 dark:text-white">${{ today.toFixed(4) }}</span>
<Icon
<button
v-if="hasBreakdown"
name="infoCircle"
size="xs"
type="button"
:aria-label="t('admin.users.platformBreakdown')"
:aria-expanded="showBreakdown"
class="text-gray-400 dark:text-gray-500"
/>
@click.stop="showBreakdown = !showBreakdown"
@keydown.esc="showBreakdown = false"
@blur="showBreakdown = false"
>
<Icon name="infoCircle" size="xs" />
</button>
</div>
<div class="mt-0.5 flex items-center gap-1.5">
<div class="mt-0.5 flex flex-wrap items-center gap-1.5">
<span class="text-gray-500 dark:text-gray-400">{{ t('admin.users.total') }}:</span>
<span class="font-medium text-gray-900 dark:text-white">${{ total.toFixed(4) }}</span>
</div>
<div
v-if="hasBreakdown"
class="pointer-events-none absolute left-full top-0 z-50 ml-2 min-w-[220px] whitespace-nowrap rounded-md bg-gray-900 px-3 py-2 text-xs text-white opacity-0 shadow-xl transition-opacity duration-100 group-hover/usage:opacity-100 dark:bg-dark-600"
:class="showBreakdown ? 'block' : 'hidden md:group-hover/usage:block'"
class="pointer-events-none absolute right-0 top-full z-50 mt-2 w-64 max-w-[calc(100vw-4rem)] rounded-md bg-gray-900 px-3 py-2 text-xs text-white shadow-xl dark:bg-dark-600 md:left-full md:right-auto md:top-0 md:ml-2 md:mt-0"
>
<div class="mb-1.5 flex items-center justify-between gap-3 border-b border-white/10 pb-1 text-[11px] opacity-80">
<span>{{ t('admin.users.platformBreakdown') }}</span>
@@ -43,7 +50,7 @@
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { computed, ref } from 'vue'
import { useI18n } from 'vue-i18n'
import Icon from '@/components/icons/Icon.vue'
import type { PlatformUsage } from '@/api/admin/dashboard'
@@ -55,6 +62,7 @@ const props = defineProps<{
}>()
const { t } = useI18n()
const showBreakdown = ref(false)
// 与 UserDashboardStats 保持一致:把"总值 - 各平台之和"的差作为"其他"行展示,
// 避免 tooltip 内各平台费用加总与列首总值对不上。
@@ -2,7 +2,7 @@
<BaseDialog :show="show" :title="t('admin.users.attributes.title')" width="wide" @close="emit('close')">
<div class="space-y-4">
<!-- Header with Add Button -->
<div class="flex items-center justify-between">
<div class="flex flex-wrap items-center justify-between gap-3">
<p class="text-sm text-gray-500 dark:text-dark-400">
{{ t('admin.users.attributes.description') }}
</p>
@@ -48,7 +48,7 @@
<!-- Attribute Info -->
<div class="min-w-0 flex-1">
<div class="flex items-center gap-2">
<div class="flex flex-wrap items-center gap-2 [overflow-wrap:anywhere]">
<span class="font-medium text-gray-900 dark:text-white">{{ attr.name }}</span>
<span class="rounded bg-gray-100 px-1.5 py-0.5 font-mono text-xs text-gray-500 dark:bg-dark-700 dark:text-dark-400">
{{ attr.key }}
@@ -0,0 +1,31 @@
import { describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
import PlatformUsageBreakdown from '../PlatformUsageBreakdown.vue'
vi.mock('vue-i18n', () => ({ useI18n: () => ({ t: (key: string) => key }) }))
describe('PlatformUsageBreakdown touch controls', () => {
it('opens details by tapping and dismisses them with another tap, Escape or blur', async () => {
const wrapper = mount(PlatformUsageBreakdown, {
props: { today: 1, total: 2, byPlatform: [{ platform: 'openai', today_actual_cost: 1, total_actual_cost: 2 }] }
})
const trigger = wrapper.get('button')
expect(trigger.attributes('aria-expanded')).toBe('false')
await trigger.trigger('click')
expect(trigger.attributes('aria-expanded')).toBe('true')
expect(wrapper.text()).toContain('OpenAI')
await trigger.trigger('click')
expect(trigger.attributes('aria-expanded')).toBe('false')
await trigger.trigger('click')
await trigger.trigger('keydown', { key: 'Escape' })
expect(trigger.attributes('aria-expanded')).toBe('false')
await trigger.trigger('click')
await trigger.trigger('blur')
expect(trigger.attributes('aria-expanded')).toBe('false')
})
it('does not show a details control for zero usage', () => {
const wrapper = mount(PlatformUsageBreakdown, { props: { today: 0, total: 0 } })
expect(wrapper.find('button').exists()).toBe(false)
})
})
+8 -8
View File
@@ -5,7 +5,7 @@
<template #filters>
<div class="flex flex-wrap items-center gap-3">
<!-- Left: Search + Active Filters -->
<div class="flex flex-1 flex-wrap items-center gap-3">
<div class="flex min-w-0 basis-full flex-wrap items-center gap-3 md:basis-auto md:flex-1">
<!-- Search Box -->
<div class="relative w-full md:w-64">
<Icon
@@ -124,7 +124,7 @@
</div>
<!-- Right: Actions and Settings -->
<div class="flex flex-wrap items-center justify-end gap-2">
<div class="flex w-full flex-wrap items-center justify-start gap-2 md:w-auto md:justify-end">
<!-- Mobile: Secondary buttons (icon only) -->
<div class="flex items-center gap-2 md:contents">
<!-- Refresh Button -->
@@ -149,7 +149,7 @@
<!-- Dropdown menu -->
<div
v-if="showFilterDropdown"
class="absolute right-0 top-full z-50 mt-1 w-48 rounded-lg border border-gray-200 bg-white py-1 shadow-lg dark:border-dark-600 dark:bg-dark-800"
class="absolute left-0 top-full z-50 mt-1 max-h-80 w-48 overflow-y-auto rounded-lg border border-gray-200 bg-white py-1 shadow-lg dark:border-dark-600 dark:bg-dark-800 lg:left-auto lg:right-0"
>
<!-- Built-in filters -->
<button
@@ -205,7 +205,7 @@
<!-- Dropdown menu -->
<div
v-if="showColumnDropdown"
class="absolute right-0 top-full z-50 mt-1 max-h-80 w-48 overflow-y-auto rounded-lg border border-gray-200 bg-white py-1 shadow-lg dark:border-dark-600 dark:bg-dark-800"
class="absolute left-0 top-full z-50 mt-1 max-h-80 w-48 overflow-y-auto rounded-lg border border-gray-200 bg-white py-1 shadow-lg dark:border-dark-600 dark:bg-dark-800 lg:left-auto lg:right-0"
>
<button
v-for="col in toggleableColumns"
@@ -264,8 +264,8 @@
</button>
<!-- Create User Button (full width on mobile, auto width on desktop) -->
<button @click="showCreateModal = true" class="btn btn-primary flex-1 md:flex-initial">
<Icon name="plus" size="md" class="mr-2" />
<button @click="showCreateModal = true" class="btn btn-primary flex-1 whitespace-nowrap md:flex-initial">
<Icon name="plus" size="md" class="mr-2 shrink-0" />
{{ t('admin.users.createUser') }}
</button>
</div>
@@ -293,13 +293,13 @@
<template #cell-email="{ value }">
<div class="flex items-center gap-2">
<div
class="flex h-8 w-8 items-center justify-center rounded-full bg-primary-100 dark:bg-primary-900/30"
class="flex h-8 w-8 shrink-0 items-center justify-center rounded-full bg-primary-100 dark:bg-primary-900/30"
>
<span class="text-sm font-medium text-primary-700 dark:text-primary-300">
{{ value.charAt(0).toUpperCase() }}
</span>
</div>
<span class="font-medium text-gray-900 dark:text-white">{{ value }}</span>
<span class="min-w-0 [overflow-wrap:anywhere] font-medium text-gray-900 dark:text-white">{{ value }}</span>
</div>
</template>