You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.3 KiB
68 lines
2.3 KiB
export const cmdNameMap = {
|
|
pump_rotate_start: '泵开始转动',
|
|
pump_rotate_stop: '泵停止转动',
|
|
solution_pre_fill_start: '预充',
|
|
solution_add_start: '加液',
|
|
solution_drain_start: '排空',
|
|
}
|
|
|
|
export const generateColors = (count: number): string[] => {
|
|
const colors: string[] = []
|
|
for (let i = 0; i < count; i++) {
|
|
// Increase hue step to make colors more distinct
|
|
const hue = (i * 360) / count
|
|
// Introduce variation in saturation and lightness with larger steps
|
|
const saturation = 30 + (i % 5) * 20 // Alternate between 30, 50, 70, 90, 110
|
|
const lightness = 30 + (i % 4) * 20 // Alternate between 30, 50, 70, 90
|
|
// Convert HSL to RGB
|
|
const rgb = hslToRgb(hue, saturation, lightness)
|
|
// Convert RGB to hex
|
|
const hex = rgbToHex(rgb.r, rgb.g, rgb.b)
|
|
colors.push(hex)
|
|
}
|
|
return colors
|
|
}
|
|
|
|
const hslToRgb = (h: number, s: number, l: number): { r: number, g: number, b: number } => {
|
|
s /= 100
|
|
l /= 100
|
|
const k = (n: number) => (n + h / 30) % 12
|
|
const a = s * Math.min(l, 1 - l)
|
|
const f = (n: number) =>
|
|
l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)))
|
|
return {
|
|
r: Math.round(f(0) * 255),
|
|
g: Math.round(f(8) * 255),
|
|
b: Math.round(f(4) * 255),
|
|
}
|
|
}
|
|
|
|
const rgbToHex = (r: number, g: number, b: number): string => {
|
|
const toHex = (c: number) => `0${c.toString(16)}`.slice(-2)
|
|
return `#${toHex(r)}${toHex(g)}${toHex(b)}`
|
|
}
|
|
|
|
export const colors = generateColors(100)
|
|
|
|
export function isNumber(value: any) {
|
|
return typeof value === 'number' && !Number.isNaN(value)
|
|
}
|
|
|
|
export function formatDateTime(template: string = 'YYYY/MM/DD HH:mm:ss', now: Date = new Date()): string {
|
|
const tokens: Record<string, string> = {
|
|
YYYY: String(now.getFullYear()),
|
|
MM: String(now.getMonth() + 1).padStart(2, '0'),
|
|
DD: String(now.getDate()).padStart(2, '0'),
|
|
HH: String(now.getHours()).padStart(2, '0'),
|
|
mm: String(now.getMinutes()).padStart(2, '0'),
|
|
ss: String(now.getSeconds()).padStart(2, '0'),
|
|
}
|
|
|
|
return template.replace(/YYYY|MM|DD|HH|mm|ss/g, token => tokens[token]!)
|
|
}
|
|
|
|
export function allPropertiesDefined(obj: Record<string, any>, excludeKeys: string[] = []): boolean {
|
|
return Object.entries(obj).every(([key, value]) => {
|
|
return excludeKeys.includes(key) || value === false ? true : value
|
|
})
|
|
}
|