fix: vxe-grid proxy.query 分页兜底(page 缺省时返回全量,E2 重写覆盖了 QA cd7d4fd 修复导致 models/version 0 条)
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* - 降级:API 不可达时回退 localStorage(iaop.admin.models.v1,旧版 key),UI 标注「离线演示模式」;
|
||||
* - 迁移:检测 localStorage 有数据且服务端在线时提示导入。
|
||||
*/
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
|
||||
import { Page, VbenButton } from '@vben/common-ui';
|
||||
import { message } from 'antdv-next';
|
||||
@@ -62,15 +62,23 @@ const gridOptions: VxeTableGridOptions = {
|
||||
{ title: '操作', field: 'action', width: 170, slots: { default: 'action' } },
|
||||
],
|
||||
proxy: {
|
||||
query: async ({ page }) => ({
|
||||
items: models.value.slice((page.currentPage - 1) * page.pageSize, page.currentPage * page.pageSize),
|
||||
query: async ({ page } = {}) => {
|
||||
// page 可能缺省(分页未就绪的首次查询),兜底返回全量
|
||||
const cur = page?.currentPage ?? 1;
|
||||
const size = page?.pageSize ?? models.value.length || 10;
|
||||
return {
|
||||
items: models.value.slice((cur - 1) * size, cur * size),
|
||||
total: models.value.length,
|
||||
}),
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const [Grid, gridApi] = useVbenVxeGrid({ gridOptions });
|
||||
|
||||
// 数据变化自动刷新表格(双保险:init 的 refresh 与 watch 都触发 query)
|
||||
watch(models, () => gridApi.query());
|
||||
|
||||
async function refresh() {
|
||||
gridApi.query();
|
||||
}
|
||||
@@ -85,6 +93,8 @@ async function init() {
|
||||
try {
|
||||
await loadFromServer();
|
||||
online.value = true;
|
||||
await nextTick();
|
||||
refresh();
|
||||
// 迁移提示:本地有数据且服务端在线(且本地有服务端没有的模型)
|
||||
const local = loadLocal();
|
||||
const serverNames = new Set(models.value.map((m) => `${m.name}@${m.version}`));
|
||||
|
||||
@@ -40,10 +40,15 @@ const gridOptions: VxeTableGridOptions = {
|
||||
{ title: '说明', field: 'note', minWidth: 200 },
|
||||
],
|
||||
proxy: {
|
||||
query: async ({ page }) => ({
|
||||
items: rows.value.slice((page.currentPage - 1) * page.pageSize, page.currentPage * page.pageSize),
|
||||
query: async ({ page } = {}) => {
|
||||
// page 可能缺省(分页未就绪的首次查询),兜底返回全量
|
||||
const cur = page?.currentPage ?? 1;
|
||||
const size = page?.pageSize ?? rows.value.length || 10;
|
||||
return {
|
||||
items: rows.value.slice((cur - 1) * size, cur * size),
|
||||
total: rows.value.length,
|
||||
}),
|
||||
};
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user