Browse Source

style(SmsbFileUpload): Format code and fix indentation

Shinohara Haruna 6 months ago
parent
commit
69a553d035

+ 40 - 32
smsb-plus-ui/src/components/SmsbFileUpload/SmsbFileUploader.vue

@@ -7,9 +7,7 @@
       <div class="upload-text">
         <em>拖拽文件到此处或</em>
         <br />
-        <el-button type="primary" class="select-button">
-          点击选择文件
-        </el-button>
+        <el-button type="primary" class="select-button"> 点击选择文件 </el-button>
       </div>
     </el-upload>
 
@@ -47,12 +45,13 @@
                   <el-tag type="danger">上传失败</el-tag>
                   <el-tooltip v-if="uploadStates[ossId]?.errorMessage"
                               :content="uploadStates[ossId]?.errorMessage || '未知错误'" placement="top">
-                    <el-icon style="margin-left: 4px;vertical-align: middle;cursor: help;">
+                    <el-icon style="margin-left: 4px; vertical-align: middle; cursor: help">
                       <QuestionFilled />
                     </el-icon>
                   </el-tooltip>
                 </span>
-                <el-tag v-else-if="uploadStates[ossId]?.status === 'merging'" type="warning" effect="light">合并中...</el-tag>
+                <el-tag v-else-if="uploadStates[ossId]?.status === 'merging'" type="warning"
+                        effect="light">合并中...</el-tag>
                 <el-tag v-else-if="uploadStates[ossId]?.status === 'pending'" type="info">待上传</el-tag>
                 <el-tag v-else type="info" effect="plain">未知状态 ({{ uploadStates[ossId]?.status }})</el-tag>
               </div>
@@ -104,8 +103,8 @@
 </template>
 
 <script setup lang="ts">
-import { ref, computed, reactive, onMounted, watch, defineProps, defineEmits } from "vue";
-import { UploadFilled, QuestionFilled } from "@element-plus/icons-vue";
+import { ref, computed, reactive, onMounted, watch, defineProps, defineEmits } from 'vue';
+import { UploadFilled, QuestionFilled } from '@element-plus/icons-vue';
 
 // ================= 类型声明 =================
 interface UploadState {
@@ -127,15 +126,15 @@ const props = defineProps({
     default: null
   }
 }); // only declared once
-const emit = defineEmits(["update:modelValue"]); // only declared once
+const emit = defineEmits(['update:modelValue']); // only declared once
 
 const fileTypes = ref([
-  { label: "图片", value: "image" },
-  { label: "视频", value: "video" },
-  { label: "文档", value: "document" },
-  { label: "其它", value: "other" },
+  { label: '图片', value: 'image' },
+  { label: '视频', value: 'video' },
+  { label: '文档', value: 'document' },
+  { label: '其它', value: 'other' }
 ]);
-const selectedType = ref("");
+const selectedType = ref('');
 
 const fileList = ref<any[]>([]);
 const displayFileList = computed(() => fileList.value);
@@ -143,7 +142,7 @@ const displayFileList = computed(() => fileList.value);
 // ossId 用于文件唯一标识
 const ossId = computed({
   get: () => props.modelValue,
-  set: (val) => emit("update:modelValue", val)
+  set: (val) => emit('update:modelValue', val)
 });
 
 const uploadStates = reactive<Record<string | number, UploadState>>({});
@@ -151,9 +150,7 @@ const uploadHistory = ref<UploadHistoryEntry[]>([]);
 const MAX_HISTORY_ITEMS = 10;
 
 const isUploading = computed(() => {
-  return Object.values(uploadStates).some(
-    (state) => state.status === "uploading"
-  );
+  return Object.values(uploadStates).some((state) => state.status === 'uploading');
 });
 
 // ================= 监听器 =================
@@ -164,17 +161,16 @@ watch(
   }
 );
 
-
 function formatFileSize(bytes: number): string {
-  if (bytes < 1024) return bytes + " B";
-  if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + " KB";
-  if (bytes < 1024 * 1024 * 1024) return (bytes / 1024 / 1024).toFixed(1) + " MB";
-  return (bytes / 1024 / 1024 / 1024).toFixed(1) + " GB";
+  if (bytes < 1024) return bytes + ' B';
+  if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB';
+  if (bytes < 1024 * 1024 * 1024) return (bytes / 1024 / 1024).toFixed(1) + ' MB';
+  return (bytes / 1024 / 1024 / 1024).toFixed(1) + ' GB';
 }
 
 // TODO: 上传历史的持久化与回显逻辑可根据业务扩展
 function loadHistory() {
-  const raw = localStorage.getItem("smsb-upload-history");
+  const raw = localStorage.getItem('smsb-upload-history');
   if (raw) {
     try {
       uploadHistory.value = JSON.parse(raw);
@@ -184,7 +180,7 @@ function loadHistory() {
   }
 }
 function saveHistory() {
-  localStorage.setItem("smsb-upload-history", JSON.stringify(uploadHistory.value.slice(0, MAX_HISTORY_ITEMS)));
+  localStorage.setItem('smsb-upload-history', JSON.stringify(uploadHistory.value.slice(0, MAX_HISTORY_ITEMS)));
 }
 // TODO: 可扩展:支持多文件上传/批量操作时的历史记录批量追加
 function addHistoryEntry(file: any, status: string) {
@@ -192,7 +188,7 @@ function addHistoryEntry(file: any, status: string) {
     name: file.name,
     size: file.size,
     status,
-    uploadTime: new Date().toLocaleString(),
+    uploadTime: new Date().toLocaleString()
   });
   uploadHistory.value = uploadHistory.value.slice(0, MAX_HISTORY_ITEMS);
   saveHistory();
@@ -228,7 +224,7 @@ function handleFileChange(uploadFile: any, uploadFiles: any[]) {
   // 避免重复添加
   if (!fileList.value.some((f) => f.uid === uploadFile.uid)) {
     fileList.value.push(uploadFile);
-    uploadStates[uploadFile.uid] = { status: "pending" };
+    uploadStates[uploadFile.uid] = { status: 'pending' };
   }
 }
 function handleFileRemove(uploadFile: any, uploadFiles: any[]) {
@@ -243,15 +239,15 @@ function handleManualRemove(fileToRemove: any) {
 // TODO: 对接实际上传API,完善错误处理与用户提示,支持多文件上传/批量操作
 async function handleUpload() {
   for (const file of fileList.value) {
-    uploadStates[file.uid] = { status: "uploading", progress: 0 };
+    uploadStates[file.uid] = { status: 'uploading', progress: 0 };
     try {
       // 这里只是模拟上传,实际应替换为后端API
       await new Promise((resolve) => setTimeout(resolve, 1500));
-      uploadStates[file.uid] = { status: "success", progress: 100 };
-      addHistoryEntry(file, "success");
+      uploadStates[file.uid] = { status: 'success', progress: 100 };
+      addHistoryEntry(file, 'success');
     } catch (e: any) {
-      uploadStates[file.uid] = { status: "error", errorMessage: e?.message || "上传失败" };
-      addHistoryEntry(file, "error");
+      uploadStates[file.uid] = { status: 'error', errorMessage: e?.message || '上传失败' };
+      addHistoryEntry(file, 'error');
     }
   }
 }
@@ -267,7 +263,11 @@ async function handleUpload() {
   box-sizing: border-box;
   padding: 0 0 16px 0;
 }
-.upload-area, .file-list, .upload-actions, .history-list {
+
+.upload-area,
+.file-list,
+.upload-actions,
+.history-list {
   width: 100%;
 }
 
@@ -280,35 +280,43 @@ async function handleUpload() {
   text-align: center;
   width: 100%;
 }
+
 .upload-icon {
   font-size: 40px;
   color: #409eff;
   margin-bottom: 10px;
 }
+
 .upload-text {
   font-size: 16px;
   color: #606266;
 }
+
 .select-button {
   margin-top: 10px;
 }
+
 .type-selection {
   margin-bottom: 12px;
   display: flex;
   align-items: center;
 }
+
 .type-select {
   width: 180px;
 }
+
 .file-list {
   margin-bottom: 16px;
   width: 100%;
 }
+
 .upload-actions {
   margin: 18px 0 12px 0;
   display: flex;
   gap: 12px;
 }
+
 .history-list {
   margin-top: 18px;
 }

+ 43 - 60
smsb-plus-ui/src/views/smsb/minioData/index.vue

@@ -1,6 +1,7 @@
 <template>
   <div class="p-2">
-    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
+    <transition :enter-active-class="proxy?.animate.searchAnimate.enter"
+                :leave-active-class="proxy?.animate.searchAnimate.leave">
       <div v-show="showSearch" class="mb-[10px]">
         <el-card shadow="hover" :style="{ height: '70px' }">
           <el-row :gutter="20" align="middle">
@@ -50,38 +51,29 @@
             </el-form-item>
             <el-form-item label="分类" prop="tag">
               <el-select v-model="queryParams.tag" style="width: 150px" placeholder="请选择分类" clearable>
-                <el-option v-for="dict in smsb_source_classify" :key="dict.value" :label="dict.label" :value="dict.value" />
+                <el-option v-for="dict in smsb_source_classify" :key="dict.value" :label="dict.label"
+                           :value="dict.value" />
               </el-select>
             </el-form-item>
             <el-form-item label="目录" prop="treeId">
-              <el-tree-select
-                v-model="queryParams.treeId"
-                :data="sourceTreeOptions"
-                :props="{ value: 'id', label: 'name', children: 'children' }"
-                value-key="id"
-                placeholder="请选择归属目录"
-                check-strictly
-                @change="handleQuery"
-                style="width: 200px"
-                clearable
-              />
+              <el-tree-select v-model="queryParams.treeId" :data="sourceTreeOptions"
+                              :props="{ value: 'id', label: 'name', children: 'children' }" value-key="id"
+                              placeholder="请选择归属目录" check-strictly @change="handleQuery" style="width: 200px"
+                              clearable />
             </el-form-item>
             <el-form-item label="时间" style="width: 250px">
-              <el-date-picker
-                v-model="dateRangeCreateTime"
-                value-format="YYYY-MM-DD HH:mm:ss"
-                type="daterange"
-                range-separator="-"
-                start-placeholder="开始日期"
-                end-placeholder="结束日期"
-                :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
-              ></el-date-picker>
+              <el-date-picker v-model="dateRangeCreateTime" value-format="YYYY-MM-DD HH:mm:ss" type="daterange"
+                              range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
+                              :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"></el-date-picker>
             </el-form-item>
             <el-form-item>
               <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
               <el-button icon="Refresh" @click="resetQuery">重置</el-button>
-              <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['source:minioData:add']"> 上传 </el-button>
-              <el-button type="primary" plain icon="Switch" @click="handleTrans" v-hasPermi="['source:minioData:add']"> 转码进度 </el-button>
+              <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['source:minioData:add']"> 上传
+              </el-button>
+              <el-button type="primary" plain icon="Switch" @click="handleTrans" v-hasPermi="['source:minioData:add']">
+                转码进度
+              </el-button>
               <!--              <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['source:minioData:edit']"
                               >修改
                             </el-button>
@@ -145,41 +137,41 @@
                           <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['source:minioData:edit']"></el-button>
                         </el-tooltip>-->
             <el-tooltip content="删除" placement="top">
-              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['source:minioData:remove']"></el-button>
+              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
+                         v-hasPermi="['source:minioData:remove']"></el-button>
             </el-tooltip>
             <el-tooltip content="引用情况" placement="top">
-              <el-button link type="primary" icon="List" @click="handleUse(scope.row)" v-hasPermi="['source:minioData:edit']"></el-button>
+              <el-button link type="primary" icon="List" @click="handleUse(scope.row)"
+                         v-hasPermi="['source:minioData:edit']"></el-button>
             </el-tooltip>
           </template>
         </el-table-column>
       </el-table>
 
-      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
+      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
+                  v-model:limit="queryParams.pageSize" @pagination="getList" />
     </el-card>
     <!-- 添加或修改文件资源对话框 -->
-    <el-dialog :title="dialog.title" v-model="dialog.visible" append-to-body :style="{ maxWidth: '90vw', maxHeight: '90vh' }">
-      <el-row :gutter="20" style="display: flex;">
-        <el-col :span="10" style="height: 100%; overflow: auto; border-right: 1px solid #eee; padding-right: 10px;">
-          <el-tree
-            ref="sourceTreeRef"
-            :data="sourceTreeOptions"
-            show-checkbox
-            node-key="id"
-            :props="{ value: 'id', label: 'name', children: 'children' }"
-            :check-strictly="true"
-            :default-expand-all="false"
-            @check="handleTreeCheck"
-            style="height: 100%"
-          ></el-tree>
+    <el-dialog :title="dialog.title" v-model="dialog.visible" append-to-body
+               :style="{ maxWidth: '90vw', maxHeight: '90vh' }">
+      <el-row :gutter="20" style="display: flex">
+        <el-col :span="10" style="height: 100%; overflow: auto; border-right: 1px solid #eee; padding-right: 10px">
+          <el-tree ref="sourceTreeRef" :data="sourceTreeOptions" show-checkbox node-key="id"
+                   :props="{ value: 'id', label: 'name', children: 'children' }" :check-strictly="true"
+                   :default-expand-all="false" @check="handleTreeCheck" style="height: 100%"></el-tree>
         </el-col>
-        <el-col :span="14" style="height: 100%; display: flex; flex-direction: column; overflow: auto; padding-left: 10px;">
-          <el-form ref="minioDataFormRef" :model="form" :rules="rules" label-width="80px" style="flex: 1 1 auto; height: 100%; display: flex; flex-direction: column;">
+        <el-col :span="14"
+                style="height: 100%; display: flex; flex-direction: column; overflow: auto; padding-left: 10px">
+          <el-form ref="minioDataFormRef" :model="form" :rules="rules" label-width="80px"
+                   style="flex: 1 1 auto; height: 100%; display: flex; flex-direction: column">
             <el-form-item label="分类" prop="tag">
               <el-select v-model="form.tag" placeholder="请选择分类">
-                <el-option v-for="dict in smsb_source_classify" :key="dict.value" :label="dict.label" :value="parseInt(dict.value)"></el-option>
+                <el-option v-for="dict in smsb_source_classify" :key="dict.value" :label="dict.label"
+                           :value="parseInt(dict.value)"></el-option>
               </el-select>
             </el-form-item>
-            <el-form-item label="" style="flex: 1 1 auto; display: flex; flex-direction: column; justify-content: flex-start;">
+            <el-form-item label=""
+                          style="flex: 1 1 auto; display: flex; flex-direction: column; justify-content: flex-start">
               <!-- 原始上传组件保留,供参考:
               <smsb-file-upload v-model="form.ossId" />
               -->
@@ -220,13 +212,8 @@
           <el-table-column label="用户名" align="left" prop="createUser" width="100" :show-overflow-tooltip="true" />
           <el-table-column label="创建时间" align="left" prop="createTime" width="160" />
         </el-table>
-        <pagination
-          v-show="transTotal > 0"
-          :total="transTotal"
-          v-model:page="transQueryParams.pageNum"
-          v-model:limit="transQueryParams.pageSize"
-          @pagination="getTransList"
-        />
+        <pagination v-show="transTotal > 0" :total="transTotal" v-model:page="transQueryParams.pageNum"
+                    v-model:limit="transQueryParams.pageSize" @pagination="getTransList" />
       </el-card>
     </el-dialog>
 
@@ -236,7 +223,8 @@
     </el-dialog>
 
     <!-- 引用情况弹窗 -->
-    <el-dialog :title="useDialog.title" v-model="useDialog.visible" width="1000px" append-to-body :style="{ height: '850px' }">
+    <el-dialog :title="useDialog.title" v-model="useDialog.visible" width="1000px" append-to-body
+               :style="{ height: '850px' }">
       <el-card shadow="never">
         <el-table v-loading="loading" :data="itemRecordList">
           <el-table-column label="名称" align="left" prop="itemName" />
@@ -254,13 +242,8 @@
           <el-table-column label="创建人" align="left" prop="createUser" width="120" :show-overflow-tooltip="true" />
           <el-table-column label="创建时间" align="left" prop="createTime" width="150" />
         </el-table>
-        <pagination
-          v-show="itemTotal > 0"
-          :total="itemTotal"
-          v-model:page="dialogQueryParams.pageNum"
-          v-model:limit="dialogQueryParams.pageSize"
-          @pagination="getItemListByFileId"
-        />
+        <pagination v-show="itemTotal > 0" :total="itemTotal" v-model:page="dialogQueryParams.pageNum"
+                    v-model:limit="dialogQueryParams.pageSize" @pagination="getItemListByFileId" />
       </el-card>
     </el-dialog>
   </div>