You can not select more than 25 topics
Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- /*
- * @Author: 赵伟
- * @Date: 2024-11-29 09:27:19
- * @Description: 用于 BasicInfo 和 BasicTableInfo 组件的常用转化格式
- */
-
- // 格式化日期
- export { formatDate } from '@/utils/date';
-
- /**
- * 格式化字符串数组
- * @param value - 字符串数组
- * @returns 逗号分隔的字符串
- */
- export const formatList = (value: string[] | null | undefined): string => {
- if (
- value === undefined ||
- value === null ||
- Array.isArray(value) === false ||
- value.length === 0
- ) {
- return '--';
- }
- return value.join(',');
- };
-
- /**
- * 格式化布尔值
- * @param value - 布尔值
- * @returns "是" 或 "否"
- */
- export const formatBoolean = (value: boolean): string => {
- return value ? '是' : '否';
- };
-
- type FormatEnum = (value: string | number) => string;
-
- /**
- * 格式化枚举
- * @param options - 枚举选项
- * @returns 格式化枚举函数
- */
- export const formatEnum = (options: { value: string | number; label: string }[]): FormatEnum => {
- return (value: string | number) => {
- const option = options.find((item) => item.value === value);
- return option ? option.label : '--';
- };
- };
|