消毒机设备
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.

127 lines
3.7 KiB

2 months ago
2 months ago
2 months ago
  1. export function formatDateTime(template: string = 'YYYY-MM-DD HH:mm:ss', timestamp?: number): string {
  2. const now = timestamp ? new Date(timestamp) : new Date()
  3. const tokens: Record<string, string> = {
  4. YYYY: String(now.getFullYear()),
  5. MM: String(now.getMonth() + 1).padStart(2, '0'),
  6. DD: String(now.getDate()).padStart(2, '0'),
  7. HH: String(now.getHours()).padStart(2, '0'),
  8. mm: String(now.getMinutes()).padStart(2, '0'),
  9. ss: String(now.getSeconds()).padStart(2, '0'),
  10. }
  11. return template.replace(/YYYY|MM|DD|HH|mm|ss/g, token => tokens[token]!)
  12. }
  13. export function roundNumber(num: string | number, digits: number) {
  14. num = Number(num)
  15. if (!num) {
  16. return num
  17. }
  18. digits = digits || 0
  19. return Number(num.toFixed(digits))
  20. }
  21. export const deviceStateMap = <Record<string, any>>{
  22. idle: '空闲',
  23. init: '初始化设备',
  24. preheat: '预热中',
  25. disinfection: '消毒中',
  26. degradation: '降解中',
  27. finished: '消毒完成',
  28. dehumidificationBeforeDisinfection: '消毒前除湿',
  29. dehumidificationAfterDisinfection: '消毒后除湿',
  30. emptyLineLiquid: '排空管路',
  31. }
  32. export const sealStateMap = <Record<string, any>>{
  33. idle: '空闲',
  34. initDevice: '初始化',
  35. iniflating: '打压中',
  36. leakText: '检漏中',
  37. stopping: '停止中',
  38. }
  39. export const compareJSON = (obj1: any, obj2: any) => {
  40. const result: Record<string, any> = {}
  41. // 遍历obj1的所有属性
  42. for (const key in obj1) {
  43. if (Object.prototype.hasOwnProperty.call(obj1, key)) {
  44. if (!Object.prototype.hasOwnProperty.call(obj2, key)) {
  45. // obj2中不存在该属性
  46. result[key] = { obj1: obj1[key], obj2: undefined }
  47. }
  48. else if (typeof obj1[key] !== typeof obj2[key]) {
  49. // 类型不同
  50. result[key] = { obj1: obj1[key], obj2: obj2[key] }
  51. }
  52. else if (typeof obj1[key] === 'object' && obj1[key] !== null && obj2[key] !== null) {
  53. // 递归比较对象
  54. const nestedDiff = compareJSON(obj1[key], obj2[key])
  55. if (Object.keys(nestedDiff).length > 0) {
  56. result[key] = nestedDiff
  57. }
  58. }
  59. else if (obj1[key] !== obj2[key]) {
  60. // 基本类型值不同
  61. result[key] = { oldVal: obj1[key], newVal: obj2[key] }
  62. }
  63. }
  64. }
  65. return result
  66. }
  67. let isFullscreen = false
  68. export const openFullscreen = () => {
  69. const elem = document.documentElement
  70. if (!isFullscreen) {
  71. isFullscreen = true
  72. elem.requestFullscreen()
  73. }
  74. else {
  75. isFullscreen = false
  76. document.exitFullscreen()
  77. }
  78. }
  79. export const convertValuesToString = (jsonObj: Record<string, any>, exName: string) => {
  80. const result: Record<string, any> = {}
  81. for (const [key, value] of Object.entries(jsonObj)) {
  82. if (key !== exName) {
  83. result[key] = String(value)
  84. }
  85. else {
  86. result[key] = value
  87. }
  88. }
  89. return result
  90. }
  91. function isNumber(str: string | number) {
  92. // 先转换为数字,再用 isNaN 判断是否为 NaN
  93. return !Number.isNaN(Number(str)) && Number.isFinite(Number(str))
  94. }
  95. export const convertValuesToInt = (jsonObj: Record<string, any>) => {
  96. const result: Record<string, any> = {}
  97. for (const [key, value] of Object.entries(jsonObj)) {
  98. if (key !== 'name' && isNumber(value)) {
  99. result[key] = Number(value)
  100. }
  101. else {
  102. result[key] = value
  103. }
  104. }
  105. return result
  106. }
  107. export const DEVICE_STATES = {
  108. IDLE: 'idle', // 空闲
  109. INIT: 'init', // 初始化
  110. PREHEAT: 'preheat', // 预热
  111. DISINFECTION: 'disinfection', // 消毒
  112. DEGRADATION: 'degradation', // 降解
  113. FINISHED: 'finished', // 结束
  114. DEHUMIDIFICATION_BEFORE: 'dehumidification_before_disinfection', // 消毒前除湿
  115. DEHUMIDIFICATION_AFTER: 'dehumidification_after_disinfection', // 消毒后除湿
  116. EMPTY_LINE: 'empty_liquid_from_the_line', // 清空管路
  117. }