UNPKG

tav-ui

Version:
236 lines (233 loc) 8.44 kB
import { createVNode, Fragment, computed } from 'vue'; import { Tooltip } from 'ant-design-vue'; import '../../../../../utils/index2.mjs'; import { TaButton } from '../../../../button/index2.mjs'; import '../../utils/index2.mjs'; import FileCardRowEditor from '../components/FileCardRowEditor/index2.mjs'; import { fileDocSvg, fileXlsSvg, filePptSvg, filePdfSvg, fileImageSvg, fileUnknownSvg, fileLinkSvg } from '../file-svg2.mjs'; import { DEFAULT_FILE_ACCEPT_TYPES, DEFAULT_FILE_OFFICE_TYPES, DEFAULT_FILE_IMAGE_TYPES } from '../../consts2.mjs'; import TaFileListItemAction from '../components/ListItemAction2.mjs'; import { isVersionColVisible } from '../../utils/visibile2.mjs'; import { isFunction } from '../../../../../utils/is2.mjs'; function defaultItemsBuilder(mode, enabledRowEdit, enabledVersion, actions, handleRowEditClick, hanldeVersionClick) { const DEFAULT_COLUMNS = [{ field: "avator", slots: { default: ({ row }) => { const svg = (fileSuffix) => { if (DEFAULT_FILE_ACCEPT_TYPES.includes(fileSuffix)) { if (DEFAULT_FILE_OFFICE_TYPES.includes(fileSuffix)) { if (fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[0]) || fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[1]) || fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[2]) || fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[3])) { return fileDocSvg; } else if (fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[4]) || fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[5]) || fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[6]) || fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[7])) { return fileXlsSvg; } else if (fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[8]) || fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[9]) || fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[10]) || fileSuffix.includes(DEFAULT_FILE_OFFICE_TYPES[11])) { return filePptSvg; } else { return filePdfSvg; } } else if (DEFAULT_FILE_IMAGE_TYPES.includes(fileSuffix)) { return fileImageSvg; } else { return fileUnknownSvg; } } else { return fileUnknownSvg; } }; return createVNode(Fragment, null, [row.hyperlink !== 1 ? svg(row.suffix) : fileLinkSvg]); } } }, { field: "content", children: [{ field: "fullName", editRender: { enabled: mode !== "read" && enabledRowEdit }, slots: { edit: ({ row }) => { return createVNode(FileCardRowEditor, { "row": row, "onChange": async (payload) => { await handleRowEditClick(payload, row); } }, null); }, default: ({ row }) => { const renderVersion = isVersionColVisible(enabledVersion, row.hyperlink, row.auto); const versionContent = renderVersion ? createVNode(Fragment, null, [`\u3010v${row.version}\u3011`]) : null; const defaultContent = row.hyperlink !== 1 ? createVNode(Fragment, null, [createVNode("div", { "style": "max-width: calc(100% - 70px - 10px)" }, [createVNode(Tooltip, { "placement": "top", "destroyTooltipOnHide": true }, { title: () => createVNode("span", null, [row.fullName]), default: () => createVNode("span", { "style": { display: "inline-block", overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis", width: "100%" } }, [row.fullName]) })]), createVNode("div", { "style": "max-width: 70px" }, [createVNode("span", { "style": { display: "inline-block", overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis", width: "100%" } }, [versionContent])])]) : createVNode(Fragment, null, [createVNode("div", { "style": "max-width: calc(50% - 10px)" }, [createVNode(Tooltip, { "placement": "top", "destroyTooltipOnHide": true }, { title: () => createVNode("span", null, [row.name]), default: () => createVNode("span", { "style": { display: "inline-block", lineHeight: "1", overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis", width: "100%" } }, [row.name]) })]), createVNode("div", { "style": "max-width: calc(50% - 10px)" }, [createVNode(TaButton, { "style": { minWidth: 0, padding: 0, lineHeight: "14px", height: "14px", fontSize: "12px", width: "100%" }, "type": "link", "size": "small", "onClick": (e) => { e.stopPropagation(); window.open(row.address.includes("//") ? row.address : `//${row.address}`)?.focus(); } }, { default: () => [createVNode(Tooltip, { "placement": "top", "destroyTooltipOnHide": true }, { title: () => createVNode("span", null, [row.address]), default: () => createVNode("span", { "style": { display: "inline-block", overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis", width: "100%" } }, [row.address]) })] })])]); return defaultContent; } } }, { field: "description", children: [ { field: "createByName", slots: { default: ({ row }) => createVNode(Tooltip, { "placement": "top", "destroyTooltipOnHide": true }, { title: () => createVNode("span", null, [row.createByName]), default: () => createVNode("span", { "style": { display: "inline-block", lineHeight: "1", overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis", width: "100%" } }, [row.createByName]) }) } }, { field: "updateTime", slots: { default: ({ row }) => createVNode(Tooltip, { "placement": "top", "destroyTooltipOnHide": true }, { title: () => createVNode("span", null, [row.updateTime]), default: () => createVNode("span", { "style": { display: "inline-block", lineHeight: "1", overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis", width: "100%" } }, [row.updateTime]) }) } } ] }] }, { field: "action", slots: { default: ({ row }) => { return createVNode(TaFileListItemAction, { "actions": actions.value(row), "hideInlineLabel": true, "hideDropdownIcon": true }, null); } } }]; return DEFAULT_COLUMNS; } function useItems(options) { const { mergedProps, actions, handleRowEditClick, hanldeVersionClick } = options; return computed(() => { const items = mergedProps.value.items; const mode = mergedProps.value.mode; const enabledRowEdit = mergedProps.value.enabledRowEdit; const enabledVersion = mergedProps.value.enabledVersion; let result = defaultItemsBuilder(mode, enabledRowEdit, enabledVersion, actions, handleRowEditClick, hanldeVersionClick); if (items && isFunction(items)) { result = items(result); } return result; }); } export { defaultItemsBuilder, useItems }; //# sourceMappingURL=use-items2.mjs.map