|
@@ -0,0 +1,579 @@
|
|
|
+// 工位的设备列表
|
|
|
+import router from '@ohos.router'
|
|
|
+import axios from '@ohos/axios'
|
|
|
+import EquipmentRequest from '../utils/EquipmentRequest'
|
|
|
+
|
|
|
+
|
|
|
+export class HardwareModel {
|
|
|
+ name?: string
|
|
|
+ text?: string
|
|
|
+ type?: Resource
|
|
|
+ open?: Resource
|
|
|
+ colse?: Resource
|
|
|
+ select?: boolean
|
|
|
+ temp?: number
|
|
|
+ manufacturer?: string //: "厂家",
|
|
|
+ brand?: string //"品牌或型号,比如JBC",
|
|
|
+ deviceName?: string //"设备自定义名称或资产编号",
|
|
|
+ deviceType?: string // "类别,比如电络铁",
|
|
|
+ deviceNo?: string // "设备编号,唯一号",
|
|
|
+ devicePic?: string // "图片",
|
|
|
+ state?: number //"状态:0正常,-1:离线,1故障",
|
|
|
+ workshop?: string //"产线",
|
|
|
+ station?: string //"工站/工位",
|
|
|
+ devicePosition?: string // "空间位置,目前暂时不用",
|
|
|
+ data?: HardwareModel[]
|
|
|
+ enable?: boolean | string //是否启用了设备
|
|
|
+ imageSource?: ResourceStr
|
|
|
+ length?: string
|
|
|
+ height?: string
|
|
|
+ value?: string //硬件设备的一个数据
|
|
|
+}
|
|
|
+
|
|
|
+interface ImageDictModel {
|
|
|
+ sansedeng: ResourceStr
|
|
|
+ saomaqiang: ResourceStr
|
|
|
+ diannengbiao: ResourceStr
|
|
|
+ multimeter: ResourceStr
|
|
|
+ dukaqi: ResourceStr
|
|
|
+ chengkongdianyuan: ResourceStr
|
|
|
+ shukongdian: ResourceStr
|
|
|
+ diandongluosidao: ResourceStr
|
|
|
+ zhaomingdeng: ResourceStr
|
|
|
+}
|
|
|
+
|
|
|
+interface DeviceData {
|
|
|
+ data?: DeviceData2
|
|
|
+}
|
|
|
+
|
|
|
+interface DeviceData2 {
|
|
|
+ data?: deviceValueModel
|
|
|
+}
|
|
|
+
|
|
|
+interface deviceValueModel {
|
|
|
+ RFID?: string
|
|
|
+ temperature?: string
|
|
|
+ state?: string //静电手环
|
|
|
+}
|
|
|
+
|
|
|
+@Entry
|
|
|
+@Component
|
|
|
+struct StationDevicesPage {
|
|
|
+ //注释掉的是假数据,实际更具请求硬件获取
|
|
|
+ @State private items: Array<HardwareModel> = [
|
|
|
+ {
|
|
|
+ deviceName: '三色灯',
|
|
|
+ value: '',
|
|
|
+ deviceNo: "ONNM4FUSB00",
|
|
|
+ imageSource: $r("app.media.sansedeng"),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deviceName: '读卡器',
|
|
|
+ value: '',
|
|
|
+ deviceNo: "ONNM4FUSB00",
|
|
|
+ imageSource: $r('app.media.dukaqi'),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deviceName: '电烙铁',
|
|
|
+ value: '',
|
|
|
+ deviceNo: "ONNM4FUSB00",
|
|
|
+ imageSource: $r('app.media.dianlaotie'),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deviceName: '电子手环',
|
|
|
+ value: '',
|
|
|
+ deviceNo: "ONNM4FUSB00",
|
|
|
+ imageSource: $r('app.media.zhaomingdeng'),
|
|
|
+ },
|
|
|
+ {
|
|
|
+ deviceName: '排烟机',
|
|
|
+ value: '',
|
|
|
+ deviceNo: "EC2A-IM24R-01",
|
|
|
+ imageSource: $r('app.media.paiyanji'),
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ imageDict: ImageDictModel = {
|
|
|
+ sansedeng: $r("app.media.sansedeng"),
|
|
|
+ saomaqiang: $r('app.media.saomaqiang'),
|
|
|
+ diannengbiao: $r('app.media.diannengbiao'),
|
|
|
+ multimeter: $r('app.media.multimeter'),
|
|
|
+ dukaqi: $r('app.media.dukaqi'),
|
|
|
+ chengkongdianyuan: $r('app.media.chengkongdianyuan'),
|
|
|
+ shukongdian: $r('app.media.shukongdian'),
|
|
|
+ diandongluosidao: $r('app.media.diandongluosidao'),
|
|
|
+ zhaomingdeng: $r('app.media.zhaomingdeng')
|
|
|
+ }
|
|
|
+ scroller: Scroller = new Scroller()
|
|
|
+ getDeviceList = async () => {
|
|
|
+ console.log("==========")
|
|
|
+ let res: HardwareModel = await EquipmentRequest.get('/api/v1/device/list') as HardwareModel
|
|
|
+
|
|
|
+ let deviceValues: HardwareModel = await EquipmentRequest.get('/api/v1/station/data') as HardwareModel
|
|
|
+ console.log("==========", JSON.stringify(res), JSON.stringify(deviceValues))
|
|
|
+
|
|
|
+ // let ybkc: HardwareModel = new HardwareModel()
|
|
|
+ // let gaoduchi: HardwareModel = new HardwareModel()
|
|
|
+ // deviceValues?.data?.forEach((item) => {
|
|
|
+ // if (item.deviceNo == "1106-50100") {
|
|
|
+ // ybkc.value = item.length
|
|
|
+ // }
|
|
|
+ // if (item.deviceNo == "1150-300C00") {
|
|
|
+ // gaoduchi.value = item.height
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+
|
|
|
+
|
|
|
+ // let array: HardwareModel[] | undefined = res?.data?.filter((device) => {
|
|
|
+ // device.imageSource = Reflect.get(this.imageDict, device.devicePic!)
|
|
|
+ // return device.enable! === true || device.enable! === "true"
|
|
|
+ // })
|
|
|
+ // array?.forEach((item) => {
|
|
|
+ // if (item.deviceNo == "1106-50100") {
|
|
|
+ // item.value = ybkc.value
|
|
|
+ // }
|
|
|
+ // if (item.deviceNo == "1150-300C00") {
|
|
|
+ // item.value = gaoduchi.value
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // this.items = array ?? []
|
|
|
+ //
|
|
|
+ // this.getDeviceCurrentData()
|
|
|
+ }
|
|
|
+ // 点击选择了设备之后
|
|
|
+ @State currentDevice: HardwareModel = {}
|
|
|
+ openDeviceOperationDialog = (d: HardwareModel) => {
|
|
|
+ this.currentDevice = d
|
|
|
+ if (d.deviceName == "三色灯") {
|
|
|
+ this.lightDController.open()
|
|
|
+ }
|
|
|
+ else if (d.deviceName == "排烟机") {
|
|
|
+ this.paiyanjiController.open()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 三色灯dialoag
|
|
|
+ lightDController = new CustomDialogController({
|
|
|
+ builder: ThreeColorsLight({
|
|
|
+ device: this.currentDevice
|
|
|
+ }),
|
|
|
+ alignment: DialogAlignment.Center,
|
|
|
+ customStyle: true,
|
|
|
+ })
|
|
|
+ // 排烟机
|
|
|
+ paiyanjiController = new CustomDialogController({
|
|
|
+ builder: PaiYanjiDialog({
|
|
|
+ device: this.currentDevice
|
|
|
+ }),
|
|
|
+ alignment: DialogAlignment.Center,
|
|
|
+ customStyle: true,
|
|
|
+ })
|
|
|
+
|
|
|
+ async getDeviceCurrentData() {
|
|
|
+ let rfidData: DeviceData = await axios.get("http://192.168.100.146:8000/api/v1/device/data/recentlyRecord/YMC1502")
|
|
|
+ let hantaiData: DeviceData = await axios.get("http://192.168.100.146:8000/api/v1/device/data/recentlyRecord/GT-615000")
|
|
|
+ let jingdianshouhuanData: DeviceData = await axios.get("http://192.168.100.146:8000/api/v1/device/data/recentlyRecord/SP-JD01C00")
|
|
|
+
|
|
|
+
|
|
|
+ this.items[1] = {
|
|
|
+ deviceName: '读卡器',
|
|
|
+ value: rfidData?.data?.data?.RFID ?? "000",
|
|
|
+ deviceNo: "ONNM4FUSB00",
|
|
|
+ imageSource: $r('app.media.dukaqi'),
|
|
|
+ }
|
|
|
+
|
|
|
+ this.items[2] = {
|
|
|
+ deviceName: '电烙铁',
|
|
|
+ value: hantaiData?.data?.data?.temperature + "℃",
|
|
|
+ deviceNo: "ONNM4FUSB00",
|
|
|
+ imageSource: $r('app.media.dianlaotie'),
|
|
|
+ }
|
|
|
+
|
|
|
+ let state = jingdianshouhuanData?.data?.data?.state == "1" ? "未佩戴" : "已佩戴"
|
|
|
+ this.items[3] = {
|
|
|
+ deviceName: '电子手环',
|
|
|
+ value: state,
|
|
|
+ deviceNo: "ONNM4FUSB00",
|
|
|
+ imageSource: $r('app.media.dianzishouhuan'),
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // console.log("==========", JSON.stringify(rfidData))
|
|
|
+ // console.log("==========", JSON.stringify(hantaiData))
|
|
|
+ // console.log("==========", JSON.stringify(jingdianshouhuanData))
|
|
|
+ }
|
|
|
+
|
|
|
+ aboutToAppear(): void {
|
|
|
+ // this.getDeviceList()
|
|
|
+ setInterval(() => {
|
|
|
+ this.getDeviceCurrentData()
|
|
|
+
|
|
|
+ }, 1500)
|
|
|
+ }
|
|
|
+
|
|
|
+ build() {
|
|
|
+
|
|
|
+ Column() {
|
|
|
+ Row() {
|
|
|
+ Image($r('app.media.back_white'))
|
|
|
+ .height(px2vp(48))
|
|
|
+ .width(px2vp(48))
|
|
|
+ .onClick(async () => {
|
|
|
+ router.back()
|
|
|
+ })
|
|
|
+
|
|
|
+ Text("刷新")
|
|
|
+ .fontColor('#FFFFFF')
|
|
|
+ .fontWeight(FontWeight.Medium)
|
|
|
+ .fontSize(24)
|
|
|
+ .margin({ left: 20 })
|
|
|
+ .onClick(() => {
|
|
|
+ this.getDeviceList()
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ .width('100%')
|
|
|
+ .height('8%')
|
|
|
+ .alignItems(VerticalAlign.Center)
|
|
|
+ .justifyContent(FlexAlign.Start)
|
|
|
+
|
|
|
+ Column() {
|
|
|
+
|
|
|
+ // Scroll(this.scroller){
|
|
|
+ Grid(this.scroller) {
|
|
|
+ ForEach(this.items, (item: HardwareModel, index) => {
|
|
|
+ GridItem() {
|
|
|
+
|
|
|
+ Row() {
|
|
|
+ Column() {
|
|
|
+ Text(item.deviceName)
|
|
|
+ .fontColor('#FFFFFF')
|
|
|
+ .fontWeight(FontWeight.Medium)
|
|
|
+ .fontSize(24)
|
|
|
+
|
|
|
+ // Text(item.deviceNo)
|
|
|
+ // .fontColor('#FFFFFF')
|
|
|
+ // .opacity(0.6)
|
|
|
+ // .fontWeight(FontWeight.Regular)
|
|
|
+ // .fontSize(20)
|
|
|
+ Text(item.value)
|
|
|
+ .fontColor('#ffffff')
|
|
|
+ .opacity(0.8)
|
|
|
+ .fontWeight(FontWeight.Regular)
|
|
|
+ .fontSize(18)
|
|
|
+ .margin({ bottom: 8 })
|
|
|
+ Row() {
|
|
|
+ Image(item.imageSource)
|
|
|
+ .width(px2vp(120))
|
|
|
+ .height(px2vp(120))
|
|
|
+
|
|
|
+ }.height('50%')
|
|
|
+ .width('100%')
|
|
|
+ .padding({ left: 10 })
|
|
|
+ }
|
|
|
+ .width('100%')
|
|
|
+ .padding(10)
|
|
|
+ .borderRadius(10)
|
|
|
+ .alignItems(HorizontalAlign.Start)
|
|
|
+ .height('100%')
|
|
|
+ }
|
|
|
+ .width('100%')
|
|
|
+ .height('30%')
|
|
|
+ .padding({ left: 10 })
|
|
|
+ .borderRadius(10)
|
|
|
+ .backgroundColor('#66ffffff')
|
|
|
+ .onClick(() => {
|
|
|
+ this.openDeviceOperationDialog(item)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ .columnsTemplate('1fr 1fr 1fr 1fr 1fr 1fr')
|
|
|
+ .columnsGap(10)
|
|
|
+ .rowsGap(10)
|
|
|
+ .width('100%')
|
|
|
+ .height('100%')
|
|
|
+ .editMode(true) //设置Grid是否进入编辑模式,进入编辑模式可以拖拽Grid组件内部GridItem
|
|
|
+ .supportAnimation(true) //设置Grid是否开启拖拽补位动画
|
|
|
+ .height('80%')
|
|
|
+ .width('100%')
|
|
|
+ .padding({ top: 10 })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .backgroundImage($r('app.media.zhihuigc'))
|
|
|
+ .backgroundImageSize({ width: '100%', height: '100%' })
|
|
|
+ .width('100%')
|
|
|
+ .height('100%')
|
|
|
+ .padding(20)
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+@Extend(Button)
|
|
|
+function DeviceBtnS(color: ResourceColor) {
|
|
|
+ .fontColor(Color.White).width(70).height(30).backgroundColor(color)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// 三色灯
|
|
|
+interface SSDModel {
|
|
|
+ uiType: "Text" | "Button",
|
|
|
+ textValue: string,
|
|
|
+ key: string
|
|
|
+ value: string
|
|
|
+ btnColor: ResourceColor
|
|
|
+}
|
|
|
+
|
|
|
+interface SSDParamsData {
|
|
|
+ lighting: string
|
|
|
+ buzzer: string
|
|
|
+ flash: string
|
|
|
+}
|
|
|
+
|
|
|
+interface SSDParams {
|
|
|
+ deviceNo: string
|
|
|
+ data: SSDParamsData
|
|
|
+}
|
|
|
+
|
|
|
+interface PaiYanJiPData {
|
|
|
+ ch0?: string,
|
|
|
+ name?: string
|
|
|
+}
|
|
|
+
|
|
|
+interface PYJParams {
|
|
|
+ deviceNo: string
|
|
|
+ data?: PaiYanJiPData
|
|
|
+}
|
|
|
+
|
|
|
+@CustomDialog
|
|
|
+struct PaiYanjiDialog {
|
|
|
+ controller: CustomDialogController
|
|
|
+ @Prop device: HardwareModel
|
|
|
+
|
|
|
+ start() {
|
|
|
+
|
|
|
+
|
|
|
+ EquipmentRequest.post("/api/v1/device/setup", {
|
|
|
+ deviceNo: this.device.deviceNo ?? "",
|
|
|
+ data: {
|
|
|
+ ch0: "1"
|
|
|
+ },
|
|
|
+ } as PYJParams)
|
|
|
+ }
|
|
|
+
|
|
|
+ stop() {
|
|
|
+ EquipmentRequest.post("/api/v1/device/setup", {
|
|
|
+ deviceNo: this.device.deviceNo ?? "",
|
|
|
+ data: {
|
|
|
+ ch0: "0"
|
|
|
+ },
|
|
|
+ } as PYJParams)
|
|
|
+ }
|
|
|
+
|
|
|
+ build() {
|
|
|
+ Row() {
|
|
|
+ Button({ type: ButtonType.Capsule }) {
|
|
|
+ Text("开启")
|
|
|
+ }
|
|
|
+ .fontColor(Color.White)
|
|
|
+ .width(70)
|
|
|
+ .height(30)
|
|
|
+ .backgroundColor($r("app.color.green_100"))
|
|
|
+ .onClick(() => {
|
|
|
+ this.start()
|
|
|
+ })
|
|
|
+
|
|
|
+ Button({ type: ButtonType.Capsule }) {
|
|
|
+ Text("关闭")
|
|
|
+ }
|
|
|
+ .fontColor(Color.White)
|
|
|
+ .width(70)
|
|
|
+ .height(30)
|
|
|
+ .backgroundColor($r("app.color.gray_6666"))
|
|
|
+ .onClick(() => {
|
|
|
+ this.stop()
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ .justifyContent(FlexAlign.SpaceEvenly)
|
|
|
+ .padding({ left: 15 })
|
|
|
+ .width(300)
|
|
|
+ .height(190)
|
|
|
+ .backgroundColor(Color.White)
|
|
|
+ .borderRadius(10)
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+@CustomDialog
|
|
|
+struct ThreeColorsLight {
|
|
|
+ controller: CustomDialogController
|
|
|
+ @Prop device: HardwareModel
|
|
|
+ @State operations: SSDModel[][] = [
|
|
|
+ [{
|
|
|
+ uiType: 'Text',
|
|
|
+ textValue: "亮灯",
|
|
|
+ key: "lighting",
|
|
|
+ value: "todo",
|
|
|
+ btnColor: $r("app.color.red_100")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "红灯",
|
|
|
+ key: "lighting",
|
|
|
+ value: "red",
|
|
|
+ btnColor: $r("app.color.red_100")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "黄灯",
|
|
|
+ key: "lighting",
|
|
|
+ value: "yellow",
|
|
|
+ btnColor: $r("app.color.yellow_1")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "绿灯",
|
|
|
+ key: "lighting",
|
|
|
+ value: "green",
|
|
|
+ btnColor: $r("app.color.green_100")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "关闭",
|
|
|
+ key: "lighting",
|
|
|
+ value: "off",
|
|
|
+ btnColor: $r("app.color.gray_6666")
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ [{
|
|
|
+ uiType: 'Text',
|
|
|
+ textValue: "蜂鸣",
|
|
|
+ key: "buzzer",
|
|
|
+ value: "todo",
|
|
|
+ btnColor: $r("app.color.red_100")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "大声",
|
|
|
+ key: "buzzer",
|
|
|
+ value: "loud",
|
|
|
+ btnColor: $r("app.color.red_100")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "小声",
|
|
|
+ key: "buzzer",
|
|
|
+ value: "low",
|
|
|
+ btnColor: $r("app.color.green_100")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "关闭",
|
|
|
+ key: "buzzer",
|
|
|
+ value: "off",
|
|
|
+ btnColor: $r("app.color.gray_6666")
|
|
|
+ },
|
|
|
+ ],
|
|
|
+
|
|
|
+
|
|
|
+ [{
|
|
|
+ uiType: 'Text',
|
|
|
+ textValue: "闪光",
|
|
|
+ key: "flash",
|
|
|
+ value: "todo",
|
|
|
+ btnColor: $r("app.color.red_100")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "闪光快",
|
|
|
+ key: "flash",
|
|
|
+ value: "fast",
|
|
|
+ btnColor: $r("app.color.red_100")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "闪光中",
|
|
|
+ key: "flash",
|
|
|
+ value: "middle",
|
|
|
+ btnColor: $r("app.color.yellow_1")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "闪光慢",
|
|
|
+ key: "flash",
|
|
|
+ value: "slow",
|
|
|
+ btnColor: $r("app.color.green_100")
|
|
|
+ },
|
|
|
+ {
|
|
|
+ uiType: 'Button',
|
|
|
+ textValue: "关闭",
|
|
|
+ key: "flash",
|
|
|
+ value: "off",
|
|
|
+ btnColor: $r("app.color.gray_6666")
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ ]
|
|
|
+ toOperation = (m: SSDModel) => {
|
|
|
+ console.log("toOperation", JSON.stringify(m))
|
|
|
+ let data: SSDParamsData = {
|
|
|
+ lighting: '',
|
|
|
+ buzzer: '',
|
|
|
+ flash: ''
|
|
|
+ }
|
|
|
+
|
|
|
+ Reflect.set(data, m.key, m.value)
|
|
|
+
|
|
|
+
|
|
|
+ console.log("toOperation", JSON.stringify(data))
|
|
|
+
|
|
|
+ EquipmentRequest.post("/api/v1/device/setup", {
|
|
|
+ deviceNo: this.device.deviceNo ?? "",
|
|
|
+ data: data
|
|
|
+ } as SSDParams)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ build() {
|
|
|
+ Column() {
|
|
|
+
|
|
|
+ ForEach(this.operations, (ops: SSDModel[], index) => {
|
|
|
+ ListItem() {
|
|
|
+ Row({ space: 10 }) {
|
|
|
+ ForEach(ops, (op: SSDModel) => {
|
|
|
+ if (op.uiType === "Text") {
|
|
|
+ Text(op.textValue)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Button({ type: ButtonType.Capsule }) {
|
|
|
+ Text(op.textValue)
|
|
|
+ }.DeviceBtnS(op.btnColor)
|
|
|
+ .onClick(() => {
|
|
|
+ this.toOperation(op)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ .justifyContent(FlexAlign.SpaceEvenly)
|
|
|
+ .alignItems(HorizontalAlign.Start)
|
|
|
+ .padding({ left: 15 })
|
|
|
+ .width(400)
|
|
|
+ .height(240)
|
|
|
+ .backgroundColor(Color.White)
|
|
|
+ .borderRadius(10)
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|