liu
23 小时以前 18340ebdeb405be3ba01eb4d1600d9b26cee7ccd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { Recordable } from '@vben/types';
 
export * from './rangePickerProps';
export * from './routerHelper';
 
// 从共享包导出 URL 工具函数
export { isUrl } from '@vben/utils';
 
/**
 * 查找数组对象的某个下标
 * @param {Array} ary 查找的数组
 * @param {Function} fn 判断的方法
 */
type Fn<T = any> = (item: T, index: number, array: Array<T>) => boolean;
export const findIndex = <T = Recordable<any>>(
  ary: Array<T>,
  fn: Fn<T>,
): number => {
  if (ary.findIndex) {
    return ary.findIndex((item, index, array) => fn(item, index, array));
  }
  let index = -1;
  ary.some((item: T, i: number, ary: Array<T>) => {
    const ret: boolean = fn(item, i, ary);
    if (ret) {
      index = i;
      return true;
    }
    return false;
  });
  return index;
};
 
/**
 * 去掉表格列的固定(fixed)配置
 *
 * 用于「查看审批明细 / 详情」等只读场景:此时表格容器较窄,
 * 固定列会挤占可视宽度,把产品名称、单位、备注等列遮住。
 *
 * @param columns 原始表格列配置
 */
export function withoutFixedColumns<T>(columns?: null | T[]): T[] {
  return (columns ?? []).map((column) => {
    const { fixed: _fixed, ...rest } = column as Recordable<any>;
    return rest as unknown as T;
  });
}