@ysgroup/ui 0.1.4 → 0.1.5
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 +37 -3
- 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";
|
|
@@ -76,6 +77,9 @@ const emit = defineEmits<{
|
|
|
76
77
|
const keyword = ref("");
|
|
77
78
|
const dialogOpen = ref(false);
|
|
78
79
|
const editing = ref<Record<string, unknown> | null>(null);
|
|
80
|
+
const currentPage = ref(1);
|
|
81
|
+
const pageSize = ref(20);
|
|
82
|
+
const PAGE_SIZES = [20, 50, 100];
|
|
79
83
|
|
|
80
84
|
const allSpecs = computed<FieldSpec[]>(
|
|
81
85
|
() => (FIELD_SPECS as unknown as Record<string, FieldSpec[]>)[props.table] ?? [],
|
|
@@ -100,6 +104,21 @@ const filtered = computed(() => {
|
|
|
100
104
|
);
|
|
101
105
|
});
|
|
102
106
|
|
|
107
|
+
// 搜索词变化时重置到第一页
|
|
108
|
+
watch(keyword, () => { currentPage.value = 1; });
|
|
109
|
+
// 行数变化(外部数据更新)时若当前页超出则回到第一页
|
|
110
|
+
watch(() => filtered.value.length, (len) => {
|
|
111
|
+
const maxPage = Math.max(1, Math.ceil(len / pageSize.value));
|
|
112
|
+
if (currentPage.value > maxPage) currentPage.value = 1;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const paged = computed(() => {
|
|
116
|
+
const start = (currentPage.value - 1) * pageSize.value;
|
|
117
|
+
return filtered.value.slice(start, start + pageSize.value);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const showPagination = computed(() => filtered.value.length > 20);
|
|
121
|
+
|
|
103
122
|
function display(row: Record<string, unknown>, f: FieldSpec): string {
|
|
104
123
|
const v = props.rowDisplay ? props.rowDisplay(row, f.key, row[f.key]) : row[f.key];
|
|
105
124
|
if (f.widget === "switch") return v ? "是" : "否";
|
|
@@ -149,7 +168,7 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
149
168
|
<el-button v-if="!readonly" type="primary" @click="onCreate">{{ createLabel || "新建" }}</el-button>
|
|
150
169
|
</div>
|
|
151
170
|
|
|
152
|
-
<el-table :data="
|
|
171
|
+
<el-table :data="paged" v-loading="loading" stripe border size="small" table-layout="fixed" row-key="_id">
|
|
153
172
|
<el-table-column
|
|
154
173
|
v-for="c in displayColumns"
|
|
155
174
|
:key="c.key"
|
|
@@ -170,6 +189,17 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
170
189
|
</el-table-column>
|
|
171
190
|
</el-table>
|
|
172
191
|
|
|
192
|
+
<el-pagination
|
|
193
|
+
v-if="showPagination"
|
|
194
|
+
v-model:current-page="currentPage"
|
|
195
|
+
v-model:page-size="pageSize"
|
|
196
|
+
:page-sizes="PAGE_SIZES"
|
|
197
|
+
:total="filtered.length"
|
|
198
|
+
layout="total, sizes, prev, pager, next"
|
|
199
|
+
class="ys-crud__pagination"
|
|
200
|
+
@size-change="currentPage = 1"
|
|
201
|
+
/>
|
|
202
|
+
|
|
173
203
|
<YsFormDialog
|
|
174
204
|
v-if="!externalEditor"
|
|
175
205
|
v-model="dialogOpen"
|
|
@@ -191,4 +221,8 @@ function onSubmit(payload: Record<string, unknown>) {
|
|
|
191
221
|
.ys-crud__spacer {
|
|
192
222
|
flex: 1;
|
|
193
223
|
}
|
|
224
|
+
.ys-crud__pagination {
|
|
225
|
+
margin-top: 12px;
|
|
226
|
+
justify-content: flex-end;
|
|
227
|
+
}
|
|
194
228
|
</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";
|