gaoluyang
9 天以前 6ebcfebf58fe23ea401de1050b15ba85e41763a9
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<script lang="ts" setup>
import type { MesHomeApi } from '#/api/mes/home';
 
import { computed } from 'vue';
 
import { CountTo } from '@vben/common-ui';
import { IconifyIcon } from '@vben/icons';
 
import { Card, Col, Divider, Row } from 'ant-design-vue';
 
import { useHomeAccess } from '#/utils/use-home-access';
 
import { HOME_BLOCK_MENUS } from '../data';
 
defineOptions({ name: 'MesHomeKpiCards' });
 
const props = defineProps<{
  summary: MesHomeApi.Summary;
}>();
 
const emit = defineEmits<{
  navigate: [name: string];
}>();
 
/** 菜单没开的模块,对应 KPI 卡不展示 */
const { canSeeMenu } = useHomeAccess();
 
/** 是否有质量数据(合格品 + 不良品 > 0) */
const hasQualityData = computed(
  () =>
    props.summary.todayQualifiedQuantity +
      props.summary.todayUnqualifiedQuantity >
    0,
);
 
/** 质量合格率 = 合格品 / (合格品 + 不良品) * 100,无数据时为 0 */
const qualityRate = computed(() => {
  const total =
    props.summary.todayQualifiedQuantity +
    props.summary.todayUnqualifiedQuantity;
  if (total === 0) {
    return 0;
  }
  return (props.summary.todayQualifiedQuantity / total) * 100;
});
</script>
 
<template>
  <Row :gutter="16">
    <Col
      v-if="canSeeMenu(HOME_BLOCK_MENUS.workOrder)"
      :lg="6"
      :md="12"
      :sm="12"
      :xl="6"
      :xs="24"
      class="mb-4"
    >
      <Card
        class="kpi-card cursor-pointer transition-all hover:-translate-y-1 hover:shadow-lg"
        @click="emit('navigate', HOME_BLOCK_MENUS.workOrder)"
      >
        <div class="flex items-center gap-4">
          <div
            class="flex size-14 flex-shrink-0 items-center justify-center rounded-xl text-white"
            style="background: linear-gradient(135deg, #409eff, #66b1ff)"
          >
            <IconifyIcon class="size-7" icon="lucide:file-text" />
          </div>
          <div>
            <div class="text-muted-foreground mb-1 text-sm">生产订单</div>
            <div class="flex items-baseline gap-1">
              <CountTo
                class="text-2xl font-bold leading-tight text-[#409eff]"
                :end-val="summary.workOrderActiveCount"
                :duration="1500"
              />
              <span class="text-muted-foreground text-xs">进行中</span>
            </div>
            <div class="text-muted-foreground mt-1 text-xs">
              <span>待排产 {{ summary.workOrderPrepareCount }}</span>
              <Divider type="vertical" />
              <span>已完成 {{ summary.workOrderFinishedCount }}</span>
            </div>
          </div>
        </div>
      </Card>
    </Col>
    <Col
      v-if="canSeeMenu(HOME_BLOCK_MENUS.feedback)"
      :lg="6"
      :md="12"
      :sm="12"
      :xl="6"
      :xs="24"
      class="mb-4"
    >
      <Card
        class="kpi-card cursor-pointer transition-all hover:-translate-y-1 hover:shadow-lg"
        @click="emit('navigate', HOME_BLOCK_MENUS.feedback)"
      >
        <div class="flex items-center gap-4">
          <div
            class="flex size-14 flex-shrink-0 items-center justify-center rounded-xl text-white"
            style="background: linear-gradient(135deg, #67c23a, #85ce61)"
          >
            <IconifyIcon class="size-7" icon="lucide:bar-chart-3" />
          </div>
          <div>
            <div class="text-muted-foreground mb-1 text-sm">今日产量</div>
            <div class="flex items-baseline gap-1">
              <CountTo
                class="text-2xl font-bold leading-tight text-[#67c23a]"
                :end-val="summary.todayOutput"
                :duration="1500"
              />
              <span class="text-muted-foreground text-xs">件</span>
            </div>
            <div class="text-muted-foreground mt-1 text-xs">
              <span>昨日 {{ summary.yesterdayOutput }} 件</span>
            </div>
          </div>
        </div>
      </Card>
    </Col>
    <Col
      v-if="canSeeMenu(HOME_BLOCK_MENUS.feedback)"
      :lg="6"
      :md="12"
      :sm="12"
      :xl="6"
      :xs="24"
      class="mb-4"
    >
      <Card
        class="kpi-card cursor-pointer transition-all hover:-translate-y-1 hover:shadow-lg"
        @click="emit('navigate', HOME_BLOCK_MENUS.feedback)"
      >
        <div class="flex items-center gap-4">
          <div
            class="flex size-14 flex-shrink-0 items-center justify-center rounded-xl text-white"
            style="background: linear-gradient(135deg, #e6a23c, #ebb563)"
          >
            <IconifyIcon class="size-7" icon="lucide:circle-check" />
          </div>
          <div>
            <div class="text-muted-foreground mb-1 text-sm">质量合格率</div>
            <div class="flex items-baseline gap-1">
              <CountTo
                class="text-2xl font-bold leading-tight text-[#e6a23c]"
                :decimals="1"
                :end-val="qualityRate"
                :duration="1500"
              />
              <span class="text-muted-foreground text-xs">%</span>
            </div>
            <div class="text-muted-foreground mt-1 text-xs">
              <template v-if="hasQualityData">
                <span>合格 {{ summary.todayQualifiedQuantity }}</span>
                <Divider type="vertical" />
                <span>不良 {{ summary.todayUnqualifiedQuantity }}</span>
              </template>
              <span v-else>暂无数据</span>
            </div>
          </div>
        </div>
      </Card>
    </Col>
    <Col
      v-if="canSeeMenu(HOME_BLOCK_MENUS.machinery)"
      :lg="6"
      :md="12"
      :sm="12"
      :xl="6"
      :xs="24"
      class="mb-4"
    >
      <Card
        class="kpi-card cursor-pointer transition-all hover:-translate-y-1 hover:shadow-lg"
        @click="emit('navigate', HOME_BLOCK_MENUS.machinery)"
      >
        <div class="flex items-center gap-4">
          <div
            class="flex size-14 flex-shrink-0 items-center justify-center rounded-xl text-white"
            style="background: linear-gradient(135deg, #7c3aed, #9461f5)"
          >
            <IconifyIcon class="size-7" icon="lucide:cpu" />
          </div>
          <div>
            <div class="text-muted-foreground mb-1 text-sm">设备状态</div>
            <div class="flex items-baseline gap-1">
              <CountTo
                class="text-2xl font-bold leading-tight text-[#7c3aed]"
                :end-val="summary.machineryProducing"
                :duration="1500"
              />
              <span class="text-muted-foreground text-xs">
                / {{ summary.machineryTotal }} 运行中
              </span>
            </div>
            <div class="text-muted-foreground mt-1 text-xs">
              <span class="text-red-400">停机 {{ summary.machineryStop }}</span>
              <Divider type="vertical" />
              <span class="text-orange-400">
                维护 {{ summary.machineryMaintenance }}
              </span>
            </div>
          </div>
        </div>
      </Card>
    </Col>
  </Row>
</template>