diff --git a/backend/routes/devices.js b/backend/routes/devices.js index bc63963..63b1d9e 100644 --- a/backend/routes/devices.js +++ b/backend/routes/devices.js @@ -31,7 +31,7 @@ Rack.hasMany(Device, { foreignKey: 'rackId' }); router.get('/', validateQuery(queryDeviceSchema), async (req, res) => { try { - const { keyword, status, type, rackId, page = 1, pageSize = 10 } = req.query; + const { keyword, status, type, rackId, roomId, page = 1, pageSize = 10 } = req.query; const offset = (page - 1) * pageSize; // 构建查询条件 @@ -101,6 +101,11 @@ router.get('/', validateQuery(queryDeviceSchema), async (req, res) => { where.rackId = rackId; } + // 机房筛选 - 通过机柜关联查询 + if (roomId && roomId !== 'all') { + where['$Rack.roomId$'] = roomId; + } + // 执行查询 - 优化:使用 JOIN 避免 N+1 查询问题 const { count, rows } = await Device.findAndCountAll({ where, diff --git a/frontend/src/pages/ConsumableStatistics.jsx b/frontend/src/pages/ConsumableStatistics.jsx index 8e56379..2c66df2 100644 --- a/frontend/src/pages/ConsumableStatistics.jsx +++ b/frontend/src/pages/ConsumableStatistics.jsx @@ -157,39 +157,81 @@ const QuickFilterBtn = styled(Button)` const FilterCard = styled(motion.div)` background: ${designTokens.colors.background.card}; - padding: 20px 24px; + padding: 24px; border-radius: 16px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); margin-bottom: 24px; border: 1px solid ${designTokens.colors.border}; - display: flex; - align-items: center; - gap: 16px; - flex-wrap: wrap; @media (max-width: 768px) { padding: 16px; } `; +const FilterRow = styled.div` + display: flex; + align-items: center; + gap: 24px; + flex-wrap: wrap; + + @media (max-width: 768px) { + flex-direction: column; + align-items: stretch; + gap: 16px; + } +`; + +const FilterGroup = styled.div` + display: flex; + align-items: center; + gap: 12px; + + @media (max-width: 768px) { + flex-direction: column; + align-items: flex-start; + gap: 8px; + } +`; + const FilterItem = styled.div` display: flex; flex-direction: column; - gap: 6px; + gap: 8px; .filter-label { - font-size: 12px; + font-size: 13px; font-weight: 600; - color: ${designTokens.colors.text.secondary}; - text-transform: uppercase; - letter-spacing: 0.5px; + color: ${designTokens.colors.text.primary}; + display: flex; + align-items: center; + gap: 6px; + + &::before { + content: ''; + width: 3px; + height: 12px; + background: ${designTokens.colors.primary.main}; + border-radius: 2px; + } + } +`; + +const FilterActions = styled.div` + display: flex; + align-items: center; + gap: 12px; + margin-left: auto; + + @media (max-width: 768px) { + margin-left: 0; + width: 100%; } `; const StatsGrid = styled(motion.div)` display: grid; grid-template-columns: repeat(4, 1fr); - gap: 20px; + gap: 16px; margin-bottom: 24px; @media (max-width: 1200px) { @@ -204,7 +246,7 @@ const StatsGrid = styled(motion.div)` const StatsCard = styled(motion.div)` background: ${designTokens.colors.background.card}; border-radius: 16px; - padding: 24px; + padding: 20px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04); border: 1px solid ${designTokens.colors.border}; position: relative; @@ -213,8 +255,9 @@ const StatsCard = styled(motion.div)` transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); &:hover { - transform: translateY(-4px); - box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08); + transform: translateY(-6px); + box-shadow: 0 12px 32px rgba(0, 0, 0, 0.1); + border-color: ${props => props.$borderColor || designTokens.colors.primary.main}40; } &::before { @@ -223,44 +266,40 @@ const StatsCard = styled(motion.div)` top: 0; left: 0; right: 0; - height: 3px; + height: 4px; background: ${props => props.$accent || designTokens.colors.primary.gradient}; } + .card-content { + display: flex; + flex-direction: column; + gap: 12px; + } + + .card-header { + display: flex; + align-items: center; + justify-content: space-between; + } + .card-icon { width: 48px; height: 48px; - border-radius: 12px; + border-radius: 14px; display: flex; align-items: center; justify-content: center; - font-size: 22px; - margin-bottom: 16px; + font-size: 24px; background: ${props => props.$iconBg || 'rgba(99, 102, 241, 0.1)'}; color: ${props => props.$iconColor || designTokens.colors.primary.main}; - } - - .card-value { - font-size: 36px; - font-weight: 700; - color: ${designTokens.colors.text.primary}; - line-height: 1.2; - margin-bottom: 4px; - } - - .card-label { - font-size: 14px; - color: ${designTokens.colors.text.secondary}; + box-shadow: 0 4px 12px ${props => props.$iconShadow || 'rgba(99, 102, 241, 0.2)'}; } .card-trend { - position: absolute; - top: 24px; - right: 24px; display: flex; align-items: center; gap: 4px; - font-size: 13px; + font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 20px; @@ -280,6 +319,25 @@ const StatsCard = styled(motion.div)` background: rgba(107, 114, 128, 0.1); } } + + .card-body { + display: flex; + flex-direction: column; + gap: 4px; + } + + .card-value { + font-size: 32px; + font-weight: 700; + color: ${designTokens.colors.text.primary}; + line-height: 1; + } + + .card-label { + font-size: 13px; + color: ${designTokens.colors.text.secondary}; + font-weight: 500; + } `; const BentoGrid = styled(motion.div)` @@ -312,12 +370,12 @@ const BentoCard = styled(motion.div)` } .card-header { - padding: 20px 24px; + padding: 18px 24px; border-bottom: 1px solid ${designTokens.colors.border}; display: flex; align-items: center; justify-content: space-between; - background: linear-gradient(135deg, #fafbfc 0%, #f5f7fa 100%); + background: ${designTokens.colors.background.main}; .header-left { display: flex; @@ -325,19 +383,20 @@ const BentoCard = styled(motion.div)` gap: 12px; .header-icon { - width: 36px; - height: 36px; - border-radius: 10px; + width: 40px; + height: 40px; + border-radius: 12px; display: flex; align-items: center; justify-content: center; - font-size: 18px; + font-size: 20px; background: ${props => props.$iconBg || designTokens.colors.primary.gradient}; color: white; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); } .header-title { - font-size: 16px; + font-size: 15px; font-weight: 600; color: ${designTokens.colors.text.primary}; } @@ -345,19 +404,24 @@ const BentoCard = styled(motion.div)` .header-extra { color: ${designTokens.colors.text.secondary}; - font-size: 13px; + font-size: 12px; + font-weight: 500; + padding: 4px 10px; + background: ${designTokens.colors.background.card}; + border-radius: 8px; + border: 1px solid ${designTokens.colors.border}; } } .card-body { - padding: 20px 24px; + padding: 0; } `; const InOutComparison = styled.div` display: grid; grid-template-columns: 1fr 1fr; - gap: 20px; + gap: 16px; @media (max-width: 576px) { grid-template-columns: 1fr; @@ -366,99 +430,146 @@ const InOutComparison = styled.div` const ComparisonItem = styled.div` padding: 20px; - border-radius: 12px; + border-radius: 14px; background: ${props => props.$bg || 'transparent'}; text-align: center; + transition: all 0.3s ease; + border: 1px solid ${props => props.$color}20; + + &:hover { + background: ${props => props.$bg || 'transparent'}; + border-color: ${props => props.$color}40; + transform: translateY(-2px); + } .item-icon { - font-size: 28px; - margin-bottom: 12px; + width: 56px; + height: 56px; + margin: 0 auto 14px; + border-radius: 16px; + display: flex; + align-items: center; + justify-content: center; + font-size: 26px; + background: ${props => props.$color}15; color: ${props => props.$color}; } .item-value { - font-size: 32px; + font-size: 34px; font-weight: 700; color: ${props => props.$color}; margin-bottom: 4px; + line-height: 1; } .item-label { font-size: 14px; color: ${designTokens.colors.text.secondary}; - margin-bottom: 8px; + margin-bottom: 10px; + font-weight: 500; } .item-sub { font-size: 13px; color: ${designTokens.colors.text.secondary}; + display: flex; + align-items: center; + justify-content: center; + gap: 4px; strong { color: ${props => props.$color}; + font-weight: 600; } } `; const CategoryGrid = styled.div` display: grid; - grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); - gap: 16px; + grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); + gap: 12px; `; const CategoryCard = styled(motion.div)` - padding: 20px; + padding: 16px; border-radius: 12px; - background: linear-gradient(135deg, #fafbfc 0%, #f5f7fa 100%); + background: ${designTokens.colors.background.card}; border: 1px solid ${designTokens.colors.border}; text-align: center; cursor: pointer; - transition: all 0.3s ease; + transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); + position: relative; + overflow: hidden; + + &::before { + content: ''; + position: absolute; + top: 0; + left: 0; + right: 0; + height: 3px; + background: ${props => props.$color}; + opacity: 0; + transition: opacity 0.3s ease; + } &:hover { - transform: translateY(-2px); - box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06); + transform: translateY(-4px); + box-shadow: 0 8px 24px ${props => props.$color}20; border-color: ${props => props.$color}40; + + &::before { + opacity: 1; + } } .category-badge { display: inline-flex; align-items: center; gap: 6px; - padding: 6px 14px; - border-radius: 20px; - font-size: 13px; - font-weight: 500; + padding: 5px 12px; + border-radius: 16px; + font-size: 12px; + font-weight: 600; margin-bottom: 12px; background: ${props => props.$color}15; color: ${props => props.$color}; + text-transform: uppercase; + letter-spacing: 0.5px; .dot { - width: 8px; - height: 8px; + width: 6px; + height: 6px; border-radius: 50%; background: currentColor; } } .category-count { - font-size: 28px; + font-size: 32px; font-weight: 700; color: ${designTokens.colors.text.primary}; margin-bottom: 4px; + line-height: 1; } .category-label { - font-size: 13px; + font-size: 12px; color: ${designTokens.colors.text.secondary}; - margin-bottom: 12px; + margin-bottom: 10px; + font-weight: 500; } .category-stock { - font-size: 13px; + font-size: 12px; color: ${designTokens.colors.text.secondary}; + padding-top: 8px; + border-top: 1px solid ${designTokens.colors.border}40; strong { color: ${designTokens.colors.text.primary}; + font-weight: 600; } } `; @@ -466,15 +577,18 @@ const CategoryCard = styled(motion.div)` const StyledTable = styled(Table)` .ant-table { background: transparent; + font-size: 13px; } .ant-table-thead > tr > th { background: linear-gradient(135deg, #fafbfc 0%, #f5f7fa 100%); font-weight: 600; - font-size: 13px; + font-size: 12px; color: ${designTokens.colors.text.secondary}; border-bottom: 1px solid ${designTokens.colors.border}; - padding: 14px 16px; + padding: 12px 16px; + text-transform: uppercase; + letter-spacing: 0.5px; } .ant-table-tbody > tr > td { @@ -483,7 +597,11 @@ const StyledTable = styled(Table)` } .ant-table-tbody > tr:hover > td { - background: rgba(99, 102, 241, 0.02); + background: rgba(99, 102, 241, 0.03); + } + + .ant-table-wrapper { + border-radius: 0 0 16px 16px; } `; @@ -921,45 +1039,71 @@ const ConsumableStatistics = () => { - - 时间范围 - { - setDateRange(dates); - setQuickFilter(null); - }} - style={{ ...datePickerStyles.range, width: 280 }} - allowClear={false} - /> - - - 耗材类别 - - - + + + + 时间范围 + { + setDateRange(dates); + setQuickFilter(null); + }} + style={{ ...datePickerStyles.range, width: 320 }} + allowClear={false} + /> + + + 耗材类别 + + + + + + + + @@ -968,11 +1112,22 @@ const ConsumableStatistics = () => { $accent={designTokens.colors.primary.gradient} $iconBg="rgba(99, 102, 241, 0.1)" $iconColor={designTokens.colors.primary.main} - whileHover={{ y: -4 }} + $iconShadow="rgba(99, 102, 241, 0.2)" + $borderColor={designTokens.colors.primary.main} + whileHover={{ y: -6 }} > -
-
{summary?.total || 0}
-
耗材种类
+
+
+
+
+ 总览 +
+
+
+
{summary?.total || 0}
+
耗材种类
+
+
{ $accent={designTokens.colors.warning.gradient} $iconBg="rgba(245, 158, 11, 0.1)" $iconColor={designTokens.colors.warning.main} - whileHover={{ y: -4 }} + $iconShadow="rgba(245, 158, 11, 0.2)" + $borderColor={designTokens.colors.warning.main} + whileHover={{ y: -6 }} > -
-
- {summary?.lowStock || 0} -
-
库存预警
- {summary?.lowStock > 0 && ( -
- 需关注 +
+
+
+ {summary?.lowStock > 0 && ( +
+ 需关注 +
+ )}
- )} +
+
+ {summary?.lowStock || 0} +
+
库存预警
+
+
{ $accent={designTokens.colors.success.gradient} $iconBg="rgba(16, 185, 129, 0.1)" $iconColor={designTokens.colors.success.main} - whileHover={{ y: -4 }} + $iconShadow="rgba(16, 185, 129, 0.2)" + $borderColor={designTokens.colors.success.main} + whileHover={{ y: -6 }} > -
-
- {stats?.inQuantity || 0} +
+
+
+
+ 入库 +
+
+
+
+ {stats?.inQuantity || 0} +
+
期间入库
+
-
期间入库
{ $accent={designTokens.colors.secondary.gradient} $iconBg="rgba(236, 72, 153, 0.1)" $iconColor={designTokens.colors.secondary.main} - whileHover={{ y: -4 }} + $iconShadow="rgba(236, 72, 153, 0.2)" + $borderColor={designTokens.colors.secondary.main} + whileHover={{ y: -6 }} > -
-
- {stats?.outQuantity || 0} +
+
+
+
+ 出库 +
+
+
+
+ {stats?.outQuantity || 0} +
+
期间出库
+
-
期间出库
@@ -1055,32 +1240,38 @@ const ConsumableStatistics = () => {
{stats?.outQuantity || 0}
-
= 0 ? 'rgba(16, 185, 129, 0.06)' : 'rgba(239, 68, 68, 0.06)', - borderRadius: 12, - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - gap: 8, - }}> + = 0 ? 'rgba(16, 185, 129, 0.08)' : 'rgba(239, 68, 68, 0.08)'} 0%, ${netQuantity >= 0 ? 'rgba(5, 150, 105, 0.04)' : 'rgba(185, 28, 28, 0.04)'} 100%)`, + borderRadius: 14, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + gap: 12, + border: `1px solid ${netQuantity >= 0 ? 'rgba(16, 185, 129, 0.2)' : 'rgba(239, 68, 68, 0.2)'}`, + }} + > {netQuantity >= 0 ? ( <> - - + + 净入库 +{netQuantity} 件 ) : ( <> - - - 净出库 {netQuantity} 件 + + + 净出库 {Math.abs(netQuantity)} 件 )} -
+
@@ -1132,10 +1323,23 @@ const ConsumableStatistics = () => {
库存预警
- + {lowStockItems.length > 0 ? ( + + ) : ( + + 全部充足 + + )}
{ @@ -271,6 +275,8 @@ function DeviceManagement() { setKeyword(values.keyword || ''); setStatus(values.status || 'all'); setType(values.type || 'all'); + setRoomId(values.roomId || 'all'); + setRackId(values.rackId || 'all'); setPagination((prev) => ({ ...prev, current: 1 })); @@ -283,6 +289,8 @@ function DeviceManagement() { setKeyword(''); setStatus('all'); setType('all'); + setRoomId('all'); + setRackId('all'); searchForm.resetFields(); setTimeout(() => setSearching(false), 300); @@ -919,6 +927,43 @@ function DeviceManagement() { + + + + + + + +