StationDevicesPage.ets 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. // 工位的设备列表
  2. import router from '@ohos.router'
  3. import EquipmentRequest from '../utils/EquipmentRequest'
  4. export class HardwareModel {
  5. name?: string
  6. text?: string
  7. type?: Resource
  8. open?: Resource
  9. colse?: Resource
  10. select?: boolean
  11. temp?: number
  12. manufacturer?: string //: "厂家",
  13. brand?: string //"品牌或型号,比如JBC",
  14. deviceName?: string //"设备自定义名称或资产编号",
  15. deviceType?: string // "类别,比如电络铁",
  16. deviceNo?: string // "设备编号,唯一号",
  17. devicePic?: string // "图片",
  18. state?: number //"状态:0正常,-1:离线,1故障",
  19. workshop?: string //"产线",
  20. station?: string //"工站/工位",
  21. devicePosition?: string // "空间位置,目前暂时不用",
  22. data?: HardwareModel[]
  23. enable?: boolean | string //是否启用了设备
  24. imageSource?: ResourceStr
  25. length?: string
  26. height?: string
  27. value?: string //硬件设备的一个数据
  28. }
  29. interface ImageDictModel {
  30. sansedeng: ResourceStr
  31. saomaqiang: ResourceStr
  32. diannengbiao: ResourceStr
  33. multimeter: ResourceStr
  34. dukaqi: ResourceStr
  35. chengkongdianyuan: ResourceStr
  36. shukongdian: ResourceStr
  37. diandongluosidao: ResourceStr
  38. zhaomingdeng: ResourceStr
  39. }
  40. @Entry
  41. @Component
  42. struct StationDevicesPage {
  43. //注释掉的是假数据,实际更具请求硬件获取
  44. @State private items: Array<HardwareModel> = [
  45. // {
  46. // name: '三色灯',
  47. // text: '装配工位001',
  48. // type: $r('app.media.sansedeng'),
  49. // open: $r('app.media.open'),
  50. // colse: $r('app.media.colse'),
  51. // select: true,
  52. // temp: 1,
  53. // deviceName: "三色灯"
  54. // }
  55. ]
  56. imageDict: ImageDictModel = {
  57. sansedeng: $r("app.media.sansedeng"),
  58. saomaqiang: $r('app.media.saomaqiang'),
  59. diannengbiao: $r('app.media.diannengbiao'),
  60. multimeter: $r('app.media.multimeter'),
  61. dukaqi: $r('app.media.dukaqi'),
  62. chengkongdianyuan: $r('app.media.chengkongdianyuan'),
  63. shukongdian: $r('app.media.shukongdian'),
  64. diandongluosidao: $r('app.media.diandongluosidao'),
  65. zhaomingdeng: $r('app.media.zhaomingdeng')
  66. }
  67. scroller: Scroller = new Scroller()
  68. getDeviceList = async () => {
  69. console.log("==========")
  70. let res: HardwareModel = await EquipmentRequest.get('/api/v1/device/list') as HardwareModel
  71. let deviceValues: HardwareModel = await EquipmentRequest.get('/api/v1/station/data') as HardwareModel
  72. let ybkc: HardwareModel = new HardwareModel()
  73. let gaoduchi: HardwareModel = new HardwareModel()
  74. deviceValues?.data?.forEach((item) => {
  75. if (item.deviceNo == "1106-50100") {
  76. ybkc.value = item.length
  77. }
  78. if (item.deviceNo == "1150-300C00") {
  79. gaoduchi.value = item.height
  80. }
  81. })
  82. console.log("==========", JSON.stringify(res), JSON.stringify(deviceValues))
  83. let array: HardwareModel[] | undefined = res?.data?.filter((device) => {
  84. device.imageSource = Reflect.get(this.imageDict, device.devicePic!)
  85. return device.enable! === true || device.enable! === "true"
  86. })
  87. array?.forEach((item) => {
  88. if (item.deviceNo == "1106-50100") {
  89. item.value = ybkc.value
  90. }
  91. if (item.deviceNo == "1150-300C00") {
  92. item.value = gaoduchi.value
  93. }
  94. })
  95. this.items = array ?? []
  96. }
  97. // 点击选择了设备之后
  98. @State currentDevice: HardwareModel = {}
  99. openDeviceOperationDialog = (d: HardwareModel) => {
  100. this.currentDevice = d
  101. if (d.deviceName == "三色灯") {
  102. this.lightDController.open()
  103. }
  104. else if (d.deviceNo == "EC2A-IM24R00") {
  105. this.theOtherController.open()
  106. }
  107. }
  108. // 三色灯dialoag
  109. lightDController = new CustomDialogController({
  110. builder: ThreeColorsLight({
  111. device: this.currentDevice
  112. }),
  113. alignment: DialogAlignment.Center,
  114. customStyle: true,
  115. })
  116. // 另一个灯的
  117. theOtherController = new CustomDialogController({
  118. builder: TheOtherLight({
  119. device: this.currentDevice
  120. }),
  121. alignment: DialogAlignment.Center,
  122. customStyle: true,
  123. })
  124. aboutToAppear(): void {
  125. this.getDeviceList()
  126. }
  127. build() {
  128. Column() {
  129. Row() {
  130. Image($r('app.media.back_white'))
  131. .height(px2vp(48))
  132. .width(px2vp(48))
  133. .onClick(async () => {
  134. router.back()
  135. })
  136. Text("刷新")
  137. .fontColor('#FFFFFF')
  138. .fontWeight(FontWeight.Medium)
  139. .fontSize(24)
  140. .margin({ left: 20 })
  141. .onClick(() => {
  142. this.getDeviceList()
  143. })
  144. }
  145. .width('100%')
  146. .height('8%')
  147. .alignItems(VerticalAlign.Center)
  148. .justifyContent(FlexAlign.Start)
  149. Column() {
  150. // Scroll(this.scroller){
  151. Grid(this.scroller) {
  152. ForEach(this.items, (item: HardwareModel, index) => {
  153. GridItem() {
  154. Row() {
  155. Column() {
  156. Text(item.deviceName)
  157. .fontColor('#FFFFFF')
  158. .fontWeight(FontWeight.Medium)
  159. .fontSize(24)
  160. Text(item.deviceNo)
  161. .fontColor('#FFFFFF')
  162. .opacity(0.6)
  163. .fontWeight(FontWeight.Regular)
  164. .fontSize(20)
  165. Text(item.value)
  166. .fontColor('#ffffff')
  167. .opacity(0.8)
  168. .fontWeight(FontWeight.Regular)
  169. .fontSize(18)
  170. Row() {
  171. Image(item.imageSource)
  172. .width(px2vp(120))
  173. .height(px2vp(120))
  174. }.height('50%')
  175. .width('100%')
  176. .padding({ left: 10 })
  177. }
  178. .width('100%')
  179. .padding(10)
  180. .borderRadius(10)
  181. .alignItems(HorizontalAlign.Start)
  182. .height('100%')
  183. }
  184. .width('100%')
  185. .height('30%')
  186. .padding({ left: 10 })
  187. .borderRadius(10)
  188. .backgroundColor('#66ffffff')
  189. .onClick(() => {
  190. this.openDeviceOperationDialog(item)
  191. })
  192. }
  193. })
  194. }
  195. .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr')
  196. .columnsGap(10)
  197. .rowsGap(10)
  198. .width('100%')
  199. .height('100%')
  200. .editMode(true) //设置Grid是否进入编辑模式,进入编辑模式可以拖拽Grid组件内部GridItem
  201. .supportAnimation(true) //设置Grid是否开启拖拽补位动画
  202. .height('80%')
  203. .width('100%')
  204. .padding({ top: 10 })
  205. }
  206. }
  207. .backgroundImage($r('app.media.zhihuigc'))
  208. .backgroundImageSize({ width: '100%', height: '100%' })
  209. .width('100%')
  210. .height('100%')
  211. .padding(20)
  212. }
  213. }
  214. @Extend(Button)
  215. function DeviceBtnS(color: ResourceColor) {
  216. .fontColor(Color.White).width(70).height(30).backgroundColor(color)
  217. }
  218. // 三色灯
  219. interface SSDModel {
  220. uiType: "Text" | "Button",
  221. textValue: string,
  222. key: string
  223. value: string
  224. btnColor: ResourceColor
  225. }
  226. interface SSDParamsData {
  227. lighting?: string
  228. buzzer?: string
  229. flash?: string
  230. outputs?: string
  231. }
  232. interface SSDParams {
  233. deviceNo: string
  234. data: SSDParamsData
  235. }
  236. @CustomDialog
  237. struct ThreeColorsLight {
  238. controller: CustomDialogController
  239. @Prop device: HardwareModel
  240. @State operations: SSDModel[][] = [
  241. [{
  242. uiType: 'Text',
  243. textValue: "亮灯",
  244. key: "lighting",
  245. value: "todo",
  246. btnColor: $r("app.color.red_100")
  247. },
  248. {
  249. uiType: 'Button',
  250. textValue: "红灯",
  251. key: "lighting",
  252. value: "red",
  253. btnColor: $r("app.color.red_100")
  254. },
  255. {
  256. uiType: 'Button',
  257. textValue: "黄灯",
  258. key: "lighting",
  259. value: "yellow",
  260. btnColor: $r("app.color.yellow_1")
  261. },
  262. {
  263. uiType: 'Button',
  264. textValue: "绿灯",
  265. key: "lighting",
  266. value: "green",
  267. btnColor: $r("app.color.green_100")
  268. },
  269. {
  270. uiType: 'Button',
  271. textValue: "关闭",
  272. key: "lighting",
  273. value: "off",
  274. btnColor: $r("app.color.gray_6666")
  275. },
  276. ],
  277. [{
  278. uiType: 'Text',
  279. textValue: "蜂鸣",
  280. key: "buzzer",
  281. value: "todo",
  282. btnColor: $r("app.color.red_100")
  283. },
  284. {
  285. uiType: 'Button',
  286. textValue: "大声",
  287. key: "buzzer",
  288. value: "loud",
  289. btnColor: $r("app.color.red_100")
  290. },
  291. {
  292. uiType: 'Button',
  293. textValue: "小声",
  294. key: "buzzer",
  295. value: "low",
  296. btnColor: $r("app.color.green_100")
  297. },
  298. {
  299. uiType: 'Button',
  300. textValue: "关闭",
  301. key: "buzzer",
  302. value: "off",
  303. btnColor: $r("app.color.gray_6666")
  304. },
  305. ],
  306. [{
  307. uiType: 'Text',
  308. textValue: "闪光",
  309. key: "flash",
  310. value: "todo",
  311. btnColor: $r("app.color.red_100")
  312. },
  313. {
  314. uiType: 'Button',
  315. textValue: "闪光快",
  316. key: "flash",
  317. value: "fast",
  318. btnColor: $r("app.color.red_100")
  319. },
  320. {
  321. uiType: 'Button',
  322. textValue: "闪光中",
  323. key: "flash",
  324. value: "middle",
  325. btnColor: $r("app.color.yellow_1")
  326. },
  327. {
  328. uiType: 'Button',
  329. textValue: "闪光慢",
  330. key: "flash",
  331. value: "slow",
  332. btnColor: $r("app.color.green_100")
  333. },
  334. {
  335. uiType: 'Button',
  336. textValue: "关闭",
  337. key: "flash",
  338. value: "off",
  339. btnColor: $r("app.color.gray_6666")
  340. },
  341. ],
  342. ]
  343. toOperation = (m: SSDModel) => {
  344. console.log("toOperation", JSON.stringify(m))
  345. let data: SSDParamsData = {
  346. lighting: '',
  347. buzzer: '',
  348. flash: ''
  349. }
  350. Reflect.set(data, m.key, m.value)
  351. console.log("toOperation", JSON.stringify(data))
  352. EquipmentRequest.post("/api/v1/device/setup", {
  353. deviceNo: this.device.deviceNo ?? "",
  354. data: data
  355. } as SSDParams)
  356. }
  357. build() {
  358. Column() {
  359. ForEach(this.operations, (ops: SSDModel[], index) => {
  360. ListItem() {
  361. Row({ space: 10 }) {
  362. ForEach(ops, (op: SSDModel) => {
  363. if (op.uiType === "Text") {
  364. Text(op.textValue)
  365. }
  366. else {
  367. Button({ type: ButtonType.Capsule }) {
  368. Text(op.textValue)
  369. }.DeviceBtnS(op.btnColor)
  370. .onClick(() => {
  371. this.toOperation(op)
  372. })
  373. }
  374. })
  375. }
  376. }
  377. })
  378. }
  379. .justifyContent(FlexAlign.SpaceEvenly)
  380. .alignItems(HorizontalAlign.Start)
  381. .padding({ left: 15 })
  382. .width(400)
  383. .height(240)
  384. .backgroundColor(Color.White)
  385. .borderRadius(10)
  386. }
  387. }
  388. @CustomDialog
  389. struct TheOtherLight {
  390. controller: CustomDialogController
  391. @Prop device: HardwareModel
  392. @State operations: SSDModel[][] = [
  393. [
  394. {
  395. uiType: 'Button',
  396. textValue: "红灯",
  397. key: "outputs",
  398. value: "4",
  399. btnColor: $r("app.color.red_100")
  400. },
  401. {
  402. uiType: 'Button',
  403. textValue: "黄灯",
  404. key: "outputs",
  405. value: "7",
  406. btnColor: $r("app.color.yellow_1")
  407. },
  408. {
  409. uiType: 'Button',
  410. textValue: "绿灯",
  411. key: "outputs",
  412. value: "1",
  413. btnColor: $r("app.color.green_100")
  414. },
  415. {
  416. uiType: 'Button',
  417. textValue: "关闭",
  418. key: "outputs",
  419. value: "0",
  420. btnColor: $r("app.color.gray_6666")
  421. },
  422. ],
  423. ]
  424. toOperation = (m: SSDModel) => {
  425. let data: SSDParamsData = {
  426. outputs: '',
  427. }
  428. Reflect.set(data, m.key, m.value)
  429. EquipmentRequest.post("/api/v1/device/setup", {
  430. deviceNo: this.device.deviceNo ?? "",
  431. data: data
  432. } as SSDParams)
  433. }
  434. build() {
  435. Column() {
  436. ForEach(this.operations, (ops: SSDModel[], index) => {
  437. ListItem() {
  438. Row({ space: 10 }) {
  439. ForEach(ops, (op: SSDModel) => {
  440. if (op.uiType === "Text") {
  441. Text(op.textValue)
  442. }
  443. else {
  444. Button({ type: ButtonType.Capsule }) {
  445. Text(op.textValue)
  446. }.DeviceBtnS(op.btnColor)
  447. .onClick(() => {
  448. this.toOperation(op)
  449. })
  450. }
  451. })
  452. }
  453. }
  454. })
  455. }
  456. .justifyContent(FlexAlign.SpaceEvenly)
  457. .alignItems(HorizontalAlign.Start)
  458. .padding({ left: 15 })
  459. .width(400)
  460. .height(140)
  461. .backgroundColor(Color.White)
  462. .borderRadius(10)
  463. }
  464. }