chore: save current changes

This commit is contained in:
liaibo
2025-11-23 20:04:29 +08:00
parent 994dd4e67c
commit 5d0e4c4cb6
10 changed files with 695 additions and 191 deletions
+50 -12
View File
@@ -1,13 +1,9 @@
import { DocumentTable, DocumentTableSnapshot, TableSchema } from "@/types/online-table";
import { DocumentTable, DocumentTableSnapshot, TableRowData, TableSchema } from "@/types/online-table";
// 默认表格结构:三列,文本类型,冻结首行
// 默认表格结构:全部为空列,交由用户/全屏自行定义
export const DEFAULT_TABLE_SCHEMA: TableSchema = {
columns: [
{ id: "col1", name: "名称", type: "text", width: 200 },
{ id: "col2", name: "状态", type: "select", width: 150, options: [{ value: "Todo", color: "red" }, { value: "Done", color: "green" }] },
{ id: "col3", name: "创建日期", type: "date", width: 150 },
],
frozenRowCount: 1,
columns: [],
frozenRowCount: 0,
frozenColCount: 0,
};
@@ -28,11 +24,11 @@ export const createDefaultTableSnapshot = (schema: TableSchema): DocumentTableSn
defaultRowHeight: 19,
defaultColWidth: 73,
celldata: [],
config: {},
frozen: {
row: String(schema.frozenRowCount ?? 0),
column: String(schema.frozenColCount ?? 0),
config: {
columnlen: {},
rowlen: {},
},
frozen: {},
scrollLeft: 0,
scrollTop: 0,
zoomRatio: 1,
@@ -89,3 +85,45 @@ export async function getDocumentTable(tableId: string): Promise<DocumentTable>
return response.json() as Promise<DocumentTable>;
}
/**
* 将表格的 snapshot/行数据回写 Supabase,保持内联与全屏视图一致。
*/
export async function saveOnlineTable(
tableId: string,
payload: {
title?: string;
schema?: TableSchema;
snapshot?: DocumentTableSnapshot | null;
rows?: TableRowData[];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
viewPreferences?: Record<string, any>;
},
): Promise<DocumentTable> {
const response = await fetch(`/api/tables/${tableId}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
if (!response.ok) {
const message = await response.text().catch(() => "");
throw new Error(message || "Failed to save online table.");
}
return response.json() as Promise<DocumentTable>;
}
/**
* 删除表格及其行数据。
*/
export async function deleteOnlineTable(tableId: string): Promise<void> {
const response = await fetch(`/api/tables/${tableId}`, {
method: "DELETE",
headers: { "Content-Type": "application/json" },
});
if (!response.ok) {
throw new Error("Failed to delete online table.");
}
}