Kaynağa Gözat

fix: 修复前端构建失败 — JSX v-slots 语法与 getPackageSize 容错

- hook.tsx v-slots 不支持 block body({ return ... }),改为内联表达式
- build/utils.ts getPackageSize 在 dist 目录不存在时不再 throw,
  改为 warn + callback(0),兼容 Rolldown 构建时序差异

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 2 hafta önce
ebeveyn
işleme
1d57ac1153

+ 11 - 2
haha-admin-web/build/utils.ts

@@ -83,7 +83,12 @@ const fileListTotal: number[] = [];
 const getPackageSize = options => {
   const { folder = "dist", callback, format = true } = options;
   readdir(folder, (err, files: string[]) => {
-    if (err) throw err;
+    if (err) {
+      // 目录不存在时返回 0,避免构建报错
+      console.warn(`[getPackageSize] 无法读取目录 ${folder}: ${err.message}`);
+      callback(0);
+      return;
+    }
     let count = 0;
     const checkEnd = () => {
       ++count == files.length &&
@@ -91,7 +96,11 @@ const getPackageSize = options => {
     };
     files.forEach((item: string) => {
       stat(`${folder}/${item}`, async (err, stats) => {
-        if (err) throw err;
+        if (err) {
+          console.warn(`[getPackageSize] 无法读取文件 ${folder}/${item}: ${err.message}`);
+          checkEnd();
+          return;
+        }
         if (stats.isFile()) {
           fileListTotal.push(stats.size);
           checkEnd();

+ 25 - 31
haha-admin-web/src/views/order/utils/hook.tsx

@@ -518,28 +518,24 @@ export function useOrder(tableRef: Ref) {
               <ElTable data={refundState.orderDetail?.products || []} border size="small" style="width: 100%">
                 <ElTableColumn width={55} align="center"
                   v-slots={{
-                    default: ({ $index, row: r }: any) => {
-                      const refundedQty = r.refundedQuantity || 0;
-                      const isFullyRefunded = refundedQty >= (r.productNum || 1);
-                      return (
-                        <el-checkbox
-                          model-value={refundState.selectedProducts.includes($index)}
-                          disabled={isFullyRefunded}
-                          onChange={(val: boolean) => {
-                            if (val) {
-                              refundState.selectedProducts.push($index);
-                              if (!refundState.refundQuantities[$index]) {
-                                const remaining = (r.productNum || 1) - refundedQty;
-                                refundState.refundQuantities[$index] = Math.max(1, remaining);
-                              }
-                            } else {
-                              const idx = refundState.selectedProducts.indexOf($index);
-                              if (idx > -1) refundState.selectedProducts.splice(idx, 1);
+                    default: ({ $index, row: r }: any) => (
+                      <el-checkbox
+                        model-value={refundState.selectedProducts.includes($index)}
+                        disabled={(r.refundedQuantity || 0) >= (r.productNum || 1)}
+                        onChange={(val: boolean) => {
+                          if (val) {
+                            refundState.selectedProducts.push($index);
+                            if (!refundState.refundQuantities[$index]) {
+                              const remaining = (r.productNum || 1) - (r.refundedQuantity || 0);
+                              refundState.refundQuantities[$index] = Math.max(1, remaining);
                             }
-                          }}
-                        />
-                      );
-                    }
+                          } else {
+                            const idx = refundState.selectedProducts.indexOf($index);
+                            if (idx > -1) refundState.selectedProducts.splice(idx, 1);
+                          }
+                        }}
+                      />
+                    )
                   }}
                 />
                 <ElTableColumn label="商品名称" min-width={160}>
@@ -579,16 +575,14 @@ export function useOrder(tableRef: Ref) {
                 />
                 <ElTableColumn label="退款数量" width={160} align="center"
                   v-slots={{
-                    default: ({ $index, row: r }: any) => {
-                      const maxRefundable = (r.productNum || 1) - (r.refundedQuantity || 0);
-                      return (
-                        refundState.selectedProducts.includes($index) ? (
-                          <el-input-number
-                            model-value={refundState.refundQuantities[$index] || 1}
-                            min={1}
-                            max={maxRefundable}
-                            size="small"
-                            controls-position="right"
+                    default: ({ $index, row: r }: any) => (
+                      refundState.selectedProducts.includes($index) ? (
+                        <el-input-number
+                          model-value={refundState.refundQuantities[$index] || 1}
+                          min={1}
+                          max={(r.productNum || 1) - (r.refundedQuantity || 0)}
+                          size="small"
+                          controls-position="right"
                           style="width: 120px"
                           onUpdate:modelValue={(val: number) => { refundState.refundQuantities[$index] = val; }}
                         />