diff --git a/plugins/database-webui/client/edit-dialog.vue b/plugins/database-webui/client/edit-dialog.vue index f124332..d325c59 100644 --- a/plugins/database-webui/client/edit-dialog.vue +++ b/plugins/database-webui/client/edit-dialog.vue @@ -203,7 +203,9 @@ function parseValue(): ParseResult { } case 'bigint': { try { - return { ok: true, value: BigInt(raw) as any } + const value = raw.trim() + BigInt(value) + return { ok: true, value } } catch { return { ok: false, error: '不是合法整数' } } diff --git a/plugins/database-webui/src/index.ts b/plugins/database-webui/src/index.ts index 6ce8f15..61e3547 100644 --- a/plugins/database-webui/src/index.ts +++ b/plugins/database-webui/src/index.ts @@ -53,6 +53,18 @@ export const Config: z = z.object({ pageSize: z.natural().default(50).description('每页默认行数(客户端可改)。'), }) +function serializeValue(value: unknown): unknown { + if (typeof value === 'bigint') return value.toString() + if (Array.isArray(value)) return value.map(serializeValue) + if (value instanceof Date) return value + if (value && typeof value === 'object') { + return Object.fromEntries( + Object.entries(value).map(([key, item]) => [key, serializeValue(item)]), + ) + } + return value +} + function describeFields(model: any): FieldInfo[] { const primary = new Set(([] as string[]).concat(model.primary ?? [])) const uniqueKeys = new Set() @@ -111,7 +123,7 @@ export function apply(ctx: Context, config: Config) { const rows = await (model.get as any)(table, {}, cursor) const stats = await model.stats().catch(() => ({ tables: {} as Record })) const total = stats.tables?.[table]?.count ?? rows.length - return { rows, total } + return { rows: rows.map(serializeValue), total } }, async update({ table, where, field, value }) { const model = ctx.model