gaoluyang
7 天以前 f7072c928b7cb9c8ae3bdba00e6c046e3f6f1c34
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<script lang="ts" setup>
import { computed, onMounted, ref } from 'vue';
 
import { CountTo } from '@vben/common-ui';
import { IconifyIcon } from '@vben/icons';
 
import { Col, Row } from 'ant-design-vue';
 
import { getAttendanceExceptionPage } from '#/api/hrm/attendance/exception';
import { getEmployeePage } from '#/api/hrm/employee';
import { getLeavePage } from '#/api/hrm/leave';
import { getSalaryPaymentPage } from '#/api/hrm/salary/payment';
import { getItemReceiptPage } from '#/api/mes/wm/itemreceipt';
import { getMaterialStockPage } from '#/api/mes/wm/materialstock';
import { getProductIssuePage } from '#/api/mes/wm/productissue';
import { getWarehousePage } from '#/api/mes/wm/warehouse';
 
import { useHomeAccess } from '#/utils/use-home-access';
 
defineOptions({ name: 'DashboardWarehouseHrCards' });
 
const emit = defineEmits<{
  navigate: [name: string];
}>();
 
/** 统计卡片定义:取数只调各自列表接口拿总数,菜单没开的卡不显示 */
interface StatCard {
  /** 卡片标题 */
  label: string;
  /** 单位 */
  unit: string;
  /** 副标题:数据来源 */
  hint: string;
  icon: string;
  /** 图标底色渐变(Tailwind) */
  gradient: string;
  /** 数值颜色(Tailwind) */
  color: string;
  /** 卡片归属的菜单(路由 name),关着就不用展示 */
  menu: string;
  /** 菜单对应的查询权限码,没有按钮权限的菜单留空 */
  permission?: string;
  /** 取数方法 */
  load: () => Promise<number>;
}
 
/** 查询参数:只要 total,分页大小取 1,避免拉回整页明细 */
const pageParam = { pageNo: 1, pageSize: 1 };
 
/** 从分页结果里取总数 */
async function totalOf(promise: Promise<{ total?: number }>) {
  const result = await promise;
  return result.total ?? 0;
}
 
/** 仓储物流 */
const WAREHOUSE_CARDS: StatCard[] = [
  {
    color: 'text-amber-600 dark:text-amber-400',
    gradient: 'from-amber-500 to-yellow-400',
    hint: '仓储物流 · 库存现有量',
    icon: 'lucide:package-search',
    label: '库存物料',
    load: () => totalOf(getMaterialStockPage(pageParam)),
    menu: 'MesWmMaterialStock',
    permission: 'mes:wm-material-stock:query',
    unit: '条',
  },
  {
    color: 'text-blue-600 dark:text-blue-400',
    gradient: 'from-blue-500 to-indigo-400',
    hint: '仓储物流 · 仓库设置',
    icon: 'lucide:warehouse',
    label: '仓库数量',
    load: () => totalOf(getWarehousePage(pageParam)),
    menu: 'MesWmWarehouse',
    permission: 'mes:wm-warehouse:query',
    unit: '个',
  },
  {
    color: 'text-cyan-600 dark:text-cyan-400',
    gradient: 'from-cyan-500 to-teal-400',
    hint: '仓储物流 · 采购入库',
    icon: 'lucide:package-open',
    label: '采购入库单',
    load: () => totalOf(getItemReceiptPage(pageParam)),
    menu: 'MesWmItemReceipt',
    permission: 'mes:wm-item-receipt:query',
    unit: '笔',
  },
  {
    color: 'text-violet-600 dark:text-violet-400',
    gradient: 'from-violet-500 to-purple-400',
    hint: '仓储物流 · 生产领料',
    icon: 'lucide:package',
    label: '生产领料单',
    load: () => totalOf(getProductIssuePage(pageParam)),
    menu: 'MesWmProductIssue',
    permission: 'mes:wm-product-issue:query',
    unit: '笔',
  },
];
 
/** 人力资源 */
const HR_CARDS: StatCard[] = [
  {
    color: 'text-emerald-600 dark:text-emerald-400',
    gradient: 'from-emerald-500 to-green-400',
    hint: '人力资源 · 员工管理',
    icon: 'lucide:users',
    label: '员工总数',
    load: () => totalOf(getEmployeePage(pageParam)),
    menu: 'HrmEmployee',
    permission: 'hrm:employee:query',
    unit: '人',
  },
  {
    color: 'text-orange-600 dark:text-orange-400',
    gradient: 'from-orange-500 to-amber-400',
    hint: '人力资源 · 请假申请',
    icon: 'lucide:calendar-range',
    label: '请假申请',
    load: () => totalOf(getLeavePage(pageParam)),
    menu: 'HrmLeaveApplication',
    permission: 'hrm:leave:query',
    unit: '单',
  },
  {
    color: 'text-rose-600 dark:text-rose-400',
    gradient: 'from-rose-500 to-pink-400',
    hint: '人力资源 · 考勤异常',
    icon: 'lucide:circle-alert',
    label: '考勤异常',
    load: () => totalOf(getAttendanceExceptionPage(pageParam)),
    menu: 'HrmAttendanceException',
    unit: '条',
  },
  {
    color: 'text-fuchsia-600 dark:text-fuchsia-400',
    gradient: 'from-fuchsia-500 to-pink-400',
    hint: '人力资源 · 薪资发放',
    icon: 'lucide:wallet',
    label: '薪资发放单',
    load: () => totalOf(getSalaryPaymentPage(pageParam)),
    menu: 'HrmSalaryPayment',
    unit: '单',
  },
];
 
const { canQuery, canSeeMenu } = useHomeAccess();
 
/** 菜单开着(有查询按钮权限时一并校验)才展示这张卡 */
function isVisible(card: StatCard) {
  return (
    canSeeMenu(card.menu) && (!card.permission || canQuery(card.permission))
  );
}
 
const warehouseCards = computed(() => WAREHOUSE_CARDS.filter(isVisible));
const hrCards = computed(() => HR_CARDS.filter(isVisible));
 
/** 按分组渲染,分组内无卡片时整组不渲染 */
const groups = computed(() =>
  [
    { cards: warehouseCards.value, title: '仓储物流' },
    { cards: hrCards.value, title: '人力资源' },
  ].filter((group) => group.cards.length > 0),
);
 
const values = ref<Record<string, number>>({});
 
/** 并发拉取所有可见卡片的统计值,单张失败只影响它自己 */
async function loadValues() {
  const cards = [...warehouseCards.value, ...hrCards.value];
  await Promise.all(
    cards.map(async (card) => {
      try {
        values.value[card.label] = await card.load();
      } catch {
        /* 无权限或接口异常时保持 0 */
      }
    }),
  );
}
 
/** 3D 倾斜 */
const tilts = ref<Record<string, { x: number; y: number }>>({});
 
function onMouseMove(e: MouseEvent, label: string) {
  const el = e.currentTarget as HTMLElement;
  const rect = el.getBoundingClientRect();
  const x = ((e.clientX - rect.left) / rect.width - 0.5) * 2;
  const y = ((e.clientY - rect.top) / rect.height - 0.5) * 2;
  tilts.value[label] = { x: x * -5, y: y * 5 };
}
 
function onMouseLeave(label: string) {
  tilts.value[label] = { x: 0, y: 0 };
}
 
function tiltStyle(label: string) {
  const t = tilts.value[label] ?? { x: 0, y: 0 };
  return {
    transform: `perspective(500px) rotateX(${t.y}deg) rotateY(${t.x}deg)`,
    transition:
      t.x === 0 && t.y === 0 ? 'transform 0.5s ease' : 'transform 0.1s ease',
  };
}
 
onMounted(() => {
  loadValues();
});
</script>
 
<template>
  <template v-for="group in groups" :key="group.title">
    <h3
      class="mb-3 text-base font-semibold text-gray-800 dark:text-gray-100"
    >
      {{ group.title }}
    </h3>
    <Row :gutter="16">
      <Col
        v-for="card in group.cards"
        :key="card.label"
        :lg="6"
        :md="12"
        :sm="12"
        :xl="6"
        :xs="24"
        class="mb-4"
      >
        <div
          class="glass-tilt group cursor-pointer overflow-hidden rounded-2xl border-0"
          :style="tiltStyle(card.label)"
          @mousemove="(e: MouseEvent) => onMouseMove(e, card.label)"
          @mouseleave="onMouseLeave(card.label)"
          @click="emit('navigate', card.menu)"
        >
          <div class="relative z-10 flex items-center gap-4 p-5">
            <div
              class="flex size-12 flex-shrink-0 items-center justify-center rounded-xl bg-gradient-to-br shadow-lg transition-transform duration-300 group-hover:scale-110"
              :class="card.gradient"
            >
              <IconifyIcon class="size-6 text-white" :icon="card.icon" />
            </div>
            <div class="min-w-0 flex-1">
              <div
                class="mb-1 text-xs font-medium text-gray-500 dark:text-gray-400"
              >
                {{ card.label }}
              </div>
              <div class="flex items-baseline gap-1">
                <CountTo
                  class="text-2xl font-bold leading-tight"
                  :class="card.color"
                  :end-val="values[card.label] ?? 0"
                  :duration="1200"
                />
                <span class="text-xs text-gray-400">{{ card.unit }}</span>
              </div>
              <div class="mt-1 text-xs text-gray-400">{{ card.hint }}</div>
            </div>
          </div>
          <div
            class="absolute inset-0 -z-0 bg-gradient-to-br from-gray-500/5 to-gray-400/5 opacity-0 transition-opacity duration-300 group-hover:opacity-100"
          />
          <div
            class="absolute -right-6 -top-6 size-24 rounded-full bg-gray-400/10 blur-xl transition-all duration-300 group-hover:scale-150"
          />
        </div>
      </Col>
    </Row>
  </template>
</template>
 
<style scoped>
.glass-tilt {
  background: linear-gradient(135deg, rgba(255,255,255,0.85), rgba(255,255,255,0.55));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.6);
  box-shadow:
    0 4px 24px rgba(0,0,0,0.04),
    0 1px 4px rgba(0,0,0,0.02),
    inset 0 1px 0 rgba(255,255,255,0.8);
  transform-style: preserve-3d;
}
 
.dark .glass-tilt {
  background: linear-gradient(135deg, rgba(30,30,55,0.75), rgba(20,20,40,0.5));
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow:
    0 4px 24px rgba(0,0,0,0.3),
    0 2px 8px rgba(0,0,0,0.2),
    inset 0 1px 0 rgba(255,255,255,0.05);
}
</style>