Files
bigscreenWeb/src/utils/common.ts

87 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-09-25 13:32:47 +08:00
import type { App } from 'vue'
/**
*
* @param relativeUrl
* @param domain
*/
export const fullUrl = (relativeUrl: string, domain = '') => {
return domain + '/api/system-boot/image/toStream?bgImage=' + relativeUrl
}
/**
*
* @param path
*/
export function isExternal(path: string): boolean {
return /^(https?|ftp|mailto|tel):/.test(path)
}
/**
*
*/
const padStart = (str: string, maxLength: number, fillString = ' ') => {
if (str.length >= maxLength) return str
const fillLength = maxLength - str.length
let times = Math.ceil(fillLength / fillString.length)
while ((times >>= 1)) {
fillString += fillString
if (times === 1) {
fillString += fillString
}
}
return fillString.slice(0, fillLength) + str
}
/**
*
* @param dateTime
* @param fmt yyyy-mm-dd hh:MM:ss
*/
export const timeFormat = (dateTime: string | number | null = null, fmt = 'yyyy-mm-dd hh:MM:ss') => {
if (dateTime == 'none') return '-'
if (!dateTime) dateTime = Number(new Date())
if (dateTime.toString().length === 10) {
dateTime = +dateTime * 1000
}
const date = new Date(dateTime)
let ret
const opt: any = {
'y+': date.getFullYear().toString(), // 年
'm+': (date.getMonth() + 1).toString(), // 月
'd+': date.getDate().toString(), // 日
'h+': date.getHours().toString(), // 时
'M+': date.getMinutes().toString(), // 分
's+': date.getSeconds().toString() // 秒
}
for (const k in opt) {
ret = new RegExp('(' + k + ')').exec(fmt)
if (ret) {
fmt = fmt.replace(ret[1], ret[1].length == 1 ? opt[k] : padStart(opt[k], ret[1].length, '0'))
}
}
return fmt
}
/**
* el-form 8-16
*/
export const validatePwd = (rule: any, value: string, callback: any) => {
if (value === '') {
callback(new Error('请输入密码'))
} else {
const reg = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@#$%^&+=!])(?=.*[a-zA-Z0-9])[A-Za-z\d@#$%^&+=!]{8,16}$/
if (!reg.test(value)) {
callback(new Error('密码需要包含特殊字符字母数字长度为8-16'))
} else {
callback()
}
}
}