From 53ce69a1f9d373ccaf339a2cb5cac5db56bed365 Mon Sep 17 00:00:00 2001
From: 18631081161 <2088094923@qq.com>
Date: Thu, 19 Mar 2026 19:33:13 +0800
Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
admin/nginx.conf | 1 +
admin/src/views/Dashboard.vue | 11 ++---------
admin/src/views/product/ProductForm.vue | 15 ++++++---------
server/src/controllers/stockAlert.ts | 10 +++++-----
server/tests/stockAlert.test.ts | 10 ++++------
5 files changed, 18 insertions(+), 29 deletions(-)
diff --git a/admin/nginx.conf b/admin/nginx.conf
index 528a99f5..296f9900 100644
--- a/admin/nginx.conf
+++ b/admin/nginx.conf
@@ -15,6 +15,7 @@ server {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ client_max_body_size 50m;
}
# 上传文件代理
diff --git a/admin/src/views/Dashboard.vue b/admin/src/views/Dashboard.vue
index ea1f7094..55a17cb5 100644
--- a/admin/src/views/Dashboard.vue
+++ b/admin/src/views/Dashboard.vue
@@ -55,16 +55,9 @@
-
-
-
+
-
+ {{ row.stock }}
diff --git a/admin/src/views/product/ProductForm.vue b/admin/src/views/product/ProductForm.vue
index db60229b..0b97128f 100644
--- a/admin/src/views/product/ProductForm.vue
+++ b/admin/src/views/product/ProductForm.vue
@@ -45,11 +45,7 @@
-
-
-
-
-
+
@@ -318,7 +314,7 @@
-
+ 读取自「金价配置」
主石信息
@@ -431,7 +427,7 @@ const rules = {
basePrice: [{ required: true, message: '请输入基础价格', trigger: 'blur' }],
styleNo: [{ required: true, message: '请输入款号', trigger: 'blur' }],
stock: [{ required: true, message: '请输入库存', trigger: 'blur' }],
- totalStock: [{ required: true, message: '请输入总库存', trigger: 'blur' }],
+
loss: [{ required: true, message: '请输入损耗', trigger: 'blur' }],
laborCost: [{ required: true, message: '请输入工费', trigger: 'blur' }],
categoryId: [{ required: true, validator: (_r: any, _v: any, cb: any) => form.categoryId.length > 0 ? cb() : cb(new Error('请选择分类')), trigger: 'change' }],
@@ -681,8 +677,9 @@ async function handleSubmit() {
router.replace(`/products/${res.data.id}/edit`)
}
}
- } catch {
- ElMessage.error('保存失败')
+ } catch (e: any) {
+ const msg = e?.response?.data?.message || '保存失败'
+ ElMessage.error(msg)
} finally {
saving.value = false
}
diff --git a/server/src/controllers/stockAlert.ts b/server/src/controllers/stockAlert.ts
index 1af54c7e..3b2c5189 100644
--- a/server/src/controllers/stockAlert.ts
+++ b/server/src/controllers/stockAlert.ts
@@ -3,14 +3,14 @@ import pool from '../utils/db'
import { RowDataPacket } from 'mysql2'
/**
- * Filter products where stock/totalStock < 0.1, sorted by stock ascending.
+ * Filter products where stock < 20, sorted by stock ascending.
* Pure logic extracted for testability.
*/
export function filterStockAlerts(
- products: { id: number; name: string; style_no: string; stock: number; total_stock: number }[]
+ products: { id: number; name: string; style_no: string; stock: number }[]
): typeof products {
return products
- .filter((p) => p.total_stock > 0 && p.stock / p.total_stock < 0.1)
+ .filter((p) => p.stock < 20)
.sort((a, b) => a.stock - b.stock)
}
@@ -18,9 +18,9 @@ export function filterStockAlerts(
export async function getStockAlerts(_req: Request, res: Response): Promise {
try {
const [rows] = await pool.execute(
- `SELECT id, name, style_no, stock, total_stock
+ `SELECT id, name, style_no, stock
FROM products
- WHERE total_stock > 0 AND stock / total_stock < 0.1
+ WHERE stock < 20
ORDER BY stock ASC`
)
res.json({ code: 0, data: rows })
diff --git a/server/tests/stockAlert.test.ts b/server/tests/stockAlert.test.ts
index eac470f5..41d2e465 100644
--- a/server/tests/stockAlert.test.ts
+++ b/server/tests/stockAlert.test.ts
@@ -8,28 +8,26 @@ const productArb = fc.record({
name: fc.string({ minLength: 1, maxLength: 20 }),
style_no: fc.string({ minLength: 0, maxLength: 10 }),
stock: fc.integer({ min: 0, max: 10000 }),
- total_stock: fc.integer({ min: 0, max: 10000 }),
})
// Feature: jewelry-mall, Property 7: 库存预警阈值判断
// **Validates: Requirements 8.4**
describe('Property 7: 库存预警阈值判断', () => {
- it('预警列表应恰好包含所有低库存商品且按库存从少到多排序', () => {
+ it('预警列表应恰好包含所有库存<20的商品且按库存从少到多排序', () => {
fc.assert(
fc.property(
fc.array(productArb, { minLength: 0, maxLength: 20 }),
(products) => {
const alerts = filterStockAlerts(products)
- // Every alert should satisfy the threshold condition
+ // Every alert should satisfy the threshold condition (stock < 20)
for (const a of alerts) {
- expect(a.total_stock).toBeGreaterThan(0)
- expect(a.stock / a.total_stock).toBeLessThan(0.1)
+ expect(a.stock).toBeLessThan(20)
}
// Every product meeting the condition should be in alerts
const expectedIds = products
- .filter((p) => p.total_stock > 0 && p.stock / p.total_stock < 0.1)
+ .filter((p) => p.stock < 20)
.map((p) => p.id)
const alertIds = alerts.map((a) => a.id)
expect(alertIds.sort()).toEqual(expectedIds.sort())