mirror of
				https://gitee.com/hhyykk/ipms-sjy-ui.git
				synced 2025-11-04 04:08:44 +08:00 
			
		
		
		
	Merge remote-tracking branch 'yudao/dev'
This commit is contained in:
		@@ -12,57 +12,7 @@ import dayjs from 'dayjs'
 | 
			
		||||
 * @returns 返回拼接后的时间字符串
 | 
			
		||||
 */
 | 
			
		||||
export function formatDate(date: Date, format: string): string {
 | 
			
		||||
  const we = date.getDay() // 星期
 | 
			
		||||
  const z = getWeek(date) // 周
 | 
			
		||||
  const qut = Math.floor((date.getMonth() + 3) / 3).toString() // 季度
 | 
			
		||||
  const opt: { [key: string]: string } = {
 | 
			
		||||
    'Y+': date.getFullYear().toString(), // 年
 | 
			
		||||
    'm+': (date.getMonth() + 1).toString(), // 月(月份从0开始,要+1)
 | 
			
		||||
    'd+': date.getDate().toString(), // 日
 | 
			
		||||
    'H+': date.getHours().toString(), // 时
 | 
			
		||||
    'M+': date.getMinutes().toString(), // 分
 | 
			
		||||
    'S+': date.getSeconds().toString(), // 秒
 | 
			
		||||
    'q+': qut // 季度
 | 
			
		||||
  }
 | 
			
		||||
  // 中文数字 (星期)
 | 
			
		||||
  const week: { [key: string]: string } = {
 | 
			
		||||
    '0': '日',
 | 
			
		||||
    '1': '一',
 | 
			
		||||
    '2': '二',
 | 
			
		||||
    '3': '三',
 | 
			
		||||
    '4': '四',
 | 
			
		||||
    '5': '五',
 | 
			
		||||
    '6': '六'
 | 
			
		||||
  }
 | 
			
		||||
  // 中文数字(季度)
 | 
			
		||||
  const quarter: { [key: string]: string } = {
 | 
			
		||||
    '1': '一',
 | 
			
		||||
    '2': '二',
 | 
			
		||||
    '3': '三',
 | 
			
		||||
    '4': '四'
 | 
			
		||||
  }
 | 
			
		||||
  if (/(W+)/.test(format))
 | 
			
		||||
    format = format.replace(
 | 
			
		||||
      RegExp.$1,
 | 
			
		||||
      RegExp.$1.length > 1 ? (RegExp.$1.length > 2 ? '星期' + week[we] : '周' + week[we]) : week[we]
 | 
			
		||||
    )
 | 
			
		||||
  if (/(Q+)/.test(format))
 | 
			
		||||
    format = format.replace(
 | 
			
		||||
      RegExp.$1,
 | 
			
		||||
      RegExp.$1.length == 4 ? '第' + quarter[qut] + '季度' : quarter[qut]
 | 
			
		||||
    )
 | 
			
		||||
  if (/(Z+)/.test(format))
 | 
			
		||||
    format = format.replace(RegExp.$1, RegExp.$1.length == 3 ? '第' + z + '周' : z + '')
 | 
			
		||||
  for (const k in opt) {
 | 
			
		||||
    const r = new RegExp('(' + k + ')').exec(format)
 | 
			
		||||
    // 若输入的长度不为1,则前面补零
 | 
			
		||||
    if (r)
 | 
			
		||||
      format = format.replace(
 | 
			
		||||
        r[1],
 | 
			
		||||
        RegExp.$1.length == 1 ? opt[k] : opt[k].padStart(RegExp.$1.length, '0')
 | 
			
		||||
      )
 | 
			
		||||
  }
 | 
			
		||||
  return format
 | 
			
		||||
  return dayjs(date).format(format)
 | 
			
		||||
}
 | 
			
		||||
// 日期格式化
 | 
			
		||||
export function parseTime(time: any, pattern?: string) {
 | 
			
		||||
 
 | 
			
		||||
@@ -137,3 +137,21 @@ export const generateUUID = () => {
 | 
			
		||||
    return (c === 'x' ? random : (random & 0x3) | 0x8).toString(16)
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * element plus 的文件大小 Formatter 实现
 | 
			
		||||
 *
 | 
			
		||||
 * @param row 行数据
 | 
			
		||||
 * @param column 字段
 | 
			
		||||
 * @param cellValue 字段值
 | 
			
		||||
 */
 | 
			
		||||
// @ts-ignore
 | 
			
		||||
export const fileSizeFormatter = (row, column, cellValue) => {
 | 
			
		||||
  const fileSize = cellValue
 | 
			
		||||
  const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
 | 
			
		||||
  const srcSize = parseFloat(fileSize)
 | 
			
		||||
  const index = Math.floor(Math.log(srcSize) / Math.log(1024))
 | 
			
		||||
  const size = srcSize / Math.pow(1024, index)
 | 
			
		||||
  const sizeStr = size.toFixed(2) //保留的小数位数
 | 
			
		||||
  return sizeStr + ' ' + unitArr[index]
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user