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.

201 lines
5.9 KiB

1 year ago
<template>
<div>
1 year ago
<div class="row py-1 q-col-gutter-sm">
<div class="col-2">
<q-select
v-model="valueReactive.datasource"
:label="$t('developer.backend.export.liquibase.datasource')"
outlined
dense
emit-value
map-options
:options="datasourceOptionsRef"
@update:model-value="
(value) => {
datasourceChanged(value);
}
"
></q-select>
</div>
<div class="col-2">
<q-select
v-model="valueReactive.schema"
:label="$t('developer.backend.export.liquibase.schema')"
outlined
dense
emit-value
map-options
:options="schemaOptionsRef"
@update:model-value="
(value) => {
schemaChanged(valueReactive.datasource, value);
}
"
></q-select>
</div>
<div class="col-8">
<q-select
v-model="valueReactive.tables"
:label="$t('developer.backend.export.liquibase.tables')"
outlined
dense
emit-value
map-options
multiple
use-chips
:options="tablesOptionsRef"
@update:model-value="
(value) => {
if (value) {
if (value.length > 1) {
valueReactive.sql = 'select * from ${table}';
} else {
valueReactive.sql = 'select * from ' + value;
}
1 year ago
}
}
1 year ago
"
>
<template #append>
<q-btn
:title="$t('selectAll')"
icon="bi-check-square"
flat
dense
:disable="!(tablesOptionsRef?.length > 0)"
@click.stop.prevent="
() => {
const selecteds = [];
if (tablesOptionsRef) {
for (const table of tablesOptionsRef) {
selecteds.push(table.value);
}
}
valueReactive.tables = selecteds;
}
"
/>
<q-btn
:title="$t('unSelectAll')"
icon="bi-square"
flat
dense
:disable="!(tablesOptionsRef?.length > 0)"
@click.stop.prevent="
() => {
valueReactive.tables = [];
}
"
/>
</template>
</q-select>
</div>
</div>
<div class="row py-1 q-col-gutter-sm">
<div class="col-12">
1 year ago
<w-code-mirror v-model="valueReactive.sql" label="SQL" :rows="5" lang="sql"></w-code-mirror>
1 year ago
</div>
</div>
1 year ago
<div class="row justify-center q-gutter-md py-2">
1 year ago
<w-progress-btn
1 year ago
ref="progressBtnRef"
icon="bi-database-down"
:label="$t('export')"
1 year ago
data-url="/api/jdbc/data/traceExporterExecuteProgress"
1 year ago
@click="exportData"
1 year ago
@success="
(progressInfo) => {
Downloader.get(Environment.apiContextPath('/api/mvc/download?filePath=' + encodeURIComponent(progressInfo.result)));
}
"
1 year ago
></w-progress-btn>
1 year ago
</div>
1 year ago
</div>
</template>
<script setup lang="ts">
1 year ago
import { ref, reactive, onMounted, onUpdated } from 'vue';
1 year ago
import { useI18n } from 'vue-i18n';
1 year ago
import { axios, Environment, DialogManager, Downloader } from 'platform-core';
1 year ago
1 year ago
const { t } = useI18n();
const progressBtnRef = ref();
1 year ago
const datasourceOptionsRef = ref([]);
1 year ago
const schemaOptionsRef = ref([]);
const tablesOptionsRef = ref([]);
1 year ago
1 year ago
const valueReactive = reactive({
datasource: undefined,
schema: undefined,
tables: undefined,
sql: undefined,
});
1 year ago
const loadDatasource = () => {
axios.get(Environment.apiContextPath('/api/system/datasource?pageable=false&sortBy=name')).then((response) => {
const data = response?.data.content;
1 year ago
const datasourceOptions = [];
1 year ago
if (data && data.length > 0) {
for (let item of data) {
1 year ago
datasourceOptions.push({ label: item.name, value: item.name });
1 year ago
}
}
1 year ago
datasourceOptionsRef.value = datasourceOptions;
1 year ago
});
};
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;
1 year ago
const schemaOptions = [];
1 year ago
if (data && data.length > 0) {
for (let item of data) {
1 year ago
schemaOptions.push({ label: item.name, value: item.name });
1 year ago
}
}
1 year ago
schemaOptionsRef.value = schemaOptions;
tablesOptionsRef.value = [];
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;
1 year ago
const tablesOptions = [];
1 year ago
if (data && data.length > 0) {
for (let item of data) {
1 year ago
tablesOptions.push({ label: item.name, value: item.name });
1 year ago
}
}
1 year ago
tablesOptionsRef.value = tablesOptions;
1 year ago
});
};
1 year ago
const exportData = (e) => {
1 year ago
DialogManager.confirm(t('developer.backend.export.liquibase.export.tip'), () => {
const data = valueReactive;
const config = {
datasource: data.datasource,
schema: data.schema,
tables: [],
};
const length = data.tables.length;
const sql = length === 1 ? data.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
}
1 year ago
axios.post(Environment.apiContextPath('/api/jdbc/data/exportData'), config).then((response) => {
progressBtnRef.value.start();
});
1 year ago
});
};
1 year ago
onMounted(() => {
loadDatasource();
1 year ago
datasourceChanged('');
});
1 year ago
</script>