Ben Lin
2024-06-25 4969a965adc32d3194763edfa4a4f74a7f26cd06
src/components/Upload/src/props.ts
@@ -1,15 +1,46 @@
/*
 * @Description: file content
 * @Author: your name
 * @version:
 * @Date: 2024-03-24 11:16:46
 * @LastEditors: your name
 * @LastEditTime: 2024-06-13 14:47:33
 */
import type { PropType } from 'vue';
import { FileBasicColumn } from './typing';
import { BaseFileItem, FileBasicColumn } from './types/typing';
import type { Options } from 'sortablejs';
import { Merge } from '@/utils/types';
import { propTypes } from '@/utils/propTypes';
import { BasicColumn } from '@/components/Table';
type SortableOptions = Merge<
  Omit<Options, 'onEnd'>,
  {
    onAfterEnd?: <T = any, R = any>(params: T) => R;
    // ...可扩展
  }
>;
export type handleFnKey = "record" | "valueKey" | "uidKey"
export type previewColumnsFnType = {
  handleRemove: (record: Record<handleFnKey, any>) => any;
  handleAdd: (record: Record<handleFnKey, any>) => any;
};
export const previewType = {
  previewColumns: {
    type: [Array, Function] as PropType<
      BasicColumn[] | ((arg: previewColumnsFnType) => BasicColumn[])
    >,
    required: false,
  },
  beforePreviewData: {
    type: Function as PropType<(arg: BaseFileItem[] | any) => Recordable<any>>,
    default: null,
    required: false,
  },
};
type ListType = 'text' | 'picture' | 'picture-card';
export const basicProps = {
  disabled: { type: Boolean, default: false },
  listType: {
    type: String as PropType<ListType>,
    default: 'picture-card',
  },
  helpText: {
    type: String as PropType<string>,
    default: '',
@@ -22,7 +53,7 @@
  // 最大数量的文件,Infinity不限制
  maxNumber: {
    type: Number as PropType<number>,
    default: Infinity,
    default: 1,
  },
  // 根据后缀,或者其他
  accept: {
@@ -31,7 +62,7 @@
  },
  multiple: {
    type: Boolean as PropType<boolean>,
    default: true,
    default: false,
  },
  uploadParams: {
    type: Object as PropType<any>,
@@ -50,6 +81,17 @@
    type: String as PropType<string>,
    default: null,
  },
  fileListOpenDrag: {
    type: Boolean,
    default: true,
  },
  fileListDragOptions: {
    type: Object as PropType<SortableOptions>,
    default: () => ({}),
  },
  // support xxx.xxx.xx
  resultField: propTypes.string.def(''),
};
export const uploadContainerProps = {
@@ -66,18 +108,24 @@
    type: Boolean as PropType<boolean>,
    default: false,
  },
  ...previewType,
};
export const previewProps = {
  value: {
    type: Array as PropType<string[]>,
    type: Array as PropType<BaseFileItem[] | any[]>,
    default: () => [],
  },
  maxNumber: {
    type: Number as PropType<number>,
    default: 1,
  },
  ...previewType,
};
export const fileListProps = {
  columns: {
    type: Array as PropType<FileBasicColumn[]>,
    type: Array as PropType<BasicColumn[] | FileBasicColumn[]>,
    default: null,
  },
  actionColumn: {
@@ -88,4 +136,12 @@
    type: Array as PropType<any[]>,
    default: null,
  },
  openDrag: {
    type: Boolean,
    default: false,
  },
  dragOptions: {
    type: Object as PropType<SortableOptions>,
    default: () => ({}),
  },
};