|
@@ -1,7 +1,10 @@
|
|
-import { Component, ViewEncapsulation } from '@angular/core';
|
|
|
|
|
|
+// device-management.component.ts
|
|
|
|
+import { Component, ViewEncapsulation, OnInit } from '@angular/core';
|
|
import { DatePipe } from '@angular/common';
|
|
import { DatePipe } from '@angular/common';
|
|
import { RouterModule } from '@angular/router';
|
|
import { RouterModule } from '@angular/router';
|
|
import { CompDeviceItem } from './comp-device-item/comp-device-item';
|
|
import { CompDeviceItem } from './comp-device-item/comp-device-item';
|
|
|
|
+import { FormsModule } from '@angular/forms';
|
|
|
|
+import { CloudObject, CloudQuery } from '../../../lib/ncloud';
|
|
|
|
|
|
@Component({
|
|
@Component({
|
|
standalone: true,
|
|
standalone: true,
|
|
@@ -10,66 +13,144 @@ import { CompDeviceItem } from './comp-device-item/comp-device-item';
|
|
imports: [
|
|
imports: [
|
|
DatePipe,
|
|
DatePipe,
|
|
RouterModule,
|
|
RouterModule,
|
|
- CompDeviceItem
|
|
|
|
|
|
+ CompDeviceItem,
|
|
|
|
+ FormsModule
|
|
],
|
|
],
|
|
templateUrl: './device-management.component.html',
|
|
templateUrl: './device-management.component.html',
|
|
encapsulation: ViewEncapsulation.None
|
|
encapsulation: ViewEncapsulation.None
|
|
})
|
|
})
|
|
-export class DeviceManagementComponent {
|
|
|
|
- listType:string = "list"
|
|
|
|
- deviceList:Array<any> = [
|
|
|
|
- {
|
|
|
|
- "did": "DEV-2023-001",
|
|
|
|
- "name": "CNC 铣床 #01",
|
|
|
|
- "type": "CNC加工中心",
|
|
|
|
- "location": "车间A/产线3",
|
|
|
|
- "status": "运行中",
|
|
|
|
- "health": 89,
|
|
|
|
- "lastMaintenance": new Date()
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- "did": "DEV-2023-002",
|
|
|
|
- "name": "注塑机 #05",
|
|
|
|
- "type": "注塑机",
|
|
|
|
- "location": "车间B/产线1",
|
|
|
|
- "status": "待机",
|
|
|
|
- "health": 76,
|
|
|
|
- "lastMaintenance": new Date()
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- "did": "DEV-2023-003",
|
|
|
|
- "name": "装配机器人 #03",
|
|
|
|
- "type": "装配机器人",
|
|
|
|
- "location": "车间C/产线2",
|
|
|
|
- "status": "维护中",
|
|
|
|
- "health": 65,
|
|
|
|
- "lastMaintenance": new Date()
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- "did": "DEV-2023-004",
|
|
|
|
- "name": "质检仪 #02",
|
|
|
|
- "type": "检测设备",
|
|
|
|
- "location": "车间A/产线1",
|
|
|
|
- "status": "运行中",
|
|
|
|
- "health": 92,
|
|
|
|
- "lastMaintenance": new Date()
|
|
|
|
- },
|
|
|
|
- {
|
|
|
|
- "did": "DEV-2023-005",
|
|
|
|
- "name": "包装机 #07",
|
|
|
|
- "type": "包装设备",
|
|
|
|
- "location": "车间C/产线3",
|
|
|
|
- "status": "已停止",
|
|
|
|
- "health": 58,
|
|
|
|
- "lastMaintenance": new Date()
|
|
|
|
- }
|
|
|
|
-]
|
|
|
|
-currentTime: Date = new Date();
|
|
|
|
- ngOnInit(): void {
|
|
|
|
|
|
+export class DeviceManagementComponent implements OnInit {
|
|
|
|
+ listType: string = "list";
|
|
|
|
+ deviceList: Array<any> = [];
|
|
|
|
+ currentTime: Date = new Date();
|
|
|
|
+
|
|
|
|
+ // 筛选条件
|
|
|
|
+ filter = {
|
|
|
|
+ type: '全部',
|
|
|
|
+ status: '全部',
|
|
|
|
+ location: '全部车间'
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ // 添加/编辑设备
|
|
|
|
+ editingDevice: any = null;
|
|
|
|
+ isAddModalVisible = false;
|
|
|
|
+ newDevice = {
|
|
|
|
+ name: '',
|
|
|
|
+ type: 'CNC加工中心',
|
|
|
|
+ location: '车间A/产线1',
|
|
|
|
+ status: '运行中',
|
|
|
|
+ health: 90
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ constructor() {}
|
|
|
|
+
|
|
|
|
+ async ngOnInit() {
|
|
// 更新时间,每秒更新一次
|
|
// 更新时间,每秒更新一次
|
|
setInterval(() => {
|
|
setInterval(() => {
|
|
this.currentTime = new Date();
|
|
this.currentTime = new Date();
|
|
}, 1000);
|
|
}, 1000);
|
|
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ await this.loadDevices();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async loadDevices() {
|
|
|
|
+ const query = new CloudQuery("Device");
|
|
|
|
+
|
|
|
|
+ // 添加筛选条件
|
|
|
|
+ if (this.filter.type !== '全部') {
|
|
|
|
+ query.equalTo("type", this.filter.type);
|
|
|
|
+ }
|
|
|
|
+ if (this.filter.status !== '全部') {
|
|
|
|
+ query.equalTo("status", this.filter.status);
|
|
|
|
+ }
|
|
|
|
+ if (this.filter.location !== '全部车间') {
|
|
|
|
+ query.equalTo("location", this.filter.location);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const devices = await query.find();
|
|
|
|
+ this.deviceList = devices.map((device:any) => ({
|
|
|
|
+ id: device.id,
|
|
|
|
+ did: device.get("did"),
|
|
|
|
+ name: device.get("name"),
|
|
|
|
+ type: device.get("type"),
|
|
|
|
+ location: device.get("location"),
|
|
|
|
+ status: device.get("status"),
|
|
|
|
+ health: device.get("health"),
|
|
|
|
+ lastMaintenance: new Date(device.get("lastMaintenance")?.iso || new Date())
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async applyFilter() {
|
|
|
|
+ await this.loadDevices();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async resetFilter() {
|
|
|
|
+ this.filter = {
|
|
|
|
+ type: '全部',
|
|
|
|
+ status: '全部',
|
|
|
|
+ location: '全部车间'
|
|
|
|
+ };
|
|
|
|
+ await this.loadDevices();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ showAddModal() {
|
|
|
|
+ this.isAddModalVisible = true;
|
|
|
|
+ this.editingDevice = null;
|
|
|
|
+ this.newDevice = {
|
|
|
|
+ name: '',
|
|
|
|
+ type: 'CNC加工中心',
|
|
|
|
+ location: '车间A/产线1',
|
|
|
|
+ status: '运行中',
|
|
|
|
+ health: 90
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ showEditModal(device: any) {
|
|
|
|
+ this.isAddModalVisible = true;
|
|
|
|
+ this.editingDevice = device;
|
|
|
|
+ this.newDevice = {
|
|
|
|
+ name: device.name,
|
|
|
|
+ type: device.type,
|
|
|
|
+ location: device.location,
|
|
|
|
+ status: device.status,
|
|
|
|
+ health: device.health
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async saveDevice() {
|
|
|
|
+ const deviceObj = this.editingDevice
|
|
|
|
+ ? new CloudObject("Device")
|
|
|
|
+ : new CloudObject("Device");
|
|
|
|
+
|
|
|
|
+ if (this.editingDevice) {
|
|
|
|
+ deviceObj.id = this.editingDevice.id;
|
|
|
|
+ } else {
|
|
|
|
+ // 为新设备生成ID
|
|
|
|
+ const now = new Date();
|
|
|
|
+ const did = `DEV-${now.getFullYear()}-${(now.getMonth() + 1).toString().padStart(2, '0')}${now.getDate().toString().padStart(2, '0')}-${Math.floor(1000 + Math.random() * 9000)}`;
|
|
|
|
+ deviceObj.set({ did });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ deviceObj.set({
|
|
|
|
+ name: this.newDevice.name,
|
|
|
|
+ type: this.newDevice.type,
|
|
|
|
+ location: this.newDevice.location,
|
|
|
|
+ status: this.newDevice.status,
|
|
|
|
+ health: this.newDevice.health,
|
|
|
|
+ lastMaintenance: new Date().toISOString()
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ await deviceObj.save();
|
|
|
|
+ this.isAddModalVisible = false;
|
|
|
|
+ await this.loadDevices();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ async deleteDevice(device: any) {
|
|
|
|
+ if (confirm(`确定要删除设备 ${device.name} 吗?`)) {
|
|
|
|
+ const deviceObj = new CloudObject("Device");
|
|
|
|
+ deviceObj.id = device.id;
|
|
|
|
+ await deviceObj.destroy();
|
|
|
|
+ await this.loadDevices();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|