@ysgroup/ui 0.1.14 → 0.1.16
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.
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import { FIELD_SPECS, ENUM_META } from "@ysgroup/contracts";
|
|
|
7
7
|
import { enumLabel } from "../tokens-runtime";
|
|
8
8
|
import YsFormDialog from "./YsFormDialog.vue";
|
|
9
9
|
import YsRowActionMenu from "./YsRowActionMenu.vue";
|
|
10
|
+
import YsTableToolbar from "./YsTableToolbar.vue";
|
|
10
11
|
|
|
11
12
|
interface FieldSpec {
|
|
12
13
|
key: string;
|
|
@@ -79,7 +80,6 @@ const dialogOpen = ref(false);
|
|
|
79
80
|
const editing = ref<Record<string, unknown> | null>(null);
|
|
80
81
|
const currentPage = ref(1);
|
|
81
82
|
const pageSize = ref(20);
|
|
82
|
-
const PAGE_SIZES = [20, 50, 100];
|
|
83
83
|
|
|
84
84
|
const allSpecs = computed<FieldSpec[]>(() => (FIELD_SPECS as unknown as Record<string, FieldSpec[]>)[props.table] ?? []);
|
|
85
85
|
|
|
@@ -96,11 +96,7 @@ const filtered = computed(() => {
|
|
|
96
96
|
const kw = keyword.value.trim().toLowerCase();
|
|
97
97
|
if (!kw) return props.rows;
|
|
98
98
|
return props.rows.filter((r) =>
|
|
99
|
-
displayColumns.value.some((c) =>
|
|
100
|
-
String(r[c.key] ?? "")
|
|
101
|
-
.toLowerCase()
|
|
102
|
-
.includes(kw),
|
|
103
|
-
),
|
|
99
|
+
displayColumns.value.some((c) => display(r, c).toLowerCase().includes(kw)),
|
|
104
100
|
);
|
|
105
101
|
});
|
|
106
102
|
|
|
@@ -122,8 +118,6 @@ const paged = computed(() => {
|
|
|
122
118
|
return filtered.value.slice(start, start + pageSize.value);
|
|
123
119
|
});
|
|
124
120
|
|
|
125
|
-
const showPagination = computed(() => filtered.value.length > 20);
|
|
126
|
-
|
|
127
121
|
function display(row: Record<string, unknown>, f: FieldSpec): string {
|
|
128
122
|
const v = props.rowDisplay ? props.rowDisplay(row, f.key, row[f.key]) : row[f.key];
|
|
129
123
|
if (f.widget === "switch") return v ? "是" : "否";
|
|
@@ -162,11 +156,9 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
162
156
|
|
|
163
157
|
<template>
|
|
164
158
|
<div class="ys-crud">
|
|
165
|
-
<
|
|
166
|
-
<el-
|
|
167
|
-
|
|
168
|
-
<el-button v-if="!readonly" type="primary" @click="onCreate">{{ createLabel || "新建" }}</el-button>
|
|
169
|
-
</div>
|
|
159
|
+
<YsTableToolbar v-model:keyword="keyword">
|
|
160
|
+
<template #actions><el-button v-if="!readonly" type="primary" @click="onCreate">{{ createLabel || "新建" }}</el-button></template>
|
|
161
|
+
</YsTableToolbar>
|
|
170
162
|
|
|
171
163
|
<el-table :data="paged" v-loading="loading" stripe border size="small" table-layout="fixed" row-key="_id">
|
|
172
164
|
<el-table-column v-for="c in displayColumns" :key="c.key" :label="c.title" :width="columnWidth(c)" show-overflow-tooltip>
|
|
@@ -187,15 +179,10 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
187
179
|
</el-table-column>
|
|
188
180
|
</el-table>
|
|
189
181
|
|
|
190
|
-
<
|
|
191
|
-
v-if="showPagination"
|
|
182
|
+
<YsTablePagination
|
|
192
183
|
v-model:current-page="currentPage"
|
|
193
184
|
v-model:page-size="pageSize"
|
|
194
|
-
:page-sizes="PAGE_SIZES"
|
|
195
185
|
:total="filtered.length"
|
|
196
|
-
layout="total, sizes, prev, pager, next"
|
|
197
|
-
class="ys-crud__pagination"
|
|
198
|
-
@size-change="currentPage = 1"
|
|
199
186
|
/>
|
|
200
187
|
|
|
201
188
|
<YsFormDialog v-if="!externalEditor" v-model="dialogOpen" :table="table" :record="editing" :hidden="hiddenInForm" :saving="saving" @submit="onSubmit" />
|
|
@@ -203,16 +190,4 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
203
190
|
</template>
|
|
204
191
|
|
|
205
192
|
<style scoped>
|
|
206
|
-
.ys-crud__toolbar {
|
|
207
|
-
display: flex;
|
|
208
|
-
align-items: center;
|
|
209
|
-
margin-bottom: 12px;
|
|
210
|
-
}
|
|
211
|
-
.ys-crud__spacer {
|
|
212
|
-
flex: 1;
|
|
213
|
-
}
|
|
214
|
-
.ys-crud__pagination {
|
|
215
|
-
margin-top: 12px;
|
|
216
|
-
justify-content: flex-end;
|
|
217
|
-
}
|
|
218
193
|
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{
|
|
3
|
+
total: number;
|
|
4
|
+
currentPage: number;
|
|
5
|
+
pageSize: number;
|
|
6
|
+
}>();
|
|
7
|
+
|
|
8
|
+
const emit = defineEmits<{
|
|
9
|
+
"update:currentPage": [value: number];
|
|
10
|
+
"update:pageSize": [value: number];
|
|
11
|
+
}>();
|
|
12
|
+
|
|
13
|
+
const PAGE_SIZES = [20, 50, 100];
|
|
14
|
+
|
|
15
|
+
function updatePageSize(value: number): void {
|
|
16
|
+
emit("update:pageSize", value);
|
|
17
|
+
emit("update:currentPage", 1);
|
|
18
|
+
}
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<el-pagination
|
|
23
|
+
v-if="total > 20"
|
|
24
|
+
:current-page="currentPage"
|
|
25
|
+
:page-size="pageSize"
|
|
26
|
+
:page-sizes="PAGE_SIZES"
|
|
27
|
+
:total="total"
|
|
28
|
+
layout="total, sizes, prev, pager, next"
|
|
29
|
+
class="ys-table-pagination"
|
|
30
|
+
@update:current-page="emit('update:currentPage', $event)"
|
|
31
|
+
@update:page-size="updatePageSize"
|
|
32
|
+
/>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<style scoped>
|
|
36
|
+
.ys-table-pagination {
|
|
37
|
+
margin-top: 12px;
|
|
38
|
+
justify-content: flex-end;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
defineProps<{
|
|
3
|
+
keyword: string;
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
}>();
|
|
6
|
+
|
|
7
|
+
const emit = defineEmits<{
|
|
8
|
+
"update:keyword": [value: string];
|
|
9
|
+
}>();
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<div class="ys-table-toolbar">
|
|
14
|
+
<el-input
|
|
15
|
+
:model-value="keyword"
|
|
16
|
+
:placeholder="placeholder || '搜索'"
|
|
17
|
+
clearable
|
|
18
|
+
class="ys-table-toolbar__search"
|
|
19
|
+
@update:model-value="emit('update:keyword', String($event))"
|
|
20
|
+
/>
|
|
21
|
+
<slot />
|
|
22
|
+
<div class="ys-table-toolbar__spacer" />
|
|
23
|
+
<slot name="actions" />
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
|
|
27
|
+
<style scoped>
|
|
28
|
+
.ys-table-toolbar {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
gap: 10px;
|
|
32
|
+
margin-bottom: 12px;
|
|
33
|
+
flex-wrap: wrap;
|
|
34
|
+
}
|
|
35
|
+
.ys-table-toolbar__search {
|
|
36
|
+
width: 200px;
|
|
37
|
+
}
|
|
38
|
+
.ys-table-toolbar__spacer {
|
|
39
|
+
flex: 1;
|
|
40
|
+
}
|
|
41
|
+
</style>
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* @ysgroup/ui —— 平台组件库(基于 Element Plus 封装,令牌来自 @ysgroup/theme)。 */
|
|
2
2
|
|
|
3
3
|
export { default as YsCrudTable } from "./components/YsCrudTable.vue";
|
|
4
|
+
export { default as YsTableToolbar } from "./components/YsTableToolbar.vue";
|
|
5
|
+
export { default as YsTablePagination } from "./components/YsTablePagination.vue";
|
|
4
6
|
export { default as YsRowActionMenu } from "./components/YsRowActionMenu.vue";
|
|
5
7
|
export type { YsRowAction } from "./components/YsRowActionMenu.vue";
|
|
6
8
|
export { default as YsFormDialog } from "./components/YsFormDialog.vue";
|