@ysgroup/ui 0.1.4 → 0.1.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.
- package/package.json +2 -2
- package/src/components/YsCrudTable.vue +39 -4
- package/src/index.ts +0 -2
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<!-- YsCrudTable —— 只读表格 + 行"编辑"按钮呼出 YsFormDialog。
|
|
2
|
-
规范:表格上不挂载任何行内编辑组件(体验与性能)。
|
|
2
|
+
规范:表格上不挂载任何行内编辑组件(体验与性能)。
|
|
3
|
+
超过 20 条自动显示分页器(20 / 50 / 100 档,默认每页 20 条)。 -->
|
|
3
4
|
<script setup lang="ts">
|
|
4
|
-
import { computed, ref } from "vue";
|
|
5
|
+
import { computed, ref, watch } from "vue";
|
|
5
6
|
import { ElMessageBox } from "element-plus";
|
|
6
7
|
import { FIELD_SPECS, ENUM_META } from "@ysgroup/contracts";
|
|
7
8
|
import { enumLabel } from "../tokens-runtime";
|
|
@@ -64,6 +65,7 @@ const props = defineProps<{
|
|
|
64
65
|
rowDisplay?: (row: Record<string, unknown>, field: string, value: unknown) => unknown;
|
|
65
66
|
saving?: boolean;
|
|
66
67
|
externalEditor?: boolean;
|
|
68
|
+
actionWidth?: number;
|
|
67
69
|
}>();
|
|
68
70
|
|
|
69
71
|
const emit = defineEmits<{
|
|
@@ -76,6 +78,9 @@ const emit = defineEmits<{
|
|
|
76
78
|
const keyword = ref("");
|
|
77
79
|
const dialogOpen = ref(false);
|
|
78
80
|
const editing = ref<Record<string, unknown> | null>(null);
|
|
81
|
+
const currentPage = ref(1);
|
|
82
|
+
const pageSize = ref(20);
|
|
83
|
+
const PAGE_SIZES = [20, 50, 100];
|
|
79
84
|
|
|
80
85
|
const allSpecs = computed<FieldSpec[]>(
|
|
81
86
|
() => (FIELD_SPECS as unknown as Record<string, FieldSpec[]>)[props.table] ?? [],
|
|
@@ -100,6 +105,21 @@ const filtered = computed(() => {
|
|
|
100
105
|
);
|
|
101
106
|
});
|
|
102
107
|
|
|
108
|
+
// 搜索词变化时重置到第一页
|
|
109
|
+
watch(keyword, () => { currentPage.value = 1; });
|
|
110
|
+
// 行数变化(外部数据更新)时若当前页超出则回到第一页
|
|
111
|
+
watch(() => filtered.value.length, (len) => {
|
|
112
|
+
const maxPage = Math.max(1, Math.ceil(len / pageSize.value));
|
|
113
|
+
if (currentPage.value > maxPage) currentPage.value = 1;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const paged = computed(() => {
|
|
117
|
+
const start = (currentPage.value - 1) * pageSize.value;
|
|
118
|
+
return filtered.value.slice(start, start + pageSize.value);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const showPagination = computed(() => filtered.value.length > 20);
|
|
122
|
+
|
|
103
123
|
function display(row: Record<string, unknown>, f: FieldSpec): string {
|
|
104
124
|
const v = props.rowDisplay ? props.rowDisplay(row, f.key, row[f.key]) : row[f.key];
|
|
105
125
|
if (f.widget === "switch") return v ? "是" : "否";
|
|
@@ -149,7 +169,7 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
149
169
|
<el-button v-if="!readonly" type="primary" @click="onCreate">{{ createLabel || "新建" }}</el-button>
|
|
150
170
|
</div>
|
|
151
171
|
|
|
152
|
-
<el-table :data="
|
|
172
|
+
<el-table :data="paged" v-loading="loading" stripe border size="small" table-layout="fixed" row-key="_id">
|
|
153
173
|
<el-table-column
|
|
154
174
|
v-for="c in displayColumns"
|
|
155
175
|
:key="c.key"
|
|
@@ -159,7 +179,7 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
159
179
|
>
|
|
160
180
|
<template #default="{ row }">{{ display(row, c) }}</template>
|
|
161
181
|
</el-table-column>
|
|
162
|
-
<el-table-column v-if="!readonly" label="操作" width="260">
|
|
182
|
+
<el-table-column v-if="!readonly" label="操作" :width="actionWidth ?? 260">
|
|
163
183
|
<template #default="{ row }">
|
|
164
184
|
<el-button size="small" @click="onEdit(row)">编辑</el-button>
|
|
165
185
|
<slot name="row-actions" :row="row" />
|
|
@@ -170,6 +190,17 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
170
190
|
</el-table-column>
|
|
171
191
|
</el-table>
|
|
172
192
|
|
|
193
|
+
<el-pagination
|
|
194
|
+
v-if="showPagination"
|
|
195
|
+
v-model:current-page="currentPage"
|
|
196
|
+
v-model:page-size="pageSize"
|
|
197
|
+
:page-sizes="PAGE_SIZES"
|
|
198
|
+
:total="filtered.length"
|
|
199
|
+
layout="total, sizes, prev, pager, next"
|
|
200
|
+
class="ys-crud__pagination"
|
|
201
|
+
@size-change="currentPage = 1"
|
|
202
|
+
/>
|
|
203
|
+
|
|
173
204
|
<YsFormDialog
|
|
174
205
|
v-if="!externalEditor"
|
|
175
206
|
v-model="dialogOpen"
|
|
@@ -191,4 +222,8 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
191
222
|
.ys-crud__spacer {
|
|
192
223
|
flex: 1;
|
|
193
224
|
}
|
|
225
|
+
.ys-crud__pagination {
|
|
226
|
+
margin-top: 12px;
|
|
227
|
+
justify-content: flex-end;
|
|
228
|
+
}
|
|
194
229
|
</style>
|
package/src/index.ts
CHANGED
|
@@ -7,5 +7,3 @@ export { default as YsLoginPage } from "./components/YsLoginPage.vue";
|
|
|
7
7
|
export { default as YsSettingsCenterDialog } from "./components/YsSettingsCenterDialog.vue";
|
|
8
8
|
export { default as YsPortalGrid } from "./components/YsPortalGrid.vue";
|
|
9
9
|
export { enumOptions, enumLabel, type EnumOption } from "./tokens-runtime";
|
|
10
|
-
|
|
11
|
-
export const YS_UI_VERSION = "0.1.4";
|