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

358 lines
10 KiB

2 months ago
2 weeks ago
2 months ago
2 weeks ago
2 weeks ago
2 months ago
2 weeks ago
2 weeks ago
3 weeks ago
2 weeks ago
2 weeks ago
2 months ago
2 months ago
2 weeks ago
2 months ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
3 weeks ago
2 weeks ago
2 months ago
2 weeks ago
2 months ago
3 weeks ago
2 weeks ago
2 months ago
2 months ago
2 months ago
3 weeks ago
2 weeks ago
2 months ago
2 weeks ago
2 months ago
2 weeks ago
3 weeks ago
2 weeks ago
2 months ago
  1. import { sendCmd, syncSendCmd } from 'apis/system'
  2. import { cloneDeep } from 'lodash'
  3. import { defineStore } from 'pinia'
  4. import { ref, watch } from 'vue'
  5. import { FtMessage } from '@/libs/message'
  6. // 常量定义
  7. const LOG_ITEMS = Array.from({ length: 12 }, (_, i) => ({
  8. value: i + 1,
  9. name: `${i + 1} Log`,
  10. }))
  11. const PRESSURE_TYPES = [
  12. { name: '常压', value: 'constantPressure' },
  13. { name: '正压', value: 'positivePressure' },
  14. { name: '负压', value: 'negativePressure' },
  15. ]
  16. // 默认配方函数
  17. // const createDefaultFormulaInfo = (): Formula.FormulaItem => ({
  18. // continued_gs: 200,
  19. // continued_humi: 60,
  20. // continued_satur: 60,
  21. // injection_pump_speed: 10,
  22. // loglevel: 6,
  23. // max_humidity: 90,
  24. // pre_heat_time_s: 120,
  25. // proportional_valve_default_value: 10,
  26. // stoped_gs: 300,
  27. // stoped_humi: 85,
  28. // stoped_satur: 85,
  29. // dvalue_correct_coefficient: 0
  30. // name: '默认配方',
  31. // })
  32. // 清空配方函数
  33. // const createResetFormulaInfo = (): Formula.FormulaItem => ({
  34. // continued_gs: '',
  35. // continued_humi: '',
  36. // continued_satur: '',
  37. // injection_pump_speed: '',
  38. // loglevel: '',
  39. // max_humidity: '',
  40. // pre_heat_time_s: '',
  41. // proportional_valve_default_value: '',
  42. // stoped_gs: '',
  43. // stoped_humi: '',
  44. // stoped_satur: '',
  45. // name: '',
  46. // })
  47. export const useFormulaStore = defineStore('formula', () => {
  48. // 状态定义
  49. const logEnums = LOG_ITEMS
  50. const pressurList = PRESSURE_TYPES
  51. const logLevelOptions = ref<System.Option[]>([])
  52. const defaultFormulaInfo = ref<Formula.FormulaItem | null>(null)
  53. // const resetFormulaInfo = ref<Formula.FormulaItem>(createResetFormulaInfo())
  54. const pressurOptionList = ref<string[]>(['10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', '100%'])
  55. const currentSelectedFormulaInfo = ref<Formula.FormulaItem>(cloneDeep(defaultFormulaInfo.value)) // 当前列表选中的配方信息
  56. const selectedFormulaInfo = ref<Formula.FormulaItem | null>(cloneDeep(defaultFormulaInfo.value)) // 选中执行的配方信息
  57. const formulaConfigList = ref<Formula.FormulaConfig[]>([])
  58. const formulaList = ref<Formula.FormulaItem[]>([])
  59. const loglevel = ref<string>('1')
  60. const flip = ref(true)
  61. const currentSelectedIndex = ref<number | null>(null) // 左侧列表选中值 从0开始
  62. // 标签单位映射表,用于显示各参数的单位
  63. const labelUnitMap: Record<string, any> = {
  64. injection_pump_speed: 'g/min',
  65. continued_gs: 'ppm',
  66. stoped_gs: 'ppm',
  67. max_humidity: '%RH',
  68. pre_heat_time_s: '秒',
  69. continued_humi: '%RH',
  70. stoped_humi: '%RH',
  71. continued_satur: '%RS',
  72. stoped_satur: '%RS',
  73. loglevel: 'Log',
  74. dvalue_correct_coefficient: '',
  75. record_period_min: '秒',
  76. record_printer_period_min: '分钟',
  77. }
  78. watch(
  79. defaultFormulaInfo,
  80. (newVal) => {
  81. currentSelectedFormulaInfo.value = cloneDeep(newVal)
  82. },
  83. { deep: true },
  84. )
  85. /**
  86. * @function mapConfigToFormula
  87. * @param {Formula.FormulaConfig[]} config -
  88. * @desc
  89. */
  90. const mapConfigToFormula = (config: Formula.FormulaConfig[]) => {
  91. const formulaMap: Record<string, any> = {}
  92. config.forEach((item) => {
  93. formulaMap[item.setting_id] = Number(item.val)
  94. if (item.val_type === 'enum' && item.setting_id === 'loglevel') {
  95. updateLogLevels(item)
  96. }
  97. })
  98. formulaMap.name = '默认配置'
  99. return formulaMap as Formula.FormulaItem
  100. }
  101. /**
  102. * @function updateFormulaConfigData
  103. * @param {Formula.FormulaConfig[]} data -
  104. * @desc
  105. */
  106. const updateFormulaConfigData = (data: Formula.FormulaConfig[]) => {
  107. // const visibleConfig = data.filter(item => item.is_visible_in_formula_page)
  108. formulaConfigList.value = data
  109. defaultFormulaInfo.value = mapConfigToFormula(data)
  110. }
  111. const getFormualDefaultData = async () => {
  112. const defaultParams = {
  113. className: 'SettingMgrService',
  114. fnName: 'getAllSetting',
  115. params: {},
  116. }
  117. const res = await sendCmd(defaultParams)
  118. updateFormulaConfigData(res)
  119. }
  120. /**
  121. * @function updateLogLevels
  122. * @param {Formula.FormulaConfig} logLevelItem -
  123. * @desc
  124. */
  125. const updateLogLevels = (logLevelItem: Formula.FormulaConfig) => {
  126. const list: System.Option[] = []
  127. const { enum_display_names, enums } = logLevelItem
  128. loglevel.value = String(logLevelItem.default_val)
  129. enums?.forEach((item: number, index: number) => {
  130. list.push({
  131. label: enum_display_names?.[index] || '',
  132. value: item,
  133. })
  134. })
  135. logLevelOptions.value = list
  136. }
  137. /**
  138. * @function updateLogLevel
  139. * @param {string} level -
  140. * @desc
  141. */
  142. const updateLogLevel = (level: string) => {
  143. loglevel.value = level
  144. }
  145. /**
  146. * @function updatePressurList
  147. * @param {string[]} pressurData -
  148. * @desc
  149. */
  150. const updatePressurList = (pressurData: string[]) => {
  151. pressurOptionList.value = cloneDeep(pressurData)
  152. }
  153. /**
  154. * @function updateSelectedFormulaData
  155. * @param {Formula.FormulaItem} formulaItem -
  156. * @desc
  157. */
  158. const updateCurrentSelectedFormulaData = (formulaItem: Formula.FormulaItem) => {
  159. console.log('formulaItem--', formulaItem)
  160. currentSelectedFormulaInfo.value = cloneDeep(formulaItem)
  161. }
  162. /**
  163. * @function updateSelectedFormula
  164. * @param {Formula.FormulaItem} formulaItem -
  165. * @desc
  166. */
  167. const updateSelectedFormula = (formulaItem: Formula.FormulaItem) => {
  168. selectedFormulaInfo.value = cloneDeep(formulaItem)
  169. }
  170. /**
  171. * @function initFormulaList
  172. * @desc
  173. */
  174. const initFormulaList = async () => {
  175. try {
  176. const params = {
  177. className: 'SettingMgrService',
  178. fnName: 'getAllFormula',
  179. params: {},
  180. }
  181. const res = await syncSendCmd(params)
  182. if (res.rely) {
  183. formulaList.value = res.rely
  184. if (res.rely.length > 0) {
  185. console.log('selectedIndex.value--', currentSelectedIndex.value)
  186. currentSelectedFormulaInfo.value = res.rely[res.rely.length - 1]
  187. currentSelectedIndex.value = res.rely.length - 1
  188. }
  189. else {
  190. currentSelectedIndex.value = null
  191. }
  192. }
  193. else {
  194. formulaList.value = []
  195. currentSelectedIndex.value = null
  196. }
  197. }
  198. catch (error) {
  199. console.error('获取配方列表失败', error)
  200. }
  201. }
  202. /**
  203. *
  204. * @param {string} settingName -
  205. * @param {string} settingVal -
  206. * @returns {Promise<void>}
  207. */
  208. const setSettingFormulaConfig = async (settingName: string, settingVal: string) => {
  209. await sendCmd({
  210. className: 'SettingMgrService',
  211. fnName: 'setSettingVal',
  212. params: {
  213. settingName,
  214. settingVal: settingVal?.toString(),
  215. },
  216. })
  217. }
  218. /**
  219. * @function initFormulaData
  220. * @desc
  221. */
  222. const initFormulaData = () => {
  223. selectedFormulaInfo.value = cloneDeep(defaultFormulaInfo.value)
  224. resetToDefaultFormula()
  225. }
  226. /**
  227. * @function resetToDefaultFormula
  228. * @desc
  229. */
  230. const resetToDefaultFormula = () => {
  231. currentSelectedFormulaInfo.value = cloneDeep(defaultFormulaInfo.value)
  232. }
  233. /**
  234. * @function saveDisinfectFormula
  235. * @param {Formula.FormulaItem} formData -
  236. * @desc
  237. */
  238. const startDisinfectFormula = async (formData: Formula.FormulaItem) => {
  239. try {
  240. const params = {
  241. className: 'DisinfectionCtrlServiceExt',
  242. fnName: 'startWithFormula',
  243. params: {
  244. formulaid: formData.formula_id,
  245. },
  246. }
  247. await sendCmd(params)
  248. FtMessage.success('已启动消毒程序')
  249. }
  250. catch (error) {
  251. console.error('保存消毒配方失败', error)
  252. FtMessage.error('启动消毒程序失败')
  253. }
  254. }
  255. const updateFlip = (data: boolean) => {
  256. flip.value = data
  257. }
  258. const updateCurrentSelectedIndex = (index: number | null) => {
  259. currentSelectedIndex.value = index
  260. }
  261. const onAddFormula = () => {
  262. const params = {
  263. className: 'SettingMgrService',
  264. fnName: 'addNewFormula',
  265. }
  266. return syncSendCmd(params)
  267. }
  268. /**
  269. *
  270. * @param {string} formula_id - ID
  271. * @param {Formula.FormulaItem} formulaForm -
  272. */
  273. const editFormula = (formula_id: string, formulaForm: Formula.FormulaItem) => {
  274. const editParams = {
  275. className: 'SettingMgrService',
  276. fnName: 'updateFormula',
  277. params: {
  278. formula_id,
  279. formula: cloneDeep(formulaForm),
  280. },
  281. }
  282. return syncSendCmd(editParams)
  283. }
  284. // 删除配方
  285. const delFormula = (formulaId: string) => {
  286. const delParams = {
  287. className: 'SettingMgrService',
  288. fnName: 'delFormula',
  289. params: {
  290. formula_id: formulaId,
  291. },
  292. }
  293. return syncSendCmd(delParams)
  294. }
  295. // 开始执行
  296. const startFormula = (formulaId: string) => {
  297. const params = {
  298. className: 'DisinfectionCtrlServiceExt',
  299. fnName: 'startWithFormula',
  300. params: {
  301. formulaid: formulaId,
  302. },
  303. }
  304. return syncSendCmd(params)
  305. }
  306. return {
  307. // 属性
  308. logEnums,
  309. pressurList,
  310. pressurOptionList,
  311. currentSelectedFormulaInfo,
  312. formulaList,
  313. formulaConfigList,
  314. loglevel,
  315. logLevelOptions,
  316. selectedFormulaInfo,
  317. defaultFormulaInfo,
  318. flip,
  319. currentSelectedIndex,
  320. labelUnitMap,
  321. // 方法
  322. updatePressurList,
  323. updateCurrentSelectedFormulaData,
  324. initFormulaData,
  325. initFormulaList,
  326. updateSelectedFormula,
  327. updateFormulaConfigData,
  328. startDisinfectFormula,
  329. updateLogLevel,
  330. resetToDefaultFormula,
  331. getFormualDefaultData,
  332. updateFlip,
  333. updateCurrentSelectedIndex,
  334. setSettingFormulaConfig,
  335. onAddFormula,
  336. editFormula,
  337. delFormula,
  338. startFormula,
  339. }
  340. })