mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 15:36:49 +08:00
feat:捷径根据参数自动打开
This commit is contained in:
@@ -8,8 +8,7 @@ dayjs.extend(relativeTime)
|
|||||||
dayjs.locale(ZH_CN)
|
dayjs.locale(ZH_CN)
|
||||||
|
|
||||||
export function avatarText(value: string) {
|
export function avatarText(value: string) {
|
||||||
if (!value)
|
if (!value) return ''
|
||||||
return ''
|
|
||||||
const nameArray = value.split(' ')
|
const nameArray = value.split(' ')
|
||||||
|
|
||||||
return nameArray.map(word => word.charAt(0).toUpperCase()).join('')
|
return nameArray.map(word => word.charAt(0).toUpperCase()).join('')
|
||||||
@@ -19,7 +18,9 @@ export function avatarText(value: string) {
|
|||||||
export function kFormatter(num: number) {
|
export function kFormatter(num: number) {
|
||||||
const regex = /\B(?=(\d{3})+(?!\d))/g
|
const regex = /\B(?=(\d{3})+(?!\d))/g
|
||||||
|
|
||||||
return Math.abs(num) > 9999 ? `${Math.sign(num) * +((Math.abs(num) / 1000).toFixed(1))}k` : Math.abs(num).toFixed(0).replace(regex, ',')
|
return Math.abs(num) > 9999
|
||||||
|
? `${Math.sign(num) * +(Math.abs(num) / 1000).toFixed(1)}k`
|
||||||
|
: Math.abs(num).toFixed(0).replace(regex, ',')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -29,9 +30,11 @@ export function kFormatter(num: number) {
|
|||||||
* @param {string} value date to format
|
* @param {string} value date to format
|
||||||
* @param {Intl.DateTimeFormatOptions} formatting Intl object to format with
|
* @param {Intl.DateTimeFormatOptions} formatting Intl object to format with
|
||||||
*/
|
*/
|
||||||
export function formatDate(value: string, formatting: Intl.DateTimeFormatOptions = { month: 'short', day: 'numeric', year: 'numeric' }) {
|
export function formatDate(
|
||||||
if (!value)
|
value: string,
|
||||||
return value
|
formatting: Intl.DateTimeFormatOptions = { month: 'short', day: 'numeric', year: 'numeric' },
|
||||||
|
) {
|
||||||
|
if (!value) return value
|
||||||
|
|
||||||
return new Intl.DateTimeFormat('en-US', formatting).format(new Date(value))
|
return new Intl.DateTimeFormat('en-US', formatting).format(new Date(value))
|
||||||
}
|
}
|
||||||
@@ -46,21 +49,19 @@ export function formatDateToMonthShort(value: string, toTimeForCurrentDay = true
|
|||||||
const date = new Date(value)
|
const date = new Date(value)
|
||||||
let formatting: Record<string, string> = { month: 'short', day: 'numeric' }
|
let formatting: Record<string, string> = { month: 'short', day: 'numeric' }
|
||||||
|
|
||||||
if (toTimeForCurrentDay && isToday(date))
|
if (toTimeForCurrentDay && isToday(date)) formatting = { hour: 'numeric', minute: 'numeric' }
|
||||||
formatting = { hour: 'numeric', minute: 'numeric' }
|
|
||||||
|
|
||||||
return new Intl.DateTimeFormat('en-US', formatting).format(new Date(value))
|
return new Intl.DateTimeFormat('en-US', formatting).format(new Date(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const prefixWithPlus = (value: number) => value > 0 ? `+${value}` : value
|
export const prefixWithPlus = (value: number) => (value > 0 ? `+${value}` : value)
|
||||||
|
|
||||||
// 格式化为Sxx
|
// 格式化为Sxx
|
||||||
export const formatSeason = (value: string) => value ? `S${value.padStart(2, '0')}` : ''
|
export const formatSeason = (value: string) => (value ? `S${value.padStart(2, '0')}` : '')
|
||||||
|
|
||||||
// 格式化为xx[TGMK]B
|
// 格式化为xx[TGMK]B
|
||||||
export function formatFileSize(bytes: number) {
|
export function formatFileSize(bytes: number) {
|
||||||
if (bytes < 0)
|
if (bytes < 0) throw new Error('字节数不能为负数。')
|
||||||
throw new Error('字节数不能为负数。')
|
|
||||||
|
|
||||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||||
let size = bytes
|
let size = bytes
|
||||||
@@ -82,22 +83,18 @@ export function formatSeconds(seconds: number) {
|
|||||||
|
|
||||||
let formattedTime = ''
|
let formattedTime = ''
|
||||||
|
|
||||||
if (hours > 0)
|
if (hours > 0) formattedTime += `${hours}小时`
|
||||||
formattedTime += `${hours}小时`
|
|
||||||
|
|
||||||
if (minutes > 0)
|
if (minutes > 0) formattedTime += `${minutes}分`
|
||||||
formattedTime += `${minutes}分`
|
|
||||||
|
|
||||||
if ((remainingSeconds > 0 || formattedTime === '') && hours <= 0)
|
if ((remainingSeconds > 0 || formattedTime === '') && hours <= 0) formattedTime += `${remainingSeconds}秒`
|
||||||
formattedTime += `${remainingSeconds}秒`
|
|
||||||
|
|
||||||
return formattedTime
|
return formattedTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// YYYY-MM-DD 转化为Date
|
// YYYY-MM-DD 转化为Date
|
||||||
export function parseDate(dateString: string): Date | null {
|
export function parseDate(dateString: string): Date | null {
|
||||||
if (!dateString)
|
if (!dateString) return null
|
||||||
return null
|
|
||||||
const [year, month, day] = dateString.split('-').map(Number)
|
const [year, month, day] = dateString.split('-').map(Number)
|
||||||
|
|
||||||
return new Date(year, month - 1, day)
|
return new Date(year, month - 1, day)
|
||||||
@@ -105,8 +102,7 @@ export function parseDate(dateString: string): Date | null {
|
|||||||
|
|
||||||
// 文件大小格式化
|
// 文件大小格式化
|
||||||
export function formatBytes(bytes: number, decimals = 2) {
|
export function formatBytes(bytes: number, decimals = 2) {
|
||||||
if (bytes === 0)
|
if (bytes === 0) return '0 bytes'
|
||||||
return '0 bytes'
|
|
||||||
|
|
||||||
const k = 1024
|
const k = 1024
|
||||||
const dm = decimals < 0 ? 0 : decimals
|
const dm = decimals < 0 ? 0 : decimals
|
||||||
@@ -119,11 +115,9 @@ export function formatBytes(bytes: number, decimals = 2) {
|
|||||||
|
|
||||||
// 格式化剧集列表
|
// 格式化剧集列表
|
||||||
export function formatEp(nums: number[]): string {
|
export function formatEp(nums: number[]): string {
|
||||||
if (!nums.length)
|
if (!nums.length) return ''
|
||||||
return ''
|
|
||||||
|
|
||||||
if (nums.length === 1)
|
if (nums.length === 1) return nums[0].toString()
|
||||||
return nums[0].toString()
|
|
||||||
|
|
||||||
// 将数组升序排序
|
// 将数组升序排序
|
||||||
nums.sort((a, b) => a - b)
|
nums.sort((a, b) => a - b)
|
||||||
@@ -134,44 +128,22 @@ export function formatEp(nums: number[]): string {
|
|||||||
for (let i = 1; i < nums.length; i++) {
|
for (let i = 1; i < nums.length; i++) {
|
||||||
if (nums[i] === end + 1) {
|
if (nums[i] === end + 1) {
|
||||||
end = nums[i]
|
end = nums[i]
|
||||||
}
|
} else {
|
||||||
else {
|
if (start === end) formattedRanges.push(start.toString())
|
||||||
if (start === end)
|
else formattedRanges.push(`${start.toString()}-${end.toString()}`)
|
||||||
formattedRanges.push(start.toString())
|
|
||||||
|
|
||||||
else
|
|
||||||
formattedRanges.push(`${start.toString()}-${end.toString()}`)
|
|
||||||
|
|
||||||
start = end = nums[i]
|
start = end = nums[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start === end)
|
if (start === end) formattedRanges.push(start.toString())
|
||||||
formattedRanges.push(start.toString())
|
else formattedRanges.push(`${start.toString()}-${end.toString()}`)
|
||||||
|
|
||||||
else
|
|
||||||
formattedRanges.push(`${start.toString()}-${end.toString()}`)
|
|
||||||
|
|
||||||
return formattedRanges.join('、')
|
return formattedRanges.join('、')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 将yyyy-mm-dd hh:mm:ss转换为时间差,如:1小时前,1天前
|
// 将yyyy-mm-dd hh:mm:ss转换为时间差,如:1小时前,1天前
|
||||||
export function formatDateDifference(dateString: string): string {
|
export function formatDateDifference(dateString: string): string {
|
||||||
// const timeDifference = dayjs().millisecond() - dayjs(dateString).millisecond()
|
if (!dateString) return ''
|
||||||
// const secondsDifference = Math.floor(timeDifference / 1000)
|
|
||||||
// const minutesDifference = Math.floor(secondsDifference / 60)
|
|
||||||
// const hoursDifference = Math.floor(minutesDifference / 60)
|
|
||||||
// const daysDifference = Math.floor(hoursDifference / 24)
|
|
||||||
|
|
||||||
// if (daysDifference > 0)
|
|
||||||
// return `${daysDifference}天前`
|
|
||||||
// else if (hoursDifference > 0)
|
|
||||||
// return `${hoursDifference}小时前`
|
|
||||||
// else if (minutesDifference > 0)
|
|
||||||
// return `${minutesDifference}分钟前`
|
|
||||||
// else
|
|
||||||
// return '刚刚'
|
|
||||||
if (!dateString)
|
|
||||||
return ''
|
|
||||||
return dayjs(dateString).fromNow()
|
return dayjs(dateString).fromNow()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// 👉 IsEmpty
|
// 👉 IsEmpty
|
||||||
export function isEmpty(value: unknown): boolean {
|
export function isEmpty(value: unknown): boolean {
|
||||||
if (value === null || value === undefined || value === '')
|
if (value === null || value === undefined || value === '') return true
|
||||||
return true
|
|
||||||
|
|
||||||
return !!(Array.isArray(value) && value.length === 0)
|
return !!(Array.isArray(value) && value.length === 0)
|
||||||
}
|
}
|
||||||
@@ -33,73 +32,6 @@ export function isToday(date: Date) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 计算时间差,返回xx天/xx小时/xx分钟/xx秒
|
|
||||||
*
|
|
||||||
* @deprecated 建议使用:@core/utils/formatters.ts formatDateDifference
|
|
||||||
*/
|
|
||||||
export function calculateTimeDifference(inputTime: string): string {
|
|
||||||
if (!inputTime)
|
|
||||||
return ''
|
|
||||||
|
|
||||||
const inputDate = new Date(inputTime.replaceAll(/-/g, '/'))
|
|
||||||
const currentDate = new Date()
|
|
||||||
|
|
||||||
const timeDifference = currentDate.getTime() - inputDate.getTime()
|
|
||||||
const secondsDifference = Math.floor(timeDifference / 1000)
|
|
||||||
|
|
||||||
if (secondsDifference < 60) {
|
|
||||||
return `${secondsDifference}秒`
|
|
||||||
}
|
|
||||||
else if (secondsDifference < 3600) {
|
|
||||||
const minutes = Math.floor(secondsDifference / 60)
|
|
||||||
|
|
||||||
return `${minutes}分钟`
|
|
||||||
}
|
|
||||||
else if (secondsDifference < 86400) {
|
|
||||||
const hours = Math.floor(secondsDifference / 3600)
|
|
||||||
|
|
||||||
return `${hours}小时`
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const days = Math.floor(secondsDifference / 86400)
|
|
||||||
|
|
||||||
return `${days}天`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 计算时间差,返回xx天xx小时xx分钟
|
|
||||||
export function calculateTimeDiff(inputTime: string): string {
|
|
||||||
if (!inputTime)
|
|
||||||
return ''
|
|
||||||
|
|
||||||
// 使用当前时区
|
|
||||||
const inputDate = new Date(inputTime.replaceAll(/-/g, '/'))
|
|
||||||
const currentDate = new Date()
|
|
||||||
|
|
||||||
const timeDifference = currentDate.getTime() - inputDate.getTime()
|
|
||||||
const secondsDifference = Math.floor(timeDifference / 1000)
|
|
||||||
|
|
||||||
const days = Math.floor(secondsDifference / 86400)
|
|
||||||
const hours = Math.floor(secondsDifference % 86400 / 3600)
|
|
||||||
const minutes = Math.floor(secondsDifference % 86400 % 3600 / 60)
|
|
||||||
const secones = Math.floor(secondsDifference % 60)
|
|
||||||
|
|
||||||
if (days > 0)
|
|
||||||
return `${days}天${hours}小时${minutes}分钟`
|
|
||||||
|
|
||||||
else if (hours > 0)
|
|
||||||
return `${hours}小时${minutes}分钟`
|
|
||||||
|
|
||||||
else if (minutes > 0)
|
|
||||||
return `${minutes}分钟`
|
|
||||||
|
|
||||||
else if (secones > 0)
|
|
||||||
return `${secones}秒`
|
|
||||||
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断一个数组subArray是不是在另一个数组mainArray中
|
// 判断一个数组subArray是不是在另一个数组mainArray中
|
||||||
export function isContained(subArray: any[], mainArray: any[]): boolean {
|
export function isContained(subArray: any[], mainArray: any[]): boolean {
|
||||||
return subArray.every(element => mainArray.includes(element))
|
return subArray.every(element => mainArray.includes(element))
|
||||||
@@ -112,8 +44,7 @@ export function isIntersected(array1: any[], array2: any[]): boolean {
|
|||||||
|
|
||||||
export function isNullOrEmptyObject(obj: any): boolean {
|
export function isNullOrEmptyObject(obj: any): boolean {
|
||||||
// 首先判断是否为 null 或 undefined
|
// 首先判断是否为 null 或 undefined
|
||||||
if (obj === null || obj === undefined)
|
if (obj === null || obj === undefined) return true
|
||||||
return true
|
|
||||||
|
|
||||||
// 然后判断是否为空对象
|
// 然后判断是否为空对象
|
||||||
return !!(typeof obj === 'object' && Object.keys(obj).length === 0)
|
return !!(typeof obj === 'object' && Object.keys(obj).length === 0)
|
||||||
@@ -127,3 +58,10 @@ export function checkPrefersColorSchemeIsDark(): boolean {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从URL中获取参数值
|
||||||
|
export function getQueryValue(key: string, url = window.location.href): string {
|
||||||
|
const reg = new RegExp(`[?&]${key}=([^&#]*)`, 'i')
|
||||||
|
const res = reg.exec(url)
|
||||||
|
return res ? res[1] : ''
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import MessageView from '@/views/system/MessageView.vue'
|
|||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import { useDisplay } from 'vuetify'
|
import { useDisplay } from 'vuetify'
|
||||||
|
import { getQueryValue } from '@/@core/utils'
|
||||||
|
|
||||||
// 显示器宽度
|
// 显示器宽度
|
||||||
const display = useDisplay()
|
const display = useDisplay()
|
||||||
@@ -75,6 +76,29 @@ async function sendMessage() {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
scrollMessageToEnd()
|
scrollMessageToEnd()
|
||||||
|
const shortcut = getQueryValue('shortcut')
|
||||||
|
if (shortcut) {
|
||||||
|
switch (shortcut) {
|
||||||
|
case 'nameTest':
|
||||||
|
nameTestDialog.value = true
|
||||||
|
break
|
||||||
|
case 'netTest':
|
||||||
|
netTestDialog.value = true
|
||||||
|
break
|
||||||
|
case 'logging':
|
||||||
|
loggingDialog.value = true
|
||||||
|
break
|
||||||
|
case 'ruleTest':
|
||||||
|
ruleTestDialog.value = true
|
||||||
|
break
|
||||||
|
case 'systemTest':
|
||||||
|
systemTestDialog.value = true
|
||||||
|
break
|
||||||
|
case 'message':
|
||||||
|
messageDialog.value = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user