feat:【infra】文件管理:100%

This commit is contained in:
YunaiV
2025-12-21 16:33:24 +08:00
parent aea01e4025
commit 311b9c241f
5 changed files with 71 additions and 89 deletions

View File

@@ -37,18 +37,18 @@
</view>
<!-- 操作按钮 -->
<view class="mt-16rpx flex justify-end gap-16rpx">
<wd-button
v-if="hasAccessByCodes(['infra:file-config:update']) && !item.master"
size="small" type="info" @click.stop="handleMaster(item)"
>
设为主配置
</wd-button>
<wd-button
v-if="hasAccessByCodes(['infra:file-config:update'])"
size="small" type="info" @click.stop="handleTest(item)"
>
测试
</wd-button>
<wd-button
v-if="hasAccessByCodes(['infra:file-config:update']) && !item.master"
size="small" type="warning" @click.stop="handleMaster(item)"
>
设为主配置
</wd-button>
</view>
</view>
</view>
@@ -151,30 +151,27 @@ function handleDetail(item: FileConfig) {
/** 测试文件配置 */
async function handleTest(item: FileConfig) {
try {
toast.loading('测试上传中...')
const url = await testFileConfig(item.id!)
toast.close()
uni.showModal({
title: '测试上传成功',
content: '是否要访问该文件?',
confirmText: '访问',
cancelText: '取消',
success: (res) => {
if (res.confirm && url) {
// 复制链接到剪贴板
uni.setClipboardData({
data: url,
success: () => {
toast.success('链接已复制,请在浏览器中打开')
},
})
}
},
})
} catch {
toast.show('测试失败')
}
toast.loading('测试上传中...')
const url = await testFileConfig(item.id!)
toast.close()
uni.showModal({
title: '测试上传成功',
content: '是否要访问该文件?',
confirmText: '访问',
success: (res) => {
if (!res.confirm || !url) {
return
}
// 复制链接到剪贴板
uni.setClipboardData({
data: url,
success: () => {
uni.hideToast()
toast.success('链接已复制,请在浏览器中打开')
},
})
},
})
}
/** 设为主配置 */
@@ -193,7 +190,7 @@ function handleMaster(item: FileConfig) {
// 刷新列表
handleQuery()
} catch {
toast.show('设置失败')
toast.close()
}
},
})

View File

@@ -13,7 +13,7 @@
>
<view class="p-24rpx">
<view class="mb-16rpx flex items-center justify-between">
<view class="text-32rpx text-[#333] font-semibold line-clamp-1">
<view class="line-clamp-1 text-32rpx text-[#333] font-semibold">
{{ item.name || item.path }}
</view>
</view>
@@ -29,19 +29,20 @@
<text class="mr-8rpx shrink-0 text-[#999]">文件大小</text>
<text>{{ formatFileSize(item.size) }}</text>
</view>
<!-- 文件预览 -->
<view v-if="item.type && item.type.includes('image')" class="mb-12rpx">
<image
:src="item.url"
mode="aspectFit"
class="h-200rpx w-full rounded-8rpx"
@click.stop="handlePreviewImage(item.url)"
/>
</view>
<view class="mb-12rpx flex items-center text-28rpx text-[#666]">
<text class="mr-8rpx text-[#999]">上传时间</text>
<text>{{ formatDateTime(item.createTime) || '-' }}</text>
</view>
<view v-if="item.type && item.type.includes('image')" class="mb-12rpx">
<wd-img
:src="item.url"
mode="aspectFit"
width="100%"
height="200rpx"
enable-preview
@click.stop
/>
</view>
<!-- 操作按钮 -->
<view class="mt-16rpx flex justify-end gap-16rpx">
<wd-button size="small" type="info" @click.stop="handleCopyUrl(item)">
@@ -86,6 +87,7 @@ import { uploadFile } from '@/api/infra/file'
import { useAccess } from '@/hooks/useAccess'
import { http } from '@/http/http'
import { formatDateTime } from '@/utils/date'
import { formatFileSize } from '@/utils/download'
import FileSearchForm from './file-search-form.vue'
/** 文件信息 */
@@ -110,15 +112,6 @@ const queryParams = ref({
pageSize: 10,
})
/** 格式化文件大小 */
function formatFileSize(size?: number) {
if (!size) return '-'
if (size < 1024) return `${size} B`
if (size < 1024 * 1024) return `${(size / 1024).toFixed(2)} KB`
if (size < 1024 * 1024 * 1024) return `${(size / 1024 / 1024).toFixed(2)} MB`
return `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`
}
/** 查询列表 */
async function getList() {
loadMoreState.value = 'loading'
@@ -191,14 +184,6 @@ function handleCopyUrl(item: FileInfo) {
})
}
/** 预览图片 */
function handlePreviewImage(url?: string) {
if (!url) return
uni.previewImage({
urls: [url],
})
}
/** 查看详情 */
function handleDetail(item: FileInfo) {
uni.navigateTo({

View File

@@ -18,17 +18,17 @@
<wd-cell title="文件类型" :value="String(formData?.type ?? '-')" />
<wd-cell title="上传时间" :value="formatDateTime(formData?.createTime) || '-'" />
</wd-cell-group>
<!-- 文件预览 -->
<view v-if="formData?.type && formData.type.includes('image')" class="m-24rpx">
<view class="mb-16rpx text-28rpx text-[#999]">
文件预览
</view>
<image
<wd-img
:src="formData.url"
mode="aspectFit"
class="w-full rounded-8rpx"
@click="handlePreviewImage"
width="100%"
height="400rpx"
enable-preview
/>
</view>
</view>
@@ -57,6 +57,7 @@ import { useAccess } from '@/hooks/useAccess'
import { http } from '@/http/http'
import { navigateBackPlus } from '@/utils'
import { formatDateTime } from '@/utils/date'
import { formatFileSize } from '@/utils/download'
/** 文件信息 */
interface FileInfo {
@@ -86,15 +87,6 @@ const toast = useToast()
const formData = ref<FileInfo>()
const deleting = ref(false)
/** 格式化文件大小 */
function formatFileSize(size?: number) {
if (!size) return '-'
if (size < 1024) return `${size} B`
if (size < 1024 * 1024) return `${(size / 1024).toFixed(2)} KB`
if (size < 1024 * 1024 * 1024) return `${(size / 1024 / 1024).toFixed(2)} MB`
return `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`
}
/** 返回上一页 */
function handleBack() {
navigateBackPlus('/pages-infra/file/index')
@@ -122,19 +114,12 @@ function handleCopyUrl() {
uni.setClipboardData({
data: formData.value.url,
success: () => {
uni.hideToast()
toast.success('复制成功')
},
})
}
/** 预览图片 */
function handlePreviewImage() {
if (!formData.value?.url) return
uni.previewImage({
urls: [formData.value.url],
})
}
/** 删除 */
function handleDelete() {
if (!props.id) {

View File

@@ -23,7 +23,14 @@
<wd-cell title="操作名" :value="formData?.subType || '-'" />
<wd-cell title="操作内容" :value="formData?.action || '-'" />
<wd-cell v-if="formData?.extra" title="操作拓展参数" :value="formData.extra" />
<wd-cell title="请求 URL" :value="getRequestUrl()" />
<wd-cell title="请求 URL">
<template #value>
<text v-if="formData?.requestMethod && formData?.requestUrl">
{{ formData.requestMethod }} {{ formData.requestUrl }}
</text>
<text v-else>-</text>
</template>
</wd-cell>
<wd-cell title="操作时间" :value="formatDateTime(formData?.createTime) || '-'" />
<wd-cell title="业务编号" :value="String(formData?.bizId ?? '-')" />
</wd-cell-group>
@@ -59,15 +66,6 @@ function handleBack() {
navigateBackPlus('/pages-system/operate-log/index')
}
/** 获取请求 URL */
// TODO @AI放在界面里这里不要这么搞
function getRequestUrl() {
if (formData.value?.requestMethod && formData.value?.requestUrl) {
return `${formData.value.requestMethod} ${formData.value.requestUrl}`
}
return '-'
}
/** 加载操作日志详情 */
async function getDetail() {
if (!props.id) {

View File

@@ -106,3 +106,20 @@ function resolveFileName(url: string): string {
return url.slice(url.lastIndexOf('/') + 1) || defaultName
}
}
/** 格式化文件大小 */
export function formatFileSize(size?: number): string {
if (!size) {
return '-'
}
if (size < 1024) {
return `${size} B`
}
if (size < 1024 * 1024) {
return `${(size / 1024).toFixed(2)} KB`
}
if (size < 1024 * 1024 * 1024) {
return `${(size / 1024 / 1024).toFixed(2)} MB`
}
return `${(size / 1024 / 1024 / 1024).toFixed(2)} GB`
}