HomeView.ets 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370
  1. import BusinessConstant, { DeviceType } from '../common/constants/BusinessConstant'
  2. import MesAioRequest from '../common/util/request/MesAioRequest'
  3. import TimeUtil from '../Common/util/TimeUtil'
  4. import RequestParamModel from '../viewmodel/warehouse/RequestParamModel'
  5. import {
  6. MqttAsync,
  7. MqttConnectOptions,
  8. MqttSubscribeOptions,
  9. MqttPublishOptions,
  10. MqttResponse,
  11. MqttMessage,
  12. MqttClient,
  13. } from '@ohos/mqtt';
  14. import MqttUploadData from '../viewmodel/mqtt/MqttUploadData'
  15. import TempHumiditySensor from '../viewmodel/device/TempHumiditySensor'
  16. import ElectricScrewdriverPresetModel from '../model/ElectricScrewdriverPresetModel';
  17. import ElectricSolderingIronPresetModel from '../model/ElectricSolderingIronPresetModel';
  18. @Component
  19. export struct HomeView {
  20. private mqttAsyncClient: MqttClient | null = null;
  21. // Set Client Configuration
  22. @State subscribeTopic: string = BusinessConstant.mqttSubscribeTopic;
  23. @State subscribeTopic2: string = BusinessConstant.mqttSubscribeTopic2;
  24. @State publishTopic: string = BusinessConstant.mqttPublishTopic;
  25. @State payload: string = '';
  26. @State url: string = BusinessConstant.mqttUrl;
  27. @State clientId: string = BusinessConstant.mqttClientId;
  28. @State userName: string = BusinessConstant.mqttUserName;
  29. @State password: string = BusinessConstant.mqttPassword;
  30. @State connectedCount: number = 0;
  31. // @State isConnect: boolean = false;
  32. @State isPromise: boolean = false;
  33. @State numList: number[] = [1,2,3]
  34. @State planFinish: PlanFinish = {}
  35. @State tempHumiditySensor: TempHumiditySensor = {OnlineStatus: 0}
  36. @State onlineDeviceNum: number = 0
  37. @State userStatistics: UserStatistics = {}
  38. @State outsourceStatistics: OutsourceStatistics = {}
  39. @State vehicleStatistics: VehicleStatistics = {}
  40. @State processStatistics: ProductProcessStatistics = {}
  41. private swiperController: SwiperController = new SwiperController()
  42. async aboutToAppear() {
  43. ElectricScrewdriverPresetModel.initTaskDB(getContext())
  44. ElectricSolderingIronPresetModel.initTaskDB(getContext())
  45. await this.createClient();
  46. await this.connect();
  47. await this.subscribe();
  48. this.planFinish = await MesAioRequest.post("/api/v1/process/census/task/count", {} as RequestParamModel)
  49. this.userStatistics = await MesAioRequest.post("/api/v1/test/userStatistics", {} as RequestParamModel)
  50. this.outsourceStatistics = await MesAioRequest.post("/api/v1/test/outsourceStatistics", {} as RequestParamModel)
  51. this.vehicleStatistics = await MesAioRequest.post("/api/v1/test/vehicleStatistics", {} as RequestParamModel)
  52. this.processStatistics = await MesAioRequest.post("/api/v1/test/productProcessStatistics", {} as RequestParamModel)
  53. }
  54. build() {
  55. Column() {
  56. // 顶部状态栏
  57. Row() {
  58. Text(TimeUtil.getDateAndWeek())
  59. .fontSize($r('app.float.fontSize_6_4'))
  60. .fontColor($r('app.color.FFFFFF'))
  61. .fontWeight(FontWeight.Lighter)
  62. Text(' ' + TimeUtil.getTimePeriod())
  63. .fontSize($r('app.float.fontSize_7'))
  64. .fontColor($r('app.color.FFFFFF'))
  65. .fontWeight(FontWeight.Lighter)
  66. Text(' ' + TimeUtil.getHourAndMinute())
  67. .fontSize($r('app.float.fontSize_7'))
  68. .fontColor($r('app.color.FFFFFF'))
  69. .fontWeight(FontWeight.Lighter)
  70. Row() {
  71. Image($r('app.media.state_ai'))
  72. .width($r('app.float.virtualSize_9_6'))
  73. .height($r('app.float.virtualSize_9_6'))
  74. .fillColor($r('app.color.FFFFFF'))
  75. Image($r('app.media.state_ipc'))
  76. .width($r('app.float.virtualSize_9_6'))
  77. .height($r('app.float.virtualSize_9_6'))
  78. .fillColor($r('app.color.FFFFFF'))
  79. Image($r('app.media.state_voice'))
  80. .width($r('app.float.virtualSize_9_6'))
  81. .height($r('app.float.virtualSize_9_6'))
  82. .fillColor($r('app.color.FFFFFF'))
  83. Image($r('app.media.state_microphone'))
  84. .width($r('app.float.virtualSize_9_6'))
  85. .height($r('app.float.virtualSize_9_6'))
  86. .fillColor($r('app.color.FFFFFF'))
  87. }
  88. .width('10%')
  89. .justifyContent(FlexAlign.SpaceEvenly)
  90. .alignItems(VerticalAlign.Bottom)
  91. .margin({right: 1})
  92. .height('100%')
  93. }
  94. .width('100%')
  95. .height('3.4%')
  96. .alignItems(VerticalAlign.Bottom)
  97. .justifyContent(FlexAlign.End)
  98. // 登录人员信息
  99. Row({space: 5}) {
  100. Row().width('2.8%')
  101. Image($r('app.media.state_user'))
  102. .width($r('app.float.virtualSize_19_2'))
  103. .height($r('app.float.virtualSize_19_2'))
  104. .fillColor($r('app.color.FFFFFF'))
  105. Text('李明华')
  106. .fontSize($r('app.float.fontSize_6_4'))
  107. .fontColor($r('app.color.FFFFFF'))
  108. .fontWeight(FontWeight.Regular)
  109. }
  110. .width('100%')
  111. .height('4%')
  112. .alignItems(VerticalAlign.Center)
  113. // 首页:时间和编辑栏
  114. Row({space: 10}) {
  115. Text(TimeUtil.getHourAndMinute())
  116. .fontSize($r('app.float.fontSize_28'))
  117. .fontColor($r('app.color.FFFFFF'))
  118. .fontWeight(FontWeight.Lighter)
  119. Text(TimeUtil.getDateAndWeek() + TimeUtil.getTimePeriod())
  120. .fontSize($r('app.float.fontSize_15_2'))
  121. .fontColor($r('app.color.FFFFFF'))
  122. .fontWeight(FontWeight.Lighter)
  123. .opacity(0.6)
  124. Blank()
  125. Image($r('app.media.home_edit'))
  126. .width($r('app.float.virtualSize_16_8'))
  127. .height($r('app.float.virtualSize_16_8'))
  128. .fillColor($r('app.color.FFFFFF'))
  129. }
  130. .width('94.4%')
  131. .height('14.9%')
  132. Swiper(this.swiperController) {
  133. ForEach(this.numList, (index:number) => {
  134. Column() {
  135. // 第一行卡片
  136. Row() {
  137. // 制造订单
  138. Column(){
  139. Row() {
  140. Text('制造订单')
  141. .fontSize($r('app.float.fontSize_12'))
  142. .fontColor($r('app.color.FFFFFF'))
  143. .fontWeight(FontWeight.Medium)
  144. }
  145. .height('17%')
  146. .width('85.5%')
  147. .alignItems(VerticalAlign.Bottom)
  148. // Row() {
  149. // Text(BusinessConstant.stationName)
  150. // .fontSize($r('app.float.fontSize_6_4'))
  151. // .fontColor($r('app.color.FFFFFF'))
  152. // .fontWeight(FontWeight.Lighter)
  153. // .opacity(0.6)
  154. // }
  155. // .height('6.6%')
  156. // .width('85.5%')
  157. // .alignItems(VerticalAlign.Bottom)
  158. Row().height('13%')
  159. Column() {
  160. Text((this.planFinish?.monthFinish! ? this.planFinish.monthFinish : 0) + '/' + (this.planFinish?.monthPlan! ? this.planFinish.monthPlan : 0))
  161. .fontSize($r('app.float.fontSize_28'))
  162. .fontColor($r('app.color.FFFFFF'))
  163. .fontWeight(FontWeight.Lighter)
  164. .maxLines(1)
  165. .opacity(0.6)
  166. Text('本月进度')
  167. .fontSize($r('app.float.fontSize_6_4'))
  168. .fontColor($r('app.color.FFFFFF'))
  169. .fontWeight(FontWeight.Lighter)
  170. }
  171. .height('35%')
  172. .width('85.5%')
  173. .alignItems(HorizontalAlign.Start)
  174. Row() {
  175. Row() {
  176. Text(this.planFinish?.dayPlan! ? this.planFinish.dayPlan.toString() : '0')
  177. .fontSize($r('app.float.fontSize_15_2'))
  178. .fontColor($r('app.color.FFFFFF'))
  179. .fontWeight(FontWeight.Lighter)
  180. }
  181. .width('33.3%')
  182. .justifyContent(FlexAlign.Center)
  183. Row() {
  184. Text(this.planFinish?.dayFinish! ? this.planFinish.dayFinish.toString() : '0')
  185. .fontSize($r('app.float.fontSize_15_2'))
  186. .fontColor($r('app.color.FFFFFF'))
  187. .fontWeight(FontWeight.Lighter)
  188. }
  189. .width('33.3%')
  190. .justifyContent(FlexAlign.Center)
  191. Row() {
  192. Text(this.planFinish?.dayRate! ? this.planFinish.dayRate + '%' : '0%')
  193. .fontSize($r('app.float.fontSize_15_2'))
  194. .fontColor($r('app.color.FFFFFF'))
  195. .fontWeight(FontWeight.Lighter)
  196. }
  197. .width('33.3%')
  198. .justifyContent(FlexAlign.Center)
  199. }
  200. .height('20%')
  201. .width('85.5%')
  202. .alignItems(VerticalAlign.Bottom)
  203. Row() {
  204. Row() {
  205. Text('今日计划')
  206. .fontSize($r('app.float.fontSize_6_4'))
  207. .fontColor($r('app.color.FFFFFF'))
  208. .fontWeight(FontWeight.Lighter)
  209. }
  210. .width('33.3%')
  211. .justifyContent(FlexAlign.Center)
  212. Row() {
  213. Text('今日完成')
  214. .fontSize($r('app.float.fontSize_6_4'))
  215. .fontColor($r('app.color.FFFFFF'))
  216. .fontWeight(FontWeight.Lighter)
  217. }
  218. .width('33.3%')
  219. .justifyContent(FlexAlign.Center)
  220. Row() {
  221. Text('今日完成率')
  222. .fontSize($r('app.float.fontSize_6_4'))
  223. .fontColor($r('app.color.FFFFFF'))
  224. .fontWeight(FontWeight.Lighter)
  225. }
  226. .width('33.3%')
  227. .justifyContent(FlexAlign.Center)
  228. }
  229. .height('15%')
  230. .width('85.5%')
  231. .alignItems(VerticalAlign.Top)
  232. .justifyContent(FlexAlign.SpaceAround)
  233. }
  234. .width('32.8%')
  235. .height('100%')
  236. .borderRadius($r('app.float.virtualSize_6_4'))
  237. .backgroundImage($r("app.media.home_bg_process_task"))
  238. .backgroundImageSize(ImageSize.Contain)
  239. //温湿度
  240. Column() {
  241. Row() {
  242. Text('温湿度')
  243. .fontSize($r('app.float.fontSize_12'))
  244. .fontColor($r('app.color.FFFFFF'))
  245. .fontWeight(FontWeight.Medium)
  246. }
  247. .height('18.5%')
  248. .width('100%')
  249. .alignItems(VerticalAlign.Bottom)
  250. .justifyContent(FlexAlign.Center)
  251. Row(){}.height('18.5%')
  252. Row(){
  253. Text((this.tempHumiditySensor?.OnlineStatus! === 1 && this.tempHumiditySensor?.Temperature) ? this.tempHumiditySensor.Temperature / 10 + '℃' : '-')
  254. .fontSize($r('app.float.fontSize_28'))
  255. .fontColor($r('app.color.FFFFFF'))
  256. .fontWeight(FontWeight.Lighter)
  257. }
  258. .height('22.5%')
  259. .alignItems(VerticalAlign.Bottom)
  260. Row(){}.height('15.5%')
  261. Row({space: 2}) {
  262. Image($r('app.media.home_temp_and_humidity'))
  263. .width($r('app.float.virtualSize_9_6'))
  264. .height($r('app.float.virtualSize_9_6'))
  265. .fillColor($r('app.color.FFFFFF'))
  266. Text((this.tempHumiditySensor?.OnlineStatus! === 1 && this.tempHumiditySensor?.Humidity) ? this.tempHumiditySensor.Humidity / 10 + '%' : '-')
  267. .fontSize($r('app.float.fontSize_15_2'))
  268. .fontColor($r('app.color.FFFFFF'))
  269. .fontWeight(FontWeight.Lighter)
  270. }
  271. .alignItems(VerticalAlign.Center)
  272. }
  273. .width('16%')
  274. .height('100%')
  275. .borderRadius($r('app.float.virtualSize_6_4'))
  276. .backgroundImage($r("app.media.home_bg_temp_and_humidity"))
  277. .backgroundImageSize(ImageSize.Cover)
  278. // 工位设备
  279. Column() {
  280. Row() {
  281. Text('工位')
  282. .fontSize($r('app.float.fontSize_12'))
  283. .fontColor($r('app.color.FFFFFF'))
  284. .fontWeight(FontWeight.Medium)
  285. }
  286. .height('18.5%')
  287. .width('100%')
  288. .alignItems(VerticalAlign.Bottom)
  289. .justifyContent(FlexAlign.Center)
  290. // Row() {
  291. // Text(BusinessConstant.stationName)
  292. // .fontSize($r('app.float.fontSize_6_4'))
  293. // .fontColor($r('app.color.FFFFFF'))
  294. // .fontWeight(FontWeight.Lighter)
  295. // .opacity(0.6)
  296. // }
  297. // .height('6.6%')
  298. Blank()
  299. Row() {
  300. Column() {
  301. Text('16')
  302. .fontSize($r('app.float.fontSize_19_2'))
  303. .fontColor($r('app.color.FFFFFF'))
  304. .fontWeight(FontWeight.Lighter)
  305. .textAlign(TextAlign.Start)
  306. Text('数量')
  307. .fontSize($r('app.float.fontSize_6_4'))
  308. .fontColor($r('app.color.FFFFFF'))
  309. .fontWeight(FontWeight.Lighter)
  310. }
  311. .width('38%')
  312. .height('80%')
  313. Divider().vertical(true)
  314. .color($r('app.color.FFFFFF'))
  315. .opacity(0.1)
  316. .height('50%')
  317. Column() {
  318. Text(this.onlineDeviceNum.toString())
  319. .fontSize($r('app.float.fontSize_19_2'))
  320. .fontColor($r('app.color.30D158'))
  321. .fontWeight(FontWeight.Lighter)
  322. .textAlign(TextAlign.Start)
  323. Text('在线设备')
  324. .fontSize($r('app.float.fontSize_6_4'))
  325. .fontColor($r('app.color.FFFFFF'))
  326. .fontWeight(FontWeight.Lighter)
  327. }
  328. .width('38%')
  329. .height('80%')
  330. }
  331. .height('29.4%')
  332. .width('100%')
  333. .justifyContent(FlexAlign.Center)
  334. .alignItems(VerticalAlign.Top)
  335. }
  336. .width('16%')
  337. .height('100%')
  338. .borderRadius($r('app.float.virtualSize_6_4'))
  339. .backgroundImage($r("app.media.home_bg_workstation_device"))
  340. .backgroundImageSize(ImageSize.Cover)
  341. // 在岗人员
  342. Column() {
  343. Row() {
  344. Text('人员')
  345. .fontSize($r('app.float.fontSize_12'))
  346. .fontColor($r('app.color.FFFFFF'))
  347. .fontWeight(FontWeight.Medium)
  348. }
  349. .height('18.5%')
  350. .width('100%')
  351. .alignItems(VerticalAlign.Bottom)
  352. .justifyContent(FlexAlign.Center)
  353. Row() {}.height('18%')
  354. Column() {
  355. Text(this.userStatistics?.onDutyNum ? this.userStatistics?.onDutyNum.toString() : '0')
  356. .fontSize($r('app.float.fontSize_28'))
  357. .fontColor($r('app.color.FFFFFF'))
  358. .fontWeight(FontWeight.Lighter)
  359. Row() {}.height('8%')
  360. Text('在岗人数')
  361. .fontSize($r('app.float.fontSize_6_4'))
  362. .fontColor($r('app.color.FFFFFF'))
  363. .fontWeight(FontWeight.Lighter)
  364. }
  365. .height('27.5%')
  366. Row() {}.height('11%')
  367. Column({space: 5}) {
  368. Text(this.userStatistics?.totalNum ? this.userStatistics?.totalNum.toString() : '0')
  369. .fontSize($r('app.float.fontSize_15_2'))
  370. .fontColor($r('app.color.FFFFFF'))
  371. .fontWeight(FontWeight.Lighter)
  372. Text('总人数')
  373. .fontSize($r('app.float.fontSize_6_4'))
  374. .fontColor($r('app.color.FFFFFF'))
  375. .fontWeight(FontWeight.Lighter)
  376. }
  377. .justifyContent(FlexAlign.Center)
  378. }
  379. .width('16%')
  380. .height('100%')
  381. .borderRadius($r('app.float.virtualSize_6_4'))
  382. .backgroundImage($r("app.media.home_bg_on_the_job_staff"))
  383. .backgroundImageSize(ImageSize.Cover)
  384. // 委外
  385. Column() {
  386. Row() {
  387. Text('委外')
  388. .fontSize($r('app.float.fontSize_12'))
  389. .fontColor($r('app.color.FFFFFF'))
  390. .fontWeight(FontWeight.Medium)
  391. }
  392. .height('18.5%')
  393. .width('100%')
  394. .alignItems(VerticalAlign.Bottom)
  395. .justifyContent(FlexAlign.Center)
  396. Row() {}.height('18%')
  397. Column() {
  398. Text(this.outsourceStatistics?.weekComplete ? this.outsourceStatistics.weekComplete.toString() : '0')
  399. .fontSize($r('app.float.fontSize_28'))
  400. .fontColor($r('app.color.FFFFFF'))
  401. .fontWeight(FontWeight.Lighter)
  402. Row() {}.height('8%')
  403. Text('本周完成')
  404. .fontSize($r('app.float.fontSize_6_4'))
  405. .fontColor($r('app.color.FFFFFF'))
  406. .fontWeight(FontWeight.Lighter)
  407. }
  408. .height('27.5%')
  409. Row() {}.height('11%')
  410. Column({space: 5}) {
  411. Text(this.outsourceStatistics?.orderNum ? this.outsourceStatistics.orderNum.toString() : '0')
  412. .fontSize($r('app.float.fontSize_15_2'))
  413. .fontColor($r('app.color.FFFFFF'))
  414. .fontWeight(FontWeight.Lighter)
  415. Text('订单数量')
  416. .fontSize($r('app.float.fontSize_6_4'))
  417. .fontColor($r('app.color.FFFFFF'))
  418. .fontWeight(FontWeight.Lighter)
  419. }
  420. .justifyContent(FlexAlign.Center)
  421. }
  422. .width('16%')
  423. .height('100%')
  424. .borderRadius($r('app.float.virtualSize_6_4'))
  425. .backgroundImage($r("app.media.home_bg_electronic_report"))
  426. .backgroundImageSize(ImageSize.Cover)
  427. }
  428. .width('100%')
  429. .height('45.5%')
  430. .justifyContent(FlexAlign.SpaceBetween)
  431. Row() {}.height('1%')
  432. // 第二行卡片
  433. Row() {
  434. //缺料情况
  435. Column() {
  436. Row() {
  437. Text('缺料情况')
  438. .fontSize($r('app.float.fontSize_12'))
  439. .fontColor($r('app.color.FFFFFF'))
  440. .fontWeight(FontWeight.Medium)
  441. }
  442. .height('18.5%')
  443. .width('100%')
  444. .alignItems(VerticalAlign.Bottom)
  445. .justifyContent(FlexAlign.Center)
  446. Row() {}.height('18%')
  447. Column() {
  448. Text('1')
  449. .fontSize($r('app.float.fontSize_28'))
  450. .fontColor($r('app.color.FFFFFF'))
  451. .fontWeight(FontWeight.Lighter)
  452. Row() {}.height('8%')
  453. Text('产品数量')
  454. .fontSize($r('app.float.fontSize_6_4'))
  455. .fontColor($r('app.color.FFFFFF'))
  456. .fontWeight(FontWeight.Lighter)
  457. }
  458. .height('27.5%')
  459. Row() {}.height('11%')
  460. Row() {
  461. Column({space: 5}) {
  462. Text('1')
  463. .fontSize($r('app.float.fontSize_15_2'))
  464. .fontColor($r('app.color.FFFFFF'))
  465. .fontWeight(FontWeight.Lighter)
  466. Text('订单数量')
  467. .fontSize($r('app.float.fontSize_6_4'))
  468. .fontColor($r('app.color.FFFFFF'))
  469. .fontWeight(FontWeight.Lighter)
  470. }
  471. .width('42.6%')
  472. Divider().vertical(true)
  473. .color($r('app.color.FFFFFF'))
  474. .opacity(0.1)
  475. .height('50%')
  476. Column({space: 5}) {
  477. Text('1')
  478. .fontSize($r('app.float.fontSize_15_2'))
  479. .fontColor($r('app.color.FFFFFF'))
  480. .fontWeight(FontWeight.Lighter)
  481. Text('产品型号')
  482. .fontSize($r('app.float.fontSize_6_4'))
  483. .fontColor($r('app.color.FFFFFF'))
  484. .fontWeight(FontWeight.Lighter)
  485. }
  486. .width('42.6%')
  487. }
  488. .justifyContent(FlexAlign.Center)
  489. .width('100%')
  490. .height('25%')
  491. }
  492. .width('16%')
  493. .height('100%')
  494. .borderRadius($r('app.float.virtualSize_6_4'))
  495. .backgroundImage($r("app.media.home_bg_order_schedule"))
  496. .backgroundImageSize(ImageSize.Cover)
  497. // 试验情况
  498. Column() {
  499. Row() {
  500. Text('试验情况')
  501. .fontSize($r('app.float.fontSize_12'))
  502. .fontColor($r('app.color.FFFFFF'))
  503. .fontWeight(FontWeight.Medium)
  504. }
  505. .height('18.5%')
  506. .width('100%')
  507. .alignItems(VerticalAlign.Bottom)
  508. .justifyContent(FlexAlign.Center)
  509. Row() {}.height('18%')
  510. Column() {
  511. Text('0')
  512. .fontSize($r('app.float.fontSize_28'))
  513. .fontColor($r('app.color.FFFFFF'))
  514. .fontWeight(FontWeight.Lighter)
  515. Row() {}.height('8%')
  516. Text('正在执行的订单')
  517. .fontSize($r('app.float.fontSize_6_4'))
  518. .fontColor($r('app.color.FFFFFF'))
  519. .fontWeight(FontWeight.Lighter)
  520. }
  521. .height('27.5%')
  522. Row() {}.height('11%')
  523. Row() {
  524. Column({space: 5}) {
  525. Text('0')
  526. .fontSize($r('app.float.fontSize_15_2'))
  527. .fontColor($r('app.color.FFFFFF'))
  528. .fontWeight(FontWeight.Lighter)
  529. Text('排队订单')
  530. .fontSize($r('app.float.fontSize_6_4'))
  531. .fontColor($r('app.color.FFFFFF'))
  532. .fontWeight(FontWeight.Lighter)
  533. }
  534. .width('42.6%')
  535. Divider().vertical(true)
  536. .color($r('app.color.FFFFFF'))
  537. .opacity(0.1)
  538. .height('50%')
  539. Column({space: 5}) {
  540. Text('0')
  541. .fontSize($r('app.float.fontSize_15_2'))
  542. .fontColor($r('app.color.FFFFFF'))
  543. .fontWeight(FontWeight.Lighter)
  544. Text('排队产品')
  545. .fontSize($r('app.float.fontSize_6_4'))
  546. .fontColor($r('app.color.FFFFFF'))
  547. .fontWeight(FontWeight.Lighter)
  548. }
  549. .width('42.6%')
  550. }
  551. .justifyContent(FlexAlign.Center)
  552. .width('100%')
  553. .height('25%')
  554. }
  555. .width('16%')
  556. .height('100%')
  557. .borderRadius($r('app.float.virtualSize_6_4'))
  558. .backgroundImage($r("app.media.home_bg_work_order_issuance"))
  559. .backgroundImageSize(ImageSize.Cover)
  560. // 智能仓储
  561. Column() {
  562. Row() {
  563. Text('智能仓储')
  564. .fontSize($r('app.float.fontSize_12'))
  565. .fontColor($r('app.color.FFFFFF'))
  566. .fontWeight(FontWeight.Medium)
  567. }
  568. .height('18.5%')
  569. .width('100%')
  570. .alignItems(VerticalAlign.Bottom)
  571. .justifyContent(FlexAlign.Center)
  572. Row() {}.height('10%')
  573. Row() {
  574. Stack() {
  575. Progress({ value: (this.vehicleStatistics?.totalNum! ? this.vehicleStatistics.totalNum : 0), total: BusinessConstant.maxStorageLocation, type: ProgressType.Ring})
  576. .width($r('app.float.virtualSize_58'))
  577. .height($r('app.float.virtualSize_58'))
  578. .style({strokeWidth: $r('app.float.virtualSize_6_4')})
  579. .color(new LinearGradient([{ color: $r('app.color.73C3FF'), offset: 0.0 },
  580. { color:$r('app.color.1050FF'), offset: 1.0 }]))
  581. .backgroundColor($r('app.color.10FFFFFF'))
  582. Row() {
  583. Text(this.vehicleStatistics?.totalNum! ? (this.vehicleStatistics.totalNum * 100 / BusinessConstant.maxStorageLocation).toFixed(1) : '0')
  584. .fontSize($r('app.float.fontSize_15_2'))
  585. .fontColor($r('app.color.FFFFFF'))
  586. .fontWeight(FontWeight.Lighter)
  587. Text('%')
  588. .fontSize($r('app.float.fontSize_8'))
  589. .fontColor($r('app.color.FFFFFF'))
  590. .fontWeight(FontWeight.Lighter)
  591. }
  592. }
  593. }
  594. .height('38.5%')
  595. Row() {
  596. Text('仓储占用')
  597. .fontSize($r('app.float.fontSize_6_4'))
  598. .fontColor($r('app.color.FFFFFF'))
  599. .fontWeight(FontWeight.Lighter)
  600. }
  601. .height('8%')
  602. Row() {
  603. Column() {
  604. Text(this.vehicleStatistics?.totalNum! ? this.vehicleStatistics.totalNum.toString() : '0')
  605. .fontSize($r('app.float.fontSize_15_2'))
  606. .fontColor($r('app.color.FFFFFF'))
  607. .fontWeight(FontWeight.Lighter)
  608. Row() {}.height('5%')
  609. Text('总料箱')
  610. .fontSize($r('app.float.fontSize_6_4'))
  611. .fontColor($r('app.color.FFFFFF'))
  612. .fontWeight(FontWeight.Lighter)
  613. }
  614. .width('38%')
  615. .height('100%')
  616. .justifyContent(FlexAlign.Center)
  617. Divider().vertical(true)
  618. .color($r('app.color.FFFFFF'))
  619. .opacity(0.1)
  620. .height('40%')
  621. Column() {
  622. Text(this.vehicleStatistics?.emptyNum! ? this.vehicleStatistics.emptyNum.toString() : '0')
  623. .fontSize($r('app.float.fontSize_15_2'))
  624. .fontColor($r('app.color.FFFFFF'))
  625. .fontWeight(FontWeight.Lighter)
  626. .textAlign(TextAlign.Start)
  627. Row() {}.height('5%')
  628. Text('空箱')
  629. .fontSize($r('app.float.fontSize_6_4'))
  630. .fontColor($r('app.color.FFFFFF'))
  631. .fontWeight(FontWeight.Lighter)
  632. }
  633. .width('38%')
  634. .height('100%')
  635. .justifyContent(FlexAlign.Center)
  636. }
  637. .height('25%')
  638. .width('100%')
  639. .justifyContent(FlexAlign.Center)
  640. .alignItems(VerticalAlign.Center)
  641. }
  642. .width('16%')
  643. .height('100%')
  644. .borderRadius($r('app.float.virtualSize_6_4'))
  645. .backgroundImage($r("app.media.home_bg_intellectual_storage"))
  646. .backgroundImageSize(ImageSize.Cover)
  647. // 工艺管理
  648. Column() {
  649. Row() {
  650. Text('工艺管理')
  651. .fontSize($r('app.float.fontSize_12'))
  652. .fontColor($r('app.color.FFFFFF'))
  653. .fontWeight(FontWeight.Medium)
  654. }
  655. .height('18.5%')
  656. .width('100%')
  657. .alignItems(VerticalAlign.Bottom)
  658. .justifyContent(FlexAlign.Center)
  659. Row() {}.height('10%')
  660. Row() {
  661. Stack() {
  662. Progress({ value: (this.processStatistics?.productProcessNum! ? this.processStatistics.productProcessNum : 0), total: (this.processStatistics?.productNum! ? this.processStatistics.productNum : 100), type: ProgressType.Ring})
  663. .width($r('app.float.virtualSize_58'))
  664. .height($r('app.float.virtualSize_58'))
  665. .style({strokeWidth: $r('app.float.virtualSize_6_4')})
  666. .color(new LinearGradient([{ color: $r('app.color.73C3FF'), offset: 0.0 },
  667. { color:$r('app.color.1050FF'), offset: 1.0 }]))
  668. .backgroundColor($r('app.color.10FFFFFF'))
  669. Row() {
  670. Text(this.processStatistics?.productProcessNum! && this.processStatistics?.productNum! ? (this.processStatistics.productProcessNum * 100 / this.processStatistics.productNum).toFixed(1) : '0')
  671. .fontSize($r('app.float.fontSize_15_2'))
  672. .fontColor($r('app.color.FFFFFF'))
  673. .fontWeight(FontWeight.Lighter)
  674. Text('%')
  675. .fontSize($r('app.float.fontSize_8'))
  676. .fontColor($r('app.color.FFFFFF'))
  677. .fontWeight(FontWeight.Lighter)
  678. }
  679. }
  680. }
  681. .height('38.5%')
  682. Row() {
  683. Text('覆盖产品')
  684. .fontSize($r('app.float.fontSize_6_4'))
  685. .fontColor($r('app.color.FFFFFF'))
  686. .fontWeight(FontWeight.Lighter)
  687. }
  688. .height('8%')
  689. Row() {
  690. Column() {
  691. Text(this.processStatistics?.processPublishedNum! ? this.processStatistics.processPublishedNum.toString() : '0')
  692. .fontSize($r('app.float.fontSize_15_2'))
  693. .fontColor($r('app.color.FFFFFF'))
  694. .fontWeight(FontWeight.Lighter)
  695. Row() {}.height('5%')
  696. Text('已发布')
  697. .fontSize($r('app.float.fontSize_6_4'))
  698. .fontColor($r('app.color.FFFFFF'))
  699. .fontWeight(FontWeight.Lighter)
  700. }
  701. .width('38%')
  702. .height('100%')
  703. .justifyContent(FlexAlign.Center)
  704. Divider().vertical(true)
  705. .color($r('app.color.FFFFFF'))
  706. .opacity(0.1)
  707. .height('40%')
  708. Column() {
  709. Text(this.processStatistics?.processUnpublishedNum! ? this.processStatistics.processUnpublishedNum.toString() : '0')
  710. .fontSize($r('app.float.fontSize_15_2'))
  711. .fontColor($r('app.color.FFFFFF'))
  712. .fontWeight(FontWeight.Lighter)
  713. .textAlign(TextAlign.Start)
  714. Row() {}.height('5%')
  715. Text('未发布')
  716. .fontSize($r('app.float.fontSize_6_4'))
  717. .fontColor($r('app.color.FFFFFF'))
  718. .fontWeight(FontWeight.Lighter)
  719. }
  720. .width('38%')
  721. .height('100%')
  722. .justifyContent(FlexAlign.Center)
  723. }
  724. .height('25%')
  725. .width('100%')
  726. .justifyContent(FlexAlign.Center)
  727. .alignItems(VerticalAlign.Center)
  728. }
  729. .width('16%')
  730. .height('100%')
  731. .borderRadius($r('app.float.virtualSize_6_4'))
  732. .backgroundImage($r("app.media.home_bg_process_management"))
  733. .backgroundImageSize(ImageSize.Cover)
  734. // 质量检验
  735. Column(){
  736. Row() {
  737. Text('质量检验')
  738. .fontSize($r('app.float.fontSize_12'))
  739. .fontColor($r('app.color.FFFFFF'))
  740. .fontWeight(FontWeight.Medium)
  741. }
  742. .height('17%')
  743. .width('85.5%')
  744. .alignItems(VerticalAlign.Bottom)
  745. Row() {}.height('10%')
  746. Row() {
  747. Column() {
  748. Stack() {
  749. Progress({ value: 1, total: 1, type: ProgressType.Ring})
  750. .width($r('app.float.virtualSize_58'))
  751. .height($r('app.float.virtualSize_58'))
  752. .style({strokeWidth: $r('app.float.virtualSize_6_4')})
  753. .color(new LinearGradient([{ color: $r('app.color.73C3FF'), offset: 0.0 },
  754. { color:$r('app.color.1050FF'), offset: 1.0 }]))
  755. .backgroundColor($r('app.color.10FFFFFF'))
  756. Row() {
  757. Text('100')
  758. .fontSize($r('app.float.fontSize_15_2'))
  759. .fontColor($r('app.color.FFFFFF'))
  760. .fontWeight(FontWeight.Lighter)
  761. Text('%')
  762. .fontSize($r('app.float.fontSize_8'))
  763. .fontColor($r('app.color.FFFFFF'))
  764. .fontWeight(FontWeight.Lighter)
  765. }
  766. }
  767. Row() {
  768. Text('合格率')
  769. .fontSize($r('app.float.fontSize_6_4'))
  770. .fontColor($r('app.color.FFFFFF'))
  771. .fontWeight(FontWeight.Lighter)
  772. }
  773. .height('17.2%')
  774. }
  775. .width('40%')
  776. Column() {
  777. Stack() {
  778. Progress({ value: 0, total: 100, type: ProgressType.Ring})
  779. .width($r('app.float.virtualSize_58'))
  780. .height($r('app.float.virtualSize_58'))
  781. .style({strokeWidth: $r('app.float.virtualSize_6_4')})
  782. .color(new LinearGradient([{ color: $r('app.color.73C3FF'), offset: 0.0 },
  783. { color:$r('app.color.1050FF'), offset: 1.0 }]))
  784. .backgroundColor($r('app.color.10FFFFFF'))
  785. Row() {
  786. Text('0')
  787. .fontSize($r('app.float.fontSize_15_2'))
  788. .fontColor($r('app.color.FFFFFF'))
  789. .fontWeight(FontWeight.Lighter)
  790. Text('%')
  791. .fontSize($r('app.float.fontSize_8'))
  792. .fontColor($r('app.color.FFFFFF'))
  793. .fontWeight(FontWeight.Lighter)
  794. }
  795. }
  796. Row() {
  797. Text('返工率')
  798. .fontSize($r('app.float.fontSize_6_4'))
  799. .fontColor($r('app.color.FFFFFF'))
  800. .fontWeight(FontWeight.Lighter)
  801. }
  802. .height('17.2%')
  803. }
  804. .width('40%')
  805. }
  806. .width('100%')
  807. .height('46.5%')
  808. .justifyContent(FlexAlign.Center)
  809. Row() {
  810. Column() {
  811. Text('0')
  812. .fontSize($r('app.float.fontSize_15_2'))
  813. .fontColor($r('app.color.FFFFFF'))
  814. .fontWeight(FontWeight.Lighter)
  815. Row() {}.height('5%')
  816. Text('检验单')
  817. .fontSize($r('app.float.fontSize_6_4'))
  818. .fontColor($r('app.color.FFFFFF'))
  819. .fontWeight(FontWeight.Lighter)
  820. }
  821. .width('21%')
  822. .height('100%')
  823. .justifyContent(FlexAlign.Center)
  824. Divider().vertical(true)
  825. .color($r('app.color.FFFFFF'))
  826. .opacity(0.1)
  827. .height('40%')
  828. Column() {
  829. Text('0')
  830. .fontSize($r('app.float.fontSize_15_2'))
  831. .fontColor($r('app.color.FFFFFF'))
  832. .fontWeight(FontWeight.Lighter)
  833. .textAlign(TextAlign.Start)
  834. Row() {}.height('5%')
  835. Text('不合格品审理单')
  836. .fontSize($r('app.float.fontSize_6_4'))
  837. .fontColor($r('app.color.FFFFFF'))
  838. .fontWeight(FontWeight.Lighter)
  839. .textAlign(TextAlign.Center)
  840. .maxLines(2)
  841. }
  842. .width('21%')
  843. .height('100%')
  844. .justifyContent(FlexAlign.Center)
  845. Divider().vertical(true)
  846. .color($r('app.color.FFFFFF'))
  847. .opacity(0.1)
  848. .height('40%')
  849. Column() {
  850. Text('10')
  851. .fontSize($r('app.float.fontSize_15_2'))
  852. .fontColor($r('app.color.FFFFFF'))
  853. .fontWeight(FontWeight.Lighter)
  854. .textAlign(TextAlign.Start)
  855. Row() {}.height('5%')
  856. Text('合格件')
  857. .fontSize($r('app.float.fontSize_6_4'))
  858. .fontColor($r('app.color.FFFFFF'))
  859. .fontWeight(FontWeight.Lighter)
  860. }
  861. .width('21%')
  862. .height('100%')
  863. .justifyContent(FlexAlign.Center)
  864. Divider().vertical(true)
  865. .color($r('app.color.FFFFFF'))
  866. .opacity(0.1)
  867. .height('40%')
  868. Column() {
  869. Text('0')
  870. .fontSize($r('app.float.fontSize_15_2'))
  871. .fontColor($r('app.color.FFFFFF'))
  872. .fontWeight(FontWeight.Lighter)
  873. .textAlign(TextAlign.Start)
  874. Row() {}.height('5%')
  875. Text('返工件')
  876. .fontSize($r('app.float.fontSize_6_4'))
  877. .fontColor($r('app.color.FFFFFF'))
  878. .fontWeight(FontWeight.Lighter)
  879. }
  880. .width('21%')
  881. .height('100%')
  882. .justifyContent(FlexAlign.Center)
  883. }
  884. .height('25%')
  885. .width('100%')
  886. .justifyContent(FlexAlign.Center)
  887. .alignItems(VerticalAlign.Center)
  888. }
  889. .width('32.8%')
  890. .height('100%')
  891. .borderRadius($r('app.float.virtualSize_6_4'))
  892. .backgroundImage($r("app.media.home_bg_quality_management"))
  893. .backgroundImageSize(ImageSize.Cover)
  894. }
  895. .width('100%')
  896. .height('45.5%')
  897. .justifyContent(FlexAlign.SpaceBetween)
  898. }
  899. .width('100%')
  900. .height('100%')
  901. })
  902. }
  903. .width('94.4%')
  904. .height('77.7%')
  905. }
  906. .width('100%')
  907. .height('100%')
  908. }
  909. createClient(): undefined | void {
  910. console.log("hhtest", '请求连接');
  911. if (this.mqttAsyncClient) {
  912. return;
  913. }
  914. this.mqttAsyncClient = MqttAsync.createMqtt({
  915. url: this.url,
  916. clientId: this.clientId,
  917. persistenceType: 1,
  918. });
  919. let num = 0
  920. while (num < 5) {
  921. if (!this.mqttAsyncClient) {
  922. this.mqttAsyncClient = MqttAsync.createMqtt({
  923. url: this.url,
  924. clientId: this.clientId,
  925. persistenceType: 1,
  926. });
  927. }
  928. num++
  929. }
  930. if (!this.mqttAsyncClient) {
  931. console.log("hhtest", '创建失败');
  932. return;
  933. }
  934. this.messageArrived()
  935. this.connectLost()
  936. this.mqttAsyncClient.setMqttTrace(6);
  937. // // this.showLog("create client success");
  938. }
  939. async connect(): Promise<undefined | void> {
  940. console.info('hhtest', "connect");
  941. // // this.showLog("connect");
  942. let options: MqttConnectOptions = {
  943. userName: this.userName,
  944. password: this.password,
  945. cleanSession:false,
  946. connectTimeout: 300
  947. };
  948. if (this.mqttAsyncClient == null) {
  949. return;
  950. }
  951. if (!(await this.isConnected())) {
  952. if (this.isPromise) {
  953. this.mqttAsyncClient.connect(options).then((data: MqttResponse) => {
  954. console.info('hhtest', "connect result:" + JSON.stringify(data));
  955. this.connectedCount++;
  956. }).catch((data: MqttResponse) => {
  957. console.info('hhtest', "connect fail result:" + JSON.stringify(data));
  958. })
  959. } else {
  960. this.mqttAsyncClient.connect(options, (err: Error, data: MqttResponse) => {
  961. if (!err) {
  962. console.info('hhtest', "connect result:" + JSON.stringify(data));
  963. if (data.message == "Connect Success") {
  964. console.info('hhtest', "connect result connectedCount:");
  965. this.connectedCount++;
  966. }
  967. } else {
  968. console.info('hhtest', "connect error:" + JSON.stringify(err));
  969. }
  970. });
  971. }
  972. }
  973. }
  974. async publish(): Promise<undefined | void> {
  975. console.info('hhtest', "publish");
  976. let publishOption: MqttPublishOptions = {
  977. topic: this.publishTopic,
  978. qos: 1,
  979. payload: this.payload
  980. }
  981. console.log('hhtest', 'publish msg:----------' + JSON.stringify(this.payload))
  982. console.log('hhtest', 'publish msg:----------' + JSON.stringify(publishOption))
  983. if (this.mqttAsyncClient == null) {
  984. return;
  985. }
  986. if (await this.isConnected()) {
  987. if (this.isPromise) {
  988. this.mqttAsyncClient.publish(publishOption).then((data: MqttResponse) => {
  989. console.info('hhtest', "publish success result:" + JSON.stringify(data));
  990. }).catch((err: MqttResponse) => {
  991. console.info('hhtest', "publish fail result:" + JSON.stringify(err));
  992. })
  993. } else {
  994. this.mqttAsyncClient.publish(publishOption, (err: Error, data: MqttResponse) => {
  995. console.info('hhtest', "publish response:");
  996. if (!err) {
  997. console.info('hhtest', "publish result:" + JSON.stringify(data));
  998. } else {
  999. console.info('hhtest', "publish error:" + JSON.stringify(err));
  1000. }
  1001. });
  1002. }
  1003. }
  1004. }
  1005. async subscribe(): Promise<undefined | void> {
  1006. console.info('hhtest', "subscribe");
  1007. let subscribeOption: MqttSubscribeOptions = {
  1008. topic: this.subscribeTopic,
  1009. qos: 2
  1010. }
  1011. if (this.mqttAsyncClient == null) {
  1012. console.info('hhtest', "client not created");
  1013. return;
  1014. }
  1015. if (await this.isConnected()) {
  1016. if (this.isPromise) {
  1017. this.mqttAsyncClient.subscribe(subscribeOption).then((data: MqttResponse) => {
  1018. console.info('hhtest', "subscribe success result:" + JSON.stringify(data));
  1019. }).catch((err: MqttResponse) => {
  1020. console.info('hhtest', "subscribe fail result:" + JSON.stringify(err));
  1021. })
  1022. } else {
  1023. this.mqttAsyncClient.subscribe(subscribeOption, (err: Error, data: MqttResponse) => {
  1024. if (!err) {
  1025. console.info('hhtest', "subscribe result:" + JSON.stringify(data));
  1026. } else {
  1027. console.info('hhtest', "subscribe error:" + JSON.stringify(err));
  1028. }
  1029. });
  1030. }
  1031. }
  1032. if (this.subscribeTopic === this.subscribeTopic2) {
  1033. return
  1034. }
  1035. let subscribeOption2: MqttSubscribeOptions = {
  1036. topic: this.subscribeTopic2,
  1037. qos: 2
  1038. }
  1039. if (await this.isConnected()) {
  1040. if (this.isPromise) {
  1041. this.mqttAsyncClient.subscribe(subscribeOption2).then((data: MqttResponse) => {
  1042. console.info('hhtest', "subscribe success result:" + JSON.stringify(data));
  1043. }).catch((err: MqttResponse) => {
  1044. console.info('hhtest', "subscribe fail result:" + JSON.stringify(err));
  1045. })
  1046. } else {
  1047. this.mqttAsyncClient.subscribe(subscribeOption2, (err: Error, data: MqttResponse) => {
  1048. if (!err) {
  1049. console.info('hhtest', "subscribe result:" + JSON.stringify(data));
  1050. } else {
  1051. console.info('hhtest', "subscribe error:" + JSON.stringify(err));
  1052. }
  1053. });
  1054. }
  1055. }
  1056. }
  1057. messageArrived(): undefined | void {
  1058. console.info('hhtest', "messageArrived");
  1059. if (this.mqttAsyncClient == null) {
  1060. return;
  1061. }
  1062. this.mqttAsyncClient.messageArrived((err: Error, data: MqttMessage) => {
  1063. if (!err) {
  1064. // this.showLog(msg);
  1065. let dataStr = JSON.stringify(data);
  1066. console.info('hhtest', "messageArrived message:" + dataStr);
  1067. if (dataStr.indexOf(this.subscribeTopic2) === -1) {
  1068. return
  1069. }
  1070. let updateData: MqttUploadData = JSON.parse(data.payload) as MqttUploadData;
  1071. if (!updateData || !updateData.d || updateData.d.length <= 0) {
  1072. console.info('hhtest', "updateData没有解析成功" + JSON.stringify(updateData));
  1073. return
  1074. }
  1075. let device0: TempHumiditySensor = { Temperature: 0, Humidity: 0, OnlineStatus: 0 }
  1076. this.onlineDeviceNum = 0
  1077. let collectFlag: Array<boolean> = [false]
  1078. for (const element of updateData.d) {
  1079. if (BusinessConstant.attrMap.has(element.tag)) {
  1080. let deviceType: string = BusinessConstant.attrMap.get(element.tag) ?? '';
  1081. switch (deviceType) {
  1082. case DeviceType.TempHumiditySensor:
  1083. collectFlag[0] = true
  1084. if (element.tag! === 'Temperature') {
  1085. device0.Temperature = element.value
  1086. } else if (element.tag! === 'Humidity') {
  1087. device0.Humidity = element.value
  1088. }
  1089. device0.OnlineStatus = 1
  1090. this.onlineDeviceNum++
  1091. break;
  1092. case DeviceType.WeldFumeExtractor:
  1093. this.onlineDeviceNum++
  1094. break;
  1095. case DeviceType.ElectricSolderingIron:
  1096. this.onlineDeviceNum++
  1097. break;
  1098. case DeviceType.ElectricScrewdriver:
  1099. this.onlineDeviceNum++
  1100. break;
  1101. case DeviceType.AntiWristStrap:
  1102. this.onlineDeviceNum++
  1103. break;
  1104. case DeviceType.CardReader:
  1105. this.onlineDeviceNum++
  1106. break;
  1107. case DeviceType.Lighting:
  1108. this.onlineDeviceNum++
  1109. break;
  1110. }
  1111. }
  1112. }
  1113. if (collectFlag[0]) {
  1114. this.tempHumiditySensor = device0;
  1115. } else {
  1116. this.tempHumiditySensor = {
  1117. OnlineStatus: 0
  1118. }
  1119. }
  1120. console.info('hhtest', "this.tempHumiditySensor" + JSON.stringify(this.tempHumiditySensor));
  1121. } else {
  1122. console.info('hhtest', "messageArrived error:" + JSON.stringify(err));
  1123. }
  1124. });
  1125. }
  1126. async unsubscribe(): Promise<undefined | void> {
  1127. console.info('hhtest', "unsubscribe");
  1128. let subscribeOption: MqttSubscribeOptions = {
  1129. topic: this.subscribeTopic,
  1130. qos: 2
  1131. }
  1132. if (this.mqttAsyncClient == null) {
  1133. return;
  1134. }
  1135. if (await this.isConnected()) {
  1136. if (this.isPromise) {
  1137. this.mqttAsyncClient.unsubscribe(subscribeOption).then((data: MqttResponse) => {
  1138. console.info('hhtest', "unsubscribe success result:" + JSON.stringify(data));
  1139. }).catch((err: MqttResponse) => {
  1140. console.info('hhtest', "unsubscribe fail result:" + JSON.stringify(err));
  1141. })
  1142. } else {
  1143. this.mqttAsyncClient.unsubscribe(subscribeOption, (err: Error, data: MqttResponse) => {
  1144. if (!err) {
  1145. console.info('hhtest', "unsubscribe result:" + JSON.stringify(data));
  1146. } else {
  1147. console.info('hhtest', "unsubscribe error:" + JSON.stringify(err));
  1148. }
  1149. });
  1150. }
  1151. }
  1152. }
  1153. async disconnect(): Promise<undefined | void> {
  1154. console.info('hhtest', "disconnect");
  1155. if (this.mqttAsyncClient == null) {
  1156. return;
  1157. }
  1158. if (await this.isConnected()) {
  1159. if (this.isPromise) {
  1160. this.mqttAsyncClient.disconnect().then((data: MqttResponse) => {
  1161. console.info('hhtest', "disconnect success result:" + JSON.stringify(data));
  1162. }).catch((err: MqttResponse) => {
  1163. console.info('hhtest', "disconnect fail result:" + JSON.stringify(err));
  1164. })
  1165. } else {
  1166. this.mqttAsyncClient.disconnect((err: Error, data: MqttResponse) => {
  1167. if (!err) {
  1168. console.info('hhtest', "disconnect result:" + JSON.stringify(data));
  1169. } else {
  1170. console.info('hhtest', "disconnect error:" + JSON.stringify(err));
  1171. }
  1172. });
  1173. }
  1174. }
  1175. }
  1176. async isConnected(): Promise<undefined | boolean> {
  1177. console.info('hhtest', "isConnected");
  1178. if (this.mqttAsyncClient == null) {
  1179. return;
  1180. }
  1181. return this.mqttAsyncClient.isConnected().then((data: boolean) => {
  1182. console.info('hhtest', "isConnected result:" + data);
  1183. if (!data) {
  1184. }
  1185. return data;
  1186. })
  1187. }
  1188. async reconnect(): Promise<undefined | void> {
  1189. console.info('hhtest', "reconnect");
  1190. if (this.mqttAsyncClient == null) {
  1191. return;
  1192. }
  1193. if (!(await this.isConnected())) {
  1194. if (this.connectedCount == 0) {
  1195. console.info('hhtest', "reconnect: client previously not connected");
  1196. return;
  1197. }
  1198. this.mqttAsyncClient.reconnect().then((data: boolean) => {
  1199. console.info('hhtest', "reConnected result:" + data);
  1200. });
  1201. }
  1202. }
  1203. connectLost(): undefined | void {
  1204. console.info('hhtest', "connectLost");
  1205. if (this.mqttAsyncClient == null) {
  1206. return;
  1207. }
  1208. this.mqttAsyncClient.connectLost((err: Error, data: MqttResponse) => {
  1209. if (!err) {
  1210. this.reconnect();
  1211. console.info('hhtest', "connect lost cause:" + JSON.stringify(data));
  1212. } else {
  1213. console.info('hhtest', "connect lost error:" + JSON.stringify(err));
  1214. }
  1215. });
  1216. }
  1217. async destroy(): Promise<undefined | void> {
  1218. console.info('hhtest', "destroy");
  1219. if (this.mqttAsyncClient == null) {
  1220. return;
  1221. }
  1222. this.mqttAsyncClient.destroy().then((data: boolean) => {
  1223. console.info('hhtest', "destroy result:" + data);
  1224. this.mqttAsyncClient = null;
  1225. this.connectedCount = 0;
  1226. });
  1227. }
  1228. }
  1229. class PlanFinish {
  1230. // 今日完成
  1231. dayFinish?: number
  1232. // 今日完成
  1233. dayPlan?: number
  1234. // 今日完成率
  1235. dayRate?: string
  1236. // 本月完成
  1237. monthFinish?: number
  1238. // 本月计划
  1239. monthPlan?: number
  1240. // 本周完成
  1241. weekFinish?: number
  1242. // 本周计划
  1243. weekPlan?: number
  1244. }
  1245. class UserStatistics {
  1246. // 在岗人数
  1247. onDutyNum?: number
  1248. // 总人数
  1249. totalNum?: number
  1250. }
  1251. // 委外统计
  1252. class OutsourceStatistics {
  1253. // 本周完成
  1254. weekComplete?: number
  1255. // 订单数量
  1256. orderNum?: number
  1257. }
  1258. // 载具(料箱)统计
  1259. class VehicleStatistics {
  1260. // 空箱数量
  1261. emptyNum?: number
  1262. // 总料箱数量
  1263. totalNum?: number
  1264. }
  1265. // 产品工艺统计
  1266. class ProductProcessStatistics {
  1267. // 产品数量
  1268. productNum?: number
  1269. // 产品工艺数量
  1270. productProcessNum?: number
  1271. // 工艺发布数量
  1272. processPublishedNum?: number
  1273. // 工艺未发布数量
  1274. processUnpublishedNum?: number
  1275. }