diff --git a/commit_message.txt b/commit_message.txt new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/commit_message.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/renderer/store/modules/chat.js b/src/renderer/store/modules/chat.js index 9cb1906..488df6a 100644 --- a/src/renderer/store/modules/chat.js +++ b/src/renderer/store/modules/chat.js @@ -129,44 +129,9 @@ const CDTypes = { 6: 'BD_TL', 7: 'BD_QL' } -const size = 1024 -const cd_types = [ - { - value: 1, - label: 'CD 700MB', - size: 700 * size * size - }, - { - value: 2, - label: 'DVD 4.7GB', - size: 4.7 * size * size * size - }, - { - value: 3, - label: 'DVD_DL 8.5GB', - size: 8.5 * size * size * size - }, - { - value: 4, - label: 'BD 25GB', - size: 25 * size * size * size - }, - { - value: 5, - label: 'BD_DL 50GB', - size: 50 * size * size * size - }, - { - value: 6, - label: 'BD_TL 100GB', - size: 100 * size * size * size - }, - { - value: 7, - label: 'BD_QL 128GB', - size: 128 * size * size * size - } -] +// 使用跨平台文件大小计算 +const { getCurrentOSDiscTypes } = require('@/utils/fileSize') +const cd_types = getCurrentOSDiscTypes() const defaultData = { // 任务列表 diff --git a/src/renderer/utils/README_fileSize.md b/src/renderer/utils/README_fileSize.md new file mode 100644 index 0000000..c21e586 --- /dev/null +++ b/src/renderer/utils/README_fileSize.md @@ -0,0 +1,110 @@ +# 跨平台文件大小计算工具 + +## 概述 + +这个工具解决了不同操作系统下文件大小计算的差异问题: + +- **Windows**: 使用 1024 进制 (二进制,1KB = 1024 bytes) +- **macOS**: 使用 1000 进制 (十进制,1KB = 1000 bytes) +- **Linux**: 使用 1000 进制 (十进制,遵循 SI 标准,1KB = 1000 bytes) + +## 主要功能 + +### 1. 操作系统检测 +```javascript +import { getOS } from '@/utils/fileSize' + +const currentOS = getOS() // 'windows', 'mac', 'linux', 'unknown' +``` + +### 2. 获取基础单位大小 +```javascript +import { getBaseSize } from '@/utils/fileSize' + +const baseSize = getBaseSize() // 1024 (Windows/Linux) 或 1000 (macOS) +``` + +### 3. 光盘类型配置 +```javascript +import { getCurrentOSDiscTypes } from '@/utils/fileSize' + +const discTypes = getCurrentOSDiscTypes() +// 返回当前系统适配的光盘类型配置 +``` + +### 4. 文件大小格式化 +```javascript +import { formatFileSize } from '@/utils/fileSize' + +const formatted = formatFileSize(1024*1024*1024) // "1.00 GB" (Windows) 或 "1.00 GB" (macOS) +``` + +## 使用示例 + +### 在组件中使用 +```javascript +// dashboard/index.vue +import { getCurrentOSDiscTypes } from '@/utils/fileSize' + +export default { + methods: { + updateDiscTypes() { + const typeLists = getCurrentOSDiscTypes() + this.$store.dispatch('chat/setDatas', { name: 'cd_types', data: typeLists }) + } + } +} +``` + +### 在工具函数中使用 +```javascript +// utils/index.js +import { formatFileSize } from '@/utils/fileSize' + +export const filterSize = (size) => { + if (!size || size < 0) return '0 B' + return formatFileSize(size) +} +``` + +## 光盘类型配置 + +工具自动为不同操作系统生成正确的光盘容量配置: + +| 类型 | Windows | macOS/Linux | +|------|---------|-------------| +| CD 700MB | 734,003,200 bytes | 700,000,000 bytes | +| DVD 4.7GB | 5,046,586,572 bytes | 4,700,000,000 bytes | +| BD 25GB | 26,843,545,600 bytes | 25,000,000,000 bytes | + +## 调试功能 + +```javascript +import { getDebugInfo } from '@/utils/fileSize' + +const debug = getDebugInfo() +console.log(debug) +// 输出当前系统的完整配置信息 +``` + +## 测试 + +运行测试文件查看不同系统的差异: + +```javascript +import { testFileSizeCalculation, compareOSDifferences } from '@/utils/fileSizeTest' + +testFileSizeCalculation() // 显示当前系统配置 +compareOSDifferences() // 对比不同系统差异 +``` + +## 注意事项 + +1. 工具会自动检测当前操作系统 +2. 所有大小计算都基于字节 (bytes) +3. 格式化显示会根据系统使用相应的进制 +4. 光盘容量配置会自动适配当前系统 + +## 更新历史 + +- 2024-01-XX: 初始版本,支持 Windows/macOS/Linux 跨平台文件大小计算 diff --git a/src/renderer/utils/fileSize.js b/src/renderer/utils/fileSize.js new file mode 100644 index 0000000..671379f --- /dev/null +++ b/src/renderer/utils/fileSize.js @@ -0,0 +1,125 @@ +/** + * 跨平台文件大小计算工具 + * 处理不同操作系统的文件大小差异 + */ + +// 检测操作系统 +export function getOS() { + const platform = process.platform + if (platform === 'win32') return 'windows' + if (platform === 'darwin') return 'mac' + if (platform === 'linux') return 'linux' + return 'unknown' +} + +// 获取基础单位大小 +export function getBaseSize() { + const os = getOS() + + // 不同操作系统的基础单位 + const baseSizes = { + windows: 1024, // Windows 使用 1024 进制 (二进制) + mac: 1000, // macOS 使用 1000 进制 (十进制) + linux: 1000 // Linux 使用 1000 进制 (十进制,遵循 SI 标准) + } + + return baseSizes[os] || 1000 +} + +// 计算光盘类型大小 +export function calculateDiscSize(sizeInGB, os = null) { + const baseSize = os ? getBaseSizeForOS(os) : getBaseSize() + return sizeInGB * Math.pow(baseSize, 3) +} + +// 为特定操作系统获取基础大小 +export function getBaseSizeForOS(os) { + const baseSizes = { + windows: 1024, // Windows 使用 1024 进制 (二进制) + mac: 1000, // macOS 使用 1000 进制 (十进制) + linux: 1000 // Linux 使用 1000 进制 (十进制,遵循 SI 标准) + } + return baseSizes[os] || 1000 +} + +// 光盘类型配置 +export function getDiscTypes(os = null) { + const baseSize = os ? getBaseSizeForOS(os) : getBaseSize() + + return [ + { + value: 1, + label: 'CD 700MB', + size: 700 * Math.pow(baseSize, 2) + }, + { + value: 2, + label: 'DVD 4.7GB', + size: 4.7 * Math.pow(baseSize, 3) + }, + { + value: 3, + label: 'DVD_DL 8.5GB', + size: 8.5 * Math.pow(baseSize, 3) + }, + { + value: 4, + label: 'BD 25GB', + size: 25 * Math.pow(baseSize, 3) + }, + { + value: 5, + label: 'BD_DL 50GB', + size: 50 * Math.pow(baseSize, 3) + }, + { + value: 6, + label: 'BD_TL 100GB', + size: 100 * Math.pow(baseSize, 3) + }, + { + value: 7, + label: 'BD_QL 128GB', + size: 128 * Math.pow(baseSize, 3) + } + ] +} + +// 格式化文件大小显示 +export function formatFileSize(bytes, os = null) { + if (!bytes || bytes < 0) return '0 B' + + const baseSize = os ? getBaseSizeForOS(os) : getBaseSize() + const units = ['B', 'KB', 'MB', 'GB', 'TB'] + + let size = bytes + let unitIndex = 0 + + while (size >= baseSize && unitIndex < units.length - 1) { + size /= baseSize + unitIndex++ + } + + return `${size.toFixed(2)} ${units[unitIndex]}` +} + +// 获取当前系统的光盘类型配置 +export function getCurrentOSDiscTypes() { + return getDiscTypes() +} + +// 调试信息:显示当前系统配置 +export function getDebugInfo() { + const os = getOS() + const baseSize = getBaseSize() + const discTypes = getDiscTypes() + + return { + os, + baseSize, + discTypes: discTypes.map(type => ({ + ...type, + formattedSize: formatFileSize(type.size) + })) + } +} diff --git a/src/renderer/utils/fileSizeTest.js b/src/renderer/utils/fileSizeTest.js new file mode 100644 index 0000000..69cf4db --- /dev/null +++ b/src/renderer/utils/fileSizeTest.js @@ -0,0 +1,71 @@ +/** + * 跨平台文件大小计算测试 + * 用于验证不同操作系统下的文件大小计算是否正确 + */ + +import { + getOS, + getBaseSize, + getDiscTypes, + formatFileSize, + getDebugInfo +} from './fileSize' + +// 测试函数 +export function testFileSizeCalculation() { + console.log('=== 跨平台文件大小计算测试 ===') + + // 显示当前系统信息 + const debugInfo = getDebugInfo() + console.log('当前系统:', debugInfo.os) + console.log('基础单位:', debugInfo.baseSize) + console.log('光盘类型配置:') + + debugInfo.discTypes.forEach(type => { + console.log(` ${type.label}: ${type.formattedSize} (${type.size} bytes)`) + }) + + // 测试不同操作系统的配置 + const testOS = ['windows', 'mac', 'linux'] + + testOS.forEach(os => { + console.log(`\n--- ${os.toUpperCase()} 系统配置 ---`) + const discTypes = getDiscTypes(os) + discTypes.forEach(type => { + const formatted = formatFileSize(type.size, os) + console.log(` ${type.label}: ${formatted}`) + }) + }) + + // 测试文件大小格式化 + console.log('\n--- 文件大小格式化测试 ---') + const testSizes = [1024, 1024*1024, 1024*1024*1024, 4.7*1024*1024*1024] + + testSizes.forEach(size => { + console.log(`${size} bytes = ${formatFileSize(size)}`) + }) +} + +// 比较不同系统的差异 +export function compareOSDifferences() { + console.log('\n=== 操作系统差异对比 ===') + + const testSize = 4.7 * 1024 * 1024 * 1024 // 4.7GB + + const systems = [ + { name: 'Windows', baseSize: 1024 }, + { name: 'macOS', baseSize: 1000 }, + { name: 'Linux', baseSize: 1000 } + ] + + systems.forEach(system => { + const formatted = formatFileSize(testSize, system.name.toLowerCase()) + console.log(`${system.name}: ${formatted} (基础单位: ${system.baseSize})`) + }) +} + +// 导出测试函数 +export default { + testFileSizeCalculation, + compareOSDifferences +} diff --git a/src/renderer/utils/index.js b/src/renderer/utils/index.js index f829da7..faa9eff 100644 --- a/src/renderer/utils/index.js +++ b/src/renderer/utils/index.js @@ -463,17 +463,18 @@ export function accSub(arg1, arg2) { } /** * 文件大小 字节转换单位 * @param size * @returns {string|*} */ export const filterSize = (size) => { - if (!size || size < 0) return '0kb'; - if (size < pow1024(1)) return size + ' B'; - if (size < pow1024(2)) return (size / pow1024(1)).toFixed(2) + ' KB'; - if (size < pow1024(3)) return (size / pow1024(2)).toFixed(2) + ' MB'; - if (size < pow1024(4)) return (size / pow1024(3)).toFixed(2) + ' GB'; - return (size / pow1024(4)).toFixed(2) + ' TB' + if (!size || size < 0) return '0 B'; + + // 使用跨平台文件大小格式化 + const { formatFileSize } = require('@/utils/fileSize') + return formatFileSize(size) } export const pow1024 = (num) => { - const size = 1024 - return Math.pow(size, num) + // 使用跨平台基础大小 + const { getBaseSize } = require('@/utils/fileSize') + const baseSize = getBaseSize() + return Math.pow(baseSize, num) } // 执行脚本 diff --git a/src/renderer/views/dashboard/index.vue b/src/renderer/views/dashboard/index.vue index 005ba98..558d3f1 100644 --- a/src/renderer/views/dashboard/index.vue +++ b/src/renderer/views/dashboard/index.vue @@ -969,44 +969,10 @@ export default { .then(() => { clearTimeout(outTimer) that.currentRunVal = 0 - const size = 1024 - let typeLists = [ - { - value: 1, - label: 'CD 700MB', - size: 700 * size * size - }, - { - value: 2, - label: 'DVD 4.7GB', - size: 4.7 * size * size * size - }, - { - value: 3, - label: 'DVD_DL 8.5GB', - size: 8.5 * size * size * size - }, - { - value: 4, - label: 'BD 25GB', - size: 25 * size * size * size - }, - { - value: 5, - label: 'BD_DL 50GB', - size: 50 * size * size * size - }, - { - value: 6, - label: 'BD_TL 100GB', - size: 100 * size * size * size - }, - { - value: 7, - label: 'BD_QL 128GB', - size: 128 * size * size * size - } - ] + + // 使用跨平台文件大小计算 + const { getCurrentOSDiscTypes } = require('@/utils/fileSize') + let typeLists = getCurrentOSDiscTypes() let isBD = that.changeCD.req_info.strong_list.findIndex(item => parseInt(item.strong_type) > 3) if (isBD === -1) { typeLists = typeLists.slice(0, 3) @@ -1145,16 +1111,16 @@ export default { } }) .then(() => { - that.$message({ - message: '取消成功', - type: 'success' - }) - row.task_status = 7 - if (row.ass_task && row.ass_task.length > 0) { - row.ass_task.forEach((item) => { - item.task_status = 7 - }) - } + // that.$message({ + // message: '取消成功', + // type: 'success' + // }) + // row.task_status = 7 + // if (row.ass_task && row.ass_task.length > 0) { + // row.ass_task.forEach((item) => { + // item.task_status = 7 + // }) + // } }) }, // 跳转设置