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.

93 lines
3.3 KiB

3 months ago
3 months ago
  1. export const cmdNameMap = {
  2. door_open: '开门',
  3. door_close: '关门',
  4. door_stop: '停止开关门',
  5. liquid_arm_rotation: '加液机械臂启动',
  6. liquid_arm_reset: '加液机械臂复位',
  7. liquid_arm_stop: '加液机械臂停止',
  8. liquid_pump_start: '启动加液泵',
  9. liquid_pump_stop: '停止加液泵',
  10. liquid_pump_pre_filling: '预充加液头',
  11. liquid_pump_pre_evacuation: '排空加液头',
  12. shaker_start: '摇匀',
  13. shaker_stop: '停止摇匀',
  14. pallet_elevator_lift_up: '托盘上升',
  15. pallet_elevator_lift_down: '托盘下降',
  16. pallet_elevator_stop: '托盘停止',
  17. heater_start: '开始加热',
  18. heater_stop: '停止加热',
  19. heater_start_heat_maintaining: '启动恒温',
  20. heater_stop_heat_maintaining: '停止恒温',
  21. cold_trap_start_refrigeration: '启动制冷',
  22. cold_trap_stop_refrigeration: '停止制冷',
  23. fan_start: '打开风扇',
  24. fan_stop: '关闭风扇',
  25. transportation_arm_move: '龙门架机械臂移动',
  26. transportation_arm_stop: '龙门架机械臂停止移动',
  27. transportation_arm_reset: '龙门架机械臂复位',
  28. holding_jaw_open: '打开夹爪',
  29. holding_jaw_pause: '暂停夹爪',
  30. holding_jaw_close: '闭合夹爪',
  31. cover_elevator_lift_up: '拍子抬升',
  32. cover_elevator_stop: '拍子停止',
  33. cover_elevator_reset: '拍子复位',
  34. cover_elevator_lift_down: '拍子下降',
  35. cold_trap_start_recycle: '开启循环',
  36. cold_trap_stop_recycle: '停止循环',
  37. }
  38. export const generateColors = (count: number): string[] => {
  39. const colors: string[] = []
  40. for (let i = 0; i < count; i++) {
  41. // Increase hue step to make colors more distinct
  42. const hue = (i * 360) / count
  43. // Introduce variation in saturation and lightness with larger steps
  44. const saturation = 30 + (i % 5) * 20 // Alternate between 30, 50, 70, 90, 110
  45. const lightness = 30 + (i % 4) * 20 // Alternate between 30, 50, 70, 90
  46. // Convert HSL to RGB
  47. const rgb = hslToRgb(hue, saturation, lightness)
  48. // Convert RGB to hex
  49. const hex = rgbToHex(rgb.r, rgb.g, rgb.b)
  50. colors.push(hex)
  51. }
  52. return colors
  53. }
  54. const hslToRgb = (h: number, s: number, l: number): { r: number, g: number, b: number } => {
  55. s /= 100
  56. l /= 100
  57. const k = (n: number) => (n + h / 30) % 12
  58. const a = s * Math.min(l, 1 - l)
  59. const f = (n: number) =>
  60. l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)))
  61. return {
  62. r: Math.round(f(0) * 255),
  63. g: Math.round(f(8) * 255),
  64. b: Math.round(f(4) * 255),
  65. }
  66. }
  67. const rgbToHex = (r: number, g: number, b: number): string => {
  68. const toHex = (c: number) => `0${c.toString(16)}`.slice(-2)
  69. return `#${toHex(r)}${toHex(g)}${toHex(b)}`
  70. }
  71. export const colors = generateColors(100)
  72. export function isNumber(value: any) {
  73. return typeof value === 'number' && !Number.isNaN(value)
  74. }
  75. export function formatDateTime(template: string = 'YYYY/MM/DD HH:mm:ss'): string {
  76. const now = new Date()
  77. const tokens: Record<string, string> = {
  78. YYYY: String(now.getFullYear()),
  79. MM: String(now.getMonth() + 1).padStart(2, '0'),
  80. DD: String(now.getDate()).padStart(2, '0'),
  81. HH: String(now.getHours()).padStart(2, '0'),
  82. mm: String(now.getMinutes()).padStart(2, '0'),
  83. ss: String(now.getSeconds()).padStart(2, '0'),
  84. }
  85. return template.replace(/YYYY|MM|DD|HH|mm|ss/g, token => tokens[token]!)
  86. }