|
|
@ -7,10 +7,16 @@ import { extractSdkResponseErrorMsg } from '~/utils' |
|
|
|
import { useNuxtApp } from '#app' |
|
|
|
import { useNuxtApp } from '#app' |
|
|
|
|
|
|
|
|
|
|
|
export function useTable(onTableCreate?: (tableMeta: TableType) => void) { |
|
|
|
export function useTable(onTableCreate?: (tableMeta: TableType) => void) { |
|
|
|
const table = reactive<{ title: string; table_name: string; columns: string[] }>({ |
|
|
|
const table = reactive<{ title: string; table_name: string; columns: string[]; columnsToggleInfo: Record<string, boolean> }>({ |
|
|
|
title: '', |
|
|
|
title: '', |
|
|
|
table_name: '', |
|
|
|
table_name: '', |
|
|
|
columns: ['id', 'title', 'created_at', 'updated_at'], |
|
|
|
columns: ['id', 'title', 'created_at', 'updated_at'], |
|
|
|
|
|
|
|
columnsToggleInfo: { |
|
|
|
|
|
|
|
id: true, |
|
|
|
|
|
|
|
title: true, |
|
|
|
|
|
|
|
created_at: true, |
|
|
|
|
|
|
|
updated_at: true, |
|
|
|
|
|
|
|
}, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const { $e, $api } = useNuxtApp() |
|
|
|
const { $e, $api } = useNuxtApp() |
|
|
@ -21,15 +27,18 @@ export function useTable(onTableCreate?: (tableMeta: TableType) => void) { |
|
|
|
|
|
|
|
|
|
|
|
const createTable = async () => { |
|
|
|
const createTable = async () => { |
|
|
|
if (!sqlUi?.value) return |
|
|
|
if (!sqlUi?.value) return |
|
|
|
const columns = sqlUi?.value?.getNewTableColumns().filter((col) => { |
|
|
|
const columns = sqlUi?.value |
|
|
|
if (col.column_name === 'id' && table.columns.includes('id_ag')) { |
|
|
|
?.getNewTableColumns() |
|
|
|
Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG')) |
|
|
|
.filter((col) => { |
|
|
|
col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt) |
|
|
|
if (col.column_name === 'id' && table.columns.includes('id_ag')) { |
|
|
|
col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt) |
|
|
|
Object.assign(col, sqlUi?.value?.getDataTypeForUiType({ uidt: UITypes.ID }, 'AG')) |
|
|
|
return true |
|
|
|
col.dtxp = sqlUi?.value?.getDefaultLengthForDatatype(col.dt) |
|
|
|
} |
|
|
|
col.dtxs = sqlUi?.value?.getDefaultScaleForDatatype(col.dt) |
|
|
|
return table.columns.includes(col.column_name) |
|
|
|
return true |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
return table.columns.includes(col.column_name) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.filter((col) => table.columnsToggleInfo[col.column_name]) |
|
|
|
|
|
|
|
|
|
|
|
const tableMeta = await $api.dbTable.create(project?.value?.id as string, { |
|
|
|
const tableMeta = await $api.dbTable.create(project?.value?.id as string, { |
|
|
|
...table, |
|
|
|
...table, |
|
|
|