|
@@ -5,8 +5,9 @@ import { fileContentTypeRegExp } from '@/constants';
|
|
|
|
|
|
import { fetchWithTimeout } from './fetch';
|
|
import { fetchWithTimeout } from './fetch';
|
|
|
|
|
|
|
|
+import type { SorterResult } from 'ant-design-vue/es/table/interface';
|
|
import type { GlobalToken } from 'ant-design-vue/es/theme';
|
|
import type { GlobalToken } from 'ant-design-vue/es/theme';
|
|
-import type { ApiResponse } from '@/types';
|
|
|
|
|
|
+import type { ApiResponse, PageSorts } from '@/types';
|
|
|
|
|
|
export const request = async <T>(url: string, init: RequestInit = {}, timeout?: number): Promise<T> => {
|
|
export const request = async <T>(url: string, init: RequestInit = {}, timeout?: number): Promise<T> => {
|
|
const headers: HeadersInit = {};
|
|
const headers: HeadersInit = {};
|
|
@@ -172,3 +173,33 @@ export const downloadBlob = (blob: Blob, name: string) => {
|
|
document.body.removeChild(a);
|
|
document.body.removeChild(a);
|
|
window.URL.revokeObjectURL(url);
|
|
window.URL.revokeObjectURL(url);
|
|
};
|
|
};
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 根据表格排序配置生成分页查询时的字段排序数组
|
|
|
|
+ * @param sorter 表格进行排序的字段数组
|
|
|
|
+ */
|
|
|
|
+export const getTablePageSorts = (sorter: SorterResult | SorterResult[]): PageSorts[] => {
|
|
|
|
+ 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) {
|
|
|
|
+ return sorts.map<PageSorts>((item) => ({
|
|
|
|
+ column: item.field as string,
|
|
|
|
+ asc: item.order === 'ascend',
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [
|
|
|
|
+ {
|
|
|
|
+ column: 'id',
|
|
|
|
+ asc: true,
|
|
|
|
+ },
|
|
|
|
+ ];
|
|
|
|
+};
|