xto-fronted 0.9.4 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,157 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * FilterBar 筛选栏
4
+ *
5
+ * 统一列表页筛选区排版:inline 表单 + 内建「查询/重置」操作区。
6
+ * 筛选项超过 collapsedCount 时自动支持折叠,收起时只显示前 N 项,
7
+ * 点击「展开/收起」切换,避免筛选区占据过多纵向空间。
8
+ *
9
+ * 用法:
10
+ * <FilterBar :model="searchForm" :collapsed-count="3" @search="load" @reset="onReset">
11
+ * <x-form-item label="平台" name="clientId">...</x-form-item>
12
+ * </FilterBar>
13
+ */
14
+ import { computed, nextTick, onMounted, onUpdated, ref, watch } from 'vue'
15
+ import { Icon } from '@xto/base'
16
+
17
+ defineOptions({
18
+ name: 'FilterBar'
19
+ })
20
+
21
+ const props = withDefaults(
22
+ defineProps<{
23
+ // 表单数据对象,与 x-form 的 model 一致
24
+ model: Record<string, any>
25
+ // 是否启用折叠
26
+ collapsible?: boolean
27
+ // 收起时显示的筛选项数量
28
+ collapsedCount?: number
29
+ // 初始是否收起
30
+ defaultCollapsed?: boolean
31
+ searchText?: string
32
+ resetText?: string
33
+ searchLoading?: boolean
34
+ }>(),
35
+ {
36
+ collapsible: true,
37
+ collapsedCount: 3,
38
+ defaultCollapsed: true,
39
+ searchText: '查询',
40
+ resetText: '重置',
41
+ searchLoading: false
42
+ }
43
+ )
44
+
45
+ const emit = defineEmits<{
46
+ search: []
47
+ reset: []
48
+ }>()
49
+
50
+ const formRef = ref<any>(null)
51
+ const collapsed = ref(props.defaultCollapsed)
52
+ const totalCount = ref(0)
53
+
54
+ // 应用折叠:收起时隐藏第 collapsedCount 项之后的筛选项。
55
+ // 直接操作 slot 渲染出的 .x-form-item(排除操作区),v-if 会销毁组件丢状态,不采用
56
+ const refreshItems = () => {
57
+ const formEl: HTMLElement | undefined = formRef.value?.$el
58
+ if (!formEl) return
59
+ const items = formEl.querySelectorAll(':scope > .x-form-item:not(.filter-bar__ops)')
60
+ totalCount.value = items.length
61
+ items.forEach((el, i) => {
62
+ ;(el as HTMLElement).style.display = collapsed.value && i >= props.collapsedCount ? 'none' : ''
63
+ })
64
+ }
65
+
66
+ const hasOverflow = computed(() => props.collapsible && totalCount.value > props.collapsedCount)
67
+
68
+ const toggleCollapsed = () => {
69
+ collapsed.value = !collapsed.value
70
+ }
71
+
72
+ watch(collapsed, () => nextTick(refreshItems))
73
+ onMounted(() => nextTick(refreshItems))
74
+ // 动态筛选项(v-if 切换)或折叠状态变化后重新应用
75
+ onUpdated(() => nextTick(refreshItems))
76
+
77
+ const handleSearch = () => emit('search')
78
+ const handleReset = () => emit('reset')
79
+
80
+ defineExpose({
81
+ /** 展开筛选项 */
82
+ expand: () => { collapsed.value = false },
83
+ /** 收起筛选项 */
84
+ collapse: () => { collapsed.value = true }
85
+ })
86
+ </script>
87
+
88
+ <template>
89
+ <x-card class="filter-bar">
90
+ <x-form
91
+ ref="formRef"
92
+ :model="model"
93
+ layout="inline"
94
+ @submit="handleSearch"
95
+ @reset="handleReset"
96
+ >
97
+ <slot />
98
+ <x-form-item class="filter-bar__ops">
99
+ <x-button
100
+ type="primary"
101
+ size="small"
102
+ html-type="submit"
103
+ :loading="searchLoading"
104
+ >{{ searchText }}</x-button>
105
+ <x-button size="small" html-type="reset">{{ resetText }}</x-button>
106
+ <x-button
107
+ v-if="hasOverflow"
108
+ type="text"
109
+ size="small"
110
+ class="filter-bar__toggle"
111
+ @click="toggleCollapsed"
112
+ >
113
+ {{ collapsed ? '展开' : '收起' }}
114
+ <Icon
115
+ name="caret-down"
116
+ :size="12"
117
+ class="filter-bar__caret"
118
+ :class="{ 'is-open': !collapsed }"
119
+ />
120
+ </x-button>
121
+ </x-form-item>
122
+ </x-form>
123
+ </x-card>
124
+ </template>
125
+
126
+ <style lang="scss" scoped>
127
+ .filter-bar {
128
+ display: block;
129
+ // 卡片间统一间距
130
+ margin-bottom: 4px;
131
+
132
+ :deep(.x-card__body) {
133
+ padding: 5px 8px !important;
134
+ }
135
+ }
136
+
137
+ .filter-bar__ops {
138
+ :deep(.x-button + .x-button) {
139
+ margin-left: 8px;
140
+ }
141
+ }
142
+
143
+ .filter-bar__toggle {
144
+ :deep(.x-icon),
145
+ .filter-bar__caret {
146
+ margin-left: 2px;
147
+ }
148
+ }
149
+
150
+ .filter-bar__caret {
151
+ transition: transform var(--xto-transition-duration-fast, 150ms) var(--xto-transition-easing, cubic-bezier(0.4, 0, 0.2, 1));
152
+
153
+ &.is-open {
154
+ transform: rotate(180deg);
155
+ }
156
+ }
157
+ </style>
@@ -211,7 +211,8 @@ const showMixSidebar = computed(() => {
211
211
  flex: 1;
212
212
  overflow: auto;
213
213
  background-color: var(--xto-bg-color-page, #F7F8FA);
214
- padding: 0;
214
+ // 页面统一留白:所有使用脚手架的系统一致,不再各页面自定
215
+ padding: 4px;
215
216
  }
216
217
  }
217
218
  </style>
@@ -0,0 +1,74 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * TableCard 表格卡片
4
+ *
5
+ * 统一列表页表格区排版(方案 B):操作按钮放表格卡片 header 右侧,
6
+ * 与卡片标题同行,取代单独占一行的工具栏卡片。
7
+ * 不传 title/actions/header 时与普通 x-card 完全一致。
8
+ *
9
+ * 用法:
10
+ * <TableCard title="用户列表" class="table-card">
11
+ * <template #actions>
12
+ * <x-button type="primary" size="small" @click="add">新增用户</x-button>
13
+ * </template>
14
+ * <x-table ... />
15
+ * </TableCard>
16
+ */
17
+ defineOptions({
18
+ name: 'TableCard'
19
+ })
20
+
21
+ defineProps<{
22
+ /** 卡片标题(header 左侧),也可用 #header 插槽自定义 */
23
+ title?: string
24
+ }>()
25
+ </script>
26
+
27
+ <template>
28
+ <x-card class="table-card-frame">
29
+ <template v-if="title || $slots.header || $slots.actions" #header>
30
+ <div class="table-card__header">
31
+ <div class="table-card__title">
32
+ <slot name="header">{{ title }}</slot>
33
+ </div>
34
+ <div class="table-card__actions">
35
+ <slot name="actions" />
36
+ </div>
37
+ </div>
38
+ </template>
39
+ <slot />
40
+ </x-card>
41
+ </template>
42
+
43
+ <style lang="scss" scoped>
44
+ .table-card-frame {
45
+ display: block;
46
+ // 卡片间统一间距
47
+ margin-bottom: 4px;
48
+
49
+ :deep(.x-card__header) {
50
+ padding: 10px 12px;
51
+ }
52
+ }
53
+
54
+ .table-card__header {
55
+ display: flex;
56
+ align-items: center;
57
+ justify-content: space-between;
58
+ gap: 12px;
59
+ }
60
+
61
+ .table-card__title {
62
+ font-size: 14px;
63
+ font-weight: 600;
64
+ color: var(--xto-color-text-primary, #1F2329);
65
+ }
66
+
67
+ .table-card__actions {
68
+ display: flex;
69
+ align-items: center;
70
+ flex-wrap: wrap;
71
+ gap: 8px;
72
+ margin-left: auto;
73
+ }
74
+ </style>
package/src/index.ts CHANGED
@@ -110,6 +110,8 @@ export { default as Header } from './components/Layout/Header.vue'
110
110
  export { default as Sidebar } from './components/Layout/Sidebar.vue'
111
111
  export { default as Tabs } from './components/Layout/Tabs.vue'
112
112
  export { default as Footer } from './components/Layout/Footer.vue'
113
+ export { default as FilterBar } from './components/FilterBar.vue'
114
+ export { default as TableCard } from './components/TableCard.vue'
113
115
 
114
116
  // 错误页面组件
115
117
  export { default as Login } from './views/login/index.vue'