ソースを参照

获取app menu,扫描完成后清除记录数据

panxingxin 5 年 前
コミット
d37ef896c3

+ 6 - 130
src/app/app.component.html

@@ -27,146 +27,22 @@
               </ion-label>
             </ion-item>
           </ion-menu-toggle>
-
         </ion-list>
 
-
-
-        <ion-list *ngIf="loggedIn">
-        <!-- <ion-list> -->
+        <ion-list *ngFor="let menu of menuList">
           <ion-list-header>
-            业务
+            {{menu.title}}
           </ion-list-header>
-
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/scanning">
-              <ion-icon slot="start" name="qr-scanner"></ion-icon>
-              <ion-label>
-                开单号,样品扫描
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-
-        </ion-list>
-
-
-        <ion-list *ngIf="loggedIn">
-          <!-- <ion-list> -->
-          <ion-list-header>
-            QA
-          </ion-list-header>
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/contract">
-              <ion-icon slot="start" name="book"></ion-icon>
-              <ion-label>
-                采购合同
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/sample">
-              <ion-icon slot="start" name="document"></ion-icon>
+          <ion-menu-toggle autoHide="false" *ngFor="let item of menu.children">
+            <ion-item [routerLink]="item.url">
+              <ion-icon slot="start" [name]="item.icon"></ion-icon>
               <ion-label>
-                样品单管理
+                {{item.name}}
               </ion-label>
             </ion-item>
           </ion-menu-toggle>
-
         </ion-list>
 
-
-        <ion-list *ngIf="loggedIn">
-          <!-- <ion-list> -->
-          <ion-list-header>
-            仓库样品
-          </ion-list-header>
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/store-sample-pending">
-              <ion-icon slot="start" name="alarm"></ion-icon>
-              <ion-label>
-                待备样
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/store-sample-binding">
-              <ion-icon slot="start" name="timer"></ion-icon>
-              <ion-label>
-                样品绑定
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/store-sample">
-              <ion-icon slot="start" name="home"></ion-icon>
-              <ion-label>
-                仓库样品列表
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-        </ion-list>
-
-
-        <ion-list *ngIf="loggedIn">
-          <!-- <ion-list> -->
-          <ion-list-header>
-            仓库管理
-          </ion-list-header>
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/enter-store">
-              <ion-icon slot="start" name="appstore"></ion-icon>
-              <ion-label>
-                入库扫描
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/warehouse-manage-pending">
-              <ion-icon slot="start" name="timer"></ion-icon>
-              <ion-label>
-                待备货
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-
-
-
-        </ion-list>
-
-
-        <ion-list *ngIf="loggedIn">
-          <ion-list-header>
-            QC
-          </ion-list-header>
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/store-qc">
-              <ion-icon slot="start" name="list-box"></ion-icon>
-              <ion-label>
-                QC验货初检报告列表
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/store-qc-scanning">
-              <ion-icon slot="start" name="qr-scanner"></ion-icon>
-              <ion-label>
-                QC扫描
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-          <ion-menu-toggle autoHide="false">
-            <ion-item routerLink="/store-pending">
-              <ion-icon slot="start" name="checkbox"></ion-icon>
-              <ion-label>
-                待验货物
-              </ion-label>
-            </ion-item>
-          </ion-menu-toggle>
-        </ion-list>
         <ion-item lines="none">
           <span slot="end">{{version_number}}</span>
         </ion-item>

+ 26 - 0
src/app/app.component.ts

@@ -9,6 +9,7 @@ import { LocalNotifications } from '@ionic-native/local-notifications/ngx';
 // import { WebSocketService } from '../providers/WebSocketService';
 import { Device } from '@ionic-native/device/ngx';
 import { Update } from '../providers/update'
+import { menu_list } from './menu/menu'
 
 @Component({
   selector: 'app-root',
@@ -17,6 +18,7 @@ import { Update } from '../providers/update'
 export class AppComponent {
   public loggedIn: boolean = false;
   public version_number: any
+  public menuList = []
   constructor(
     private device: Device,
     private localNotifications: LocalNotifications,
@@ -36,6 +38,7 @@ export class AppComponent {
   }
   ngOnInit() {
     this.initWebSocket()
+    this.getMenuList()
     //WS连接的IP和端口提前保存在localStorage里,现在读出来
     // this.wsService.createObservableSocket(`ws://192.168.20.32:8804/websocket/403`);
     // this.wsService.sendMessage('testhis.fullScreenImaget')
@@ -50,6 +53,29 @@ export class AppComponent {
     });
   }
 
+  // 获取该用户的菜单
+  async getMenuList() {
+    let list = await this.userData.getAppMenu()
+    let newList = []
+    for(let i of menu_list) {
+      let filterArr = []
+      for(let j of i.children) {
+        let arr = list.filter(item=>{return item.menuId===j.id})
+        if(arr.length!==0) {
+          filterArr = filterArr.concat(j)
+        }
+      }
+      // 如果有符合的菜单项则push进去
+      if(filterArr.length!==0) {
+        newList.push({
+          title: i.title,
+          children: filterArr
+        })
+      }
+    }
+    this.menuList = newList
+  }
+
   async getVersionNumber() {
     this.version_number = await this.update.getVersionNumber()
   }

+ 15 - 0
src/app/enter-store/enter-store.page.ts

@@ -29,6 +29,11 @@ export class EnterStorePage implements OnInit {
 
   @ViewChild('scanInput') scanInput;
   ngOnInit() {
+    this.storage.get('storeList').then(async (val) => {
+      if (val) {
+        this.storeList = JSON.parse(val)
+      }
+    })
     // this.getStoreDetail()
     // console.log('enter-store')
   }
@@ -38,6 +43,14 @@ export class EnterStorePage implements OnInit {
     this.initialData()
   }
 
+  ionViewDidLeave() {
+    if (this.storeList.length !== 0) {
+      this.storage.set('storeList', JSON.stringify(this.storeList))
+    } else {
+      this.storage.remove('storeList')
+    }
+  }
+
   initialData() {
     this.storeDetailList = []
     this.clicked = false
@@ -133,6 +146,8 @@ export class EnterStorePage implements OnInit {
   async saveStore() {
     await this.userData.saveStoreDetail(this.storeList)
     this.initialData()
+    this.storeList = []
+    this.storage.remove('storeList')
     // this.scanInput.setFocus();
   }
 

+ 75 - 0
src/app/menu/menu.ts

@@ -0,0 +1,75 @@
+export const menu_list = [
+    {
+        title: '业务',
+        children: [{
+            id: 1000,
+            name: '开单号,样品扫描',
+            icon: 'qr-scanner',
+            url: 'scanning'
+        }]
+    },
+    {
+        title: 'QA',
+        children: [{
+            id: 2000,
+            name: '采购合同',
+            icon: 'book',
+            url: 'contract'
+        }, {
+            id: 3000,
+            name: '样品单管理',
+            icon: 'document',
+            url: 'sample'
+        }]
+    },{
+        title: '仓库样品',
+        children: [{
+            id: 4000,
+            name: '待备样',
+            icon: 'alarm',
+            url: 'store-sample-pending'
+        }, {
+            id: 5000,
+            name: '样品绑定',
+            icon: 'timer',
+            url: 'store-sample-binding'
+        }, {
+            id: 6000,
+            name: '仓库样品列表',
+            icon: 'home',
+            url: 'store-sample'
+        }]
+    },{
+        title: '仓库管理',
+        children: [{
+            id: 7000,
+            name: '入库扫描',
+            icon: 'appstore',
+            url: 'enter-store'
+        }, {
+            id: 8000,
+            name: '待备货',
+            icon: 'timer',
+            url: 'warehouse-manage-pending'
+        }]
+    },{
+        title: 'QC',
+        children: [{
+            id: 9000,
+            name: 'QC验货初检报告列表',
+            icon: 'list-box',
+            url: 'store-qc'
+        }, {
+            id: 10000,
+            name: 'QC扫描',
+            icon: 'qr-scanner',
+            url: 'store-qc-scanning'
+        }, {
+            id: 11000,
+            name: '待验货物',
+            icon: 'checkbox',
+            url: 'store-pending'
+        }]
+    }
+
+]

+ 1 - 0
src/app/store-qc-scanning/store-qc-scanning.page.ts

@@ -132,6 +132,7 @@ export class StoreQCScanningPage implements OnInit {
     await this.userData.createQC(this.storeQCList)
     this.initialData()
     this.storage.remove('storeQCList')
+    this.storeQCList = []
   }
 
   // 记录数据

+ 24 - 0
src/providers/user-data.ts

@@ -100,6 +100,30 @@ export class UserData {
     });
   }
 
+  // 获取App menu
+  async getAppMenu(): Promise<any> {
+    const token = await this.getToken();
+    return new Promise((resolve, reject) => {
+    from(this.nativeHttp.get('http://dev.sgsino.cn/admin/menu/app',
+      {},
+      { Authorization: `Bearer ${token}`,'Content-Type': 'application/json;charset=UTF-8' })).pipe(
+        finalize(() => { })
+      ).subscribe(async data => {
+        // console.log(JSON.parse(data.data))
+        resolve(JSON.parse(data.data).data)
+      }, async err => {
+        console.log(err);
+        const toast = await this.toastCtrl.create({
+          message: '查询目录失败',
+          duration: 1000,
+          position: 'top'
+        });
+        await toast.present();
+      });
+    return;
+    })
+  }
+
   async logout(): Promise<any> {
     const alert = await this.alertController.create({
       header: '安全退出',