소스 검색

修改硬件页面,适配创客园环境。

jiaxiaoqiang 7 달 전
부모
커밋
2549d5d118

+ 1 - 1
entry/src/main/ets/pages/Index.ets

@@ -5,7 +5,7 @@ import uploadInstance from "../utils/UploadUtil"
 
 
 const TAG = "openHarmonyBridge" //webview和vue沟通的名称
-const webUrl = "http://10.88.11.200:11000"
+const webUrl = "192.168.100.10:8081"
 
 // const webUrl = "http://10.88.20.88:3005/"
 

+ 202 - 41
entry/src/main/ets/pages/StationDevicesPage.ets

@@ -1,5 +1,6 @@
 // 工位的设备列表
 import router from '@ohos.router'
+import axios from '@ohos/axios'
 import EquipmentRequest from '../utils/EquipmentRequest'
 
 
@@ -41,22 +42,55 @@ interface ImageDictModel {
   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> = [
-  //   {
-  //   name: '三色灯',
-  //   text: '装配工位001',
-  //   type: $r('app.media.sansedeng'),
-  //   open: $r('app.media.open'),
-  //   colse: $r('app.media.colse'),
-  //   select: true,
-  //   temp: 1,
-  //   deviceName: "三色灯"
-  // }
+    {
+      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"),
@@ -75,32 +109,35 @@ struct StationDevicesPage {
     let res: HardwareModel = await EquipmentRequest.get('/api/v1/device/list') as HardwareModel
 
     let deviceValues: HardwareModel = await EquipmentRequest.get('/api/v1/station/data') as HardwareModel
-
-    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
-      }
-    })
-
     console.log("==========", JSON.stringify(res), JSON.stringify(deviceValues))
-    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 ?? []
+
+    // 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 = {}
@@ -109,6 +146,9 @@ struct StationDevicesPage {
     if (d.deviceName == "三色灯") {
       this.lightDController.open()
     }
+    else if (d.deviceName == "排烟机") {
+      this.paiyanjiController.open()
+    }
   }
   // 三色灯dialoag
   lightDController = new CustomDialogController({
@@ -118,9 +158,55 @@ struct StationDevicesPage {
     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()
+    // this.getDeviceList()
+    setInterval(() => {
+      this.getDeviceCurrentData()
+
+    }, 1500)
   }
 
   build() {
@@ -162,16 +248,18 @@ struct StationDevicesPage {
                     .fontColor('#FFFFFF')
                     .fontWeight(FontWeight.Medium)
                     .fontSize(24)
-                  Text(item.deviceNo)
-                    .fontColor('#FFFFFF')
-                    .opacity(0.6)
-                    .fontWeight(FontWeight.Regular)
-                    .fontSize(20)
+
+                  // 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))
@@ -248,6 +336,77 @@ interface SSDParams {
   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
@@ -416,3 +575,5 @@ struct ThreeColorsLight {
 
 
 
+
+

+ 1 - 1
entry/src/main/ets/utils/Request.ets

@@ -12,7 +12,7 @@ import { printError, printRequest, printResponse, handleRes } from './Helps';
 import RequestParamsModel from './requestParams';
 import uploadInstance from './UploadUtil';
 
-export  const JGRequestBaseUrl = "http://10.88.11.200:8079/"
+export const JGRequestBaseUrl = "http://192.168.100.10:8079/"
 
 const DEBUG = true //
 

+ 1 - 1
entry/src/main/ets/utils/UploadUtil.ets

@@ -40,7 +40,7 @@ interface FileDataModel {
 
 class UploadUtil {
   private baseUrl: string = JGRequestBaseUrl
-  private fileUrl: string = "http://10.88.11.201:9000" //上传完成后可以查看的
+  private fileUrl: string = "http://192.168.100.10:9000" //上传完成后可以查看的
   private uploadPath: string = "/api/v1/base/upload"
   controller: web_webview.WebviewController | null = null
   ports: web_webview.WebMessagePort[] = [];

BIN
entry/src/main/resources/base/media/8b17192ca76820655776eaa2353437c.png


BIN
entry/src/main/resources/base/media/dianlaotie.png


BIN
entry/src/main/resources/base/media/dianzishouhuan.png


BIN
entry/src/main/resources/base/media/paiyanji.png


BIN
entry/src/main/resources/base/media/sansedeng.png