动态获取数据库列表

This commit is contained in:
gaofy 2023-11-14 09:49:33 +08:00
parent 3f0b751ae4
commit d9f9a3764d
2 changed files with 31 additions and 8 deletions

View File

@ -7,11 +7,17 @@ export const get = (url, params, success) => {
axios.get(HOST + url, params)
.then(res => {
success(res);
});
})
.catch(err => {
success(err);
});;
};
export const post = (url, params, success) => {
axios.post(HOST + url, params)
.then(res => {
success(res);
})
.catch(err => {
success(err);
});
};
};

View File

@ -187,10 +187,6 @@ const chartDom1 = ref(),
msgLog = ref(),
unusualMsg = ref();
const databaseOptions: { value: string, label: string }[] = [
{ value: 'zhangxinhe', label: 'zhangxinhe' },
{ value: '数据模拟20231109185403', label: '模拟数据库' }
];
const medicineCustom: any[] = [
{ name: '丙泊酚', plus: 0.5, total: 50 },
{ name: '舒芬太尼', plus: 1, total: 100 },
@ -203,6 +199,7 @@ const medicineCustom: any[] = [
{ name: '罗库溴铵', plus: 0.1, total: 10 }
];
const database = ref('数据模拟20231109185403');
const databaseOptions = ref([] as { value: string, label: string }[]);
const messageSum = ref(10);
const userName = ref('admin');
const setDatabaseDialog = ref(false);
@ -237,7 +234,7 @@ function initData() {
}
function getFeatureTable() {
featureTable.value = [];
post('/getfeature', { database: database.value, start: 1, end: 100 }, (res: any) => {
post('/getfeature', { database: database.value, start: 1, end: 50 }, (res: any) => {
if (res.status === 200) {
featureTable.value = res.data.reverse();
setTimeout(() => {
@ -246,6 +243,12 @@ function getFeatureTable() {
chartDom3.value.chartSet();
chartDom4.value.chartSet();
}, 0);
}else{
console.log(res);
ElMessage({
message: res.message,
type: 'error',
});
}
});
}
@ -304,6 +307,20 @@ function getChartData() {
}
}
function getDatabases() {
post('/getdatabases', {}, (res: any) => {
if (res.status === 200) {
console.log(res);
databaseOptions.value = [];
const hideDatabase = ['information_schema', 'mysql', 'performance_schema'];
res.data.forEach((item: any, index: number) => {
if(!hideDatabase.some(e => e === item.Database)) databaseOptions.value.push({value: item.Database, label: item.Database});
})
database.value = databaseOptions.value[0].label;
initData();
}
});
}
function msgLogScrollBottom() {
msgLog.value.scrollTo({
top: msgLog.value.scrollHeight,
@ -461,7 +478,7 @@ const tableItemCancel = (e: any) => {
e.row.speed = tableDataStore.value[e.$index].speed;
};
initData();
getDatabases();
onMounted(() => {
msgLogScrollBottom();