mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-24 10:33:50 +08:00
fix(Upload): The file name is too long bug (#3182)
* fix(Upload): The file name is too long bug * fix: preview upload result file name nowrap * chore: modify i18 to be uploaded * chore: typing & i18n --------- Co-authored-by: Li Kui <90845831+likui628@users.noreply.github.com>
This commit is contained in:
parent
87224715c3
commit
e7fbd74228
@ -21,49 +21,52 @@
|
|||||||
const { columns, actionColumn, dataSource } = props;
|
const { columns, actionColumn, dataSource } = props;
|
||||||
const columnList = [...columns, actionColumn];
|
const columnList = [...columns, actionColumn];
|
||||||
return (
|
return (
|
||||||
<table class="file-table">
|
// x scrollbar
|
||||||
<colgroup>
|
<div class="overflow-x-auto">
|
||||||
{columnList.map((item) => {
|
<table class="file-table">
|
||||||
const { width = 0, dataIndex } = item;
|
<colgroup>
|
||||||
const style: CSSProperties = {
|
|
||||||
width: `${width}px`,
|
|
||||||
minWidth: `${width}px`,
|
|
||||||
};
|
|
||||||
return <col style={width ? style : {}} key={dataIndex} />;
|
|
||||||
})}
|
|
||||||
</colgroup>
|
|
||||||
<thead>
|
|
||||||
<tr class="file-table-tr">
|
|
||||||
{columnList.map((item) => {
|
{columnList.map((item) => {
|
||||||
const { title = '', align = 'center', dataIndex } = item;
|
const { width = 0, dataIndex } = item;
|
||||||
|
const style: CSSProperties = {
|
||||||
|
width: `${width}px`,
|
||||||
|
minWidth: `${width}px`,
|
||||||
|
};
|
||||||
|
return <col style={width ? style : {}} key={dataIndex} />;
|
||||||
|
})}
|
||||||
|
</colgroup>
|
||||||
|
<thead>
|
||||||
|
<tr class="file-table-tr">
|
||||||
|
{columnList.map((item) => {
|
||||||
|
const { title = '', align = 'center', dataIndex } = item;
|
||||||
|
return (
|
||||||
|
<th class={['file-table-th', align]} key={dataIndex}>
|
||||||
|
{title}
|
||||||
|
</th>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{dataSource.map((record = {}, index) => {
|
||||||
return (
|
return (
|
||||||
<th class={['file-table-th', align]} key={dataIndex}>
|
<tr class="file-table-tr" key={`${index + record.name || ''}`}>
|
||||||
{title}
|
{columnList.map((item) => {
|
||||||
</th>
|
const { dataIndex = '', customRender, align = 'center' } = item;
|
||||||
|
const render = customRender && isFunction(customRender);
|
||||||
|
return (
|
||||||
|
<td class={['file-table-td break-all', align]} key={dataIndex}>
|
||||||
|
{render
|
||||||
|
? customRender?.({ text: record[dataIndex], record })
|
||||||
|
: record[dataIndex]}
|
||||||
|
</td>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tr>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</tr>
|
</tbody>
|
||||||
</thead>
|
</table>
|
||||||
<tbody>
|
</div>
|
||||||
{dataSource.map((record = {}, index) => {
|
|
||||||
return (
|
|
||||||
<tr class="file-table-tr" key={`${index + record.name || ''}`}>
|
|
||||||
{columnList.map((item) => {
|
|
||||||
const { dataIndex = '', customRender, align = 'center' } = item;
|
|
||||||
const render = customRender && isFunction(customRender);
|
|
||||||
return (
|
|
||||||
<td class={['file-table-td', align]} key={dataIndex}>
|
|
||||||
{render
|
|
||||||
? customRender?.({ text: record[dataIndex], record })
|
|
||||||
: record[dataIndex]}
|
|
||||||
</td>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
import { defineComponent, reactive, ref, toRefs, unref, computed, PropType } from 'vue';
|
import { defineComponent, reactive, ref, toRefs, unref, computed, PropType } from 'vue';
|
||||||
import { Upload, Alert } from 'ant-design-vue';
|
import { Upload, Alert } from 'ant-design-vue';
|
||||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||||
// import { BasicTable, useTable } from '/@/components/Table';
|
|
||||||
// hooks
|
// hooks
|
||||||
import { useUploadType } from './useUpload';
|
import { useUploadType } from './useUpload';
|
||||||
import { useMessage } from '/@/hooks/web/useMessage';
|
import { useMessage } from '/@/hooks/web/useMessage';
|
||||||
@ -165,14 +164,6 @@
|
|||||||
emit('delete', record);
|
emit('delete', record);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 预览
|
|
||||||
// function handlePreview(record: FileItem) {
|
|
||||||
// const { thumbUrl = '' } = record;
|
|
||||||
// createImgPreview({
|
|
||||||
// imageList: [thumbUrl],
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
async function uploadApiByItem(item: FileItem) {
|
async function uploadApiByItem(item: FileItem) {
|
||||||
const { api } = props;
|
const { api } = props;
|
||||||
if (!api || !isFunction(api)) {
|
if (!api || !isFunction(api)) {
|
||||||
@ -276,15 +267,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
columns: createTableColumns() as any[],
|
columns: createTableColumns(),
|
||||||
actionColumn: createActionColumn(handleRemove) as any,
|
actionColumn: createActionColumn(handleRemove),
|
||||||
register,
|
register,
|
||||||
closeModal,
|
closeModal,
|
||||||
getHelpText,
|
getHelpText,
|
||||||
getStringAccept,
|
getStringAccept,
|
||||||
getOkButtonProps,
|
getOkButtonProps,
|
||||||
beforeUpload,
|
beforeUpload,
|
||||||
// registerTable,
|
|
||||||
fileListRef,
|
fileListRef,
|
||||||
state,
|
state,
|
||||||
isUploadingRef,
|
isUploadingRef,
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, watch, ref } from 'vue';
|
import { defineComponent, watch, ref } from 'vue';
|
||||||
// import { BasicTable, useTable } from '/@/components/Table';
|
|
||||||
import FileList from './FileList.vue';
|
import FileList from './FileList.vue';
|
||||||
import { BasicModal, useModalInner } from '/@/components/Modal';
|
import { BasicModal, useModalInner } from '/@/components/Modal';
|
||||||
import { previewProps } from './props';
|
import { previewProps } from './props';
|
||||||
@ -61,14 +60,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 预览
|
|
||||||
// function handlePreview(record: PreviewFileItem) {
|
|
||||||
// const { url = '' } = record;
|
|
||||||
// createImgPreview({
|
|
||||||
// imageList: [url],
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 下载
|
// 下载
|
||||||
function handleDownload(record: PreviewFileItem) {
|
function handleDownload(record: PreviewFileItem) {
|
||||||
const { url = '' } = record;
|
const { url = '' } = record;
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
import type { BasicColumn, ActionItem } from '/@/components/Table';
|
import type { BasicColumn, ActionItem } from '/@/components/Table';
|
||||||
import { FileItem, PreviewFileItem, UploadResultStatus } from './typing';
|
import { FileBasicColumn, FileItem, PreviewFileItem, UploadResultStatus } from './typing';
|
||||||
import {
|
import { isImgTypeByName } from './helper';
|
||||||
// checkImgType,
|
|
||||||
isImgTypeByName,
|
|
||||||
} from './helper';
|
|
||||||
import { Progress, Tag } from 'ant-design-vue';
|
import { Progress, Tag } from 'ant-design-vue';
|
||||||
import TableAction from '/@/components/Table/src/components/TableAction.vue';
|
import TableAction from '/@/components/Table/src/components/TableAction.vue';
|
||||||
import ThumbUrl from './ThumbUrl.vue';
|
import ThumbUrl from './ThumbUrl.vue';
|
||||||
@ -12,7 +9,7 @@ import { useI18n } from '/@/hooks/web/useI18n';
|
|||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
// 文件上传列表
|
// 文件上传列表
|
||||||
export function createTableColumns(): BasicColumn[] {
|
export function createTableColumns(): FileBasicColumn[] {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
dataIndex: 'thumbUrl',
|
dataIndex: 'thumbUrl',
|
||||||
@ -38,12 +35,12 @@ export function createTableColumns(): BasicColumn[] {
|
|||||||
status = 'success';
|
status = 'success';
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<span>
|
<div>
|
||||||
<p class="truncate mb-1" title={text}>
|
<p class="truncate mb-1 max-w-[280px]" title={text}>
|
||||||
{text}
|
{text}
|
||||||
</p>
|
</p>
|
||||||
<Progress percent={percent} size="small" status={status} />
|
<Progress percent={percent} size="small" status={status} />
|
||||||
</span>
|
</div>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -55,11 +52,6 @@ export function createTableColumns(): BasicColumn[] {
|
|||||||
return text && (text / 1024).toFixed(2) + 'KB';
|
return text && (text / 1024).toFixed(2) + 'KB';
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// dataIndex: 'type',
|
|
||||||
// title: '文件类型',
|
|
||||||
// width: 100,
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
title: t('component.upload.fileStatue'),
|
title: t('component.upload.fileStatue'),
|
||||||
@ -73,12 +65,12 @@ export function createTableColumns(): BasicColumn[] {
|
|||||||
return <Tag color="blue">{() => t('component.upload.uploading')}</Tag>;
|
return <Tag color="blue">{() => t('component.upload.uploading')}</Tag>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text || t('component.upload.pending');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
export function createActionColumn(handleRemove: Function): BasicColumn {
|
export function createActionColumn(handleRemove: Function): FileBasicColumn {
|
||||||
return {
|
return {
|
||||||
width: 120,
|
width: 120,
|
||||||
title: t('component.upload.operating'),
|
title: t('component.upload.operating'),
|
||||||
@ -92,12 +84,6 @@ export function createActionColumn(handleRemove: Function): BasicColumn {
|
|||||||
onClick: handleRemove.bind(null, record),
|
onClick: handleRemove.bind(null, record),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
// if (checkImgType(record)) {
|
|
||||||
// actions.unshift({
|
|
||||||
// label: t('component.upload.preview'),
|
|
||||||
// onClick: handlePreview.bind(null, record),
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
return <TableAction actions={actions} outside={true} />;
|
return <TableAction actions={actions} outside={true} />;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { BasicColumn } from '../../Table';
|
||||||
import { UploadApiResult } from '/@/api/sys/model/uploadModel';
|
import { UploadApiResult } from '/@/api/sys/model/uploadModel';
|
||||||
|
|
||||||
export enum UploadResultStatus {
|
export enum UploadResultStatus {
|
||||||
@ -24,7 +25,7 @@ export interface PreviewFileItem {
|
|||||||
type: string;
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileBasicColumn {
|
export interface FileBasicColumn extends Omit<BasicColumn, 'customRender'> {
|
||||||
/**
|
/**
|
||||||
* Renderer of the table cell. The return value should be a VNode, or an object for colSpan/rowSpan config
|
* Renderer of the table cell. The return value should be a VNode, or an object for colSpan/rowSpan config
|
||||||
* @type Function | ScopedSlot
|
* @type Function | ScopedSlot
|
||||||
@ -36,20 +37,9 @@ export interface FileBasicColumn {
|
|||||||
*/
|
*/
|
||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
/**
|
|
||||||
* Width of this column
|
|
||||||
* @type string | number
|
|
||||||
*/
|
|
||||||
width?: number;
|
|
||||||
/**
|
/**
|
||||||
* Display field of the data record, could be set like a.b.c
|
* Display field of the data record, could be set like a.b.c
|
||||||
* @type string
|
* @type string
|
||||||
*/
|
*/
|
||||||
dataIndex: string;
|
dataIndex: string;
|
||||||
/**
|
|
||||||
* specify how content is aligned
|
|
||||||
* @default 'left'
|
|
||||||
* @type string
|
|
||||||
*/
|
|
||||||
align?: 'left' | 'right' | 'center';
|
|
||||||
}
|
}
|
||||||
|
@ -107,6 +107,7 @@
|
|||||||
"fileName": "File name",
|
"fileName": "File name",
|
||||||
"fileSize": "File size",
|
"fileSize": "File size",
|
||||||
"fileStatue": "File status",
|
"fileStatue": "File status",
|
||||||
|
"pending": "Pendig",
|
||||||
"startUpload": "Start upload",
|
"startUpload": "Start upload",
|
||||||
"uploadSuccess": "Upload successfully",
|
"uploadSuccess": "Upload successfully",
|
||||||
"uploadError": "Upload failed",
|
"uploadError": "Upload failed",
|
||||||
|
@ -107,6 +107,7 @@
|
|||||||
"fileName": "文件名",
|
"fileName": "文件名",
|
||||||
"fileSize": "文件大小",
|
"fileSize": "文件大小",
|
||||||
"fileStatue": "状态",
|
"fileStatue": "状态",
|
||||||
|
"pending": "待上传",
|
||||||
"startUpload": "开始上传",
|
"startUpload": "开始上传",
|
||||||
"uploadSuccess": "上传成功",
|
"uploadSuccess": "上传成功",
|
||||||
"uploadError": "上传失败",
|
"uploadError": "上传失败",
|
||||||
|
Loading…
Reference in New Issue
Block a user