feat: file copy url

pull/5/MERGE
xingyu 2023-04-27 13:45:39 +08:00
parent 110a352a1c
commit dc98ffb224
2 changed files with 18 additions and 10 deletions

View File

@ -2,7 +2,7 @@ import { BasicColumn, FormSchema, useRender } from '@/components/Table'
export const columns: BasicColumn[] = [ export const columns: BasicColumn[] = [
{ {
title: '日志编号', title: '编号',
dataIndex: 'id', dataIndex: 'id',
width: 100 width: 100
}, },
@ -11,15 +11,10 @@ export const columns: BasicColumn[] = [
dataIndex: 'name', dataIndex: 'name',
width: 200 width: 200
}, },
{
title: '文件路径',
dataIndex: 'path',
width: 250
},
{ {
title: '文件 URL', title: '文件 URL',
dataIndex: 'url', dataIndex: 'url',
width: 300, width: 180,
customRender: ({ text }) => { customRender: ({ text }) => {
return useRender.renderImg(text) return useRender.renderImg(text)
} }
@ -32,7 +27,7 @@ export const columns: BasicColumn[] = [
{ {
title: '文件大小', title: '文件大小',
dataIndex: 'size', dataIndex: 'size',
width: 180, width: 120,
customRender: ({ text }) => { customRender: ({ text }) => {
const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const srcSize = parseFloat(text) const srcSize = parseFloat(text)
@ -44,7 +39,10 @@ export const columns: BasicColumn[] = [
{ {
title: '文件类型', title: '文件类型',
dataIndex: 'type', dataIndex: 'type',
width: 180 width: 100,
customRender: ({ text }) => {
return useRender.renderTag(text)
}
}, },
{ {
title: '文件内容', title: '文件内容',

View File

@ -17,6 +17,7 @@
<template v-if="column.key === 'action'"> <template v-if="column.key === 'action'">
<TableAction <TableAction
:actions="[ :actions="[
{ icon: IconEnum.VIEW, label: '复制链接', onClick: handleCopy.bind(null, record) },
{ {
icon: IconEnum.DELETE, icon: IconEnum.DELETE,
color: 'error', color: 'error',
@ -36,9 +37,10 @@
</div> </div>
</template> </template>
<script lang="ts" setup name="InfraFile"> <script lang="ts" setup name="InfraFile">
import { ref } from 'vue' import { ref, unref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage' import { useMessage } from '@/hooks/web/useMessage'
import { useCopyToClipboard } from '@/hooks/web/useCopyToClipboard'
import { IconEnum } from '@/enums/appEnum' import { IconEnum } from '@/enums/appEnum'
import { BasicUpload } from '@/components/Upload' import { BasicUpload } from '@/components/Upload'
import { BasicTable, useTable, TableAction } from '@/components/Table' import { BasicTable, useTable, TableAction } from '@/components/Table'
@ -49,6 +51,7 @@ import { uploadApi } from '@/api/base/upload'
const { t } = useI18n() const { t } = useI18n()
const { createMessage } = useMessage() const { createMessage } = useMessage()
const { clipboardRef, copiedRef } = useCopyToClipboard()
const uploadParams = ref({ const uploadParams = ref({
Authorization: 'Bearer ' + getAccessToken(), Authorization: 'Bearer ' + getAccessToken(),
@ -75,6 +78,13 @@ function handleChange() {
reload() reload()
} }
function handleCopy(record: Recordable) {
clipboardRef.value = record.url
if (unref(copiedRef)) {
createMessage.warning('复制成功')
}
}
async function handleDelete(record: Recordable) { async function handleDelete(record: Recordable) {
await deleteFile(record.id) await deleteFile(record.id)
createMessage.success(t('common.delSuccessText')) createMessage.success(t('common.delSuccessText'))