Browse Source

feat(system): 优化导出文件命名格式

- 新增 dateUtils.ts 工具类,提供 parseTime 函数用于格式化日期- 修改 handHistory、items、levels 和 structures 页面中的导出功能- 使用 parseTime 函数替代原生 Date().getTime(),生成更易读的文件名
-统一文件命名格式为 "类型年月日时分秒.xlsx"
fugui001 4 tháng trước cách đây
mục cha
commit
4e58b131df

+ 39 - 0
src/utils/dateUtils.ts

@@ -0,0 +1,39 @@
+// src/utils/dateUtils.ts
+export function parseTime(time: string | number | Date, cFormat?: string): string {
+  if (arguments.length === 0) {
+    return '';
+  }
+
+  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}';
+  let date: Date;
+
+  // 如果是字符串,尝试解析为 Date
+  if (typeof time === 'string') {
+    date = new Date(time);
+  } else if (time instanceof Date) {
+    date = time;
+  } else {
+    date = new Date(time * 1000); // 时间戳(毫秒)
+  }
+
+  // 确保日期有效
+  if (isNaN(date.getTime())) {
+    return '';
+  }
+
+  // 定义映射表
+  const map: Record<string, string> = {
+    'y': date.getFullYear().toString(),
+    'm': (date.getMonth() + 1).toString().padStart(2, '0'),
+    'd': date.getDate().toString().padStart(2, '0'),
+    'h': date.getHours().toString().padStart(2, '0'),
+    'i': date.getMinutes().toString().padStart(2, '0'),
+    's': date.getSeconds().toString().padStart(2, '0'),
+    'w': date.getDay().toString()
+  };
+
+  // 替换格式字符串中的占位符
+  return format.replace(/{([ymdhisw])}/g, (match, key) => {
+    return map[key] || match;
+  });
+}

+ 2 - 2
src/views/system/business/handHistory/index.vue

@@ -29,9 +29,9 @@
               >删除</el-button
             >
           </el-col>
-          <el-col :span="1.5">
+<!--          <el-col :span="1.5">
             <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['system:handHistory:export']">导出</el-button>
-          </el-col>
+          </el-col>-->
           <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
         </el-row>
       </template>

+ 3 - 2
src/views/system/business/items/index.vue

@@ -98,7 +98,8 @@
 <script setup name="Items" lang="ts">
 import { listItems, getItems, delItems, addItems, updateItems } from '@/api/system/business/items';
 import { ItemsVO, ItemsQuery, ItemsForm } from '@/api/system/business/items/types';
-
+// ✅ 引入 parseTime
+import { parseTime } from '@/utils/dateUtils';
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 
 const itemsList = ref<ItemsVO[]>([]);
@@ -237,7 +238,7 @@ const handleExport = () => {
     {
       ...queryParams.value
     },
-    `道具_${new Date().getTime()}.xlsx`
+    `道具${parseTime(new Date(), '{y}{m}{d}{h}{i}{s}')}.xlsx`
   );
 };
 

+ 3 - 1
src/views/system/business/levels/index.vue

@@ -132,6 +132,8 @@ import { listLevels, getLevels, delLevels, addLevels, updateLevels } from '@/api
 import { LevelsVO, LevelsQuery, LevelsForm } from '@/api/system/business/levels/types';
 import { defineProps, onMounted, watch } from 'vue';
 import { useBlindStructureInfo } from '@/api/system/business/levels/useBlindStructureId';
+// ✅ 引入 parseTime
+import { parseTime } from '@/utils/dateUtils';
 
 const props = defineProps({
   blindStructureId: {
@@ -303,7 +305,7 @@ const handleExport = () => {
     {
       ...queryParams.value
     },
-    `盲注等级_${new Date().getTime()}.xlsx`
+    `盲注等级${parseTime(new Date(), '{y}{m}{d}{h}{i}{s}')}.xlsx`
   );
 };
 

+ 4 - 1
src/views/system/business/structures/index.vue

@@ -180,6 +180,9 @@ import { StructuresVO, StructuresQuery, StructuresForm } from '@/api/system/busi
 import { ref } from 'vue';
 import LevelsIndex from '@/views/system/business/levels/index.vue';
 import * as XLSX from 'xlsx';
+
+// ✅ 引入 parseTime
+import { parseTime } from '@/utils/dateUtils';
 // 控制 Dialog 是否显示
 const levelsDialogVisible = ref(false);
 
@@ -359,7 +362,7 @@ const handleExport = () => {
     {
       ...queryParams.value
     },
-    `structures_${new Date().getTime()}.xlsx`
+    `盲注表${parseTime(new Date(), '{y}{m}{d}{h}{i}{s}')}.xlsx`
   );
 };
 onMounted(() => {