车间能级提升-智能设备管理系统
朱桂飞
2025-02-20 f0bb114ba37709cbe1aa55047fbf0c57cc07ab9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<script setup lang="ts">
import { onMounted, ref } from 'vue';
 
import { AnalysisOverview, type AnalysisOverviewItem, Page, type WorkbenchTrendItem, WorkbenchTrends } from '@vben/common-ui';
import { DictEnum } from '@vben/constants';
 
import { listFixture } from '#/api/eims/fixture';
import { operLogList } from '#/api/monitor/operlog';
import { dictDataInfo } from '#/api/system/dict/dict-data';
import { SYS_OPER_TYPE } from '#/constants/dict';
 
const fixtureList = ref<AnalysisOverviewItem[]>([
  {
    icon: 'svg:card',
    title: '工具总数',
    totalTitle: '工具总数',
    totalValue: 0,
    value: 0
  },
  {
    icon: 'svg:cake',
    title: '可用工具数',
    totalTitle: '可用工具数',
    totalValue: 0,
    value: 0
  },
  {
    icon: 'svg:download',
    title: '借出总数',
    totalTitle: '借出总数',
    totalValue: 0,
    value: 0
  },
  {
    icon: 'svg:bell',
    title: '最近更新',
    totalTitle: '最近更新',
    totalValue: 0,
    value: 0
  }
]);
const logList = ref<WorkbenchTrendItem[]>([]);
 
async function initFixtrueList() {
  const data = await listFixture({
    pageNum: 1,
    pageSize: 100_000
  });
  if (!data) {
    console.error('Failed to fetch data.');
    return;
  }
 
  const rows = data.rows;
  const now = Date.now(); // 获取当前时间的时间戳
  const sevenDaysAgo = now - 7 * 24 * 60 * 60 * 1000; // 计算7天前的时间戳
 
  const kongxian = rows.filter((item) => item.borrowStatus === '0' || item.borrowStatus === null);
  const jiechu = rows.filter((item) => item.borrowStatus === '1');
  const zuijin = rows.filter((item) => new Date(item.createTime).getTime() >= sevenDaysAgo);
 
  fixtureList.value[0]!.value = fixtureList.value[0]!.totalValue = data.total || 0;
  fixtureList.value[1]!.value = fixtureList.value[1]!.totalValue = kongxian.length;
  fixtureList.value[2]!.value = fixtureList.value[2]!.totalValue = jiechu.length;
  fixtureList.value[3]!.value = fixtureList.value[3]!.totalValue = zuijin.length;
}
 
async function initLogList() {
  const params = { title: '借用记录', orderByColumn: 'operTime', isAsc: 'desc' };
  const res = await operLogList({
    pageNum: 1,
    pageSize: 20,
    ...params
  });
  let list = res?.rows;
  list = list.filter((i) => i.businessType.toString() === SYS_OPER_TYPE.ADD || i.businessType.toString() === SYS_OPER_TYPE.EDIT);
  list = list.filter((i) => i.jsonResult !== null && JSON.parse(i.jsonResult).code === 200);
 
  const recordStatusList = await dictDataInfo(DictEnum.FIXTURE_BORROW_RECORD_STATUS);
  list.forEach((row) => {
    const operParam = JSON.parse(row.operParam);
    const label = recordStatusList.find((item) => item.dictValue === operParam.status)?.dictLabel;
    logList.value.push({
      avatar: 'svg:avatar-1',
      content: `${row?.deptName}  ${row?.operName} <a>${label}</a> ${operParam?.fixtureName} `,
      date: row.operTime,
      title: row.title
    });
  });
}
onMounted(() => {
  initFixtrueList();
  initLogList();
});
</script>
 
<template>
  <Page :auto-content-height="true">
    <div class="h-full">
      <AnalysisOverview :items="fixtureList" />
      <WorkbenchTrends :items="logList" class="mt-5" title="最新动态" />
      <div class="h-5"></div>
    </div>
  </Page>
</template>
 
<style scoped></style>