123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- 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'))
- }
- }
|