Quellcode durchsuchen

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

YunaiV vor 4 Monaten
Ursprung
Commit
311b9c241f

+ 28 - 31
src/pages-infra/file/components/config-list.vue

@@ -38,16 +38,16 @@
           <!-- 操作按钮 -->
           <!-- 操作按钮 -->
           <view class="mt-16rpx flex justify-end gap-16rpx">
           <view class="mt-16rpx flex justify-end gap-16rpx">
             <wd-button
             <wd-button
-              v-if="hasAccessByCodes(['infra:file-config:update'])"
-              size="small" type="info" @click.stop="handleTest(item)"
+              v-if="hasAccessByCodes(['infra:file-config:update']) && !item.master"
+              size="small" type="info" @click.stop="handleMaster(item)"
             >
             >
-              测试
+              设为主配置
             </wd-button>
             </wd-button>
             <wd-button
             <wd-button
-              v-if="hasAccessByCodes(['infra:file-config:update']) && !item.master"
-              size="small" type="warning" @click.stop="handleMaster(item)"
+              v-if="hasAccessByCodes(['infra:file-config:update'])"
+              size="small" type="info" @click.stop="handleTest(item)"
             >
             >
-              设为主配置
+              测试
             </wd-button>
             </wd-button>
           </view>
           </view>
         </view>
         </view>
@@ -151,30 +151,27 @@ function handleDetail(item: FileConfig) {
 
 
 /** 测试文件配置 */
 /** 测试文件配置 */
 async function handleTest(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()
         handleQuery()
       } catch {
       } catch {
-        toast.show('设置失败')
+        toast.close()
       }
       }
     },
     },
   })
   })

+ 11 - 26
src/pages-infra/file/components/file-list.vue

@@ -13,7 +13,7 @@
       >
       >
         <view class="p-24rpx">
         <view class="p-24rpx">
           <view class="mb-16rpx flex items-center justify-between">
           <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 }}
               {{ item.name || item.path }}
             </view>
             </view>
           </view>
           </view>
@@ -29,19 +29,20 @@
             <text class="mr-8rpx shrink-0 text-[#999]">文件大小:</text>
             <text class="mr-8rpx shrink-0 text-[#999]">文件大小:</text>
             <text>{{ formatFileSize(item.size) }}</text>
             <text>{{ formatFileSize(item.size) }}</text>
           </view>
           </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">
           <view v-if="item.type && item.type.includes('image')" class="mb-12rpx">
-            <image
+            <wd-img
               :src="item.url"
               :src="item.url"
               mode="aspectFit"
               mode="aspectFit"
-              class="h-200rpx w-full rounded-8rpx"
-              @click.stop="handlePreviewImage(item.url)"
+              width="100%"
+              height="200rpx"
+              enable-preview
+              @click.stop
             />
             />
           </view>
           </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 class="mt-16rpx flex justify-end gap-16rpx">
           <view class="mt-16rpx flex justify-end gap-16rpx">
             <wd-button size="small" type="info" @click.stop="handleCopyUrl(item)">
             <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 { useAccess } from '@/hooks/useAccess'
 import { http } from '@/http/http'
 import { http } from '@/http/http'
 import { formatDateTime } from '@/utils/date'
 import { formatDateTime } from '@/utils/date'
+import { formatFileSize } from '@/utils/download'
 import FileSearchForm from './file-search-form.vue'
 import FileSearchForm from './file-search-form.vue'
 
 
 /** 文件信息 */
 /** 文件信息 */
@@ -110,15 +112,6 @@ const queryParams = ref({
   pageSize: 10,
   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() {
 async function getList() {
   loadMoreState.value = 'loading'
   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) {
 function handleDetail(item: FileInfo) {
   uni.navigateTo({
   uni.navigateTo({

+ 6 - 21
src/pages-infra/file/detail/index.vue

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

+ 8 - 10
src/pages-system/operate-log/detail/index.vue

@@ -23,7 +23,14 @@
         <wd-cell title="操作名" :value="formData?.subType || '-'" />
         <wd-cell title="操作名" :value="formData?.subType || '-'" />
         <wd-cell title="操作内容" :value="formData?.action || '-'" />
         <wd-cell title="操作内容" :value="formData?.action || '-'" />
         <wd-cell v-if="formData?.extra" title="操作拓展参数" :value="formData.extra" />
         <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="formatDateTime(formData?.createTime) || '-'" />
         <wd-cell title="业务编号" :value="String(formData?.bizId ?? '-')" />
         <wd-cell title="业务编号" :value="String(formData?.bizId ?? '-')" />
       </wd-cell-group>
       </wd-cell-group>
@@ -59,15 +66,6 @@ function handleBack() {
   navigateBackPlus('/pages-system/operate-log/index')
   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() {
 async function getDetail() {
   if (!props.id) {
   if (!props.id) {

+ 17 - 0
src/utils/download.ts

@@ -106,3 +106,20 @@ function resolveFileName(url: string): string {
     return url.slice(url.lastIndexOf('/') + 1) || defaultName
     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`
+}