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) - **Windows**: 使用 1024 进制 (二进制,1KB = 1024 bytes)
- **macOS**: 使用 1000 进制 (十进制,1KB = 1000 bytes) - **macOS**: 使用 1000 进制 (十进制,1KB = 1000 bytes)
- **Linux**: 使用 1000 进制 (十进制,遵循 SI 标准,1KB = 1000 bytes) - **Linux**: 使用 1000 进制 (十进制,遵循 SI 标准,1KB = 1000 bytes)
## 主要功能 ## 主要功能
### 1. 操作系统检测 ### 1. 操作系统检测
```javascript ```javascript
import { getOS } from '@/utils/fileSize' import { getOS } from '/src/renderer/utils/fileSize'
const currentOS = getOS() // 'windows', 'mac', 'linux', 'unknown' const currentOS = getOS() // 'windows', 'mac', 'linux', 'unknown'
``` ```
### 2. 获取基础单位大小 ### 2. 获取基础单位大小
```javascript ```javascript
import { getBaseSize } from '@/utils/fileSize' import { getBaseSize } from '/src/renderer/utils/fileSize'
const baseSize = getBaseSize() // 1024 (Windows/Linux) 或 1000 (macOS) const baseSize = getBaseSize() // 1024 (Windows/Linux) 或 1000 (macOS)
``` ```
### 3. 光盘类型配置 ### 3. 光盘类型配置
```javascript ```javascript
import { getCurrentOSDiscTypes } from '@/utils/fileSize' import { getCurrentOSDiscTypes } from '/src/renderer/utils/fileSize'
const discTypes = getCurrentOSDiscTypes() const discTypes = getCurrentOSDiscTypes()
// 返回当前系统适配的光盘类型配置 // 返回当前系统适配的光盘类型配置
``` ```
### 4. 文件大小格式化 ### 4. 文件大小格式化
```javascript ```javascript
import { formatFileSize } from '@/utils/fileSize' import { formatFileSize } from '/src/renderer/utils/fileSize'
const formatted = formatFileSize(1024*1024*1024) // "1.00 GB" (Windows) 或 "1.00 GB" (macOS) const formatted = formatFileSize(1024*1024*1024) // "1.00 GB" (Windows) 或 "1.00 GB" (macOS)
``` ```
## 使用示例 ## 使用示例
### 在组件中使用 ### 在组件中使用
```javascript ```javascript
// dashboard/index.vue // dashboard/index.vue
import { getCurrentOSDiscTypes } from '@/utils/fileSize' import { getCurrentOSDiscTypes } from '/src/renderer/utils/fileSize'
export default { export default {
methods: { methods: {
updateDiscTypes() { updateDiscTypes() {
const typeLists = getCurrentOSDiscTypes() const typeLists = getCurrentOSDiscTypes()
this.$store.dispatch('chat/setDatas', { name: 'cd_types', data: typeLists }) this.$store.dispatch('chat/setDatas', { name: 'cd_types', data: typeLists })
} }
} }
} }
``` ```
### 在工具函数中使用 ### 在工具函数中使用
```javascript ```javascript
// utils/index.js // utils/index.js
import { formatFileSize } from '@/utils/fileSize' import { formatFileSize } from '/src/renderer/utils/fileSize'
export const filterSize = (size) => { export const filterSize = (size) => {
if (!size || size < 0) return '0 B' if (!size || size < 0) return '0 B'
return formatFileSize(size) return formatFileSize(size)
} }
``` ```
## 光盘类型配置 ## 光盘类型配置
工具自动为不同操作系统生成正确的光盘容量配置: 工具自动为不同操作系统生成正确的光盘容量配置:
| 类型 | Windows | macOS/Linux | | 类型 | Windows | macOS/Linux |
|------|---------|-------------| |------|---------|-------------|
| CD 700MB | 734,003,200 bytes | 700,000,000 bytes | | CD 700MB | 734,003,200 bytes | 700,000,000 bytes |
| DVD 4.7GB | 5,046,586,572 bytes | 4,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 | | BD 25GB | 26,843,545,600 bytes | 25,000,000,000 bytes |
## 调试功能 ## 调试功能
```javascript ```javascript
import { getDebugInfo } from '@/utils/fileSize' import { getDebugInfo } from '/src/renderer/utils/fileSize'
const debug = getDebugInfo() const debug = getDebugInfo()
console.log(debug) console.log(debug)
// 输出当前系统的完整配置信息 // 输出当前系统的完整配置信息
``` ```
## 测试 ## 测试
运行测试文件查看不同系统的差异: 运行测试文件查看不同系统的差异:
```javascript ```javascript
import { testFileSizeCalculation, compareOSDifferences } from '@/utils/fileSizeTest' import { testFileSizeCalculation, compareOSDifferences } from '/src/renderer/utils/fileSizeTest'
testFileSizeCalculation() // 显示当前系统配置 testFileSizeCalculation() // 显示当前系统配置
compareOSDifferences() // 对比不同系统差异 compareOSDifferences() // 对比不同系统差异
``` ```
## 注意事项 ## 注意事项
1. 工具会自动检测当前操作系统 1. 工具会自动检测当前操作系统
2. 所有大小计算都基于字节 (bytes) 2. 所有大小计算都基于字节 (bytes)
3. 格式化显示会根据系统使用相应的进制 3. 格式化显示会根据系统使用相应的进制
4. 光盘容量配置会自动适配当前系统 4. 光盘容量配置会自动适配当前系统
## 更新历史 ## 更新历史
- 2024-01-XX: 初始版本,支持 Windows/macOS/Linux 跨平台文件大小计算 - 2024-01-XX: 初始版本,支持 Windows/macOS/Linux 跨平台文件大小计算
+4 -4
View File
@@ -465,14 +465,14 @@ export function accSub(arg1, arg2) {
export const filterSize = (size) => { export const filterSize = (size) => {
if (!size || size < 0) return '0 B'; if (!size || size < 0) return '0 B';
// 使用跨平台文件大小格式化 // 使用跨平台文件大小格式化(相对路径)
const { formatFileSize } = require('@/utils/fileSize') const { formatFileSize } = require('./fileSize')
return formatFileSize(size) return formatFileSize(size)
} }
export const pow1024 = (num) => { export const pow1024 = (num) => {
// 使用跨平台基础大小 // 使用跨平台基础大小(相对路径)
const { getBaseSize } = require('@/utils/fileSize') const { getBaseSize } = require('./fileSize')
const baseSize = getBaseSize() const baseSize = getBaseSize()
return Math.pow(baseSize, num) return Math.pow(baseSize, num)
} }
+2 -2
View File
@@ -341,6 +341,7 @@ import { mapGetters } from 'vuex'
const { app, dialog } = require('@electron/remote') const { app, dialog } = require('@electron/remote')
import UserInfo from '@/components/userInfo/userInfo.vue' import UserInfo from '@/components/userInfo/userInfo.vue'
import WorkAdd from '@/components/workAdd/workAdd.vue' import WorkAdd from '@/components/workAdd/workAdd.vue'
import { getCurrentOSDiscTypes } from '@/utils/fileSize'
const exePath = !app.isPackaged ? process.cwd() : path.dirname(process.execPath) const exePath = !app.isPackaged ? process.cwd() : path.dirname(process.execPath)
const shPath = path.join(exePath, 'CardsoonServer', 'control.sh') const shPath = path.join(exePath, 'CardsoonServer', 'control.sh')
const activePath = path.join(exePath, 'CardsoonServer', 'regist.sh') const activePath = path.join(exePath, 'CardsoonServer', 'regist.sh')
@@ -970,8 +971,7 @@ export default {
clearTimeout(outTimer) clearTimeout(outTimer)
that.currentRunVal = 0 that.currentRunVal = 0
// 使用跨平台文件大小计算 // 使用跨平台文件大小计算(相对路径)
const { getCurrentOSDiscTypes } = require('@/utils/fileSize')
let typeLists = getCurrentOSDiscTypes() let typeLists = getCurrentOSDiscTypes()
let isBD = that.changeCD.req_info.strong_list.findIndex(item => parseInt(item.strong_type) > 3) let isBD = that.changeCD.req_info.strong_list.findIndex(item => parseInt(item.strong_type) > 3)
if (isBD === -1) { if (isBD === -1) {