fix:some bug

This commit is contained in:
Lan
2024-11-25 18:30:14 +08:00
parent a247dd163d
commit 007291a2d9
10 changed files with 239 additions and 87 deletions
+1 -2
View File
@@ -1,5 +1,4 @@
import axios from 'axios'
import { useRouter } from 'vue-router'
// 从环境变量中获取 API 基础 URL
const baseURL =
@@ -13,7 +12,7 @@ const sanitizedBaseURL = typeof baseURL === 'string' ? baseURL : ''
// 创建 axios 实例
const api = axios.create({
baseURL: sanitizedBaseURL,
timeout: 10000, // 请求超时时间
timeout: 1000000000000000, // 请求超时时间
headers: {
'Content-Type': 'application/json'
}
+81
View File
@@ -0,0 +1,81 @@
/**
* 剪贴板工具函数
*/
import { useAlertStore } from '@/stores/alertStore'
interface CopyOptions {
successMsg?: string
errorMsg?: string
showMsg?: boolean
}
/**
* 复制文本到剪贴板
* @param text 要复制的文本
* @param options 配置选项
* @returns Promise<boolean> 是否复制成功
*/
export const copyToClipboard = async (
text: string,
options: CopyOptions = {}
): Promise<boolean> => {
const { successMsg = '复制成功', errorMsg = '复制失败,请手动复制', showMsg = true } = options
const alertStore = useAlertStore()
try {
// 优先使用 Clipboard API
if (navigator.clipboard && navigator.clipboard.writeText) {
await navigator.clipboard.writeText(text)
if (showMsg) alertStore.showAlert(successMsg, 'success')
return true
}
// 后备方案:使用传统的复制方法
const textarea = document.createElement('textarea')
textarea.value = text
textarea.style.position = 'fixed'
textarea.style.opacity = '0'
document.body.appendChild(textarea)
textarea.select()
const success = document.execCommand('copy')
document.body.removeChild(textarea)
if (success) {
if (showMsg) alertStore.showAlert(successMsg, 'success')
return true
} else {
throw new Error('execCommand copy failed')
}
} catch (err) {
console.error('复制失败:', err)
if (showMsg) alertStore.showAlert(errorMsg, 'error')
return false
}
}
/**
* 生成并复制取件链接
* @param code 取件码
* @returns Promise<boolean> 是否复制成功
*/
export const copyRetrieveLink = async (code: string): Promise<boolean> => {
const link = `${window.location.origin}/#/?code=${code}`
return copyToClipboard(link, {
successMsg: '取件链接已复制到剪贴板',
errorMsg: '复制失败,请手动复制取件链接'
})
}
/**
* 复制取件码
* @param code 取件码
* @returns Promise<boolean> 是否复制成功
*/
export const copyRetrieveCode = async (code: string): Promise<boolean> => {
return copyToClipboard(code, {
successMsg: '取件码已复制到剪贴板',
errorMsg: '复制失败,请手动复制取件码'
})
}
+10
View File
@@ -0,0 +1,10 @@
// 存储单位转换
export const getStorageUnit = (value: number) => {
if (value >= 1024 * 1024 * 1024) {
return Math.round(value / (1024 * 1024 * 1024)) + 'GB'
} else if (value >= 1024 * 1024) {
return Math.round(value / (1024 * 1024)) + 'MB'
} else {
return Math.round(value / 1024) + 'KB'
}
}