添加链接管理功能,包括路由配置、权限设置和在管理布局中显示链接管理菜单项
This commit is contained in:
94
src/utils/links.js
Normal file
94
src/utils/links.js
Normal file
@@ -0,0 +1,94 @@
|
||||
// 链接管理工具函数
|
||||
|
||||
// 格式化链接状态
|
||||
export function formatLinkStatus(status) {
|
||||
const statusMap = {
|
||||
'ACTIVE': '启用',
|
||||
'INACTIVE': '禁用',
|
||||
'EXPIRED': '已过期'
|
||||
}
|
||||
return statusMap[status] || status
|
||||
}
|
||||
|
||||
// 获取链接状态标签类型
|
||||
export function getLinkStatusType(status) {
|
||||
const typeMap = {
|
||||
'ACTIVE': 'success',
|
||||
'INACTIVE': 'danger',
|
||||
'EXPIRED': 'warning'
|
||||
}
|
||||
return typeMap[status] || 'info'
|
||||
}
|
||||
|
||||
// 检查链接是否过期
|
||||
export function isLinkExpired(expiredAt) {
|
||||
if (!expiredAt) return false
|
||||
return new Date(expiredAt) < new Date()
|
||||
}
|
||||
|
||||
// 计算剩余时间
|
||||
export function getRemainingTime(expiredAt) {
|
||||
if (!expiredAt) return null
|
||||
|
||||
const now = new Date()
|
||||
const expired = new Date(expiredAt)
|
||||
const diff = expired - now
|
||||
|
||||
if (diff <= 0) return '已过期'
|
||||
|
||||
const days = Math.floor(diff / (1000 * 60 * 60 * 24))
|
||||
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
|
||||
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60))
|
||||
|
||||
if (days > 0) return `${days}天${hours}小时`
|
||||
if (hours > 0) return `${hours}小时${minutes}分钟`
|
||||
return `${minutes}分钟`
|
||||
}
|
||||
|
||||
// 生成二维码URL(使用在线服务)
|
||||
export function generateQRCodeUrl(data, size = 200) {
|
||||
return `https://api.qrserver.com/v1/create-qr-code/?size=${size}x${size}&data=${encodeURIComponent(data)}`
|
||||
}
|
||||
|
||||
// 下载图片
|
||||
export function downloadImage(url, filename) {
|
||||
const link = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = filename
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
}
|
||||
|
||||
// 复制到剪贴板
|
||||
export async function copyToClipboard(text) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text)
|
||||
return true
|
||||
} catch (error) {
|
||||
console.error('复制失败:', error)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 导出CSV数据
|
||||
export function exportToCSV(data, headers, filename) {
|
||||
const csvContent = [
|
||||
headers.join(','),
|
||||
...data.map(row =>
|
||||
headers.map(header => {
|
||||
const value = row[header.key] || ''
|
||||
// 处理包含逗号的值
|
||||
return value.toString().includes(',') ? `"${value}"` : value
|
||||
}).join(',')
|
||||
)
|
||||
].join('\n')
|
||||
|
||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' })
|
||||
const link = document.createElement('a')
|
||||
link.href = URL.createObjectURL(blob)
|
||||
link.download = filename
|
||||
link.click()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user