You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
4.7 KiB

1 year ago
<template>
<div>
<w-form
ref="formRef"
:fields="[
{
1 year ago
name: 'datasource',
label: $t('developer.backend.export.liquibase.datasource'),
1 year ago
type: 'select',
1 year ago
clearable: true,
1 year ago
options: datasourceOptionsRef,
'onUpdate:modelValue': (value) => {
1 year ago
datasourceChanged(value);
1 year ago
},
},
{
1 year ago
name: 'schema',
label: $t('developer.backend.export.liquibase.schema'),
1 year ago
type: 'select',
1 year ago
options: schemaOptionsRef,
1 year ago
'onUpdate:modelValue': (value) => {
1 year ago
schemaChanged(formRef.getFieldValue('datasource'), value);
1 year ago
},
1 year ago
required: true,
1 year ago
},
{
1 year ago
name: 'tables',
label: $t('developer.backend.export.liquibase.tables'),
type: 'select',
multiple: true,
1 year ago
clearable: true,
1 year ago
options: tablesOptionsRef,
'onUpdate:modelValue': (value) => {
if (value) {
if (value.length > 1) {
formRef.setFieldValue('sql', 'select * from ${table}');
} else {
formRef.setFieldValue('sql', 'select * from ' + value);
}
}
},
required: true,
},
{ name: 'fetchSize', label: 'Fetch Size', type: 'number', defaultValue: 1000 },
{
name: 'sql',
label: 'SQL',
type: 'code-mirror',
colSpan: 4,
rows: 5,
lang: 'sql',
1 year ago
},
]"
>
1 year ago
</w-form>
<div class="row justify-center q-gutter-md py-2">
<WProgressBtn
ref="progressBtnRef"
icon="bi-database-down"
:label="$t('export')"
1 year ago
data-url="/api/jdbc/data/traceExporterExecuteProgress"
1 year ago
@click="exportData"
></WProgressBtn>
</div>
1 year ago
</div>
</template>
<script setup lang="ts">
1 year ago
import { ref, reactive, toRaw, onMounted, onUpdated } from 'vue';
import { useI18n } from 'vue-i18n';
import { axios, Environment, EnumTools, Formater, Options, DialogManager, NotifyManager, Tools } from 'platform-core';
import WProgressBtn from './WProgressBtn.vue';
1 year ago
1 year ago
const { t } = useI18n();
1 year ago
const formRef = ref();
1 year ago
const progressBtnRef = ref();
1 year ago
const datasourceOptionsRef = ref([]);
1 year ago
const schemaOptionsRef = ref([]);
const tablesOptionsRef = ref([]);
1 year ago
const loadDatasource = () => {
axios.get(Environment.apiContextPath('/api/system/datasource?pageable=false&sortBy=name')).then((response) => {
const data = response?.data.content;
if (data && data.length > 0) {
datasourceOptionsRef.value.splice(0, datasourceOptionsRef.value.length);
for (let item of data) {
datasourceOptionsRef.value.push({ label: item.name, value: item.name });
}
}
});
};
1 year ago
const datasourceChanged = (datasource: string) => {
datasource = datasource || '';
axios.get(Environment.apiContextPath('/api/jdbc/metadata/getSchemas?datasource=' + datasource)).then((response) => {
1 year ago
const data = response?.data;
if (data && data.length > 0) {
1 year ago
schemaOptionsRef.value.splice(0, schemaOptionsRef.value.length);
tablesOptionsRef.value.splice(0, tablesOptionsRef.value.length);
1 year ago
for (let item of data) {
1 year ago
schemaOptionsRef.value.push({ label: item.name, value: item.name });
1 year ago
}
}
});
};
1 year ago
const schemaChanged = (datasource: string, schema: string) => {
datasource = datasource || '';
schema = schema || '';
axios.get(Environment.apiContextPath('/api/jdbc/metadata/getTables?datasource=' + datasource + '&schema=' + schema)).then((response) => {
1 year ago
const data = response?.data;
if (data && data.length > 0) {
1 year ago
tablesOptionsRef.value.splice(0, tablesOptionsRef.value.length);
1 year ago
for (let item of data) {
1 year ago
tablesOptionsRef.value.push({ label: item.name, value: item.name });
1 year ago
}
}
});
};
1 year ago
const exportData = (e) => {
formRef.value.validate().then((value) => {
if (value) {
DialogManager.confirm(t('developer.backend.export.liquibase.export.tip'), () => {
const data = formRef.value.getData();
const config = {
datasource: data.datasource,
schema: data.schema,
tables: [],
};
const length = data.tables.length;
const sql = length === 1 ? formRef.value.getFieldValue('sql') : '';
for (let i = 0; i < length; i++) {
config.tables[i] = { name: data.tables[i], sql: sql ? sql : 'select * from ' + data.tables[i] };
}
1 year ago
axios.post(Environment.apiContextPath('/api/jdbc/data/exportData'), config).then((response) => {
1 year ago
progressBtnRef.value.start();
});
});
}
});
};
1 year ago
onMounted(() => {
loadDatasource();
1 year ago
datasourceChanged('');
});
onUpdated(() => {
loadDatasource();
1 year ago
});
</script>