Преглед на файлове

perf(components): 优化“协议内容”组件协议参数表格

1. 支持对识别结果进行排序
wangcong преди 2 месеца
родител
ревизия
7200c03104
променени са 2 файла, в които са добавени 44 реда и са изтрити 12 реда
  1. 6 4
      src/types/index.ts
  2. 38 8
      src/views/setup-protocol/ProtocolContent.vue

+ 6 - 4
src/types/index.ts

@@ -25,10 +25,12 @@ export interface PageData<T> {
 export interface PageParams {
   pageIndex: number;
   pageSize: number;
-  pageSorts?: {
-    column: string;
-    asc: boolean;
-  }[];
+  pageSorts?: PageSorts[];
+}
+
+export interface PageSorts {
+  column: string;
+  asc: boolean;
 }
 
 export interface OptionItem<T> {

+ 38 - 8
src/views/setup-protocol/ProtocolContent.vue

@@ -13,10 +13,10 @@ import { DictCode, ProtocolRecognitionResult, ProtocolType } from '@/constants';
 import CustomParams from './CustomParams.vue';
 import SelectStandardParams from './SelectStandardParams.vue';
 
-import type { FormInstance } from 'ant-design-vue';
+import type { FormInstance, TableProps } from 'ant-design-vue';
 import type { DefaultOptionType, SelectValue } from 'ant-design-vue/es/select';
-import type { Key } from 'ant-design-vue/es/table/interface';
-import type { CheckedType, FormRules, PageParams, ProtocolBaseInfo, ProtocolParamInfo } from '@/types';
+import type { Key, SorterResult } from 'ant-design-vue/es/table/interface';
+import type { CheckedType, FormRules, PageParams, PageSorts, ProtocolBaseInfo, ProtocolParamInfo } from '@/types';
 
 interface Props {
   info: Partial<ProtocolBaseInfo>;
@@ -224,9 +224,34 @@ const handleParamNameOrCodeChange = debounce(() => {
   getCurrentProtocolParams();
 }, 300);
 
-const handlePageChange = (page: number, pageSize: number) => {
-  pageParams.value.pageIndex = page;
-  pageParams.value.pageSize = pageSize;
+const handleParamTableChange: TableProps['onChange'] = (pagination, filters, sorter) => {
+  pageParams.value.pageIndex = pagination.current || 1;
+  pageParams.value.pageSize = pagination.pageSize || 10;
+
+  let sorts: SorterResult[];
+
+  if (Array.isArray(sorter)) {
+    sorts = sorter;
+  } else {
+    sorts = [sorter];
+  }
+
+  sorts = sorts.filter((item) => item.field !== undefined && item.order !== undefined);
+
+  if (sorts.length) {
+    pageParams.value.pageSorts = sorts.map<PageSorts>((item) => ({
+      column: item.field as string,
+      asc: item.order === 'ascend',
+    }));
+  } else {
+    pageParams.value.pageSorts = [
+      {
+        column: 'id',
+        asc: true,
+      },
+    ];
+  }
+
   selectedParamIds.value = [];
   getCurrentProtocolParams();
 };
@@ -475,8 +500,8 @@ defineExpose({
         showSizeChanger: true,
         hideOnSinglePage: false,
         showTotal: (total) => $t('common.pageTotal', { total }),
-        onChange: handlePageChange,
       }"
+      @change="handleParamTableChange"
     >
       <ATableColumn
         :title="$t('setupProtocol.protocolParamFields.customParamName')"
@@ -484,7 +509,12 @@ defineExpose({
         :width="180"
         fixed="left"
       />
-      <ATableColumn :title="$t('setupProtocol.protocolParamFields.result')" data-index="recognizeResult" :width="110">
+      <ATableColumn
+        :title="$t('setupProtocol.protocolParamFields.result')"
+        data-index="recognizeResult"
+        :width="110"
+        :sorter="true"
+      >
         <template #default="{ record }">
           <div
             :class="[