瀏覽代碼

万能卡片逻辑修改入库

yixiaojun 1 年之前
父節點
當前提交
62fd871955

+ 0 - 2
entry/src/main/ets/common/component/Workbin.ets

@@ -371,9 +371,7 @@ struct ChuKUA {
 
 
   @State private TasklistoutboundData:Array<Tasklist>=[]
   @State private TasklistoutboundData:Array<Tasklist>=[]
   @Link CunQuHuo:number
   @Link CunQuHuo:number
-
   scroller: Scroller = new Scroller()
   scroller: Scroller = new Scroller()
-
   @State SelectableMarker:number=0
   @State SelectableMarker:number=0
   @State SelectableMarkerOne:number=0
   @State SelectableMarkerOne:number=0
   @State SelectableMarkertwo:number=0
   @State SelectableMarkertwo:number=0

+ 1 - 1
entry/src/main/ets/common/constants/CommonConstants.ets

@@ -19,7 +19,7 @@ export default class CommonConstants {
   static FILE_URL_PREFIX : string = 'http://192.168.101.4:9000/jgfile'
   static FILE_URL_PREFIX : string = 'http://192.168.101.4:9000/jgfile'
 
 
   // 当前登录用户id
   // 当前登录用户id
-  static USER_ID : number = 0
+  static USER_ID : number = 1
 
 
   static readonly STORAGE_TYPE: string[] =  ['电子元器件', '电路板', '结构件', '辅助材料']
   static readonly STORAGE_TYPE: string[] =  ['电子元器件', '电路板', '结构件', '辅助材料']
   static readonly PARK_TYPE: string[] =  ['出入库位置', '充电位置', '工作台', '其他']
   static readonly PARK_TYPE: string[] =  ['出入库位置', '充电位置', '工作台', '其他']

+ 4 - 4
entry/src/main/ets/model/UniversalCard.ets

@@ -5,11 +5,11 @@ export default class UniversalCard {
   // id
   // id
   id?: number;
   id?: number;
   // 用户id
   // 用户id
-  userId: number
+  userId?: number
   // 卡片类型(1:智能仓储 3:工序(生产)操作 5:(设备)智汇工厂)
   // 卡片类型(1:智能仓储 3:工序(生产)操作 5:(设备)智汇工厂)
-  cardType: number
+  cardType?: number
   // 卡片状态(1:打开 2:关闭)
   // 卡片状态(1:打开 2:关闭)
-  cardStatus: number
+  cardStatus?: number
   // 卡片排序号(取数组索引)
   // 卡片排序号(取数组索引)
-  cardSort: number
+  cardSort?: number
 }
 }

+ 152 - 104
entry/src/main/ets/pages/Index.ets

@@ -8,6 +8,9 @@ import { SmartFactoryCard }from  '../common/component/SmartFactoryCard'
 import CommonConstants from '../common/constants/CommonConstants'
 import CommonConstants from '../common/constants/CommonConstants'
 import UniversalCard from  '../model/UniversalCard'
 import UniversalCard from  '../model/UniversalCard'
 import UniversalCardModel from '../model/database/UniversalCardModel';
 import UniversalCardModel from '../model/database/UniversalCardModel';
+import formProvider from '@ohos.app.form.formProvider';
+import UserInfo from '../model/UserInfo';
+
 //登录退出
 //登录退出
 @CustomDialog
 @CustomDialog
 struct login {
 struct login {
@@ -16,6 +19,7 @@ struct login {
   controller: CustomDialogController
   controller: CustomDialogController
   cancel: () => void
   cancel: () => void
   confirm: () => void
   confirm: () => void
+
   build() {
   build() {
     Column() {
     Column() {
       Text('退出登录')
       Text('退出登录')
@@ -65,13 +69,14 @@ struct login {
 //卡片服务
 //卡片服务
 @CustomDialog
 @CustomDialog
 struct confirmPopup {
 struct confirmPopup {
+  cardType: number
   @Link cardServices:UniversalCard[]
   @Link cardServices:UniversalCard[]
   controller: CustomDialogController
   controller: CustomDialogController
   cancel: () => void
   cancel: () => void
   confirm: () => void
   confirm: () => void
   @Link x: number
   @Link x: number
   @Link  y: number
   @Link  y: number
-  @Link index:number
+  @Link cardSorting:number
   build(){
   build(){
     Column(){
     Column(){
       Column(){
       Column(){
@@ -86,15 +91,41 @@ struct confirmPopup {
             .fontWeight(FontWeight.Medium)
             .fontWeight(FontWeight.Medium)
             .fontSize(px2vp(38))
             .fontSize(px2vp(38))
             .textAlign(TextAlign.Start)
             .textAlign(TextAlign.Start)
-            .onClick(()=>{
-              this.controller.close()
-              this.cardServices[this.index]= {
-                id:this.cardServices[this.index].id,
-                userId:this.cardServices[this.index].userId,
-                cardType:this.cardServices[this.index].cardType,
-                cardStatus:1,
-                cardSort:this.cardServices[this.index].cardSort,
+            .onClick(async ()=>{
+              // 第一种遍历, const后面的是变量,变量的值就是数组的元素
+              // for (const card of this.cardServices) {
+              //
+              //   card.cardStatus
+              // }
+
+              // 第二种遍历,index是数组索引
+              // 1.修改变量数组中,此卡片类型的对象(改为打开状态)
+              let temp: UniversalCard
+              let deleteIndex: number
+              for (let index=0; index < this.cardServices.length; index++) {
+                if (this.cardServices[index].cardType === this.cardType) {
+                  this.cardServices[index].cardStatus = 1
+                  temp = this.cardServices[index]
+                  deleteIndex = index
+                  break
+                }
               }
               }
+              // 2.删除变量数组中
+              this.cardServices.splice(deleteIndex, 1)
+              // 3.修改排序号
+              let sort: number = 0
+              for (let index=0; index < this.cardServices.length; index++) {
+                this.cardServices[index].cardSort = sort
+                // 4.更新数据库数据
+                await UniversalCardModel.updateUniversalCard(this.cardServices[index])
+                sort++
+              }
+              // 5.变量数组添加元素
+              temp.cardSort = this.cardServices.length
+              this.cardServices.push(temp)
+              // 6.修改数据入库
+              await UniversalCardModel.updateUniversalCard(temp)
+              this.controller.close()
             })
             })
 
 
         }.width('100%')
         }.width('100%')
@@ -111,17 +142,16 @@ struct confirmPopup {
       .height('20%')
       .height('20%')
       .width('120%')
       .width('120%')
       .backgroundColor($r('app.color.general_font_white_color'))
       .backgroundColor($r('app.color.general_font_white_color'))
-
-      Image(this.index===1?$r("app.media.processImages")
-        :this.index===2?$r('app.media.jg_circular_icon'):$r('app.media.storage'))
-        .width(px2vp(280))
-        .height(px2vp(280))
+      Image(this.cardSorting===1?$r("app.media.processImages")
+        :this.cardSorting===2?$r('app.media.jg_circular_icon'):$r('app.media.storage'))
+        .width(this.cardSorting===2?px2vp(120):px2vp(280))
+        .height(this.cardSorting===2?px2vp(120):px2vp(280))
         .borderRadius(15)
         .borderRadius(15)
     }
     }
     .alignItems(HorizontalAlign.Start)
     .alignItems(HorizontalAlign.Start)
     .width('350px')
     .width('350px')
     .height('600px')
     .height('600px')
-    .offset({x:this.x+'px', y:this.y-410+'px'})
+    .offset(this.cardSorting===2?{x:this.x+50+'px', y:this.y-270+'px'}:{x:this.x+5+'px', y:this.y-410+'px'})
   }
   }
 }
 }
 //开关重启
 //开关重启
@@ -185,7 +215,8 @@ struct shutdown {
 @Entry
 @Entry
 @Component
 @Component
 struct Index {
 struct Index {
-  @State index:number=0
+  private cardType:number=0
+  @State cardSorting:number=0
   @State x:number=0
   @State x:number=0
   @State y:number=0
   @State y:number=0
   @State cardServices:UniversalCard[] =[]
   @State cardServices:UniversalCard[] =[]
@@ -225,9 +256,10 @@ struct Index {
   })
   })
   confirmPopupDialogController: CustomDialogController = new CustomDialogController({
   confirmPopupDialogController: CustomDialogController = new CustomDialogController({
     builder: confirmPopup({
     builder: confirmPopup({
+      cardType:this.cardType,
       x:this.x,
       x:this.x,
       y:this.y,
       y:this.y,
-      index:this.index,
+      cardSorting:this.cardSorting,
       cardServices:this.cardServices
       cardServices:this.cardServices
     }
     }
       ),
       ),
@@ -235,9 +267,12 @@ struct Index {
     autoCancel:true,
     autoCancel:true,
     customStyle:true,
     customStyle:true,
   })
   })
+
   async aboutToAppear(){
   async aboutToAppear(){
-    this.cardServices= await  UniversalCardModel.getListByUserId(CommonConstants.USER_ID)
-    if (!this.cardServices||this.cardServices.length<=0) {
+    // 1.根据当前用户id查询他配置的万能卡片
+    this.cardServices = await UniversalCardModel.getListByUserId(CommonConstants.USER_ID)
+    if (!this.cardServices || this.cardServices.length <= 0) {
+      // 2.1用户第一次登录,所有的万能卡片都展示
       for (let index = 0; index < CommonConstants.CARD_TYPE_DATA.length; index++) {
       for (let index = 0; index < CommonConstants.CARD_TYPE_DATA.length; index++) {
         const card:UniversalCard = {
         const card:UniversalCard = {
           userId:CommonConstants.USER_ID,
           userId:CommonConstants.USER_ID,
@@ -245,15 +280,13 @@ struct Index {
           cardStatus:1,
           cardStatus:1,
           cardSort: index
           cardSort: index
         };
         };
-        UniversalCardModel.addUniversalCard(card)
+        // 3.1用户的万能卡片入库,(以后再次打开页面能够查询到)
+        card.id = await UniversalCardModel.addUniversalCard(card)
+        // 3.2保存到数组变量,用于展示(避免再次查询,多于的开销)
         this.cardServices.push(card)
         this.cardServices.push(card)
       }
       }
-
-
-      
     }
     }
-    console.log("查询结果"+ JSON.stringify(this.cardServices))
-
+    // 2.2查询到有万能卡片数据,就直接展示,不做任何操作
   }
   }
   build() {
   build() {
     Stack(){
     Stack(){
@@ -266,69 +299,65 @@ struct Index {
           Row() {
           Row() {
             Column() {
             Column() {
               List(){
               List(){
-                ForEach(this.cardServices,(item:UniversalCard,index)=>{
-                  ListItem(){
-                    if (item.cardType===3 && item.cardStatus === 1){
-                      Stack(){
-                        Column(){
-                          TaskComp({isHomePage: this.isHomePage})
-                          Text('生产操作')
-                            .fontSize(px2vp(27))
-                            .margin({top:5})
-                            .fontWeight(FontWeight.Medium)
-                            .fontColor($r('app.color.robot_set_card_white'))
-                        }
-                        .height('40%')
-                        .width('95%')
-                        .gesture(
-                          LongPressGesture({ repeat: false })
-                            .onActionEnd(() => {
-                              this.deleteConfirmation=1
-                            })
-                        )
-                        if (this.deleteConfirmation===1){
-                          Row(){
-                            Text('取消')
-                              .fontWeight(FontWeight.Medium)
+                ForEach(this.cardServices, (item:UniversalCard,index)=>{
+                  if (item.cardStatus === 1) {
+                    ListItem(){
+                      if (item.cardType===3){
+                        Stack(){
+                          Column(){
+                            TaskComp({isHomePage: this.isHomePage})
+                            Text('生产操作')
                               .fontSize(px2vp(27))
                               .fontSize(px2vp(27))
-                              .textAlign(TextAlign.Center)
-                              .width('20%')
-                              .height('20%')
-                              .margin(10)
-                              .borderRadius(px2vp(21))
-                              .fontColor($r('app.color.robot_set_card_blue'))
-                              .backgroundColor($r('app.color.general_font_white_color'))
-                              .onClick(()=>{
-                                this.deleteConfirmation=0
-                              })
-                            Text('删除')
+                              .margin({top:5})
                               .fontWeight(FontWeight.Medium)
                               .fontWeight(FontWeight.Medium)
-                              .fontSize(px2vp(27))
-                              .width('20%')
-                              .margin(10)
-                              .fontColor($r('app.color.general_font_white_color'))
-                              .borderRadius(px2vp(21))
-                              .height('20%')
-                              .textAlign(TextAlign.Center)
-                              .backgroundColor(  $r('app.color.robot_set_card_blue'))
-                              .onClick(()=>{
-                                this.deleteConfirmation=0
-                                this.cardServices[0]= {
-                                  id:this.cardServices[0].id,
-                                  userId:this.cardServices[0].userId,
-                                  cardType:this.cardServices[0].cardType,
-                                  cardStatus:2,
-                                  cardSort:this.cardServices[0].cardSort,
-                                }
-                              })
+                              .fontColor($r('app.color.robot_set_card_white'))
                           }
                           }
-                          .justifyContent(FlexAlign.Center)
                           .height('40%')
                           .height('40%')
                           .width('95%')
                           .width('95%')
+                          .gesture(
+                            LongPressGesture({ repeat: false })
+                              .onActionEnd(() => {
+                                this.deleteConfirmation=1
+                              })
+                          )
+                          if (this.deleteConfirmation===1){
+                            Row(){
+                              Text('取消')
+                                .fontWeight(FontWeight.Medium)
+                                .fontSize(px2vp(27))
+                                .textAlign(TextAlign.Center)
+                                .width('20%')
+                                .height('20%')
+                                .margin(10)
+                                .borderRadius(px2vp(21))
+                                .fontColor($r('app.color.robot_set_card_blue'))
+                                .backgroundColor($r('app.color.general_font_white_color'))
+                                .onClick(()=>{
+                                  this.deleteConfirmation=0
+                                })
+                              Text('删除')
+                                .fontWeight(FontWeight.Medium)
+                                .fontSize(px2vp(27))
+                                .width('20%')
+                                .margin(10)
+                                .fontColor($r('app.color.general_font_white_color'))
+                                .borderRadius(px2vp(21))
+                                .height('20%')
+                                .textAlign(TextAlign.Center)
+                                .backgroundColor(  $r('app.color.robot_set_card_blue'))
+                                .onClick(async()=>{
+                                  this.deleteConfirmation = 0
+                                  // 删除卡片
+                                  await this.deleteCard(index);
+                                })
+                            }
+                            .justifyContent(FlexAlign.Center)
+                            .height('40%')
+                            .width('95%')
+                          }
                         }
                         }
-                      }
-                    } else if (item.cardType===1 && item.cardStatus === 1){
-                      Stack(){
+                      } else if (item.cardType===1){
+                        Stack(){
                           Column(){
                           Column(){
                             Warehousing()
                             Warehousing()
                             Text('智能仓储')
                             Text('智能仓储')
@@ -375,15 +404,10 @@ struct Index {
                                 .height('20%')
                                 .height('20%')
                                 .textAlign(TextAlign.Center)
                                 .textAlign(TextAlign.Center)
                                 .backgroundColor(  $r('app.color.robot_set_card_blue'))
                                 .backgroundColor(  $r('app.color.robot_set_card_blue'))
-                                .onClick(()=>{
+                                .onClick(async ()=>{
                                   this.smartWarehouseCard=0
                                   this.smartWarehouseCard=0
-                                  this.cardServices[1]= {
-                                    id:this.cardServices[1].id,
-                                    userId:this.cardServices[1].userId,
-                                    cardType:this.cardServices[1].cardType,
-                                    cardStatus:2,
-                                    cardSort:this.cardServices[1].cardSort,
-                                  }
+                                  // 删除卡片
+                                  await this.deleteCard(index);
                                 })
                                 })
                             }
                             }
                             .justifyContent(FlexAlign.Center)
                             .justifyContent(FlexAlign.Center)
@@ -391,8 +415,8 @@ struct Index {
                             .width('95%')
                             .width('95%')
                           }
                           }
                         }
                         }
-                    } else if (item.cardType===5 && item.cardStatus === 1){
-                      Stack(){
+                      } else if (item.cardType===5){
+                        Stack(){
                           Column(){
                           Column(){
                             SmartFactoryCard()
                             SmartFactoryCard()
                             Text('智汇工厂')
                             Text('智汇工厂')
@@ -439,15 +463,10 @@ struct Index {
                                 .height('20%')
                                 .height('20%')
                                 .textAlign(TextAlign.Center)
                                 .textAlign(TextAlign.Center)
                                 .backgroundColor(  $r('app.color.robot_set_card_blue'))
                                 .backgroundColor(  $r('app.color.robot_set_card_blue'))
-                                .onClick(()=>{
+                                .onClick(async ()=>{
                                   this.SmartFactoryCarLongPressDelete=0
                                   this.SmartFactoryCarLongPressDelete=0
-                                  this.cardServices[2]= {
-                                    id:this.cardServices[2].id,
-                                    userId:this.cardServices[2].userId,
-                                    cardType:this.cardServices[2].cardType,
-                                    cardStatus:2,
-                                    cardSort:this.cardServices[2].cardSort,
-                                  }
+                                  // 删除卡片
+                                  await this.deleteCard(index);
                                 })
                                 })
                             }
                             }
                             .justifyContent(FlexAlign.Center)
                             .justifyContent(FlexAlign.Center)
@@ -455,11 +474,11 @@ struct Index {
                             .width('95%')
                             .width('95%')
                           }
                           }
                         }
                         }
+                      }
                     }
                     }
                   }
                   }
                 })
                 })
               }.lanes(3)
               }.lanes(3)
-
             }
             }
             .width('100%')
             .width('100%')
             .height('100%')
             .height('100%')
@@ -528,7 +547,8 @@ struct Index {
                   }
                   }
                   this.x=touchPoint.x
                   this.x=touchPoint.x
                   this.y=touchPoint.y
                   this.y=touchPoint.y
-                  this.index=1
+                  this.cardSorting=1
+                  this.cardType=1
                   this.confirmPopupDialogController.open()
                   this.confirmPopupDialogController.open()
 
 
                 })
                 })
@@ -581,6 +601,7 @@ struct Index {
             .gesture(
             .gesture(
               LongPressGesture({ repeat: false })
               LongPressGesture({ repeat: false })
                 .onActionEnd(() => {
                 .onActionEnd(() => {
+
                   let rect = componentLocation.getComponentRect('workingProcedure')
                   let rect = componentLocation.getComponentRect('workingProcedure')
                   let touchPoint: TouchObject = {
                   let touchPoint: TouchObject = {
                     id: 1,
                     id: 1,
@@ -592,7 +613,8 @@ struct Index {
                   }
                   }
                   this.x=touchPoint.x
                   this.x=touchPoint.x
                   this.y=touchPoint.y
                   this.y=touchPoint.y
-                  this.index=0
+                  this.cardSorting=0
+                  this.cardType=3
                   this.confirmPopupDialogController.open()
                   this.confirmPopupDialogController.open()
                 })
                 })
             )
             )
@@ -641,7 +663,8 @@ struct Index {
                     }
                     }
                     this.x=touchPoint.x
                     this.x=touchPoint.x
                     this.y=touchPoint.y
                     this.y=touchPoint.y
-                    this.index=2
+                    this.cardSorting=2
+                    this.cardType=5
                     this.confirmPopupDialogController.open()
                     this.confirmPopupDialogController.open()
                   })
                   })
               )
               )
@@ -705,6 +728,31 @@ struct Index {
     .width('100%')
     .width('100%')
 
 
   }
   }
+
+  // 删除卡片
+  private async deleteCard(index: number) {
+    // 1.修改变量中cardStatus为2,关闭状态
+    this.cardServices[index] = {
+      id: this.cardServices[index].id,
+      userId: this.cardServices[index].userId,
+      cardType: this.cardServices[index].cardType,
+      cardStatus: 2,
+      cardSort: this.cardServices[index].cardSort,
+    };
+    // 2.更新数据库,当前删除的卡片状态
+    await UniversalCardModel.updateUniversalCard(this.cardServices[index]);
+    // 3.其他数据的修改排序
+    let sort: number = 0;
+    for (let a = 0; a < this.cardServices.length; a++) {
+      if (this.cardServices[a].cardStatus === 1) {
+        this.cardServices[a].cardSort = sort;
+        // 4.更新数据库
+        await UniversalCardModel.updateUniversalCard(this.cardServices[a]);
+        sort++;
+      }
+    }
+  }
+
   // 动画效果
   // 动画效果
   pageTransition() {
   pageTransition() {
     // 设置1ms是为了使延时生效
     // 设置1ms是为了使延时生效

+ 0 - 98
entry/src/main/ets/view/IntelligentWarehousingOutbound.ets

@@ -308,7 +308,6 @@ export struct IntelligentWarehousingOutbound{
   @State videoSrc: Resource = $rawfile('lailaoship.mp4')
   @State videoSrc: Resource = $rawfile('lailaoship.mp4')
   @State textValue: string = ''
   @State textValue: string = ''
   @State inputValue: string = ''
   @State inputValue: string = ''
-
   @State ZhuangTai:number=0
   @State ZhuangTai:number=0
   @State CunQuHuo:number=0
   @State CunQuHuo:number=0
   OutboundController: CustomDialogController = new CustomDialogController({
   OutboundController: CustomDialogController = new CustomDialogController({
@@ -326,107 +325,10 @@ export struct IntelligentWarehousingOutbound{
     gridCount: 4,
     gridCount: 4,
     customStyle: true,
     customStyle: true,
   })
   })
-  ///出库确认弹窗控制器
-  // OutboundController: CustomDialogController = new CustomDialogController({
-  //   builder:Outbound({
-  //     ScanStoragelist:this.ScanStoragelist,
-  //     CunQuHuo:this.CunQuHuo,
-  //     cancel: this.onCancel,
-  //     confirm: this.onAccept,
-  //     textValue: $textValue,
-  //     inputValue: $inputValue,
-  //
-  //
-  //   }),
-  //
-  //   // gridCount: 3,
-  //   cancel: this.existApp,
-  //   //autoCancel: true,
-  //   alignment: DialogAlignment.Center,
-  //   //offset: { dx: 0, dy: -20 },
-  //   gridCount: 4,
-  //   customStyle: true,
-  // })
-
 build(){
 build(){
   Row(){
   Row(){
     Column(){
     Column(){
-     Video({
-       src: this.videoSrc,
-       previewUri: this.previewUri,
-     })
-        .width('95%')
-       .controls(false)
-        .height('80%')
-      .loop(true)
-      .autoPlay(true)
-      .border({width:0})
-      .borderRadius(20)
-
-
-      if (this.CunQuHuo===0){
-        Row(){
-        }
-        .width('100%')
-        .justifyContent(FlexAlign.Center)
 
 
-        .height('4%')
-      }else if (this.CunQuHuo===1){
-        Row(){
-          LoadingProgress()
-            .color(Color.Blue)
-            .width('10%')
-          Text('正在取物料')
-            .width('20%')
-            .fontSize('27px')
-            .height('100%')
-
-        }
-        .width('100%')
-        .justifyContent(FlexAlign.Center)
-        .height('4%')
-      }else if (this.CunQuHuo===2){
-        Row(){
-
-          LoadingProgress()
-            .color(Color.Blue)
-            .width('10%')
-          Text('正在出货')
-            .width('20%')
-            .fontSize('27px')
-            .height('100%')
-
-        }
-        .width('100%')
-        .justifyContent(FlexAlign.Center)
-        .height('4%')
-      }else if (this.CunQuHuo===3){
-        Row(){
-
-          LoadingProgress()
-            .color(Color.Blue)
-            .width('10%')
-          Text('正在存入料箱')
-            .width('20%')
-            .fontSize('27px')
-            .height('100%')
-
-        }
-        .width('100%')
-        .justifyContent(FlexAlign.Center)
-        .height('4%')
-      }
-
-
-
-      Row({space:15}){
-        /////存取料箱
-
-        Workbin()
-      }.width('100%')
-      .borderRadius(15)
-      .height('16%')
-      .justifyContent(FlexAlign.End)
     }
     }
     .width('32%')
     .width('32%')
     .height('100%')
     .height('100%')