ソースを参照

perf: 修改分页不了的问题

曾坤森 1 週間 前
コミット
5ed8b46db1

+ 3 - 0
src/api/dict.ts

@@ -14,6 +14,7 @@ export interface DictRes {
   data: DataList[];
   message: string;
   code: string;
+  totalCount: number;
 }
 export interface DictParams {
   name: string | null;
@@ -26,6 +27,8 @@ export interface DictItemParams {
   name: string;
   dictCode: number;
   description: string;
+  pageIndex?: number;
+  pageSize?: number;
 }
 export interface ItemDataList {
   id?: string;

+ 17 - 5
src/views/dashboard/alam/index.vue

@@ -126,7 +126,7 @@ const pagination = reactive({
 const generateFormModel = () => {
   return {
     pageIndex: 1,
-    pageSize: 1000,
+    pageSize: 20,
     station: null,
   } as DeviceParams;
 };
@@ -147,12 +147,24 @@ useDictList(['DeviceType', 'DeviceStatus']).then(res => {
   deviceStatusList.value.push(...res['DeviceStatus']);
 });
 formModel.value.station = obj.value.station;
-fetchAlarmTotalList(formModel.value).then(res => {
-  tableData.value.push(...res.data);
-  setLoading(false);
-});
+function fetchData() {
+  setLoading(true);
+
+  fetchAlarmTotalList(formModel.value)
+    .then(res => {
+      pagination.current = formModel.value.pageIndex;
+      pagination.pageSize = pagination.pageSize;
+      pagination.total = res.totalCount;
+      tableData.value = res.data;
+    })
+    .finally(() => {
+      setLoading(false);
+    });
+}
+fetchData();
 const onPageChange = (current: number) => {
   formModel.value.pageIndex = current;
+  fetchData();
 };
 
 const handleClick = (value: DataList) => {

+ 10 - 4
src/views/system/dict-item/index.vue

@@ -87,6 +87,9 @@
         :scrollbar="true"
         @page-change="onPageChange"
       >
+        <template #index="{ rowIndex }">
+          {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }}
+        </template>
         <template #status="{ record }">
           <a-tag :color="record.status === 1 ? 'green' : 'red'">{{
             record.status ? t('tag.status.enable') : t('tag.status.disable')
@@ -150,8 +153,8 @@ const { loading, setLoading } = useLoading(true);
 const cloneColumns = computed(() => [
   {
     title: t('searchTable.table.number'),
-    dataIndex: 'number',
-    slotName: 'number',
+    dataIndex: 'index',
+    slotName: 'index',
     ellipsis: true,
     tooltip: true,
     width: 60,
@@ -209,13 +212,15 @@ const cloneColumns = computed(() => [
 
 const basePagination: Pagination = {
   current: 1,
-  pageSize: 20,
+  pageSize: 1000,
 };
 const pagination = reactive({
   ...basePagination,
 });
 const generateFormModel = () => {
   return {
+    pageIndex: 1,
+    pageSize: 1000,
     dictId: '0',
   } as DictItemParams;
 };
@@ -227,10 +232,11 @@ const listObj = ref<ItemDataList>({} as ItemDataList);
 
 const this_ = getCurrentInstance()?.appContext.config.globalProperties;
 function searchTable() {
-  // setLoading(true);
+  setLoading(true);
   formModel.value.dictId = id.toString();
   getDictItemList(formModel.value)
     .then(res => {
+      formModel.value.pageIndex = 1;
       pagination.current = 1;
       pagination.total = res.data.length;
       renderData.value = res.data;

+ 2 - 2
src/views/system/dict/index.vue

@@ -183,7 +183,7 @@ const cloneColumns = computed(() => [
 
 const basePagination: Pagination = {
   current: 1,
-  pageSize: 20,
+  pageSize: 1000,
 };
 const pagination = reactive({
   ...basePagination,
@@ -191,7 +191,7 @@ const pagination = reactive({
 const generateFormModel = () => {
   return {
     pageIndex: 1,
-    pageSize: 20,
+    pageSize: 1000,
     name: null,
     description: null,
   } as DictParams;