|
@@ -12,6 +12,9 @@ import appRecovery from '@ohos.app.ability.appRecovery';
|
|
|
import AbilityStage from '@ohos.app.ability.AbilityStage';
|
|
|
import wantAgent from '@ohos.app.ability.wantAgent'
|
|
|
import Want from '@ohos.app.ability.Want'
|
|
|
+import socketService, { MessageInfoModel } from '../util/SocketService'
|
|
|
+import JGRequest from '../util/request/Request'
|
|
|
+import RequestParamModel from '../../viewmodel/RequestParamModel'
|
|
|
|
|
|
/*
|
|
|
* 顶部状态栏
|
|
@@ -43,15 +46,28 @@ export struct TitleStateComp {
|
|
|
this.isClick = !this.isClick
|
|
|
}
|
|
|
})
|
|
|
- // 消息弹窗控制器
|
|
|
- noticeDialogController: CustomDialogController = new CustomDialogController({
|
|
|
- builder: NoticeDialog({}),
|
|
|
- alignment: DialogAlignment.Center,
|
|
|
- customStyle: true,
|
|
|
- cancel: () => {
|
|
|
- this.isClick = !this.isClick
|
|
|
- }
|
|
|
- })
|
|
|
+ // websocket 相关 =============
|
|
|
+ creatWebsocket = () => {
|
|
|
+
|
|
|
+ socketService.connect()
|
|
|
+
|
|
|
+ socketService.registerMessageListener(async (data: Object) => {
|
|
|
+ console.log("WebSocketDemo callback", JSON.stringify(data))
|
|
|
+ this.getMessageList()
|
|
|
+ // "{\"content\":[{\"content\":\"工单:09.24.0019 工位:生产准备工位-2 呼叫工序: 检测的物料\",\"created\":\"2024-08-23 15:43:22\",\"creator\":\"admin\",\"deptId\":\"1\",\"id\":\"98\",\"msgId\":\"1\",\"orgId\":\"1\",\"state\":\"1\",\"title\":\"工位呼叫齐套物料\",\"type\":\"1\",\"updated\":\"2024-08-23 15:43:22\",\"updator\":\"admin\",\"userId\":28}],\"msgType\":\"1\"}"
|
|
|
+ })
|
|
|
+ }
|
|
|
+ @State messageInfoList: MessageInfoModel[] = []
|
|
|
+ getMessageList = async () => {
|
|
|
+ this.messageInfoList = []
|
|
|
+ let res: MessageInfoModel = await JGRequest.post("/api/v1/sys/message/userMessage", {
|
|
|
+ pageNo: 1,
|
|
|
+ pageSize: 30,
|
|
|
+ } as RequestParamModel)
|
|
|
+ this.messageInfoList = res.records ?? []
|
|
|
+ console.log("WebSocketDemo list", JSON.stringify(this.messageInfoList))
|
|
|
+ this.noticeDialogController.open()
|
|
|
+ }
|
|
|
|
|
|
aboutToAppear(): void {
|
|
|
////生产操作
|
|
@@ -63,8 +79,30 @@ export struct TitleStateComp {
|
|
|
this.kittingNum = res.kittingNum
|
|
|
this.planNum = res.planNum
|
|
|
})
|
|
|
+
|
|
|
+ this.creatWebsocket()
|
|
|
}
|
|
|
|
|
|
+ setMessageRead = async (m: MessageInfoModel, index: number) => {
|
|
|
+ let res: MessageInfoModel = await JGRequest.post("/api/v1/sys/message/confirmMessage", [m.id] as string[])
|
|
|
+ let temp = m
|
|
|
+ temp.readState = "1"
|
|
|
+ this.messageInfoList[index] = temp
|
|
|
+
|
|
|
+ }
|
|
|
+ // 消息弹窗控制器
|
|
|
+ noticeDialogController: CustomDialogController = new CustomDialogController({
|
|
|
+ builder: NoticeDialog({
|
|
|
+ messages: this.messageInfoList,
|
|
|
+ setRead: this.setMessageRead
|
|
|
+ }),
|
|
|
+ alignment: DialogAlignment.Center,
|
|
|
+ customStyle: true,
|
|
|
+ cancel: () => {
|
|
|
+ this.isClick = !this.isClick
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
build() {
|
|
|
Stack() {
|
|
|
Text()
|
|
@@ -132,7 +170,8 @@ export struct TitleStateComp {
|
|
|
// router.pushUrl({
|
|
|
// // url:"pages/OutboundStation"
|
|
|
// })
|
|
|
- this.noticeDialogController.open()
|
|
|
+ this.getMessageList()
|
|
|
+
|
|
|
})
|
|
|
|
|
|
Row() {
|
|
@@ -448,7 +487,9 @@ struct shutdown {
|
|
|
@CustomDialog
|
|
|
struct NoticeDialog {
|
|
|
controller: CustomDialogController
|
|
|
- Notices: NoticeInfo[] = []
|
|
|
+ @Prop messages: MessageInfoModel[]
|
|
|
+ setRead: (item: MessageInfoModel, index: number) => void = (item: MessageInfoModel, index: number) => {
|
|
|
+ }
|
|
|
|
|
|
build() {
|
|
|
Column({ space: 10 }) {
|
|
@@ -462,35 +503,56 @@ struct NoticeDialog {
|
|
|
|
|
|
Row() {
|
|
|
List() {
|
|
|
- ForEach(this.Notices, (item: NoticeInfo) => {
|
|
|
+ ForEach(this.messages, (item: MessageInfoModel, index: number) => {
|
|
|
ListItem() {
|
|
|
- Row() {
|
|
|
- Text(item.Notice)
|
|
|
- .fontSize($r('app.float.fontSize_38'))
|
|
|
+ Column() {
|
|
|
+ Text(item.title)
|
|
|
+ .fontSize($r('app.float.fontSize_24'))
|
|
|
.fontColor($r('app.color.general_font_color'))
|
|
|
.opacity($r('app.float.general_font_opacity'))
|
|
|
- Text(item.NoticeDate)
|
|
|
- .fontSize($r('app.float.fontSize_38'))
|
|
|
+ Text(item.content)
|
|
|
+ .fontSize($r('app.float.fontSize_20'))
|
|
|
+ .fontColor($r('app.color.general_font_color'))
|
|
|
+ .opacity($r('app.float.general_font_opacity'))
|
|
|
+ Text("来自: " + item?.creator ?? "" + item.readState!)
|
|
|
+ .fontSize($r('app.float.fontSize_20'))
|
|
|
+ .fontColor($r('app.color.general_font_color'))
|
|
|
+ .opacity($r('app.float.card_font_default_opacity'))
|
|
|
+
|
|
|
+ Text(item.created)
|
|
|
+ .fontSize($r('app.float.fontSize_20'))
|
|
|
.fontColor($r('app.color.general_font_color'))
|
|
|
.opacity($r('app.float.card_font_default_opacity'))
|
|
|
}
|
|
|
- .justifyContent(FlexAlign.SpaceBetween)
|
|
|
+ .justifyContent(FlexAlign.Start)
|
|
|
+ .alignItems(HorizontalAlign.Start)
|
|
|
.width('100%')
|
|
|
+ .margin({ bottom: 10 })
|
|
|
+ .backgroundColor(item.readState == "1" ? $r("app.color.green_100") : $r("app.color.gray_6666"))
|
|
|
+ .padding(6)
|
|
|
+ .borderRadius($r('app.float.notice_size'))
|
|
|
+ .onClick(() => {
|
|
|
+ if (this.setRead) {
|
|
|
+ this.setRead(item, index)
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- .width('90%')
|
|
|
+ .width('98%')
|
|
|
.height('80%')
|
|
|
.alignItems(VerticalAlign.Top)
|
|
|
.borderRadius($r('app.float.notice_size'))
|
|
|
.borderWidth($r('app.float.general_border_width'))
|
|
|
.borderColor($r('app.color.general_border_color'))
|
|
|
}
|
|
|
- .width('45%')
|
|
|
+ .width('50%')
|
|
|
.height('70%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
- .backgroundColor($r('app.color.page_general_background'))
|
|
|
+ .backgroundColor(Color.White)
|
|
|
.borderRadius($r('app.float.notice_size'))
|
|
|
}
|
|
|
}
|