perf 改进表格图片、文件展示组件使用方式,减少冗余

fix 修复生成树表时选项加载错误
chore 清理生成代码cli包中的测试文件
This commit is contained in:
孟帅
2024-07-25 16:47:59 +08:00
parent a37d088360
commit 804d5d5e59
121 changed files with 238 additions and 2799 deletions

View File

@@ -145,6 +145,9 @@ export function rdmLightRgbColor(): string {
// 将列表数据转为树形数据
export function convertListToTree(list: any[], idField = 'id', pidField = 'pid') {
if (!list || list.length === 0) {
return [];
}
const min = list.reduce((prev, current) => (prev[pidField] < current[pidField] ? prev : current));
const map = list.reduce((acc, item) => {
@@ -154,6 +157,13 @@ export function convertListToTree(list: any[], idField = 'id', pidField = 'pid')
list.forEach((item) => {
if (item[pidField] !== min[pidField]) {
if (!map[item[pidField]]) {
map[item[pidField]] = {};
}
if (!map[item[pidField]].children) {
map[item[pidField]].children = [];
}
map[item[pidField]].children.push(map[item[idField]]);
}
});
@@ -163,6 +173,9 @@ export function convertListToTree(list: any[], idField = 'id', pidField = 'pid')
// 从树选项中获取所有key
export function getTreeKeys(data: any[], idField = 'id') {
const keys: any = [];
if (!data || data.length === 0) {
return keys;
}
data.map((item: any) => {
keys.push(item[idField]);
if (item.children && item.children.length) {

View File

@@ -5,6 +5,7 @@ import {
NBadge,
NButton,
NIcon,
NImage,
NPopover,
NTable,
NTag,
@@ -13,10 +14,12 @@ import {
} from 'naive-ui';
import { EllipsisHorizontalCircleOutline } from '@vicons/ionicons5';
import { PageEnum } from '@/enums/pageEnum';
import { isNullObject, isObject } from './is/index';
import { isArray, isJsonString, isNullObject, isObject } from './is/index';
import { cloneDeep } from 'lodash-es';
import { VNode } from 'vue';
import { DictType, useDictStore } from '@/store/modules/dict';
import { fallbackSrc } from '@/utils/hotgo';
import {getFileExt} from "@/utils/urlUtils";
export const renderTooltip = (trigger, content) => {
return h(NTooltip, null, {
@@ -95,6 +98,71 @@ export const renderOptionTag = (type: DictType, value: any) => {
);
};
// render 图片
export const renderImage = (image: string) => {
if (!image || image === '') {
return ``;
}
return h(NImage, {
width: 32,
height: 32,
src: image,
fallbackSrc: fallbackSrc(),
style: {
width: '32px',
height: '32px',
'max-width': '100%',
'max-height': '100%',
'margin-left': '2px',
},
});
};
// render 图片组
export const renderImageGroup = (images: any) => {
if (isJsonString(images)) {
images = JSON.parse(images);
}
if (isNullObject(images) || !isArray(images)) {
return ``;
}
return images.map((image: string) => {
return renderImage(image);
});
};
// render 文件
export const renderFile = (file: string) => {
if (!file || file === '') {
return ``;
}
return h(
NAvatar,
{
size: 'small',
style: {
'margin-left': '2px',
},
},
{
default: () => getFileExt(file),
}
);
};
// render 文件组
export const renderFileGroup = (files: any) => {
if (isJsonString(files)) {
files = JSON.parse(files);
}
if (isNullObject(files) || !isArray(files)) {
return ``;
}
return files.map((file: string) => {
return renderFile(file);
});
};
export interface MemberSumma {
id: number; // 用户ID
realName: string; // 真实姓名
@@ -103,7 +171,7 @@ export interface MemberSumma {
}
// render 操作人摘要
export const renderPopoverMemberSumma = (member?: MemberSumma) => {
export const renderPopoverMemberSumma = (member: MemberSumma | null | undefined) => {
if (!member) {
return '';
}

View File

@@ -100,8 +100,13 @@ export function isJsonString(value: any) {
return false;
}
export function isNullObject(value: object) {
return isNullOrUnDef(value) || JSON.stringify(value) === '{}' || JSON.stringify(value) === '[]';
export function isNullObject(value: any) {
return (
isNullOrUnDef(value) ||
JSON.stringify(value) === '{}' ||
JSON.stringify(value) === '[]' ||
value === ''
);
}
/**