chore: use relative imports for fileSize to avoid alias issues

This commit is contained in:
24kycj
2025-10-22 17:00:06 +08:00
parent 3f20a6b16a
commit ad9c8025c6
4 changed files with 733 additions and 733 deletions
File diff suppressed because it is too large Load Diff
+110 -110
View File
@@ -1,110 +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 跨平台文件大小计算
# 跨平台文件大小计算工具
## 概述
这个工具解决了不同操作系统下文件大小计算的差异问题:
- **Windows**: 使用 1024 进制 (二进制,1KB = 1024 bytes)
- **macOS**: 使用 1000 进制 (十进制,1KB = 1000 bytes)
- **Linux**: 使用 1000 进制 (十进制,遵循 SI 标准,1KB = 1000 bytes)
## 主要功能
### 1. 操作系统检测
```javascript
import { getOS } from '/src/renderer/utils/fileSize'
const currentOS = getOS() // 'windows', 'mac', 'linux', 'unknown'
```
### 2. 获取基础单位大小
```javascript
import { getBaseSize } from '/src/renderer/utils/fileSize'
const baseSize = getBaseSize() // 1024 (Windows/Linux) 或 1000 (macOS)
```
### 3. 光盘类型配置
```javascript
import { getCurrentOSDiscTypes } from '/src/renderer/utils/fileSize'
const discTypes = getCurrentOSDiscTypes()
// 返回当前系统适配的光盘类型配置
```
### 4. 文件大小格式化
```javascript
import { formatFileSize } from '/src/renderer/utils/fileSize'
const formatted = formatFileSize(1024*1024*1024) // "1.00 GB" (Windows) 或 "1.00 GB" (macOS)
```
## 使用示例
### 在组件中使用
```javascript
// dashboard/index.vue
import { getCurrentOSDiscTypes } from '/src/renderer/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 '/src/renderer/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 '/src/renderer/utils/fileSize'
const debug = getDebugInfo()
console.log(debug)
// 输出当前系统的完整配置信息
```
## 测试
运行测试文件查看不同系统的差异:
```javascript
import { testFileSizeCalculation, compareOSDifferences } from '/src/renderer/utils/fileSizeTest'
testFileSizeCalculation() // 显示当前系统配置
compareOSDifferences() // 对比不同系统差异
```
## 注意事项
1. 工具会自动检测当前操作系统
2. 所有大小计算都基于字节 (bytes)
3. 格式化显示会根据系统使用相应的进制
4. 光盘容量配置会自动适配当前系统
## 更新历史
- 2024-01-XX: 初始版本,支持 Windows/macOS/Linux 跨平台文件大小计算
+4 -4
View File
@@ -465,14 +465,14 @@ export function accSub(arg1, arg2) {
export const filterSize = (size) => {
if (!size || size < 0) return '0 B';
// 使用跨平台文件大小格式化
const { formatFileSize } = require('@/utils/fileSize')
// 使用跨平台文件大小格式化(相对路径)
const { formatFileSize } = require('./fileSize')
return formatFileSize(size)
}
export const pow1024 = (num) => {
// 使用跨平台基础大小
const { getBaseSize } = require('@/utils/fileSize')
// 使用跨平台基础大小(相对路径)
const { getBaseSize } = require('./fileSize')
const baseSize = getBaseSize()
return Math.pow(baseSize, num)
}
+2 -2
View File
@@ -341,6 +341,7 @@ import { mapGetters } from 'vuex'
const { app, dialog } = require('@electron/remote')
import UserInfo from '@/components/userInfo/userInfo.vue'
import WorkAdd from '@/components/workAdd/workAdd.vue'
import { getCurrentOSDiscTypes } from '@/utils/fileSize'
const exePath = !app.isPackaged ? process.cwd() : path.dirname(process.execPath)
const shPath = path.join(exePath, 'CardsoonServer', 'control.sh')
const activePath = path.join(exePath, 'CardsoonServer', 'regist.sh')
@@ -970,8 +971,7 @@ export default {
clearTimeout(outTimer)
that.currentRunVal = 0
// 使用跨平台文件大小计算
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) {