|
|
|
@ -34,12 +34,13 @@ import {
|
|
|
|
|
useI18n, |
|
|
|
|
useNuxtApp, |
|
|
|
|
useTabs, |
|
|
|
|
validateTableName, |
|
|
|
|
} from '#imports' |
|
|
|
|
|
|
|
|
|
const { quickImportType, baseTemplate, importData, importColumns, importDataOnly, maxRowsToParse, sourceId, importWorker } = |
|
|
|
|
defineProps<Props>() |
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['import']) |
|
|
|
|
const emit = defineEmits(['import', 'error', 'change']) |
|
|
|
|
|
|
|
|
|
dayjs.extend(utc) |
|
|
|
|
|
|
|
|
@ -95,6 +96,8 @@ const importingTips = ref<Record<string, string>>({})
|
|
|
|
|
|
|
|
|
|
const checkAllRecord = ref<boolean[]>([]) |
|
|
|
|
|
|
|
|
|
const formError = ref() |
|
|
|
|
|
|
|
|
|
const uiTypeOptions = ref<Option[]>( |
|
|
|
|
(Object.keys(UITypes) as (keyof typeof UITypes)[]) |
|
|
|
|
.filter( |
|
|
|
@ -124,11 +127,14 @@ const data = reactive<{
|
|
|
|
|
|
|
|
|
|
const validators = computed(() => |
|
|
|
|
data.tables.reduce<Record<string, [ReturnType<typeof fieldRequiredValidator>]>>((acc: Record<string, any>, table, tableIdx) => { |
|
|
|
|
acc[`tables.${tableIdx}.table_name`] = [fieldRequiredValidator()] |
|
|
|
|
acc[`tables.${tableIdx}.table_name`] = [validateTableName] |
|
|
|
|
hasSelectColumn.value[tableIdx] = false |
|
|
|
|
|
|
|
|
|
table.columns?.forEach((column, columnIdx) => { |
|
|
|
|
acc[`tables.${tableIdx}.columns.${columnIdx}.column_name`] = [fieldRequiredValidator(), fieldLengthValidator()] |
|
|
|
|
acc[`tables.${tableIdx}.columns.${columnIdx}.column_name`] = [ |
|
|
|
|
fieldRequiredValidator(), |
|
|
|
|
fieldLengthValidator(base.value?.sources?.[0].type || ClientType.MYSQL), |
|
|
|
|
] |
|
|
|
|
acc[`tables.${tableIdx}.columns.${columnIdx}.uidt`] = [fieldRequiredValidator()] |
|
|
|
|
if (isSelect(column)) { |
|
|
|
|
hasSelectColumn.value[tableIdx] = true |
|
|
|
@ -139,10 +145,12 @@ const validators = computed(() =>
|
|
|
|
|
}, {}), |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
const { validate, validateInfos } = useForm(data, validators) |
|
|
|
|
const { validate, validateInfos, modelRef } = useForm(data, validators) |
|
|
|
|
|
|
|
|
|
const isValid = ref(!importDataOnly) |
|
|
|
|
|
|
|
|
|
const formRef = ref() |
|
|
|
|
|
|
|
|
|
watch( |
|
|
|
|
() => srcDestMapping.value, |
|
|
|
|
() => { |
|
|
|
@ -674,6 +682,39 @@ function handleUIDTChange(column, table) {
|
|
|
|
|
]) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const setErrorState = (errorsFields: any[]) => { |
|
|
|
|
const errorMap: any = {} |
|
|
|
|
for (const error of errorsFields) { |
|
|
|
|
errorMap[error.name] = error.errors |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
formError.value = errorMap |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
watch(formRef, () => { |
|
|
|
|
setTimeout(async () => { |
|
|
|
|
try { |
|
|
|
|
await validate() |
|
|
|
|
emit('change') |
|
|
|
|
formError.value = null |
|
|
|
|
} catch (e: any) { |
|
|
|
|
emit('error', e) |
|
|
|
|
setErrorState(e.errorFields) |
|
|
|
|
} |
|
|
|
|
}, 500) |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
watch(modelRef, async () => { |
|
|
|
|
try { |
|
|
|
|
await validate() |
|
|
|
|
emit('change') |
|
|
|
|
formError.value = null |
|
|
|
|
} catch (e: any) { |
|
|
|
|
emit('error', e) |
|
|
|
|
setErrorState(e.errorFields) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
|
<template> |
|
|
|
@ -694,7 +735,7 @@ function handleUIDTChange(column, table) {
|
|
|
|
|
<a-collapse v-if="data.tables && data.tables.length" v-model:activeKey="expansionPanel" class="template-collapse" accordion> |
|
|
|
|
<a-collapse-panel v-for="(table, tableIdx) of data.tables" :key="tableIdx"> |
|
|
|
|
<template #header> |
|
|
|
|
<span class="font-weight-bold text-lg flex items-center gap-2"> |
|
|
|
|
<span class="font-weight-bold text-lg flex items-center gap-2 truncate"> |
|
|
|
|
<component :is="iconMap.table" class="text-primary" /> |
|
|
|
|
{{ table.table_name }} |
|
|
|
|
</span> |
|
|
|
@ -769,7 +810,7 @@ function handleUIDTChange(column, table) {
|
|
|
|
|
</a-card> |
|
|
|
|
|
|
|
|
|
<a-card v-else> |
|
|
|
|
<a-form :model="data" name="template-editor-form" @keydown.enter="emit('import')"> |
|
|
|
|
<a-form ref="formRef" :model="data" name="template-editor-form" @keydown.enter="emit('import')"> |
|
|
|
|
<p v-if="data.tables && quickImportType === 'excel'" class="text-center"> |
|
|
|
|
{{ data.tables.length }} sheet{{ data.tables.length > 1 ? 's' : '' }} |
|
|
|
|
available for import |
|
|
|
@ -783,22 +824,24 @@ function handleUIDTChange(column, table) {
|
|
|
|
|
> |
|
|
|
|
<a-collapse-panel v-for="(table, tableIdx) of data.tables" :key="tableIdx"> |
|
|
|
|
<template #header> |
|
|
|
|
<a-form-item v-if="editableTn[tableIdx]" v-bind="validateInfos[`tables.${tableIdx}.table_name`]" no-style> |
|
|
|
|
<a-input |
|
|
|
|
v-model:value.lazy="table.table_name" |
|
|
|
|
class="max-w-xs font-weight-bold text-lg" |
|
|
|
|
size="large" |
|
|
|
|
hide-details |
|
|
|
|
:bordered="false" |
|
|
|
|
@click.stop |
|
|
|
|
@blur="handleEditableTnChange(tableIdx)" |
|
|
|
|
@keydown.enter="handleEditableTnChange(tableIdx)" |
|
|
|
|
/> |
|
|
|
|
<a-form-item v-bind="validateInfos[`tables.${tableIdx}.table_name`]" no-style> |
|
|
|
|
<div class="flex flex-col w-full"> |
|
|
|
|
<a-input |
|
|
|
|
v-model:value="table.table_name" |
|
|
|
|
class="font-weight-bold text-lg" |
|
|
|
|
size="large" |
|
|
|
|
hide-details |
|
|
|
|
:bordered="false" |
|
|
|
|
@click.stop |
|
|
|
|
@blur="handleEditableTnChange(tableIdx)" |
|
|
|
|
@keydown.enter="handleEditableTnChange(tableIdx)" |
|
|
|
|
@dblclick="setEditableTn(tableIdx, true)" |
|
|
|
|
/> |
|
|
|
|
<div v-if="formError?.[`tables.${tableIdx}.table_name`]" class="text-red-500 ml-3"> |
|
|
|
|
{{ formError?.[`tables.${tableIdx}.table_name`].join('\n') }} |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</a-form-item> |
|
|
|
|
<span v-else class="font-weight-bold text-lg flex items-center gap-2" @click="setEditableTn(tableIdx, true)"> |
|
|
|
|
<component :is="iconMap.table" class="text-primary" /> |
|
|
|
|
{{ table.table_name }} |
|
|
|
|
</span> |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<template #extra> |
|
|
|
|