import {TimeAndTitle} from "../component/TimeAndTitle" import {NavigationBar} from '../component/NavigationBar' import {StorageList} from '../component/MenuView' import { BoundOrder} from "../viewmodel/wms/OrderMaterialsStorageParams" import RequestParamModel from '../viewmodel/wms/RequestParamModel' import WmsRequest from '../common/util/request/WmsRequest' import PageRes from "../viewmodel/wms/InBoundOrderInfo" import router from '@ohos.router'; import MqttManager from '../common/util/mqtt'; import { MqttClientOptions, MqttConnectOptions } from '@ohos/mqtt'; import CommonConstants from '../common/constants/CommonConstants' import { getToken, getUserInfo } from '../common/util/request/RequestInstance' import {UserInfo} from '../viewmodel/wms/UserInfo' import UserAuthModel from '../common/util/UserAuthModel'; import DictInfo from '../viewmodel/DictInfo' import connection from '@ohos.net.connection'; import { ConfirmDialogParams } from '../viewmodel/wms/ConfirmDialogParam' import { CommonConfirmDialog } from '../component/OrderMaterialsStorageView' const TAG: string = 'MENU' @Entry @Component struct menu { @State pages: PageRes = {} @State inBoundOrders: BoundOrder[]=[] @State outBoundOrders: BoundOrder[]=[] @State loginName: string = 'admin' @State password: string = '123456' @State isConnected:boolean=false commonDialogController: CustomDialogController | null = null; private showConfirmDialog(params: ConfirmDialogParams) { if (this.commonDialogController) { this.commonDialogController.close() } this.commonDialogController = new CustomDialogController({ builder: CommonConfirmDialog({ title: params.title || '提示', message: params.message, confirmText: params.confirmText || '确定', cancelText: params.cancelText || '取消', onConfirm: params.onConfirm }), cancel: () => console.log('用户取消操作'), customStyle: true, autoCancel:false, maskColor: 'rgba(0,0,0,0.6)' }); this.commonDialogController.open(); } loadOrders = async (type: number, targetArray: BoundOrder[]) => { const pages = await WmsRequest.post('/api/v1/wmsOrder/page', { type } as RequestParamModel) as PageRes; if (pages?.records) { for (const record of pages.records) { targetArray.push({ batchCode: record.batchCode, materialName: record.materialName, materialNo: record.materialNo || '', num: record.num, created: record.created }); } } } connectMQTT=async ()=>{ const clientOptions: MqttClientOptions = { url: 'mqtt://192.168.1.3:1883', // 替换实际IP clientId: `ohos_client_${Date.now()}`, persistenceType: 1, // 使用英文逗号 // 建议开启自动重连 }; // MQTT连接配置 const connectOptions: MqttConnectOptions = { cleanSession: true, connectTimeout: 30, keepAliveInterval: 60, userName: 'optional_username', password: 'optional_password' }; try { MqttManager.init(clientOptions); this.isConnected = await MqttManager.connect(connectOptions); if (this.isConnected ) { console.info(TAG, 'MQTT connected successfully'); await MqttManager.subscribe('station100/data/devices'); } else { console.error(TAG, 'MQTT connection failed'); } } catch (err) { console.error(TAG, `MQTT error: ${JSON.stringify(err)}`); } } loginWms=async()=> { if (this.loginName && this.loginName.length > 0 && this.password && this.password.length > 0) { await getToken(this.loginName, this.password, 17, '66') .then(token => { if (token && token.length > 0) { CommonConstants.AUTH_TOKEN = token } }) if (CommonConstants.AUTH_TOKEN.length <= 0) { return } console.log("tesTag1 ssssss" ) let userInfo = await getUserInfo() as UserInfo console.log("tesTag1" + JSON.stringify(userInfo)) CommonConstants.USER_ID = userInfo.id! CommonConstants.USER_NAME = userInfo.userName! CommonConstants.USER_AVATAR = userInfo.avatar! CommonConstants.STATION_CODE = userInfo.stationCode! CommonConstants.STATION_IP = userInfo.stationIp! CommonConstants.STATION_NANE = '出入库工位' CommonConstants.STATION_ID = 66 let user = await UserAuthModel.getByUserId(userInfo.id ? userInfo.id : 0) console.log("tesTag1" + JSON.stringify(user)) if (!user || !user.id) { // 将后端数据库id作为userId, 默认是保持登录 user = { userId: userInfo.id, userName: this.loginName, password: this.password, orgId: 17, stationId: 66, stationName:'出入库工位', stationDictValue: '6', avatar: userInfo.avatar, maintainLoginStatus: 1, updateTime: new Date().getTime(), isLogin: true, } let res = await UserAuthModel.addUser(user) } CommonConstants.LOGIN_OUT = false } this.loadOrders(1, this.inBoundOrders) this.loadOrders(2, this.outBoundOrders) } async aboutToAppear() { //this.connectMQTT(); //this.loginWms(); const checkInterval = setInterval(() => { if (CommonConstants.AUTH_TOKEN!='') { clearInterval(checkInterval); // 停止轮询 setTimeout(() => { this.connectMQTT(); }, 1000); return } this.loginWms(); }, 2000); // 每500毫秒检查一次 // this.loginWms(); // 查询数据字典放到CommonConstants的DICT_DATA变量中 // let res: DictInfo[] = await WmsRequest.post('/api/v1/sys/dictData/all',) // if (res && res.length > 0) { // for (const dict of res) { // CommonConstants.DICT_DATA.set(dict.dictCode, dict.list) // } // } // try { // const netHandle = connection.getDefaultNetSync(); // if (netHandle) { // let connectionProperties = await connection.getConnectionProperties(netHandle) // if (connectionProperties && connectionProperties.linkAddresses) { // connectionProperties.linkAddresses.forEach((address: connection.LinkAddress, index: number) => { // console.info('hhtest', "get address info: " + JSON.stringify(address)); // }) // } // } // } catch (err) { // console.log('hhtest', err); // } } build() { Row() { Column() { //时间和导航标 Row(){ TimeAndTitle() }.width('100%') .height('3.4%') .alignItems(VerticalAlign.Bottom) .justifyContent(FlexAlign.End) Row(){ Image($r('app.media.general_return')) .height($r('app.float.virtualSize_56')) .width($r('app.float.virtualSize_56')) .fillColor($r('app.color.FFFFFF')) Text('智能仓储') .fontColor($r('app.color.FFFFFF')) .fontSize($r('app.float.fontSize_38')) } .height('4%') .width('100%') .justifyContent(FlexAlign.Start) .margin({left:'2%'}) .onClick(()=> { this.showConfirmDialog({ title: '退出', message: `确定退出到桌面吗?`, onConfirm: ()=> { router.back() } }); }) Row(){ NavigationBar().width('20%') } .width('100%') .height('4%') .justifyContent(FlexAlign.End) Row(){ Column(){ Text("入库") .fontColor($r('app.color.FFFFFF')) .fontSize($r('app.float.fontSize_38')) Column() { Text('空箱入库') .fontSize($r('app.float.fontSize_38')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Medium) Text('料箱编码打印和写入磁卡') .fontSize($r('app.float.fontSize_16')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Lighter) } .justifyContent(FlexAlign.Center) .width('100%') .height('23%') .borderRadius($r('app.float.virtualSize_16')) .backgroundImage($r("app.media.empty_material_inbound")) .backgroundImageSize(ImageSize.Cover) .onClick(()=>{ router.pushUrl({ url: 'pages/EmptyBoxStorage' }) }) Column() { Text('订单物料入库') .fontSize($r('app.float.fontSize_38')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Medium) Text('物料绑定料箱和订单') .fontSize($r('app.float.fontSize_16')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Lighter) } .justifyContent(FlexAlign.Center) .width('100%') .height('46%') .borderRadius($r('app.float.virtualSize_16')) .backgroundImage($r("app.media.order_material_inbound")) .backgroundImageSize(ImageSize.Cover) .onClick(()=>{ router.pushUrl({ url: 'pages/OrderMaterialsStorage' }) }) Column() { Text('零星物料入库') .fontSize($r('app.float.fontSize_38')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Medium) Text('物料绑定料箱') .fontSize($r('app.float.fontSize_16')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Lighter) } .justifyContent(FlexAlign.Center) .width('100%') .height('23%') .borderRadius($r('app.float.virtualSize_16')) .backgroundImage($r("app.media.little_material_inbound")) .backgroundImageSize(ImageSize.Cover) .onClick(()=>{ router.pushUrl({ url: 'pages/LittleMaterialsStorage' }) }) }.justifyContent(FlexAlign.SpaceAround) .height('95%') .width('30%') .alignItems(HorizontalAlign.Start) Divider() .vertical(true) .strokeWidth(1) .color($r('app.color.15FFFFFF')) .height('95%') Column(){ Text("齐套/出库") .fontColor($r('app.color.FFFFFF')) .fontSize($r('app.float.fontSize_38')) Column() { Text('工序齐套') .fontSize($r('app.float.fontSize_38')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Medium) Text('物料绑定料箱和工序') .fontSize($r('app.float.fontSize_16')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Lighter) } .justifyContent(FlexAlign.Center) .width('100%') .height('70%') .borderRadius($r('app.float.virtualSize_16')) .backgroundImage($r("app.media.process_material_kits")) .backgroundImageSize(ImageSize.Cover) .onClick(()=>{ router.pushUrl({ url: 'pages/OperationMaterialKit' }) }) Column() { Text('零星物料出库') .fontSize($r('app.float.fontSize_38')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Medium) Text('物料查询并调取') .fontSize($r('app.float.fontSize_16')) .fontColor($r('app.color.FFFFFF')) .fontWeight(FontWeight.Lighter) } .justifyContent(FlexAlign.Center) .width('100%') .height('23%') .borderRadius($r('app.float.virtualSize_16')) .backgroundImage($r("app.media.little_material_outbound")) .backgroundImageSize(ImageSize.Cover) .onClick(()=>{ router.pushUrl({ url: 'pages/LittleMaterialOutBound' }) }) } .alignItems(HorizontalAlign.Start).justifyContent(FlexAlign.SpaceAround).height('95%').width('30%') Divider() .vertical(true) .strokeWidth(1) .color($r('app.color.15FFFFFF')) .height('95%') Column(){ Text(" ") .fontColor($r('app.color.FFFFFF')) .fontSize($r('app.float.fontSize_38')) StorageList({title:"入库单",storageData: this.inBoundOrders }).height('46%') StorageList({title:"出库单",storageData: this.outBoundOrders }).height('46%'); }.alignItems(HorizontalAlign.Start).justifyContent(FlexAlign.SpaceAround).height('95%').width('30%') } .height('88.6%') .width('100%') .alignItems(VerticalAlign.Top) .justifyContent(FlexAlign.SpaceAround) } .width('100%') } .height('100%') .backgroundColor($r('app.color.000000')) } }