|
|
@@ -229,7 +229,6 @@ import {
|
|
|
updateBlindLevels,
|
|
|
downloadImportTemplate,
|
|
|
importData,
|
|
|
- insertAfter,
|
|
|
batchSave
|
|
|
} from '@/api/system/physical/blindLevels';
|
|
|
import { BlindLevelsVO, BlindLevelsQuery, BlindLevelsForm } from '@/api/system/physical/blindLevels/types';
|
|
|
@@ -369,6 +368,8 @@ const applyPagination = () => {
|
|
|
const pageSize = queryParams.value.pageSize || 10;
|
|
|
const start = (pageNum - 1) * pageSize;
|
|
|
blindLevelsList.value = allData.value.slice(start, start + pageSize);
|
|
|
+ // 同步总条数(本地插入/删除后保持分页信息正确)
|
|
|
+ total.value = allData.value.length;
|
|
|
};
|
|
|
|
|
|
/** 独立排序方法:按展示顺序字段排序(用于插入和保存后重新排序) */
|
|
|
@@ -454,11 +455,12 @@ const submitForm = () => {
|
|
|
|
|
|
/** 删除按钮操作 */
|
|
|
const handleDelete = async (row?: BlindLevelsVO) => {
|
|
|
- // 行内删除:未保存的临时数据,直接移除不弹框
|
|
|
+ // 行内删除:未保存的临时数据,直接移除不弹框(需同步从 allData 移除)
|
|
|
if (row && (row as any)._isNew) {
|
|
|
- const idx = blindLevelsList.value.findIndex((r) => r.id === row.id);
|
|
|
+ const idx = allData.value.findIndex((r) => r.id === row.id);
|
|
|
if (idx !== -1) {
|
|
|
- blindLevelsList.value.splice(idx, 1);
|
|
|
+ allData.value.splice(idx, 1);
|
|
|
+ applyPagination();
|
|
|
}
|
|
|
proxy?.$modal.msgSuccess('删除成功');
|
|
|
return;
|
|
|
@@ -589,24 +591,25 @@ const validateRows = (): string[] => {
|
|
|
|
|
|
blindLevelsList.value.forEach((row) => {
|
|
|
const errors: string[] = [];
|
|
|
- // 休息行不占级别(级别为0),跳过级别编号校验
|
|
|
- if (row.isBreak !== 1 && (!row.levelNumber || row.levelNumber <= 0)) {
|
|
|
- errors.push(`级别${row.levelNumber || '?'}:级别编号不能为空`);
|
|
|
- }
|
|
|
+ // 注:不校验级别编号——休息行 levelNumber 固定为 0;将休息行改为正式级别时 levelNumber 仍为 0,
|
|
|
+ // 但保存时(handleBatchSave)会自动按顺序重新编号,因此此处无需校验,避免误拦截。
|
|
|
+ // 错误提示中的行标识:正式级别显示“级别N”,休息行显示“休息(第N级后)”
|
|
|
+ const level = getDisplayLevel(row);
|
|
|
+ const rowLabel = typeof level === 'number' ? `级别${level}` : String(level);
|
|
|
if (row.smallBlind === null || row.smallBlind === undefined || row.smallBlind < 0) {
|
|
|
- errors.push(`级别${row.levelNumber || '?'}:小盲金额不能为空`);
|
|
|
+ errors.push(`${rowLabel}:小盲金额不能为空`);
|
|
|
}
|
|
|
if (row.bigBlind === null || row.bigBlind === undefined || row.bigBlind < 0) {
|
|
|
- errors.push(`级别${row.levelNumber || '?'}:大盲金额不能为空`);
|
|
|
+ errors.push(`${rowLabel}:大盲金额不能为空`);
|
|
|
}
|
|
|
if (row.bigBlind !== null && row.bigBlind !== undefined && row.smallBlind !== null && row.smallBlind !== undefined && row.bigBlind < row.smallBlind) {
|
|
|
- errors.push(`级别${row.levelNumber || '?'}:大盲金额不能小于小盲金额`);
|
|
|
+ errors.push(`${rowLabel}:大盲金额不能小于小盲金额`);
|
|
|
}
|
|
|
if (row.durationMinutes === null || row.durationMinutes === undefined || row.durationMinutes < 0) {
|
|
|
- errors.push(`级别${row.levelNumber || '?'}:本级别持续时间(分钟)不能为空`);
|
|
|
+ errors.push(`${rowLabel}:本级别持续时间(分钟)不能为空`);
|
|
|
}
|
|
|
- if (row.isBreak === 1 && (!row.breakDurationMinutes || row.breakDurationMinutes <= 0)) {
|
|
|
- errors.push(`级别${row.levelNumber || '?'}:休息级别为“是”时,休息分钟不能为0`);
|
|
|
+ if (row.isBreak === 1 && (row.breakDurationMinutes === null || row.breakDurationMinutes === undefined || row.breakDurationMinutes < 0)) {
|
|
|
+ errors.push(`${rowLabel}:休息级别为"是"时,休息分钟不能为空且不能小于0`);
|
|
|
}
|
|
|
if (errors.length > 0) {
|
|
|
rowErrors.value.set(row.id, errors);
|
|
|
@@ -617,31 +620,42 @@ const validateRows = (): string[] => {
|
|
|
return allErrors;
|
|
|
};
|
|
|
|
|
|
-/** 在指定级别后插入(调用API后重新加载全量数据) */
|
|
|
-const handleInsertAfter = async (row: BlindLevelsVO) => {
|
|
|
+/** 在指定级别后插入(纯本地插入,点击"保存"后才提交后端) */
|
|
|
+const handleInsertAfter = (row: BlindLevelsVO) => {
|
|
|
if (insertLoading.value) return;
|
|
|
insertLoading.value = true;
|
|
|
- const newLevelNumber = (row.levelNumber || 0) + 1;
|
|
|
- const newLevel: BlindLevelsForm = {
|
|
|
- id: undefined,
|
|
|
- blindStructureId: currentId.value as string | number,
|
|
|
- levelNumber: newLevelNumber,
|
|
|
- smallBlind: 0,
|
|
|
- bigBlind: 0,
|
|
|
- ante: 0,
|
|
|
- durationMinutes: 0,
|
|
|
- isBreak: 0,
|
|
|
- breakDurationMinutes: 0,
|
|
|
- displayOrder: 0
|
|
|
- };
|
|
|
try {
|
|
|
- await insertAfter(newLevel, row.levelNumber);
|
|
|
- proxy?.$modal.msgSuccess(`成功在第${row.levelNumber}级后插入第${newLevelNumber}级`);
|
|
|
- // 重新加载全量数据,保证 allData 与后端一致
|
|
|
- await getList();
|
|
|
- } catch (error) {
|
|
|
- proxy?.$modal.msgError('插入失败,请重试');
|
|
|
- console.error('Insert after error:', error);
|
|
|
+ const idx = allData.value.findIndex((r) => r.id === row.id);
|
|
|
+ if (idx === -1) return;
|
|
|
+
|
|
|
+ const newDisplayOrder = (row.displayOrder || 0) + 1;
|
|
|
+ // 将后续所有记录的 displayOrder+1,避免排序冲突
|
|
|
+ allData.value.forEach((item) => {
|
|
|
+ if ((item.displayOrder || 0) >= newDisplayOrder && item.id !== row.id) {
|
|
|
+ item.displayOrder = (item.displayOrder || 0) + 1;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 本地插入新行到正确位置(默认非休息的正式级别,保存时后端会重排级别号)
|
|
|
+ const newLevel: any = {
|
|
|
+ id: Date.now(), // 临时ID,保存时由后端全量替换生成新ID
|
|
|
+ _isNew: true,
|
|
|
+ blindStructureId: currentId.value as string | number,
|
|
|
+ levelNumber: row.isBreak === 1 ? 0 : (row.levelNumber || 0) + 1,
|
|
|
+ smallBlind: 0,
|
|
|
+ bigBlind: 0,
|
|
|
+ ante: 0,
|
|
|
+ durationMinutes: 0,
|
|
|
+ isBreak: 0,
|
|
|
+ breakDurationMinutes: 0,
|
|
|
+ displayOrder: newDisplayOrder
|
|
|
+ };
|
|
|
+ allData.value.splice(idx + 1, 0, newLevel);
|
|
|
+
|
|
|
+ // 重新排序并按当前页展示
|
|
|
+ allData.value.sort((a, b) => (a.displayOrder || 0) - (b.displayOrder || 0));
|
|
|
+ applyPagination();
|
|
|
+ proxy?.$modal.msgSuccess('已插入新行(点击保存后生效)');
|
|
|
} finally {
|
|
|
insertLoading.value = false;
|
|
|
}
|
|
|
@@ -664,10 +678,15 @@ const handleBatchSave = async () => {
|
|
|
saveLoading.value = true;
|
|
|
try {
|
|
|
// 直接用全量数据(blindLevelsList 中的行是 allData 的引用,编辑已同步)
|
|
|
- const allRows = allData.value.map((item: any) => ({
|
|
|
- ...item,
|
|
|
- isBreak: item.isBreak === true || item.isBreak === 1 ? 1 : 0
|
|
|
- }));
|
|
|
+ const allRows = allData.value.map((item: any) => {
|
|
|
+ const { _isNew, ...rest } = item;
|
|
|
+ return {
|
|
|
+ ...rest,
|
|
|
+ // 新插入的临时记录:去掉临时ID,由后端全量替换生成新ID
|
|
|
+ id: _isNew ? undefined : rest.id,
|
|
|
+ isBreak: rest.isBreak === true || rest.isBreak === 1 ? 1 : 0
|
|
|
+ };
|
|
|
+ });
|
|
|
|
|
|
// 保存前按展示顺序排序;自动修正级别:休息行为0不占级别,正式级别连续递增
|
|
|
allRows.sort((a, b) => (a.displayOrder || 0) - (b.displayOrder || 0));
|