util.ts
1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { dateUtil } from '/@/utils/dateUtil';
export interface RadioRecord {
  width: number;
  height: number;
  isLess: boolean;
  radio: number;
}
export const DEFAULT_ANIMATION_INTERVAL = 2000;
export const DEFAULT_RADIO_RECORD: RadioRecord = {
  width: 200,
  height: 140,
  isLess: false,
  radio: 1,
};
export const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD HH:mm:ss';
export const getUpdateTime = (updateTime?: string) => {
  return updateTime ? dateUtil(updateTime).format(DEFAULT_DATE_FORMAT) : '暂无更新时间';
};
export const calcScale = (
  width: number,
  height: number,
  widthRadio: number,
  heightRadio: number
): RadioRecord => {
  width = width * (widthRadio / 100);
  height = height * (heightRadio / 100);
  const temp = width > height ? height ** 2 : width ** 2;
  const isLess = temp < 300 * 300;
  const radio = temp / (300 * 300);
  return {
    width,
    height,
    isLess,
    radio,
  };
};
export const fontSize = ({
  radioRecord,
  basic,
  max,
  min,
}: {
  radioRecord: RadioRecord;
  basic: number;
  max?: number;
  min?: number;
}) => {
  const { radio } = radioRecord;
  let res = basic * radio;
  if (max && res > max) res = max;
  if (min && res < min) res = min;
  return res + 'px';
};